fix start code for WebAssembly

This commit is contained in:
Andrew Kelley 2021-06-30 18:39:04 -07:00
parent d606811f55
commit acf2e8fe64
3 changed files with 24 additions and 19 deletions

View file

@ -65,9 +65,16 @@ comptime {
} }
} else if (native_os == .uefi) { } else if (native_os == .uefi) {
if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" }); if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" });
} else if (native_arch.isWasm()) { } else if (native_os == .wasi) {
const wasm_start_sym = if (builtin.wasi_exec_model == .reactor) "_initialize" else "_start"; const wasm_start_sym = switch (builtin.wasi_exec_model) {
if (!@hasDecl(root, wasm_start_sym)) @export(wasm_start, .{ .name = wasm_start_sym }); .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) { } else if (native_os != .other and native_os != .freestanding) {
if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name }); if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name });
} }
@ -136,20 +143,18 @@ fn _DllMainCRTStartup(
return std.os.windows.TRUE; return std.os.windows.TRUE;
} }
fn wasm_start() callconv(.C) void { fn wasm_freestanding_start() callconv(.C) void {
// The entrypoint is marked inline because for some reason LLVM in release mode fails to inline it, // This is marked inline because for some reason LLVM in
// and we want fewer call frames in stack traces. // release mode fails to inline it, and we want fewer call frames in stack traces.
switch (native_os) { _ = @call(.{ .modifier = .always_inline }, callMain, .{});
.freestanding => { }
_ = @call(.{ .modifier = .always_inline }, callMain, .{});
}, fn wasi_start() callconv(.C) void {
.wasi => { // The function call is marked inline because for some reason LLVM in
switch (builtin.wasi_exec_model) { // release mode fails to inline it, and we want fewer call frames in stack traces.
.reactor => _ = @call(.{ .modifier = .always_inline }, callMain, .{}), switch (builtin.wasi_exec_model) {
.command => std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{})), .reactor => _ = @call(.{ .modifier = .always_inline }, callMain, .{}),
} .command => std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{})),
},
else => @compileError("unsupported OS"),
} }
} }

View file

@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void {
{ {
var case = ctx.exe("hello world with updates", target); var case = ctx.exe("hello world with updates", target);
case.addError("", &[_][]const u8{ 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 // Incorrect return type

View file

@ -24,7 +24,7 @@ pub fn addCases(ctx: *TestContext) !void {
var case = ctx.exe("hello world with updates", linux_x64); var case = ctx.exe("hello world with updates", linux_x64);
case.addError("", &[_][]const u8{ 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 // Incorrect return type