Skip to content

Commit e0b5f9f

Browse files
authored
Fix bug in dynCalls generation (#24797)
There are actually two different bug fixes here: 1. The deps for `dynCall` was not setup correctly in all cases 2. Addition to `dynCall` array from shared libraries were not being added. The code was incorrectly adding these to the `Module` object, which we stopped used for this purpose in #24399 These bugs went unnoticed because the test_dylink_i64_invoke test was not correctly being run without `WASM_BIGINT`. I have a followup to correctly / invert the `@also_with_wasm_bigint` decorator.
1 parent 1d05ff8 commit e0b5f9f

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/lib/libcore.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,11 +1735,14 @@ addToLibrary({
17351735
var f = dynCalls[sig];
17361736
return f(ptr, ...args);
17371737
},
1738-
#if DYNCALLS
1739-
$dynCall__deps: ['$dynCallLegacy'],
1740-
#else
1741-
$dynCall__deps: ['$getWasmTableEntry'],
1738+
$dynCall__deps: [
1739+
#if DYNCALLS || !WASM_BIGINT
1740+
'$dynCallLegacy',
17421741
#endif
1742+
#if !DYNCALLS
1743+
'$getWasmTableEntry',
1744+
#endif
1745+
],
17431746
#endif
17441747

17451748
// Used in library code to get JS function from wasm function pointer.

src/lib/libdylink.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,11 @@ var LibraryDylink = {
526526
#if DYNCALLS || !WASM_BIGINT
527527
$registerDynCallSymbols: (exports) => {
528528
for (var [sym, exp] of Object.entries(exports)) {
529-
if (sym.startsWith('dynCall_') && !Module.hasOwnProperty(sym)) {
530-
Module[sym] = exp;
529+
if (sym.startsWith('dynCall_')) {
530+
var sig = sym.substring(8);
531+
if (!dynCalls.hasOwnProperty(sig)) {
532+
dynCalls[sig] = exp;
533+
}
531534
}
532535
}
533536
},

test/test_core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4495,12 +4495,16 @@ def test_dylink_i64_c(self):
44954495
''', force_c=True)
44964496

44974497
@parameterized({
4498-
'': (False,),
4499-
'rtld_local': (True,),
4498+
'': [False],
4499+
'rtld_local': [True],
4500+
})
4501+
@parameterized({
4502+
'': [[]],
4503+
'nobigint': [['-sWASM_BIGINT=0']],
45004504
})
45014505
@needs_dylink
4502-
@also_with_wasm_bigint
4503-
def test_dylink_i64_invoke(self, rtld_local):
4506+
def test_dylink_i64_invoke(self, rtld_local, args):
4507+
self.cflags += args
45044508
if rtld_local:
45054509
self.set_setting('NO_AUTOLOAD_DYLIBS')
45064510
self.cflags.append('-DUSE_DLOPEN')

tools/emscripten.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,8 +918,8 @@ def should_export(sym):
918918
return settings.EXPORT_ALL or (settings.EXPORT_KEEPALIVE and sym in settings.EXPORTED_FUNCTIONS)
919919

920920

921-
def create_receiving(function_exports, tag_exports):
922-
generate_dyncall_assignment = settings.DYNCALLS and '$dynCall' in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE
921+
def create_receiving(function_exports, tag_exports, library_symbols):
922+
generate_dyncall_assignment = 'dynCalls' in library_symbols
923923
receiving = ['\n// Imports from the Wasm binary.']
924924

925925
if settings.WASM_ESM_INTEGRATION:
@@ -1006,10 +1006,10 @@ def create_receiving(function_exports, tag_exports):
10061006
return '\n'.join(receiving) + '\n'
10071007

10081008

1009-
def create_module(metadata, function_exports, global_exports, tag_exports,library_symbols):
1009+
def create_module(metadata, function_exports, global_exports, tag_exports, library_symbols):
10101010
module = []
10111011

1012-
receiving = create_receiving(function_exports, tag_exports)
1012+
receiving = create_receiving(function_exports, tag_exports, library_symbols)
10131013
receiving += create_global_exports(global_exports)
10141014
sending = create_sending(metadata, library_symbols)
10151015

0 commit comments

Comments
 (0)