diff --git a/src/lib/libcore.js b/src/lib/libcore.js index fe35375f01e89..bc3a3905fb5dc 100644 --- a/src/lib/libcore.js +++ b/src/lib/libcore.js @@ -2239,13 +2239,6 @@ addToLibrary({ __stack_high: '{{{ STACK_HIGH }}}', __stack_low: '{{{ STACK_LOW }}}', __global_base: '{{{ GLOBAL_BASE }}}', -#if WASM_EXCEPTIONS - // In dynamic linking we define tags here and feed them to each module - __cpp_exception: "new WebAssembly.Tag({'parameters': ['{{{ POINTER_WASM_TYPE }}}']})", -#endif -#if SUPPORT_LONGJMP == 'wasm' - __c_longjmp: "new WebAssembly.Tag({'parameters': ['{{{ POINTER_WASM_TYPE }}}']})", -#endif #if ASYNCIFY == 1 __asyncify_state: "new WebAssembly.Global({'value': 'i32', 'mutable': true}, 0)", __asyncify_data: "new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}', 'mutable': true}, {{{ to64(0) }}})", diff --git a/src/lib/libdylink.js b/src/lib/libdylink.js index 67bf0a851370d..c23c247de3fcf 100644 --- a/src/lib/libdylink.js +++ b/src/lib/libdylink.js @@ -276,7 +276,7 @@ var LibraryDylink = { continue; } #endif - if (typeof value == 'object') { + if (typeof value?.value != 'undefined') { // a breaking change in the wasm spec, globals are now objects // https://github.com/WebAssembly/mutable-global/issues/1 value = value.value; diff --git a/system/lib/compiler-rt/__c_longjmp.S b/system/lib/compiler-rt/__c_longjmp.S new file mode 100644 index 0000000000000..6ee12aa011c11 --- /dev/null +++ b/system/lib/compiler-rt/__c_longjmp.S @@ -0,0 +1,23 @@ +/* + * Copyright 2025 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + * + * Define the `__c_longjmp` Wasm EH tag which is used to implment setjmp/longjmp + * in LLVM. + */ + +#ifdef __wasm_exception_handling__ + +#ifdef __wasm64__ +#define PTR i64 +#else +#define PTR i32 +#endif + +.globl __c_longjmp +.tagtype __c_longjmp PTR +__c_longjmp: + +#endif // !__wasm_exception_handling__ diff --git a/system/lib/libcxxabi/src/__cpp_exception.S b/system/lib/libcxxabi/src/__cpp_exception.S new file mode 100644 index 0000000000000..27dd5a39f0dcf --- /dev/null +++ b/system/lib/libcxxabi/src/__cpp_exception.S @@ -0,0 +1,23 @@ +/* + * Copyright 2025 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + * + * Define the `__cpp_exception` Wasm EH tag which is used to implmenent C++ + * exception handling in LLVM. + */ + +#ifdef __wasm_exception_handling__ + +#ifdef __wasm64__ +#define PTR i64 +#else +#define PTR i32 +#endif + +.globl __cpp_exception +.tagtype __cpp_exception PTR +__cpp_exception: + +#endif // !__wasm_exception_handling__ diff --git a/test/code_size/test_codesize_hello_dylink.json b/test/code_size/test_codesize_hello_dylink.json index 86520d2e990cf..9a659b203d2bb 100644 --- a/test/code_size/test_codesize_hello_dylink.json +++ b/test/code_size/test_codesize_hello_dylink.json @@ -1,10 +1,10 @@ { - "a.out.js": 26969, - "a.out.js.gz": 11479, + "a.out.js": 26979, + "a.out.js.gz": 11483, "a.out.nodebug.wasm": 18567, "a.out.nodebug.wasm.gz": 9199, - "total": 45536, - "total_gz": 20678, + "total": 45546, + "total_gz": 20682, "sent": [ "__heap_base", "__indirect_function_table", diff --git a/test/code_size/test_codesize_hello_dylink_all.json b/test/code_size/test_codesize_hello_dylink_all.json index f69be3b627242..83699f6c5debc 100644 --- a/test/code_size/test_codesize_hello_dylink_all.json +++ b/test/code_size/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { - "a.out.js": 246021, + "a.out.js": 246031, "a.out.nodebug.wasm": 597767, - "total": 843788, + "total": 843798, "sent": [ "IMG_Init", "IMG_Load", diff --git a/test/test_core.py b/test/test_core.py index a1c2f7d40e9d8..45fec1197516c 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -4951,9 +4951,11 @@ def test_dylink_exceptions_try_catch_2(self): @no_js_math('JS_MATH is not compatible with MAIN_MODULE') def test_dylink_exceptions_try_catch_6(self): create_file('main.cpp', r''' + #include #include int main() { void* handle = dlopen("liblib.so", RTLD_LAZY); + assert(handle); void (*side)(void) = (void (*)(void))dlsym(handle, "side"); (side)(); return 0; diff --git a/tools/system_libs.py b/tools/system_libs.py index 1d88c31a29dfd..2501a534e904a 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -987,6 +987,7 @@ class libcompiler_rt(MTLibrary, SjLjLibrary): 'emscripten_setjmp.c', 'emscripten_exception_builtins.c', 'emscripten_tempret.s', + '__c_longjmp.S', '__trap.c', ]) @@ -1661,6 +1662,7 @@ def get_files(self): 'stdlib_typeinfo.cpp', 'private_typeinfo.cpp', 'cxa_exception_js_utils.cpp', + '__cpp_exception.S', ] if self.eh_mode == Exceptions.NONE: filenames += ['cxa_noexception.cpp']