emscripten-core / emscripten-core/emscripten
Signature mismatch between side and main module with flto
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Enabling LTO in the side module breaks the loading of the side module. To reproduce the error one can use the following code:
`catch.hpp:`
```c++
#include
#include
#include "emscripten.h"
// Part of catch2 lib that reproduces error
class StreamBufImpl : public std::streambuf {
public:
StreamBufImpl() = default;
};
class DebugOutStream {
StreamBufImpl m_streamBuf;
public:
DebugOutStream() : m_streamBuf() {}
};
auto makeStream() -> auto const* {
return new DebugOutStream();
}
```
`main_catch2.cpp:`
```c++
#include "catch.hpp"
EMSCRIPTEN_KEEPALIVE
int main( int argc, char* argv[] ) {
return EXIT_SUCCESS;
}
```
`Test_Impl.cpp:`
```c++
#include "catch.hpp"
EMSCRIPTEN_KEEPALIVE extern "C" void func() {}
```
Compiling with
`em++ -fPIC -flto -O0 -o libmain_catch2.so -sSIDE_MODULE=1 main_catch2.cpp && em++ -flto -O0 -sMAIN_MODULE=2 -sEXPORTED_FUNCTIONS=_func -sASSERTIONS=2 Test_Impl.cpp -o Test.js libmain_catch2.so`
leads to a runtime Error: `[LinkError: WebAssembly.instantiate(): Import #8 module="env" function="_ZNSt3__215basic_streambufIcNS_11char_traitsIcEEE7seekoffExNS_8ios_base7seekdirEj" error: imported function does not match the expected type]`.
em++ --version: 3.1.64
node --version: v18.20.3
Contributor guide
Assessment
This issue has not been assessed yet.