Skip to content

Commit

Permalink
[SjLj] Make Wasm SjLj run with PURE_WASI (emscripten-core#22611)
Browse files Browse the repository at this point in the history
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 emscripten-core#22566.
  • Loading branch information
aheejin authored Sep 24, 2024
1 parent 04a72c2 commit 20697f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -14484,6 +14484,21 @@ def test_wasi_random_get(self):
def test_wasi_sched_yield(self):
self.run_wasi_test_suite_test('wasi_sched_yield')

def test_wasi_with_sjlj(self):
# When PURE_WASI is set and Wasm exception is not being used, we turn off
# SUPPORT_LONGJMP by default because it uses a JS-based simulation of
# longjmp.
self.set_setting('PURE_WASI')
err = self.expect_fail([EMCC, test_file('core/test_longjmp.c')] + self.get_emcc_args())
self.assertContained('error: longjmp support was disabled (SUPPORT_LONGJMP=0)', err)

# When using Wasm exception, SUPPORT_LONGJMP defaults to 'wasm', which does
# not use the JS-based support. This should succeed.
self.emcc_args.append('-fwasm-exceptions')
# -fwasm-exceptions exports __cpp_exception, so this is necessary
self.set_setting('DEFAULT_TO_CXX')
self.do_runf(test_file('core/test_longjmp.c'), emcc_args=self.get_emcc_args())

def test_memops_bulk_memory(self):
self.emcc_args += ['--profiling-funcs', '-fno-builtin']

Expand Down
6 changes: 5 additions & 1 deletion tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,11 @@ def phase_linker_setup(options, state, newargs):
if settings.PURE_WASI:
settings.STANDALONE_WASM = 1
settings.WASM_BIGINT = 1
settings.SUPPORT_LONGJMP = 0
# WASI does not support Emscripten (JS-based) exception catching, which the
# JS-based longjmp support also uses. Emscripten EH is by default disabled
# so we don't need to do anything here.
if not settings.WASM_EXCEPTIONS:
default_setting('SUPPORT_LONGJMP', 0)

if options.no_entry:
settings.EXPECT_MAIN = 0
Expand Down

0 comments on commit 20697f1

Please sign in to comment.