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

Considering support setjmp & longjmp? #109

Closed
Brooooooklyn opened this issue Feb 13, 2024 · 5 comments
Closed

Considering support setjmp & longjmp? #109

Brooooooklyn opened this issue Feb 13, 2024 · 5 comments

Comments

@Brooooooklyn
Copy link

setjmp.h is not supported in wasi-libc at this moment: WebAssembly/wasi-libc#432
If you could support setjmp.h in emnapi, it would be very useful for C++ projects compiled to wasi target, such as https://github.com/AOMediaCodec/libavif.

For references:

@toyobayashi
Copy link
Owner

OK. Though I think setjmp/longjmp is out of the scope of emnapi, I'll investigate how it works in WASIX and Emscripten, then consider providing prebuilt static library as temporary solution before wasi-libc have it.

Happy dragon new year!

@toyobayashi
Copy link
Owner

toyobayashi commented Feb 15, 2024

WASIX and kripken's demo rely on the Asyncify feature of binaryen, which will affect runtime performance and increases code size.

Emscripten has two implementations of setjmp/longjmp, the default way relies on generated JavaScript glue code by emcc, the other relies on WebAssembly Exception Handling feature, they both require passing additional flags to llvm backend to let llvm transform the setjmp() / longjmp() call to additional runtime code.

I've created a separate repository (https://github.com/toyobayashi/wasm-sjlj) to test if the wasm EH way works in WASI, included the prebuilt libraries. I used the implementation in emscripten repo, and pass -mllvm -wasm-enable-sjlj, it looks good. Since it is not relative with Node-API, I'm not sure if it should go emnapi's repo.

Refs:

Could you try it to build libavif?

@Brooooooklyn
Copy link
Author

@toyobayashi it works! thanks for your help!

@Brooooooklyn
Copy link
Author

Can you publish a npm package that contains lib/libsetjmp.a lib/libsetjmp-mt.a and include/setjmp.h files?

@toyobayashi
Copy link
Owner

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