emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.83k stars 3.31k forks source link

Random "function signature mismatch" with dynamic libraries + Embind #13026

Open donalffons opened 3 years ago

donalffons commented 3 years ago

I get the following error randomly in the console during WASM instantiation:

013bb9fa:0x305a8c Uncaught (in promise) RuntimeError: function signature mismatch
    at _ZN8Standard8AllocateEm (<anonymous>:wasm-function[1254]:0x305a8c)
    at obj.<computed> (https://emscripten-issue-dynamic-libraries-git-master.donalffons.vercel.app/node_modules/opencascade.js/dist/release/dynamic_web.js:9:24109)
    at <anonymous>:wasm-function[646]:0x851a6
    at __post_instantiate (<anonymous>:wasm-function[208]:0x69e67)
    at callRuntimeCallbacks (https://emscripten-issue-dynamic-libraries-git-master.donalffons.vercel.app/node_modules/opencascade.js/dist/release/dynamic_web.js:9:18919)
    at initRuntime (https://emscripten-issue-dynamic-libraries-git-master.donalffons.vercel.app/node_modules/opencascade.js/dist/release/dynamic_web.js:9:14373)
    at doRun (https://emscripten-issue-dynamic-libraries-git-master.donalffons.vercel.app/node_modules/opencascade.js/dist/release/dynamic_web.js:9:2985866)
    at run (https://emscripten-issue-dynamic-libraries-git-master.donalffons.vercel.app/node_modules/opencascade.js/dist/release/dynamic_web.js:9:2986173)
    at runCaller (https://emscripten-issue-dynamic-libraries-git-master.donalffons.vercel.app/node_modules/opencascade.js/dist/release/dynamic_web.js:9:2985225)
    at removeRunDependency (https://emscripten-issue-dynamic-libraries-git-master.donalffons.vercel.app/node_modules/opencascade.js/dist/release/dynamic_web.js:9:15584)

The project is one MAIN_MODULE with a total of 24 SIDE_MODULEs. The error does not seem to be deterministic. With less SIDE_MODULEs, it seems to occurr less frequently. Also, it seems to happen less often when I'm hosting this on localhost.

MAIN_MODULE has been built with the following parameters:

emcc
-fPIC
-s ENVIRONMENT='web'
-s EXPORT_ES6=1
-s USE_ES6_IMPORT_META=0
--bind [several files]
-s MAIN_MODULE=1
-s ALLOW_MEMORY_GROWTH=1
-s AGGRESSIVE_VARIABLE_ELIMINATION=1
-O3

SIDE_MODULEs have been built with

emcc
-fPIC
-s ENVIRONMENT='web'
-s EXPORT_ES6=1
-s USE_ES6_IMPORT_META=0
--bind [several files]
-s SIDE_MODULE=1
-s ALLOW_MEMORY_GROWTH=1
-s AGGRESSIVE_VARIABLE_ELIMINATION=1
-O3

The source code of the function mentioned in the error is here. Standard_Address is typedef'd as void*, Standard_Size is size_t.

Repo with a simplified test case. Deployment of the problematic test case.

Not sure if this is related, but: If I build the MAIN_MODULE and SIDE_MODULEs with -g3, I run into the exact same issue documented in #11458 (also seemingly occurring non-deterministically).

I already spent a lot of time, trying to narrow this down further, but I've run out of ideas. Is there anyone, who knows what I could do to fix this? I'm happy to help as much as I can.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.