Skip to content

Commit 54545d5

Browse files
authored
LLVM 19 + setjmp/longjmp doc (#480)
* llvmorg-19.1.0-rc3 * document setjmp/longjmp support * README.md: mention SetjmpLongjmp.md * bump wasi-libc For following changes: * WebAssembly/wasi-libc#526 * WebAssembly/wasi-libc#529 * bump llvm to llvmorg-19.1.0-rc4 * bump llvm to llvmorg-19.1.0
1 parent adbbf2c commit 54545d5

File tree

4 files changed

+84
-5
lines changed

4 files changed

+84
-5
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,16 @@ disabled in a configure step before building with WASI SDK.
203203
## Notable Limitations
204204

205205
This repository does not yet support __C++ exceptions__. C++ code is supported
206-
only with -fno-exceptions for now. Similarly, there is not yet support for
207-
setjmp/longjmp. Work on support for [exception handling] is underway at the
208-
language level which will support both of these features.
206+
only with -fno-exceptions for now.
207+
Work on support for [exception handling] is underway at the
208+
language level which will support the features.
209209

210210
[exception handling]: https://github.com/WebAssembly/exception-handling/
211211

212+
See [C setjmp/longjmp support] about setjmp/longjmp support.
213+
214+
[C setjmp/longjmp support]: SetjmpLongjmp.md
215+
212216
This repository experimentally supports __threads__ with
213217
`--target=wasm32-wasi-threads`. It uses WebAssembly's [threads] primitives
214218
(atomics, `wait`/`notify`, shared memory) and [wasi-threads] for spawning

SetjmpLongjmp.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# C setjmp/longjmp support
2+
3+
## Build an application
4+
5+
To build an application using setjmp/longjmp, you need two things:
6+
7+
* Enable the necessary LLVM translation (`-mllvm -wasm-enable-sjlj`)
8+
9+
* Link the setjmp library (`-lsetjmp`)
10+
11+
### Example without LTO
12+
13+
```shell
14+
clang -Os -mllvm -wasm-enable-sjlj -o your_app.wasm your_app.c -lsetjmp
15+
```
16+
17+
### Example with LTO
18+
19+
```shell
20+
clang -Os -flto=full -mllvm -wasm-enable-sjlj -Wl,-mllvm,-wasm-enable-sjlj -o your_app.wasm your_app.c -lsetjmp
21+
```
22+
23+
## Run an application
24+
25+
To run the application built as in the previous section,
26+
you need to use a runtime with [exception handling proposal] support.
27+
28+
Unfortunately, there are two incompatible versions of
29+
[exception handling proposal], which is commonly implemented by runtimes.
30+
31+
* The latest version with `exnref`
32+
33+
* The [phase3] version
34+
35+
### Example with the latest exception handling proposal
36+
37+
Because the current version of WASI-SDK produces an old version
38+
of [exception handling proposal] instructions, if your runtime
39+
implements the latest version of the proposal, you need to convert
40+
your module to the latest version.
41+
42+
[toywasm] is an example of such runtimes.
43+
44+
You can use binaryen `wasm-opt` command for the conversion.
45+
46+
```shell
47+
wasm-opt --translate-to-exnref -all -o your_app.exnref.wasm your_app.wasm
48+
```
49+
50+
Then you can run it with a runtime supporting the latest version of
51+
[exception handling proposal].
52+
53+
```shell
54+
toywasm --wasi your_app.exnref.wasm
55+
```
56+
(You may need to enable the support with `-D TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING=ON`.)
57+
58+
### Example with the phase3 exception handling proposal (a bit older version)
59+
60+
If your runtime supports the [phase3] version of
61+
[exception handling proposal], which is the same version as what WASI-SDK
62+
currently produces, you can run the produced module as it is.
63+
64+
For example, the classic interpreter of [wasm-micro-runtime] is
65+
one of such runtimes.
66+
67+
```shell
68+
iwasm your_app.wasm
69+
```
70+
(You may need to enable the support with `-D WAMR_BUILD_EXCE_HANDLING=1 -D WAMR_BUILD_FAST_INTERP=0`.)
71+
72+
[exception handling proposal]: https://github.com/WebAssembly/exception-handling/
73+
[phase3]: https://github.com/WebAssembly/exception-handling/tree/main/proposals/exception-handling/legacy
74+
[toywasm]: https://github.com/yamt/toywasm
75+
[wasm-micro-runtime]: https://github.com/bytecodealliance/wasm-micro-runtime

src/llvm-project

0 commit comments

Comments
 (0)