wasi-sdk icon indicating copy to clipboard operation
wasi-sdk copied to clipboard

lto link error undefined symbol: setjmp

Open calvin2021y opened this issue 1 year ago • 9 comments

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

calvin2021y avatar Aug 22 '24 13:08 calvin2021y

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

yamt avatar Aug 22 '24 13:08 yamt

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

calvin2021y avatar Aug 22 '24 13:08 calvin2021y

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).

sbc100 avatar Aug 22 '24 15:08 sbc100

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.

calvin2021y avatar Aug 23 '24 05:08 calvin2021y

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: https://github.com/WebAssembly/wasi-libc/pull/529 for now, you can stop using lto as a workaround.

yamt avatar Aug 23 '24 06:08 yamt

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.

yamt avatar Aug 23 '24 06:08 yamt

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 ?

calvin2021y avatar Aug 23 '24 10:08 calvin2021y

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.)

yamt avatar Aug 23 '24 10:08 yamt

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

sbc100 avatar Aug 23 '24 15:08 sbc100