diff options
| author | Takeshi Yoneda <takeshi@tetrate.io> | 2021-07-01 09:02:48 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-30 20:02:48 -0400 |
| commit | bc7761d8e0bb70adb3c76c588f9f0b62937c6571 (patch) | |
| tree | 571b5b93cd6611d458cb728198b9796cff9da3ac /lib/std | |
| parent | a95ba0d10d582020dbd3e6efded53f17287ed211 (diff) | |
| download | zig-bc7761d8e0bb70adb3c76c588f9f0b62937c6571.tar.gz zig-bc7761d8e0bb70adb3c76c588f9f0b62937c6571.zip | |
Add support for WASI reactor in pure Zig-exe. (#9178)
* Add command line help for "-mexec-model"
* Define WasmExecModel enum in std.builtin.
* Drop the support for the old crt1.o in favor of crt1-command.o
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/builtin.zig | 7 | ||||
| -rw-r--r-- | lib/std/start.zig | 28 |
2 files changed, 24 insertions, 11 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 615df9b9af..7bf60f5283 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -459,6 +459,13 @@ pub const LinkMode = enum { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. +pub const WasiExecModel = enum { + command, + reactor, +}; + +/// This data structure is used by the Zig language code generation and +/// therefore must be kept in sync with the compiler implementation. pub const Version = struct { major: u32, minor: u32, diff --git a/lib/std/start.zig b/lib/std/start.zig index 7f73ba46db..b9fbb97c47 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -65,8 +65,9 @@ comptime { } } else if (native_os == .uefi) { if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" }); - } 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_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 != .other and native_os != .freestanding) { if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name }); } @@ -135,10 +136,21 @@ fn _DllMainCRTStartup( return std.os.windows.TRUE; } -fn wasm_freestanding_start() callconv(.C) void { - // This is marked inline because for some reason LLVM in release mode fails to inline it, +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. - _ = @call(.{ .modifier = .always_inline }, callMain, .{}); + 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 EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.C) usize { @@ -164,12 +176,6 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv } fn _start() callconv(.Naked) noreturn { - if (native_os == .wasi) { - // 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. - std.os.wasi.proc_exit(@call(.{ .modifier = .always_inline }, callMain, .{})); - } - switch (native_arch) { .x86_64 => { argc_argv_ptr = asm volatile ( |
