emscripten-core / emscripten-core/emscripten
Random "function signature mismatch" with dynamic libraries + Embind
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I get the following error randomly in the console during WASM instantiation:
```
013bb9fa:0x305a8c Uncaught (in promise) RuntimeError: function signature mismatch
at _ZN8Standard8AllocateEm (:wasm-function[1254]:0x305a8c)
at obj. (https://emscripten-issue-dynamic-libraries-git-master.donalffons.vercel.app/node_modules/opencascade.js/dist/release/dynamic_web.js:9:24109)
at :wasm-function[646]:0x851a6
at __post_instantiate (: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](https://git.dev.opencascade.org/gitweb/?p=occt.git;a=blob;f=src/Standard/Standard.cxx;h=78b25e1cb771e8916585cfed94288123a5314753;hb=HEAD#l238). `Standard_Address` is typedef'd as `void*`, `Standard_Size` is `size_t`.
[Repo with a simplified test case.](https://github.com/donalffons/emscripten-issue-dynamic-libraries)
[Deployment of the problematic test case.](https://emscripten-issue-dynamic-libraries-git-master.donalffons.vercel.app/)
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.
Contributor guide
Assessment
This issue has not been assessed yet.