Skip to content

Commit f0978c3

Browse files
committed
Unconditionally define wasm-eh tags in native code. NFC
This tags are sometimes also weakly defined in each object file by llvm but I hope to remove those definitions going forward and instead rely on the toolchain/compiler-rt to define them.
1 parent a7c1924 commit f0978c3

File tree

9 files changed

+38
-15
lines changed

9 files changed

+38
-15
lines changed

src/lib/libcore.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,13 +2239,6 @@ addToLibrary({
22392239
__stack_high: '{{{ STACK_HIGH }}}',
22402240
__stack_low: '{{{ STACK_LOW }}}',
22412241
__global_base: '{{{ GLOBAL_BASE }}}',
2242-
#if WASM_EXCEPTIONS
2243-
// In dynamic linking we define tags here and feed them to each module
2244-
__cpp_exception: "new WebAssembly.Tag({'parameters': ['{{{ POINTER_WASM_TYPE }}}']})",
2245-
#endif
2246-
#if SUPPORT_LONGJMP == 'wasm'
2247-
__c_longjmp: "new WebAssembly.Tag({'parameters': ['{{{ POINTER_WASM_TYPE }}}']})",
2248-
#endif
22492242
#if ASYNCIFY == 1
22502243
__asyncify_state: "new WebAssembly.Global({'value': 'i32', 'mutable': true}, 0)",
22512244
__asyncify_data: "new WebAssembly.Global({'value': '{{{ POINTER_WASM_TYPE }}}', 'mutable': true}, {{{ to64(0) }}})",

src/lib/libdylink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ var LibraryDylink = {
276276
continue;
277277
}
278278
#endif
279-
if (typeof value == 'object') {
279+
if (typeof value == 'object' && typeof value.value != 'undefined') {
280280
// a breaking change in the wasm spec, globals are now objects
281281
// https://github.com/WebAssembly/mutable-global/issues/1
282282
value = value.value;

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ function getWasmImports() {
740740
#endif
741741
#endif
742742

743-
#if hasExportedSymbol('__cpp_exception') && !RELOCATABLE
743+
#if hasExportedSymbol('__cpp_exception')
744744
___cpp_exception = wasmExports['__cpp_exception'];
745745
{{{ receivedSymbol('___cpp_exception') }}};
746746
#endif

system/lib/compiler-rt/emscripten_setjmp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void __wasm_longjmp(void* env, int val) {
7070
__builtin_wasm_throw(C_LONGJMP, arg);
7171
}
7272
#else
73+
7374
void emscripten_longjmp(uintptr_t env, int val) {
7475
// C standard:
7576
// The longjmp function cannot cause the setjmp macro to return
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2025 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*
7+
* Define the Wasm EH tags needed by LLVM
8+
*/
9+
10+
#ifdef __WASM_SJLJ__
11+
12+
#ifdef __wasm64__
13+
#define PTR i64
14+
#else
15+
#define PTR i32
16+
#endif
17+
18+
.globl __cpp_exception
19+
.tagtype __cpp_exception PTR
20+
__cpp_exception:
21+
22+
.globl __c_longjmp
23+
.tagtype __c_longjmp PTR
24+
__c_longjmp:
25+
26+
#endif // !__WASM_SJLJ__

test/code_size/test_codesize_hello_dylink.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 26969,
3-
"a.out.js.gz": 11479,
2+
"a.out.js": 26998,
3+
"a.out.js.gz": 11486,
44
"a.out.nodebug.wasm": 18567,
55
"a.out.nodebug.wasm.gz": 9199,
6-
"total": 45536,
7-
"total_gz": 20678,
6+
"total": 45565,
7+
"total_gz": 20685,
88
"sent": [
99
"__heap_base",
1010
"__indirect_function_table",

test/code_size/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 246021,
2+
"a.out.js": 246049,
33
"a.out.nodebug.wasm": 597767,
4-
"total": 843788,
4+
"total": 843816,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

test/test_core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4958,9 +4958,11 @@ def test_dylink_exceptions_try_catch_2(self):
49584958
@no_js_math('JS_MATH is not compatible with MAIN_MODULE')
49594959
def test_dylink_exceptions_try_catch_6(self):
49604960
create_file('main.cpp', r'''
4961+
#include <assert.h>
49614962
#include <dlfcn.h>
49624963
int main() {
49634964
void* handle = dlopen("liblib.so", RTLD_LAZY);
4965+
assert(handle);
49644966
void (*side)(void) = (void (*)(void))dlsym(handle, "side");
49654967
(side)();
49664968
return 0;

tools/system_libs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ class libcompiler_rt(MTLibrary, SjLjLibrary):
984984
filenames=[
985985
'stack_ops.S',
986986
'stack_limits.S',
987+
'wasm_eh_tags.S',
987988
'emscripten_setjmp.c',
988989
'emscripten_exception_builtins.c',
989990
'emscripten_tempret.s',

0 commit comments

Comments
 (0)