zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit acf2e8fe6484a48cef76c20368ff06fe9d7b264e (tree)
parent d606811f555e6906d1f8189dd2bf123cf98faf91
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 30 Jun 2021 18:39:04 -0700

fix start code for WebAssembly

Diffstat:
Mlib/std/start.zig | 39++++++++++++++++++++++-----------------
Mtest/stage2/darwin.zig | 2+-
Mtest/stage2/test.zig | 2+-
3 files changed, 24 insertions(+), 19 deletions(-)

diff --git 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, .{})), } } diff --git a/test/stage2/darwin.zig b/test/stage2/darwin.zig @@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void { { var case = ctx.exe("hello world with updates", target); case.addError("", &[_][]const u8{ - ":86:9: error: struct 'test_case.test_case' has no member named 'main'", + ":93:9: error: struct 'test_case.test_case' has no member named 'main'", }); // Incorrect return type diff --git a/test/stage2/test.zig b/test/stage2/test.zig @@ -24,7 +24,7 @@ pub fn addCases(ctx: *TestContext) !void { var case = ctx.exe("hello world with updates", linux_x64); case.addError("", &[_][]const u8{ - ":86:9: error: struct 'test_case.test_case' has no member named 'main'", + ":93:9: error: struct 'test_case.test_case' has no member named 'main'", }); // Incorrect return type