Skip to content

Commit 20697f1

Browse files
authored
[SjLj] Make Wasm SjLj run with PURE_WASI (#22611)
Previously `-sPURE_WASI` disabled SjLj support because it uses the JS-based simultion, but accidentally also disabled Wasm SjLj. This makes setting `PURE_WASI` disable SjLj support by default only when Wasm EH is not used. Also this does not force disabling; it only makes the default SjLj setting to be disabled, meaning you can experiment with it if you manually set `-sSUPPORT_LONGJMP` to be other values. Fixes #22566.
1 parent 04a72c2 commit 20697f1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

test/test_other.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14484,6 +14484,21 @@ def test_wasi_random_get(self):
1448414484
def test_wasi_sched_yield(self):
1448514485
self.run_wasi_test_suite_test('wasi_sched_yield')
1448614486

14487+
def test_wasi_with_sjlj(self):
14488+
# When PURE_WASI is set and Wasm exception is not being used, we turn off
14489+
# SUPPORT_LONGJMP by default because it uses a JS-based simulation of
14490+
# longjmp.
14491+
self.set_setting('PURE_WASI')
14492+
err = self.expect_fail([EMCC, test_file('core/test_longjmp.c')] + self.get_emcc_args())
14493+
self.assertContained('error: longjmp support was disabled (SUPPORT_LONGJMP=0)', err)
14494+
14495+
# When using Wasm exception, SUPPORT_LONGJMP defaults to 'wasm', which does
14496+
# not use the JS-based support. This should succeed.
14497+
self.emcc_args.append('-fwasm-exceptions')
14498+
# -fwasm-exceptions exports __cpp_exception, so this is necessary
14499+
self.set_setting('DEFAULT_TO_CXX')
14500+
self.do_runf(test_file('core/test_longjmp.c'), emcc_args=self.get_emcc_args())
14501+
1448714502
def test_memops_bulk_memory(self):
1448814503
self.emcc_args += ['--profiling-funcs', '-fno-builtin']
1448914504

tools/link.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,11 @@ def phase_linker_setup(options, state, newargs):
802802
if settings.PURE_WASI:
803803
settings.STANDALONE_WASM = 1
804804
settings.WASM_BIGINT = 1
805-
settings.SUPPORT_LONGJMP = 0
805+
# WASI does not support Emscripten (JS-based) exception catching, which the
806+
# JS-based longjmp support also uses. Emscripten EH is by default disabled
807+
# so we don't need to do anything here.
808+
if not settings.WASM_EXCEPTIONS:
809+
default_setting('SUPPORT_LONGJMP', 0)
806810

807811
if options.no_entry:
808812
settings.EXPECT_MAIN = 0

0 commit comments

Comments
 (0)