diff --git a/src/library_dylink.js b/src/library_dylink.js index f9f088d5e379..da269a48b9fc 100644 --- a/src/library_dylink.js +++ b/src/library_dylink.js @@ -526,9 +526,22 @@ var LibraryDylink = { return customSection; }, +#if DYNCALLS || !WASM_BIGINT + $registerDynCallSymbols: (exports) => { + for (var [sym, exp] of Object.entries(exports)) { + if (sym.startsWith('dynCall_') && !Module.hasOwnProperty(sym)) { + Module[sym] = exp; + } + } + }, +#endif + // Module.symbols <- libModule.symbols (flags.global handler) $mergeLibSymbols__deps: ['$isSymbolDefined'], $mergeLibSymbols: (exports, libName) => { +#if DYNCALLS || !WASM_BIGINT + registerDynCallSymbols(exports); +#endif // add symbols into global namespace TODO: weak linking etc. for (var [sym, exp] of Object.entries(exports)) { #if ASSERTIONS == 2 @@ -571,10 +584,6 @@ var LibraryDylink = { setImport('main') } #endif - - if (sym.startsWith('dynCall_') && !Module.hasOwnProperty(sym)) { - Module[sym] = exp; - } } }, @@ -938,6 +947,9 @@ var LibraryDylink = { '$asyncLoad', #if FILESYSTEM '$preloadedWasm', +#endif +#if DYNCALLS || !WASM_BIGINT + '$registerDynCallSymbols', #endif ], $loadDynamicLibrary__docs: ` @@ -963,6 +975,9 @@ var LibraryDylink = { if (localScope) { Object.assign(localScope, dso.exports); } +#if DYNCALLS || !WASM_BIGINT + registerDynCallSymbols(dso.exports); +#endif } else if (!dso.global) { // The library was previously loaded only locally but not // we have a request with global=true. @@ -1046,6 +1061,9 @@ var LibraryDylink = { mergeLibSymbols(exports, libName); } else if (localScope) { Object.assign(localScope, exports); +#if DYNCALLS || !WASM_BIGINT + registerDynCallSymbols(exports); +#endif } dso.exports = exports; } diff --git a/test/other/codesize/test_codesize_hello_dylink.gzsize b/test/other/codesize/test_codesize_hello_dylink.gzsize index 190e05fb52d2..b7f6d0eb72bf 100644 --- a/test/other/codesize/test_codesize_hello_dylink.gzsize +++ b/test/other/codesize/test_codesize_hello_dylink.gzsize @@ -1 +1 @@ -6285 +6307 diff --git a/test/other/codesize/test_codesize_hello_dylink.jssize b/test/other/codesize/test_codesize_hello_dylink.jssize index 61d1af505618..f238adcd67c2 100644 --- a/test/other/codesize/test_codesize_hello_dylink.jssize +++ b/test/other/codesize/test_codesize_hello_dylink.jssize @@ -1 +1 @@ -13820 +13896 diff --git a/test/test_core.py b/test/test_core.py index 846725e7a4ff..bb868f07dbf0 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -4385,18 +4385,38 @@ def test_dylink_i64_c(self): EMSCRIPTEN_KEEPALIVE int64_t function_ret_64(int32_t i, int32_t j, int32_t k); ''', force_c=True) + @parameterized({ + '': (False,), + 'rtld_local': (True,), + }) @needs_dylink @also_with_wasm_bigint - def test_dylink_i64_invoke(self): + def test_dylink_i64_invoke(self, rtld_local): + if rtld_local: + self.set_setting('NO_AUTOLOAD_DYLIBS') + self.emcc_args.append('-DUSE_DLOPEN') self.set_setting('DISABLE_EXCEPTION_CATCHING', 0) self.dylink_test(r'''\ + #include #include #include + #if USE_DLOPEN + #include + typedef int64_t (*sidey_t)(int64_t arg); + #else extern "C" int64_t sidey(int64_t arg); + #endif int main(int argc, char *argv[]) { int64_t temp = 42; + #if USE_DLOPEN + void* lib = dlopen("liblib.so", RTLD_LAZY); + assert(lib); + sidey_t sidey = (sidey_t)dlsym(lib, "sidey"); + assert(sidey); + #endif + printf("got %lld\n", sidey(temp)); printf("got %lld\n", sidey(0)); return 0;