-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webassembly linker does not export symbols #1570
Comments
Thanks for the report. LLVM just now finally merged my patch to make WebAssembly a normal (non-experimental) target. But they didn't do it before llvm 7 release. So zig 0.4.0 will have WebAssembly support without any hacks, and I'll make sure this is fixed by then. |
If anyone comes across this looking to compile zig to wasm in the meantime, here's a rough guide to getting it working at present. At least on macos: https://gist.github.com/josephg/873a21d4558fd69aeccea19c3df96672 |
Thanks for doing that, that's really handy. It's also worth mentioning that both the windows and Linux static CI builds of zig come with the webassembly target enabled. |
We could fix this in zig by not passing The entry point is exported through the module's exports and that might be undesirable if it's synthesized by zig. |
Line 21 in bc3e99c
We can have the webassembly equivalent which calls the user's main function. Likewise for |
Isn't the whole point of relocatable to be used for dynamic libraries?
Op ma 1 okt. 2018 22:39 schreef Andrew Kelley <notifications@github.com>:
… zig build-exe should not pass --relocatable to the linker. We have an
established pattern for putting the start code in
std/special/bootstrap.zig. You can see here we have the _start symbol for
ELF:
https://github.com/ziglang/zig/blob/bc3e99c5e5a5f054e57a7056a64ff08762d42e9f/std/special/bootstrap.zig#L21
We can have the webassembly equivalent which calls the user's main
function. Likewise for zig build-lib I think relocatable should be off.
Zig would generate an empty _start function, I suppose, since libraries
don't have an entry point. zig build-lib --static and zig build-obj can
have it on.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1570 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AL-sGhaJ5vzv9pyukUkoFTuN-6slxaGmks5ugn1kgaJpZM4Wzdc3>
.
|
Sure, if it worked. But since what |
After thinking about this some more, I'd say the best way forward is to replace Emitting a |
fix build-exe for --target-arch wasm32 (#1570)
Yeah it’s really not clear to me what |
#1619 was merged so I'll go ahead and close this issue. Thanks for the bug report. |
Maybe build-exe for the webassembly target should be an error and it should suggest using build-lib? |
Yeah - either that or build-exe could just alias build-lib on wasm. (Which might be what its doing now?) |
In general the difference between build-exe and build-lib is (1) the entry point code in std/special/bootstrap.zig and (2) linker flags. For webassembly since we're not doing (1) and there is no difference in (2) it's the same thing. So I think it makes sense to make build-exe an error so that there is a canonical way to do things. |
$ ./zig build-lib -O ReleaseSmall -target wasm32-wasi wasm.zig ; wasm2wat libwasm.a.o
(module
(type (;0;) (func (param i32 i32) (result i32)))
(import "env" "__linear_memory" (memory (;0;) 0))
(func $add (type 0) (param i32 i32) (result i32)
local.get 1
local.get 0
i32.add)) I can still fix it using $ wasm-ld libwasm.a.o -o libwasm2.a.o --no-entry --export=add (note unlike above, I now have to add the And now wasm2wat gives me: ; $ wasm2wat libwasm2.a.o
(module
(type (;0;) (func (param i32 i32) (result i32)))
(func $add (type 0) (param i32 i32) (result i32)
local.get 1
local.get 0
i32.add)
(memory (;0;) 2)
(global $__stack_pointer (mut i32) (i32.const 66560))
(export "memory" (memory 0))
(export "add" (func $add))) With the function and the export EDIT: This is not a regression. It is documented here but you need either It doesn't seem to work for |
The default behavior is still confusing. For ELF the symbols are in the final artifact by default, but for WASM it's the opposite. Without By default, I think the symbols are in the special linking section, but not visible with |
Given this zig program:
Compiled with
zig build-exe --release-small --target-arch wasm32 wasm.zig
, the output doesn't export the function.Run through wasm2wat, the exported output is:
... Which doesn't export the add function like it should:
Linking with
wasm-ld
from llvm 7 works fine, and produces this:... Which works just fine. (Notice the
export "add"
at the end)The text was updated successfully, but these errors were encountered: