Skip to content

Commit 62304e2

Browse files
authored
[EH] Use LLVM implementation for new Wasm EH (#23469)
This adds a new `WASM` mode in `ExceptionLibrary`, which uses the new standard Wasm (exnref) EH, adds a library variant for it, and make the tests use the new LLVM implementation instead of the Binaryen translator. The CI won't pass until llvm/llvm-project#123915 lands. This requires adding `-wasmexcept` and `-wasmsjlj` variants to `MINIMAL_TASKS` in `embuilder.py` because they are necessary to run coreX tests in CircleCI, because dylink coreX tests in CircleCI rellies on `./embuilder build MINIMAL_PIC --pic`, which is the sum of `MINIMAL_TASKS` and `MINIMAL_PIC_TASKS`. Because a new variant is added to `ExceptionLibrary`, this increases `SYSTEM` library size from 366M to 400M, roughly by 11%. We discussed about the possibility of not shipping the exnref libraries and let them be built on demand, but given that `SYSTEM` include all variants, I'm not sure how we are going to do that: https://github.com/emscripten-core/emscripten/blob/73ebb91029948e62b3a4cea9ccc8db2dd87162b5/embuilder.py#L174-L177
1 parent 5a327e9 commit 62304e2

File tree

12 files changed

+65
-18
lines changed

12 files changed

+65
-18
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ See docs/process.md for more on how version tagging works.
2020

2121
4.0.2 (in development)
2222
----------------------
23+
- The standard Wasm EH, enabled by `-sWASM_LEGACY_EXCEPTIONS=0`, now uses the
24+
LLVM backend implementation rather than the previously used Binaryen
25+
translator
26+
(https://github.com/WebAssembly/binaryen/blob/main/src/passes/TranslateEH.cpp).
27+
(#23469) No specific action from the user is required.
2328
- Added support for compiling AVX2 intrinsics, 256-bit wide intrinsic is emulated
2429
on top of 128-bit Wasm SIMD instruction set. (#23035). Pass `-msimd128 -mavx2`
2530
to enable targeting AVX2.

embuilder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
MINIMAL_TASKS = [
3333
'libcompiler_rt',
3434
'libcompiler_rt-legacysjlj',
35+
'libcompiler_rt-wasmsjlj',
3536
'libcompiler_rt-ww',
3637
'libc',
3738
'libc-debug',
@@ -40,13 +41,16 @@
4041
'libc_optz-debug',
4142
'libc++abi',
4243
'libc++abi-legacyexcept',
44+
'libc++abi-wasmexcept',
4345
'libc++abi-noexcept',
4446
'libc++abi-debug',
4547
'libc++abi-debug-legacyexcept',
48+
'libc++abi-debug-wasmexcept',
4649
'libc++abi-debug-noexcept',
4750
'libc++abi-debug-ww-noexcept',
4851
'libc++',
4952
'libc++-legacyexcept',
53+
'libc++-wasmexcept',
5054
'libc++-noexcept',
5155
'libc++-ww-noexcept',
5256
'libal',
@@ -80,6 +84,7 @@
8084
'crt1_proxy_main',
8185
'crtbegin',
8286
'libunwind-legacyexcept',
87+
'libunwind-wasmexcept',
8388
'libnoexit',
8489
'sqlite3',
8590
'sqlite3-mt',

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,8 @@ https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-
11651165
If false, emit instructions for the standardized exception handling proposal:
11661166
https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md
11671167

1168+
.. note:: Applicable during both linking and compilation
1169+
11681170
Default value: true
11691171

11701172
.. _nodejs_catch_exit:

src/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ var EXCEPTION_STACK_TRACES = false;
781781
// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/legacy/Exceptions.md
782782
// If false, emit instructions for the standardized exception handling proposal:
783783
// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md
784-
// [link]
784+
// [compile+link]
785785
var WASM_LEGACY_EXCEPTIONS = true;
786786

787787
// Emscripten throws an ExitStatus exception to unwind when exit() is called.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
144652
1+
144531

test/test_other.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,7 +3535,10 @@ def test_embind_tsgen_jspi(self):
35353535
'legacy': [1]
35363536
})
35373537
def test_embind_tsgen_exceptions(self, legacy):
3538+
if not legacy and shared.get_node_version(config.NODE_JS)[0] < 22:
3539+
self.skipTest('Node version needs to be 22 or greater to run tsgen with exnref')
35383540
self.set_setting('WASM_LEGACY_EXCEPTIONS', legacy)
3541+
35393542
# Check that when Wasm exceptions and assertions are enabled bindings still generate.
35403543
self.run_process([EMXX, test_file('other/embind_tsgen.cpp'),
35413544
'-lembind', '-fwasm-exceptions', '-sASSERTIONS',

tools/building.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ def llvm_backend_args():
9393
elif settings.SUPPORT_LONGJMP == 'wasm':
9494
args += ['-wasm-enable-sjlj']
9595

96+
if settings.WASM_EXCEPTIONS:
97+
if settings.WASM_LEGACY_EXCEPTIONS:
98+
args += ['-wasm-use-legacy-eh']
99+
else:
100+
args += ['-wasm-use-legacy-eh=0']
101+
96102
# better (smaller, sometimes faster) codegen, see binaryen#1054
97103
# and https://bugs.llvm.org/show_bug.cgi?id=39488
98104
args += ['-disable-lsr']
@@ -277,6 +283,10 @@ def link_lld(args, target, external_symbols=None):
277283

278284
if settings.WASM_EXCEPTIONS:
279285
cmd += ['-mllvm', '-wasm-enable-eh']
286+
if settings.WASM_LEGACY_EXCEPTIONS:
287+
cmd += ['-mllvm', '-wasm-use-legacy-eh']
288+
else:
289+
cmd += ['-mllvm', '-wasm-use-legacy-eh=0']
280290
if settings.WASM_EXCEPTIONS or settings.SUPPORT_LONGJMP == 'wasm':
281291
cmd += ['-mllvm', '-exception-model=wasm']
282292

tools/link.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,6 @@ def check_human_readable_list(items):
431431
extras = settings.BINARYEN_EXTRA_PASSES.split(',')
432432
passes += [('--' + p) if p[0] != '-' else p for p in extras if p]
433433

434-
# Run the translator to the standardized EH instructions.
435-
if not settings.WASM_LEGACY_EXCEPTIONS:
436-
passes += ['--emit-exnref']
437-
438434
# If we are going to run metadce then that means we will be running binaryen
439435
# tools after the main invocation, whose flags are determined here
440436
# (specifically we will run metadce and possibly also wasm-opt for import/

tools/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
'INLINING_LIMIT',
8585
'DISABLE_EXCEPTION_CATCHING',
8686
'DISABLE_EXCEPTION_THROWING',
87+
'WASM_LEGACY_EXCEPTIONS',
8788
'MAIN_MODULE',
8889
'SIDE_MODULE',
8990
'RELOCATABLE',

tools/shared.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,13 @@ def node_reference_types_flags(nodejs):
379379

380380
def node_exception_flags(nodejs):
381381
node_version = get_node_version(nodejs)
382-
# Exception handling was enabled by default in node v17.
382+
# Legacy exception handling was enabled by default in node v17.
383383
if node_version and node_version < (17, 0, 0):
384384
return ['--experimental-wasm-eh']
385-
else:
386-
return []
385+
# Standard exception handling was supported behind flag in node v22.
386+
if node_version and node_version >= (22, 0, 0) and not settings.WASM_LEGACY_EXCEPTIONS:
387+
return ['--experimental-wasm-exnref']
388+
return []
387389

388390

389391
def node_pthread_flags(nodejs):

0 commit comments

Comments
 (0)