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

lto link error undefined symbol: setjmp #479

Open
calvin2021y opened this issue Aug 22, 2024 · 9 comments
Open

lto link error undefined symbol: setjmp #479

calvin2021y opened this issue Aug 22, 2024 · 9 comments

Comments

@calvin2021y
Copy link

I try build with --target=wasm32-wasi -mllvm -wasm-enable-sjlj and -flto=full

get this error:

undefined symbol: setjmp
undefined symbol: longjmp
nm test.o |grep jmp
         U longjmp
         U setjmp

If I remove -flto=full, all work as expect:

 nm test.o |grep jmp
         U __c_longjmp
         U __wasm_longjmp
         U saveSetjmp
         U testSetjmp
@yamt
Copy link
Contributor

yamt commented Aug 22, 2024

i guess you need -Wl,-llvm,-wasm-enable-sjlj.

@calvin2021y
Copy link
Author

my link step not call from clang, so I add -mllvm -wasm-enable-sjlj into wasm-ld. this will work like -Wl,-llvm,-wasm-enable-sjlj ?

I get this error when link:

wasm-ld: error: /wasi/share/wasi-sysroot/lib/wasm32-wasi/llvm-lto/18.1.2-wasi-sdk/libsetjmp.a(rt.o): attempt to add bitcode file after LTO (__wasm_longjmp)
Error: wasm-ld failed with status: 1

@sbc100
Copy link
Member

sbc100 commented Aug 22, 2024

The options for a quick fix would be to either (1) remove -flto from you link command or (2) add -Wl,-u__wasm_longjmp (which would force that symbol to be included prior to LTO).

@calvin2021y
Copy link
Author

after add -Wl,-u__wasm_longjmp, the problem fixed.

any suggestion how to run the binary with -wasm-enable-sjl? I try wasm-interp and wasmer, not work.

@yamt
Copy link
Contributor

yamt commented Aug 23, 2024

my link step not call from clang, so I add -mllvm -wasm-enable-sjlj into wasm-ld. this will work like -Wl,-llvm,-wasm-enable-sjlj ?

I get this error when link:

wasm-ld: error: /wasi/share/wasi-sysroot/lib/wasm32-wasi/llvm-lto/18.1.2-wasi-sdk/libsetjmp.a(rt.o): attempt to add bitcode file after LTO (__wasm_longjmp)
Error: wasm-ld failed with status: 1

this looks like a bug.
a fix: WebAssembly/wasi-libc#529
for now, you can stop using lto as a workaround.

@yamt
Copy link
Contributor

yamt commented Aug 23, 2024

after add -Wl,-u__wasm_longjmp, the problem fixed.

any suggestion how to run the binary with -wasm-enable-sjl? I try wasm-interp and wasmer, not work.

you can't run it.

  • the setjmp runtime provided by wasi-sdk is not compatible with llvm 18.
    you need to use llvm 19 (an unreleased version) to build a working app.

  • you need to use a runtime with exception-handling proposal. eg. toywasm, wamr classic interpreter.

@calvin2021y
Copy link
Author

thanks for explain.

Is there a link I can download llvm19 sdk ? (like nightly build results)

after llvm 19 release, can I run the wasm binary in browser ?

@yamt
Copy link
Contributor

yamt commented Aug 23, 2024

thanks for explain.

Is there a link I can download llvm19 sdk ? (like nightly build results)

after llvm 19 release, can I run the wasm binary in browser ?

if you are more interested in browsers, i guess it's better to try emscripten. (i'm not familiar with it.)

@sbc100
Copy link
Member

sbc100 commented Aug 23, 2024

Yes, emscripten has supported setjmp/longjmp for many years out-of-the-box.

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

3 participants