diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-05-16 13:56:56 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-05-16 13:56:56 -0400 |
| commit | 81e960eb748fdb37d1d61da262ec343e2fdb2511 (patch) | |
| tree | ed4059af1ce6181457887bbfbf98a17b3bbfcf44 /std | |
| parent | 07d0aee11a5725dc22eeaa116fb59c40a1a7c99c (diff) | |
| download | zig-81e960eb748fdb37d1d61da262ec343e2fdb2511.tar.gz zig-81e960eb748fdb37d1d61da262ec343e2fdb2511.zip | |
improvements to build-lib use case of WebAssembly
* build-exe does include the startup code that supplies _start for the
wasm32-freestanding target. Previously this did not occur because
of logic excluding "freestanding".
* build-lib for wasm32-freestanding target gets linked by LLD. To avoid
infinite recursion, compiler_rt and zig libc are built as objects
rather than libraries.
- no "lib" prefix and ".wasm" extension instead of ".a". Rather than
build-lib foo.zig producing "libfoo.a", now it produces "foo.wasm".
* go back to using `.o` extension for webassembly objects
* zig libc only provides _start symbol for wasm when linking libc.
Diffstat (limited to 'std')
| -rw-r--r-- | std/special/bootstrap.zig | 10 | ||||
| -rw-r--r-- | std/special/c.zig | 2 |
2 files changed, 8 insertions, 4 deletions
diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index e6505c836b..e8f943b78c 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -25,21 +25,25 @@ nakedcc fn _start() noreturn { } switch (builtin.arch) { - builtin.Arch.x86_64 => { + .x86_64 => { argc_ptr = asm ("lea (%%rsp), %[argc]" : [argc] "=r" (-> [*]usize) ); }, - builtin.Arch.i386 => { + .i386 => { argc_ptr = asm ("lea (%%esp), %[argc]" : [argc] "=r" (-> [*]usize) ); }, - builtin.Arch.aarch64, builtin.Arch.aarch64_be => { + .aarch64, .aarch64_be => { argc_ptr = asm ("mov %[argc], sp" : [argc] "=r" (-> [*]usize) ); }, + .wasm32, .wasm64 => { + _ = callMain(); + while (true) {} + }, else => @compileError("unsupported arch"), } // If LLVM inlines stack variables into _start, they will overwrite diff --git a/std/special/c.zig b/std/special/c.zig index d5de52a6a3..281e177469 100644 --- a/std/special/c.zig +++ b/std/special/c.zig @@ -11,7 +11,7 @@ const maxInt = std.math.maxInt; const is_wasm = switch (builtin.arch) { .wasm32, .wasm64 => true, else => false}; const is_freestanding = switch (builtin.os) { .freestanding => true, else => false }; comptime { - if (is_freestanding and is_wasm) { + if (is_freestanding and is_wasm and builtin.link_libc) { @export("_start", wasm_start, .Strong); } } |
