Skip to content
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

main in a library regression #485

Open
yamt opened this issue Mar 16, 2024 · 2 comments
Open

main in a library regression #485

yamt opened this issue Mar 16, 2024 · 2 comments

Comments

@yamt
Copy link
Contributor

yamt commented Mar 16, 2024

recent wasi-libc is broken if you put main in a library.

test case: https://github.com/yamt/garbage/tree/d422b1073125b3fc8f843ce4b12280ab3982fb84/c/main_in_lib

spacetanuki% ./build-native.sh
spacetanuki% ./a.out
this is foo
spacetanuki% WASI_SDK=/opt/wasi-sdk-20.0 ./build-wasi.sh
spacetanuki% toywasm --wasi a.out
this is foo
spacetanuki% WASI_SDK=/opt/wasi-sdk-21.0 ./build-wasi.sh
spacetanuki% toywasm --wasi a.out                       
Error: [trap] unreachable executed (4): unreachable at 0001a5
frame[  2] funcpc 0001a5 (<unknown>:undefined_weak:main) callerpc 0022de
  param [0] = 00000001
  param [1] = 00010b30
frame[  1] funcpc 00226c (<unknown>:__main_void) callerpc 0001df
  local [0] = 00010b00
  local [1] = 00010b30
  local [2] = 00010b20
frame[  0] funcpc 0001ab (<unknown>:_start)
  local [0] = 00000000
2024-03-16 14:47:15 (1710568035.864123000): [117042600] instance_execute_func failed with -1
2024-03-16 14:47:15 (1710568035.864618000): [117042600] invoke failed with -1
spacetanuki% 

i guess this is a regression caused by #429

@sbc100
Copy link
Member

sbc100 commented Mar 18, 2024

Yes, it looks like its specifically this line: https://github.com/WebAssembly/wasi-libc/pull/429/files#r1290434731.

@yamt
Copy link
Contributor Author

yamt commented Jul 11, 2024

a simpler case (just an empty file w/o main function)

spacetanuki% cat a.c
spacetanuki% /opt/wasi-sdk-20.0/bin/clang a.c
wasm-ld: error: /Users/yamamoto/wasm/wasi-sdk-20.0/bin/../share/wasi-sysroot/lib/wasm32-wasi/libc.a(__main_void.o): undefined symbol: main
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
spacetanuki% /opt/wasi-sdk-21.0/bin/clang a.c
spacetanuki% toywasm --wasi a.out
Error: [trap] unreachable executed (4): unreachable at 0000e6
current pc 0000e6
frame[  2] funcpc 0000e6 (<unknown>:undefined_weak:main) callerpc 00221f
  param [0] = 00000001
  param [1] = 00010620
frame[  1] funcpc 0021ad (<unknown>:__main_void) callerpc 000120
  local [0] = 000105f0
  local [1] = 00010620
  local [2] = 00010610
frame[  0] funcpc 0000ec (<unknown>:_start)
  local [0] = 00000000
2024-07-11 11:01:40 (1720663300.957057000): [10aacc600] instance_execute_func failed with -1
2024-07-11 11:01:40 (1720663300.957537000): [10aacc600] invoke failed with -1
spacetanuki% 

yamt added a commit to yamt/wasi-libc that referenced this issue Aug 19, 2024
yamt added a commit to yamt/wasi-libc that referenced this issue Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants