Skip to content

Commit b96bbc9

Browse files
committed
Update docs
1 parent b2947d1 commit b96bbc9

2 files changed

Lines changed: 45 additions & 36 deletions

File tree

CppExceptions.md

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
# Support for C++ Exceptions
22

3-
The released artifacts for wasi-sdk at this time do not support C++ exceptions.
4-
LLVM and Clang, however, have support for C++ exceptions in WebAssembly and this
5-
is intended to serve as documentation of the current state of affairs of using
6-
C++ exceptions. It should be noted though that the current status of C++
7-
exceptions support is not intended to be the final state of support, and this is
8-
all continuing to be iterated on over time.
3+
> **Note**: this documentation does not cover wasi-sdk-31, the latest version
4+
> of wasi-sdk at this time.
95
10-
## Building wasi-sdk with exceptions
6+
From wasi-sdk-32 and onwards the artifacts produced by this repository support
7+
compiling C++ code both with and without exceptions. The sysroot for wasm
8+
targets contains two copies of the C++ standard library and headers -- one with
9+
exceptions enabled and one with exceptions disabled. These are automatically
10+
selected based on compilation flags. This means that wasi-sdk-produced binaries
11+
can avoid using wasm exceptions entirely by disabling C++ exceptions, or C++
12+
exceptions can be enabled in which case wasm exceptions will be used.
1113

12-
When building the sysroot with wasi-sdk you can pass `-DWASI_SDK_EXCEPTIONS=ON`
13-
to enable support for C++ exceptions. For example:
14-
15-
```shell script
16-
$ cmake -G Ninja -B build/sysroot -S . \
17-
-DCMAKE_TOOLCHAIN_FILE=$path/to/wasi-sdk-p1.cmake \
18-
-DWASI_SDK_EXCEPTIONS=ON
19-
```
20-
21-
The C++ standard library will be compiled with support for exceptions for the
22-
desired targets and the resulting sysroot supports using exceptions.
14+
Currently the default is for C++ exceptions to be disabled.
2315

2416
## Compiling code with C++ exceptions
2517

@@ -36,25 +28,42 @@ This can be specified for example with:
3628

3729
```shell script
3830
$ export CFLAGS="-fwasm-exceptions -mllvm -wasm-use-legacy-eh=false"
39-
$ export LDFLAGS="-lunwind"
31+
$ export LDFLAGS="-fwasm-exceptions -lunwind"
4032
```
4133

42-
## Limitations
34+
Note that `-fwasm-exceptions` must be present when linking to select the
35+
correct C++ standard library to link.
36+
37+
## Building wasi-sdk with exceptions
4338

44-
Currently C++ exceptions support in wasi-sdk does not support shared libraries.
45-
Fixing this will require resolving some miscellaneous build issues in this
46-
repository itself.
39+
When building the sysroot with wasi-sdk you can pass `-DWASI_SDK_EXCEPTIONS=ON`
40+
to enable support for C++ exceptions. For example:
4741

48-
## Future Plans
42+
```shell script
43+
$ cmake -G Ninja -B build/sysroot -S . \
44+
-DCMAKE_TOOLCHAIN_FILE=$path/to/wasi-sdk-p1.cmake \
45+
-DWASI_SDK_EXCEPTIONS=ON
46+
```
47+
48+
The C++ standard library will be compiled with support for exceptions for the
49+
desired targets and the resulting sysroot supports using exceptions. Note that
50+
enabling C++ exceptions requires LLVM 22 or later.
51+
52+
C++ exceptions are disabled by default for local builds. With a future release
53+
of LLVM 23 the dual-sysroot nature will be on-by-default.
54+
55+
## Limitations
4956

50-
There are a few tracking issues with historical discussion about C++ exceptions
51-
support in wasi-sdk such as [#334](https://github.com/WebAssembly/wasi-sdk/issues/334)
52-
and [#565](https://github.com/WebAssembly/wasi-sdk/issues/565). The major
53-
remaining items are:
57+
There are a few known limitations/bugs/todos around exceptions support in
58+
wasi-sdk at this time:
5459

55-
* Figure out support for shared libraries.
56-
* Determine how to ship a sysroot that supports both with-and-without
57-
exceptions.
58-
* Figure out how to avoid the need for extra compiler flags when using
59-
exceptions.
60-
* Figure out if a new wasm target is warranted.
60+
* Currently C++ exceptions support in wasi-sdk does not support shared
61+
libraries. Fixing this will require resolving some miscellaneous build
62+
issues in this repository itself.
63+
* Currently `-fwasm-exceptions` is a required flag to enable C++ exceptions.
64+
It's unclear whethe `-fexceptions` should also be supported as a substitute.
65+
* Currently LLVM defaults to using the legacy exception-handling proposal and
66+
this will likely change in the future. Precompiled libraries for wasi-sdk are
67+
all built with the standard exception-handlign proposal.
68+
* Currently `-lunwind` is required when linking, but this may become automatic
69+
in the future.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ disabled in a configure step before building with WASI SDK.
209209

210210
## Notable Limitations
211211

212-
* C++ exceptions are disabled by default. For more information see
213-
[CppExceptions.md].
212+
* C++ exceptions are disabled by default and require extra configuration to get
213+
working, see [CppExceptions.md].
214214
* C `setjmp`/`longjmp` require some extra configuration to get working, see
215215
[SetjmpLongjmp.md].
216216
* Most targets do not support spawning a thread. Experimental support for

0 commit comments

Comments
 (0)