Skip to content

Commit bb11bae

Browse files
authored
Fix invoke_xx function with MAIN_MODULE+DYNCALLS (#25572)
Fixes: #25560, #25551
1 parent 56ed8e9 commit bb11bae

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

test/test_core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4876,7 +4876,11 @@ def test_dylink_raii_exceptions(self):
48764876

48774877
@with_all_eh_sjlj
48784878
@with_dylink_reversed
4879-
def test_dylink_exceptions_try_catch(self):
4879+
@parameterized({
4880+
'': ([],),
4881+
'dyncalls': (['-sDYNCALLS'],),
4882+
})
4883+
def test_dylink_exceptions_try_catch(self, args):
48804884
self.dylink_test(main=r'''
48814885
#include <stdio.h>
48824886
extern void side();
@@ -4898,7 +4902,7 @@ def test_dylink_exceptions_try_catch(self):
48984902
printf("side: caught %.1f\n", f);
48994903
}
49004904
}
4901-
''', expected=['main: caught 3\nside: caught 5.3\n'])
4905+
''', expected=['main: caught 3\nside: caught 5.3\n'], cflags=args)
49024906

49034907
@with_all_eh_sjlj
49044908
@with_dylink_reversed

tools/js_manipulation.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,19 @@ def isidentifier(name):
107107

108108

109109
def make_dynCall(sig, args):
110-
# wasm2c and asyncify are not yet compatible with direct wasm table calls
111110
if settings.MEMORY64:
112111
args = list(args)
113112
args[0] = f'Number({args[0]})'
113+
# wasm2c and asyncify are not yet compatible with direct wasm table calls so use
114+
# the legacy DYNCALLS mechanism.
114115
if settings.DYNCALLS or not is_legal_sig(sig):
115116
args = ','.join(args)
116-
if not settings.MAIN_MODULE and not settings.SIDE_MODULE:
117-
# Optimize dynCall accesses in the case when not building with dynamic
118-
# linking enabled.
119-
return 'dynCall_%s(%s)' % (sig, args)
120-
else:
121-
return 'Module["dynCall_%s"](%s)' % (sig, args)
117+
if settings.MAIN_MODULE or settings.SIDE_MODULE:
118+
# In dynamic linking mode not all of the dynCall_xxx function are defined
119+
# in the main module so might not be available as global symbols.
120+
# See `registerDynCallSymbols` in `libdylink.js`.
121+
return "dynCalls['%s'](%s)" % (sig, args)
122+
return 'dynCall_%s(%s)' % (sig, args)
122123
else:
123124
call_args = ",".join(args[1:])
124125
return f'getWasmTableEntry({args[0]})({call_args})'

0 commit comments

Comments
 (0)