diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-06-30 18:39:04 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-06-30 18:39:04 -0700 |
| commit | acf2e8fe6484a48cef76c20368ff06fe9d7b264e (patch) | |
| tree | b1deefdf85b727308494b86bf9165f8cca630328 /lib/std/start.zig | |
| parent | d606811f555e6906d1f8189dd2bf123cf98faf91 (diff) | |
| download | zig-acf2e8fe6484a48cef76c20368ff06fe9d7b264e.tar.gz zig-acf2e8fe6484a48cef76c20368ff06fe9d7b264e.zip | |
fix start code for WebAssembly
Diffstat (limited to 'lib/std/start.zig')
| -rw-r--r-- | lib/std/start.zig | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig index b9fbb97c47..0a6c0320d6 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -65,9 +65,16 @@ comptime { } } else if (native_os == .uefi) { if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" }); - } else if (native_arch.isWasm()) { - const wasm_start_sym = if (builtin.wasi_exec_model == .reactor) "_initialize" else "_start"; - if (!@hasDecl(root, wasm_start_sym)) @export(wasm_start, .{ .name = wasm_start_sym }); + } else if (native_os == .wasi) { + const wasm_start_sym = switch (builtin.wasi_exec_model) { + .reactor => "_initialize", + .command => "_start", + }; + if (!@hasDecl(root, wasm_start_sym)) { + @export(wasi_start, .{ .name = wasm_start_sym }); + } + } else if (native_arch.isWasm() and native_os == .freestanding) { + if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name }); } else if (native_os != .other and native_os != .freestanding) { if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name }); } @@ -136,20 +143,18 @@ fn _DllMainCRTStartup( return std.os.windows.TRUE; } -fn wasm_start() callconv(.C) void { - // The entrypoint is marked inline because for some reason LLVM in release mode fails to inline it, - // and we want fewer call frames in stack traces. - switch (native_os) { - .freestanding => { - _ = @call(.{ .modifier = .always_inline }, callMain, .{}); - }, - .wasi => { - switch (builtin.wasi_exec_model) { - .reactor => _ = @call(.{ .modifier = .always_inline }, callMain, .{}), - .command => std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{})), - } - }, - else => @compileError("unsupported OS"), +fn wasm_freestanding_start() callconv(.C) void { + // This is marked inline because for some reason LLVM in + // release mode fails to inline it, and we want fewer call frames in stack traces. + _ = @call(.{ .modifier = .always_inline }, callMain, .{}); +} + +fn wasi_start() callconv(.C) void { + // The function call is marked inline because for some reason LLVM in + // release mode fails to inline it, and we want fewer call frames in stack traces. + switch (builtin.wasi_exec_model) { + .reactor => _ = @call(.{ .modifier = .always_inline }, callMain, .{}), + .command => std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{})), } } |
