Skip to content

Commit 3aaf218

Browse files
committed
Register side module dynCall helpers even when loaded with RTLD_LOCAL
Fixes: #22587
1 parent 17463f7 commit 3aaf218

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

src/library_dylink.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,22 @@ var LibraryDylink = {
526526
return customSection;
527527
},
528528

529+
#if DYNCALLS || !WASM_BIGINT
530+
$registerDynCallSymbols: (exports) => {
531+
for (var [sym, exp] of Object.entries(exports)) {
532+
if (sym.startsWith('dynCall_') && !Module.hasOwnProperty(sym)) {
533+
Module[sym] = exp;
534+
}
535+
}
536+
},
537+
#endif
538+
529539
// Module.symbols <- libModule.symbols (flags.global handler)
530540
$mergeLibSymbols__deps: ['$isSymbolDefined'],
531541
$mergeLibSymbols: (exports, libName) => {
542+
#if DYNCALLS || !WASM_BIGINT
543+
registerDynCallSymbols(exports);
544+
#endif
532545
// add symbols into global namespace TODO: weak linking etc.
533546
for (var [sym, exp] of Object.entries(exports)) {
534547
#if ASSERTIONS == 2
@@ -571,10 +584,6 @@ var LibraryDylink = {
571584
setImport('main')
572585
}
573586
#endif
574-
575-
if (sym.startsWith('dynCall_') && !Module.hasOwnProperty(sym)) {
576-
Module[sym] = exp;
577-
}
578587
}
579588
},
580589

@@ -938,6 +947,9 @@ var LibraryDylink = {
938947
'$asyncLoad',
939948
#if FILESYSTEM
940949
'$preloadedWasm',
950+
#endif
951+
#if DYNCALLS || !WASM_BIGINT
952+
'$registerDynCallSymbols',
941953
#endif
942954
],
943955
$loadDynamicLibrary__docs: `
@@ -963,6 +975,9 @@ var LibraryDylink = {
963975
if (localScope) {
964976
Object.assign(localScope, dso.exports);
965977
}
978+
#if DYNCALLS || !WASM_BIGINT
979+
registerDynCallSymbols(dso.exports);
980+
#endif
966981
} else if (!dso.global) {
967982
// The library was previously loaded only locally but not
968983
// we have a request with global=true.
@@ -1046,6 +1061,9 @@ var LibraryDylink = {
10461061
mergeLibSymbols(exports, libName);
10471062
} else if (localScope) {
10481063
Object.assign(localScope, exports);
1064+
#if DYNCALLS || !WASM_BIGINT
1065+
registerDynCallSymbols(exports);
1066+
#endif
10491067
}
10501068
dso.exports = exports;
10511069
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6285
1+
6307
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13820
1+
13896

test/test_core.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4385,18 +4385,38 @@ def test_dylink_i64_c(self):
43854385
EMSCRIPTEN_KEEPALIVE int64_t function_ret_64(int32_t i, int32_t j, int32_t k);
43864386
''', force_c=True)
43874387

4388+
@parameterized({
4389+
'': (False,),
4390+
'rtld_local': (True,),
4391+
})
43884392
@needs_dylink
43894393
@also_with_wasm_bigint
4390-
def test_dylink_i64_invoke(self):
4394+
def test_dylink_i64_invoke(self, rtld_local):
4395+
if rtld_local:
4396+
self.set_setting('NO_AUTOLOAD_DYLIBS')
4397+
self.emcc_args.append('-DUSE_DLOPEN')
43914398
self.set_setting('DISABLE_EXCEPTION_CATCHING', 0)
43924399
self.dylink_test(r'''\
4400+
#include <assert.h>
43934401
#include <stdio.h>
43944402
#include <stdint.h>
43954403
4404+
#if USE_DLOPEN
4405+
#include <dlfcn.h>
4406+
typedef int64_t (*sidey_t)(int64_t arg);
4407+
#else
43964408
extern "C" int64_t sidey(int64_t arg);
4409+
#endif
43974410
43984411
int main(int argc, char *argv[]) {
43994412
int64_t temp = 42;
4413+
#if USE_DLOPEN
4414+
void* lib = dlopen("liblib.so", RTLD_LAZY);
4415+
assert(lib);
4416+
sidey_t sidey = (sidey_t)dlsym(lib, "sidey");
4417+
assert(sidey);
4418+
#endif
4419+
44004420
printf("got %lld\n", sidey(temp));
44014421
printf("got %lld\n", sidey(0));
44024422
return 0;

0 commit comments

Comments
 (0)