diff --git a/test/test_other.py b/test/test_other.py index bd69c2249833e..f0c0a9a4d95f0 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -14494,6 +14494,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'] diff --git a/tools/link.py b/tools/link.py index 0892b9f15368b..d496f61364ecc 100644 --- a/tools/link.py +++ b/tools/link.py @@ -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