Skip to content

Commit 87b5d56

Browse files
authored
Support Wasm EH with LTO (#13976)
All EH tests annotated with `with_both_exception_handling` decorators pass all of `wasmlto0`, `wasmlto1`, `wasmlto2`, `wasmlto3`, and `wasmltos` modes. (`wasmltoz` fails because of a known issue with V8 that affects non-EH tests too. `wasmz` fails for the same reason.) Fixes #13665.
1 parent 9839162 commit 87b5d56

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

tests/test_other.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7277,6 +7277,17 @@ def test_lto_flags(self):
72777277
seen_bitcode = building.is_bitcode('a.o')
72787278
self.assertEqual(expect_bitcode, seen_bitcode, 'must emit LTO-capable bitcode when flags indicate so (%s)' % str(flags))
72797279

7280+
# We have LTO tests covered in 'wasmltoN' targets in test_core.py, but they
7281+
# don't run as a part of Emscripten CI, so we add a separate LTO test here.
7282+
def test_lto_wasm_exceptions(self):
7283+
if not config.V8_ENGINE or config.V8_ENGINE not in config.JS_ENGINES:
7284+
self.skipTest('d8 required to run wasm eh tests')
7285+
self.set_setting('EXCEPTION_DEBUG')
7286+
self.emcc_args += ['-fwasm-exceptions', '-flto']
7287+
self.v8_args.append('--experimental-wasm-eh')
7288+
self.js_engines = [config.V8_ENGINE]
7289+
self.do_run_from_file(test_file('core', 'test_exceptions.cpp'), test_file('core', 'test_exceptions_caught.out'))
7290+
72807291
def test_wasm_nope(self):
72817292
for opts in [[], ['-O2']]:
72827293
print(opts)

tools/building.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ def link_lld(args, target, external_symbol_list=None):
454454
for a in llvm_backend_args():
455455
cmd += ['-mllvm', a]
456456

457+
# Wasm exception handling. This is a CodeGen option for the LLVM backend, so
458+
# wasm-ld needs to take this for the LTO mode.
459+
if settings.EXCEPTION_HANDLING:
460+
cmd += ['-mllvm', '-exception-model=wasm']
461+
457462
# For relocatable output (generating an object file) we don't pass any of the
458463
# normal linker flags that are used when building and exectuable
459464
if '--relocatable' not in args and '-r' not in args:

tools/system_libs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,11 @@ class libcxx(NoExceptLibrary, MTLibrary):
970970

971971
class libunwind(NoExceptLibrary, MTLibrary):
972972
name = 'libunwind'
973+
# Because calls to _Unwind_CallPersonality are generated during LTO, libunwind
974+
# can't currently be part of LTO.
975+
# See https://bugs.llvm.org/show_bug.cgi?id=44353
976+
force_object_files = True
977+
973978
cflags = ['-Oz', '-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS']
974979
src_dir = ['system', 'lib', 'libunwind', 'src']
975980
# Without this we can't build libunwind since it will pickup the unwind.h

0 commit comments

Comments
 (0)