emscripten-core / emscripten-core/emscripten
C++ static initialization + dynamic libraries lead to a function signature mismatch error
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
While using catch2 I stumbled on an error that basically prevents the usage of std::shared_ptr in dynamic libraries when used during static initialization.
After figuring out that the singletons in catch2 are responsible I could create a simple reproducing test case:
```C++
#include
extern int get_initial_value();
static int global_const = get_initial_value();
EMSCRIPTEN_KEEPALIVE int main() {
// get_initial_value(); call here works
return 0;
}
```
I compiled the main module as
` em++ -s MAIN_MODULE=1 main.cpp -o main.js -s RUNTIME_LINKED_LIBS=[side.wasm] `
```C++
// side
#include
#include
EMSCRIPTEN_KEEPALIVE int get_initial_value() {
std::shared_ptr p( new int() );
return 0;
}
```
and the side with
`em++ side.cpp -o side.wasm -s SIDE_MODULE=2 `
Running the executable results in a `RuntimeError: function signature mismatch` from a wasm call_indirect statement.
Any help is highly appreciated!
Contributor guide
Assessment
This issue has not been assessed yet.