| ... | ... | @@ -8,17 +8,24 @@ const assert = std.debug.assert; |
| 8 | 8 | |
| 9 | 9 | var argc_ptr: [*]usize = undefined; |
| 10 | 10 | |
| 11 | const is_wasm = switch (builtin.arch) { .wasm32, .wasm64 => true, else => false}; |
| 12 | |
| 11 | 13 | comptime { |
| 12 | | const strong_linkage = builtin.GlobalLinkage.Strong; |
| 13 | 14 | if (builtin.link_libc) { |
| 14 | | @export("main", main, strong_linkage); |
| 15 | | } else if (builtin.os == builtin.Os.windows) { |
| 16 | | @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage); |
| 15 | @export("main", main, .Strong); |
| 16 | } else if (builtin.os == .windows) { |
| 17 | @export("WinMainCRTStartup", WinMainCRTStartup, .Strong); |
| 18 | } else if (is_wasm and builtin.os == .freestanding) { |
| 19 | @export("_start", wasm_freestanding_start, .Strong); |
| 17 | 20 | } else { |
| 18 | | @export("_start", _start, strong_linkage); |
| 21 | @export("_start", _start, .Strong); |
| 19 | 22 | } |
| 20 | 23 | } |
| 21 | 24 | |
| 25 | extern fn wasm_freestanding_start() void { |
| 26 | _ = callMain(); |
| 27 | } |
| 28 | |
| 22 | 29 | nakedcc fn _start() noreturn { |
| 23 | 30 | if (builtin.os == builtin.Os.wasi) { |
| 24 | 31 | std.os.wasi.proc_exit(callMain()); |
| ... | ... | @@ -40,10 +47,6 @@ nakedcc fn _start() noreturn { |
| 40 | 47 | : [argc] "=r" (-> [*]usize) |
| 41 | 48 | ); |
| 42 | 49 | }, |
| 43 | | .wasm32, .wasm64 => { |
| 44 | | _ = callMain(); |
| 45 | | while (true) {} |
| 46 | | }, |
| 47 | 50 | else => @compileError("unsupported arch"), |
| 48 | 51 | } |
| 49 | 52 | // If LLVM inlines stack variables into _start, they will overwrite |