Stream: wasi

Topic: ✔ wasi-libc setjmp.h


view this post on Zulip Namse (May 27 2024 at 11:56):

Hello, I'm trying to build Skia for Wasi, but I'm encountering a build error related to setjmp.
According to https://github.com/WebAssembly/exception-handling/issues/179, it seems that most browsers like Chrome, Firefox, and Safari have completed the implementation of exception handling.
Even though it's in Phase 3, since most browsers have completed the implementation, wouldn't it be okay for wasi-libc to provide support for it?

This is a tracking issue for the requirements for Phase 4. The text will be edited as we progress. Checkbox will be checked after the relevant PRs land. We also list Phase 2 & 3 requirements becaus...

view this post on Zulip Namse (May 27 2024 at 12:08):

According to https://github.com/WebAssembly/wasi-libc/pull/483, it seems that the implementation has been done, and just adding -mllvm, -wasm-enable-sjlj, -lsetjmp should allow the build to succeed... But why am I getting errors like error: use of undeclared identifier 'setjmp'?

Add setjmp/longjump support based on Wasm EH proposal. It's provided as a separate library (libsetjmp) from libc so that runtimes w/o EH support can still load libc.so. To use this setjmp/longjmp i...

view this post on Zulip Namse (May 27 2024 at 12:16):

Ah! It was added in wasi-sdk version 22. I've been using version 20 like a fool. Sorry about that, haha.

view this post on Zulip Notification Bot (May 27 2024 at 12:16):

Namse has marked this topic as resolved.

view this post on Zulip YAMAMOTO Takashi (Jun 01 2024 at 05:36):

you also need latest (unreleased) llvm.

view this post on Zulip Namse (Jun 02 2024 at 05:29):

@YAMAMOTO Takashi Can this feature be added in the next version of wasi-sdk?

view this post on Zulip YAMAMOTO Takashi (Jun 02 2024 at 07:09):

when llvm 19 is released and wasi-sdk is updated to include it. probably around this summer i guess.

view this post on Zulip Namse (Jun 04 2024 at 07:42):

@YAMAMOTO Takashi If I need to directly implement saveSetjmp and testSetjmp in JavaScript for the current latest wasi-sdk environment to run in a browser, what code should I follow to make it work properly?

view this post on Zulip YAMAMOTO Takashi (Jun 04 2024 at 09:42):

i'm not sure what you are trying to do.
if you are using wasi-sdk, you can use the implementation in wasi-libc.
emscripten has its own implementation.

view this post on Zulip Namse (Jun 04 2024 at 11:26):

I also don't really understand it well. I'm using the latest version of wasi-sdk 22, and it seems like there is an implementation of setjmp inside wasi-sdk... Nevertheless, even though I linked the setjmp library, the wasm binary I built wants me to import saveSetjmp. I must have done something wrong?

view this post on Zulip YAMAMOTO Takashi (Jun 04 2024 at 11:35):

saveSetjmp is old name used by pre llvm 19, including the one included by wasi-sdk-22.
llvm 19 and later will use names like __wasm_setjmp etc, which is what provided by wasi-libc included by wasi-sdk-22.
if you want to use setjmp today, you can install llvm 19 by yourself and use it to build your app, using wasi-sdk-22 sysroot.

view this post on Zulip Namse (Jun 04 2024 at 14:29):

Thank you! I built Clang and other tools directly from the latest LLVM git repository, and as a result, WebAssembly no longer requires importing saveSetjmp or testSetjmp.

I thought the saveSetjmp code I implemented was causing the issue, but the problem persists. Strangely, when decoding woff2 fonts using brotli, the ThreadId changes from 2 to 9288807377403942. It works fine on the main thread, but there's always an issue with new threads.

I'll need to investigate further to find out what else might be causing the problem. Thank you!

view this post on Zulip YAMAMOTO Takashi (Jun 05 2024 at 04:00):

what ThreadId are you talking about? wasi-threads TID?
anyway, i'm not aware of any threading-related problems with this setjmp/longjmp implementation. (well, unless the app is trying to longjmp to a jmp_buf set up by another thread, which is IIRC a undefined behavior in C/posix.)
if you find the cause, please let me know.

view this post on Zulip Namse (Jun 05 2024 at 11:34):

I found the solution.
The stack size of wasi target in rust is 4096 bytes, which was too small to run font decoding code..........
:cry:


Last updated: Dec 23 2024 at 12:05 UTC