From 0f5c730d593f90cbecd9a4b2ba5eda8bda97b0c8 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Fri, 8 Apr 2022 15:54:49 -0700 Subject: [PATCH] Fix dyncall and dynamic linking We don't compile with WASM_BIGINT so if there is a 64 bit integer in the dynamic call, Emscripten tries to call a legalizer wrapper. These legalizer wrappers are only generated in the main module so sometimes a side module tries to call a wrapper that doesn't exist. This adds an extra handler in that case. --- src/library.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/library.js b/src/library.js index 401e17d086aa4..0178e64e1400d 100644 --- a/src/library.js +++ b/src/library.js @@ -3139,7 +3139,29 @@ LibraryManager.library = { // part of thier signature, so we rely the dynCall functions generated by // wasm-emscripten-finalize if (sig.includes('j')) { +#if MAIN_MODULE + if(Module["dynCall_" + sig]){ + return dynCallLegacy(sig, ptr, args); + } else { + let new_args = []; + for(let i = 0; i < sig.length; i++){ + if(sig[i + 1] === "j"){ + new_args.push((BigInt(args[i] || 0) | (BigInt(args[i+1] || 0) << BigInt(32)))); + i++; + } else { + new_args.push(args[i]); + } + } + let result = wasmTable.get(ptr).apply(null, new_args); + if(sig[0] !== "j"){ + return result; + } + setTempRet0(Number(result >> BigInt(32))); + return Number(result & BigInt(0xffffffff)); + } +#else return dynCallLegacy(sig, ptr, args); +#endif } #endif #if ASSERTIONS