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, .{})), } } diff --git a/test/stage2/darwin.zig b/test/stage2/darwin.zig index 39e7e790d0..0bb2562385 100644 --- 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 index a9d8b142e3..a6d948fd53 100644 --- 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