-
Notifications
You must be signed in to change notification settings - Fork 215
Open
Description
I'm trying to add shared-everything support in WebAssembly port of CRuby, and found an issue.
Dependencies
- wasm-tools: with my patch to fix
_startissue - wasi-sdk: The latest main 3175485
gh run download 7227946508 --repo WebAssembly/wasi-sdk --name dist-ubuntu-bionic
Repro
$ curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v15.0.0/wasi_snapshot_preview1.command.wasm
$ cat main.c
int main(int argc, char **argv) {
return 0;
}
$ $WASI_SDK_PATH/bin/clang main.c -fPIC -Xlinker -pie -Xlinker --import-memory -Xlinker --experimental-pic -o a.out
$ wasm-tools component link a.out $WASI_SDK_PATH/share/wasi-sysroot/lib/wasm32-wasi/libc.so --adapt wasi_snapshot_preview1.command.wasm -o a.out.wasm
$ wasmtime run --wasm component-model a.out.wasm
Error: failed to run main module `a.out.wasm`
Caused by:
0: failed to invoke `run` function
1: error while executing at wasm backtrace:
0: 0x1417c - wit-component:stubs!<wasm function 0>
1: 0x1f43a - libc.so!__main_void
2: 0xae76c - a.out!_start
3: 0xb05df - wit-component:shim!adapt-a.out-_start
4: 0x5220 - wit-component:adapter:wasi_snapshot_preview1!wasi:cli/run@0.2.0-rc-2023-11-10#run
note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information
2: wasm trap: wasm `unreachable` instruction executedThe main problem here is:
__main_argc_argvis defined with hidden visibility
$ wasm-objdump -x main.o | grep "F <__main_argc_argv>"
- 0: F <__main_argc_argv> func=1 [ binding=global vis=hidden ]__main_argc_argvis referenced fromlibc.so's__main_void(which is referenced fromcrt1-command.o's_start)
but the use of__main_argc_argvinlibc.sodoesn't mark it live.
With static-link,libc.a,crt1-command.o, andmain.oare linked together into a single image, so symbols are fully resolved.
Options
There are several ways to resolve the issue. I prefer option 3 as an ideal solution, but I'd like to hear @dicej opinion before tackling it.
Option 1. Adding -Xlinker -export-if-defined=__main_argc_argv to clang command.
This is a tentative workaround without toolchain modification.
Option 2. Set __main_argc_argv's visibility as default in clang
- Need to update other compilers that use wasi-libc like Swift
- The symbol will be leaked to other images
Option 3. Move __main_void to crt1-command.o
- Linking
__main_voidinto the main module cleanly solves the liveness issue. - According to the comment, something wrong happens with
--no-gc-sections.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels