From 54545d51b3eaeafccab7ab06a349e0b28f171e2a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 25 Sep 2024 06:27:46 +0900 Subject: [PATCH] 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: * https://github.com/WebAssembly/wasi-libc/pull/526 * https://github.com/WebAssembly/wasi-libc/pull/529 * bump llvm to llvmorg-19.1.0-rc4 * bump llvm to llvmorg-19.1.0 --- README.md | 10 +++++-- SetjmpLongjmp.md | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ src/llvm-project | 2 +- src/wasi-libc | 2 +- 4 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 SetjmpLongjmp.md diff --git a/README.md b/README.md index 22138e5b6..c3c0dfa58 100644 --- a/README.md +++ b/README.md @@ -203,12 +203,16 @@ disabled in a configure step before building with WASI SDK. ## Notable Limitations This repository does not yet support __C++ exceptions__. C++ code is supported -only with -fno-exceptions for now. Similarly, there is not yet support for -setjmp/longjmp. Work on support for [exception handling] is underway at the -language level which will support both of these features. +only with -fno-exceptions for now. +Work on support for [exception handling] is underway at the +language level which will support the features. [exception handling]: https://github.com/WebAssembly/exception-handling/ +See [C setjmp/longjmp support] about setjmp/longjmp support. + +[C setjmp/longjmp support]: SetjmpLongjmp.md + This repository experimentally supports __threads__ with `--target=wasm32-wasi-threads`. It uses WebAssembly's [threads] primitives (atomics, `wait`/`notify`, shared memory) and [wasi-threads] for spawning diff --git a/SetjmpLongjmp.md b/SetjmpLongjmp.md new file mode 100644 index 000000000..df8c4af13 --- /dev/null +++ b/SetjmpLongjmp.md @@ -0,0 +1,75 @@ +# C setjmp/longjmp support + +## Build an application + +To build an application using setjmp/longjmp, you need two things: + +* Enable the necessary LLVM translation (`-mllvm -wasm-enable-sjlj`) + +* Link the setjmp library (`-lsetjmp`) + +### Example without LTO + +```shell +clang -Os -mllvm -wasm-enable-sjlj -o your_app.wasm your_app.c -lsetjmp +``` + +### Example with LTO + +```shell +clang -Os -flto=full -mllvm -wasm-enable-sjlj -Wl,-mllvm,-wasm-enable-sjlj -o your_app.wasm your_app.c -lsetjmp +``` + +## Run an application + +To run the application built as in the previous section, +you need to use a runtime with [exception handling proposal] support. + +Unfortunately, there are two incompatible versions of +[exception handling proposal], which is commonly implemented by runtimes. + +* The latest version with `exnref` + +* The [phase3] version + +### Example with the latest exception handling proposal + +Because the current version of WASI-SDK produces an old version +of [exception handling proposal] instructions, if your runtime +implements the latest version of the proposal, you need to convert +your module to the latest version. + +[toywasm] is an example of such runtimes. + +You can use binaryen `wasm-opt` command for the conversion. + +```shell +wasm-opt --translate-to-exnref -all -o your_app.exnref.wasm your_app.wasm +``` + +Then you can run it with a runtime supporting the latest version of +[exception handling proposal]. + +```shell +toywasm --wasi your_app.exnref.wasm +``` +(You may need to enable the support with `-D TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING=ON`.) + +### Example with the phase3 exception handling proposal (a bit older version) + +If your runtime supports the [phase3] version of +[exception handling proposal], which is the same version as what WASI-SDK +currently produces, you can run the produced module as it is. + +For example, the classic interpreter of [wasm-micro-runtime] is +one of such runtimes. + +```shell +iwasm your_app.wasm +``` +(You may need to enable the support with `-D WAMR_BUILD_EXCE_HANDLING=1 -D WAMR_BUILD_FAST_INTERP=0`.) + +[exception handling proposal]: https://github.com/WebAssembly/exception-handling/ +[phase3]: https://github.com/WebAssembly/exception-handling/tree/main/proposals/exception-handling/legacy +[toywasm]: https://github.com/yamt/toywasm +[wasm-micro-runtime]: https://github.com/bytecodealliance/wasm-micro-runtime diff --git a/src/llvm-project b/src/llvm-project index 26a1d6601..a4bf6cd7c 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 26a1d6601d727a96f4301d0d8647b5a42760ae0c +Subproject commit a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4 diff --git a/src/wasi-libc b/src/wasi-libc index b9ef79d7d..1b19fc65a 160000 --- a/src/wasi-libc +++ b/src/wasi-libc @@ -1 +1 @@ -Subproject commit b9ef79d7dbd47c6c5bafdae760823467c2f60b70 +Subproject commit 1b19fc65ad84b223876c50dd4fcd7d5a08c311dc