diff --git a/AUTHORS b/AUTHORS index 213b805baa8e2..75fdda50b4ec7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -606,3 +606,4 @@ a license to everyone to use it as detailed in LICENSE.) * Abdelrahman Teima * Jaap Aarts * Dimokritos Kolitsos +* Bas van Dijk diff --git a/src/lib/libdylink.js b/src/lib/libdylink.js index 3d1c63d0362cd..45a27c5834c44 100644 --- a/src/lib/libdylink.js +++ b/src/lib/libdylink.js @@ -1307,27 +1307,22 @@ var LibraryDylink = { #if DYLINK_DEBUG dbg('dlsym_js:', symbol); #endif - var result; - var newSymIndex; - var lib = LDSO.loadedLibsByHandle[handle]; #if ASSERTIONS assert(lib, `Tried to dlsym() from an unopened handle: ${handle}`); #endif - newSymIndex = Object.keys(lib.exports).indexOf(symbol); - if (newSymIndex == -1 || lib.exports[symbol].stub) { + if (!hasOwn(lib.exports, symbol) || lib.exports[symbol].stub) { dlSetError(`Tried to lookup unknown symbol "${symbol}" in dynamic lib: ${lib.name}`) return 0; } + var exportName = symbol; #if !WASM_BIGINT var origSym = 'orig$' + symbol; - result = lib.exports[origSym]; - if (result) { - newSymIndex = Object.keys(lib.exports).indexOf(origSym); + if (lib.exports[origSym]) { + exportName = origSym; } - else #endif - result = lib.exports[symbol]; + var result = lib.exports[exportName]; if (typeof result === 'function') { #if DYLINK_DEBUG @@ -1355,6 +1350,10 @@ var LibraryDylink = { #if DYLINK_DEBUG dbg('adding symbol to table:', symbol); #endif + // Other threads replay this insertion by the symbol's enumeration index + // (`_dlsym_catchup_js`). Using `indexOf` here is O(N), + // so only do so when a slot was actually allocated. + var newSymIndex = Object.keys(lib.exports).indexOf(exportName); {{{ makeSetValue('symbolIndex', 0, 'newSymIndex', '*') }}}; } } diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index 0c03a480d8bfd..6826cfa3a0965 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { - "a.out.js": 272930, + "a.out.js": 272950, "a.out.nodebug.wasm": 589512, - "total": 862442, + "total": 862462, "sent": [ "IMG_Init", "IMG_Load",