]> git.proxmox.com Git - wasi-libc.git/commit
Add libsetjmp.a/so (#483)
authorYAMAMOTO Takashi <yamamoto@midokura.com>
Mon, 1 Apr 2024 22:36:28 +0000 (07:36 +0900)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 25 Jun 2024 10:13:35 +0000 (12:13 +0200)
commit6382b7bbc3e274a5735cff6285bcb270176dd483
tree2d2de0cea5d89e53e79ea1c5d8c35ffd40d7225c
parent373f8f0149ba6045d08d388402adf2c5eb1021bf
Add libsetjmp.a/so (#483)

* Add libsetjmp.a/so

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 implementation, an application should
be compiled with `-mllvm -wasm-enable-sjlj` and linked with `-lsetjmp`.
(You need an LLVM with the change mentioned below.)

Also, you need a runtime with EH support to run such an application.

If you want to use the latest EH instructions, you can use
`binaryen --translate-eh-old-to-new` on your application.

Note: You don't need to translate libsetjmp.a/so to the new EH.
While LLVM currently produces bytecode for an old version of the EH
proposal, luckily for us, the bytecode used in this library (ie. the tag
definition and the "throw" instruction) is compatible with the latest
version of the proposal.

The runtime logic is basically copy-and-paste from:
    https://github.com/yamt/garbage/tree/wasm-sjlj-alt2/wasm/longjmp

The corresponding LLVM change:
    https://github.com/llvm/llvm-project/pull/84137
    (Note: you need this change to build setjmp/longjmp using code.
    otoh, you don't need this to build libsetjmp.)

A similar change for emscripten:
    https://github.com/emscripten-core/emscripten/pull/21502

An older version of this PR, which doesn't require LLVM changes:
    https://github.com/WebAssembly/wasi-libc/pull/467

Discussion:
    https://docs.google.com/document/d/1ZvTPT36K5jjiedF8MCXbEmYjULJjI723aOAks1IdLLg/edit

An example to use the latest EH instructions:
```
clang -mllvm -wasm-enable-sjlj -o your_app.wasm your_app.c -lsetjmp
wasm-opt --translate-eh-old-to-new -o your_app.wasm your_app.wasm
toywasm --wasi your_app.wasm
```
Note: use toywasm built with `-DTOYWASM_ENABLE_WASM_EXCEPTION_HANDLING=ON`.

An example to use the older EH instructions, which LLVM currently produces:
```
clang -mllvm -wasm-enable-sjlj -o your_app.wasm your_app.c -lsetjmp
iwasm your_app.wasm
```
Note: use wasm-micro-runtime built with `-DWAMR_BUILD_EXCE_HANDLING=1`.
Note: as of writing this, only the classic interpreter supports EH.

* Make libsetjmp build optional

* CI: Disable libsetjmp for old LLVM

* libc-top-half/musl/include/setjmp.h: fix a rebase botch
.github/workflows/main.yml
Makefile
libc-top-half/musl/arch/wasm32/bits/setjmp.h [new file with mode: 0644]
libc-top-half/musl/include/setjmp.h
libc-top-half/musl/src/setjmp/wasm32/rt.c [new file with mode: 0644]