emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.75k stars 3.3k forks source link

dynamic_cast return 0 across modules (dynamic linking) when -fvisibility=hidden is used #17698

Open Stuonts opened 2 years ago

Stuonts commented 2 years ago

Version of emscripten/emsdk: 3.1.15

This issue causes problems in a large project when it is ported to WASM + dynamic linking causing unexpected failures requiring debugging. It can be fixed if attribute ((visibility("default"))) is added to IInterface and CClass.

Tried --export-dynamic and it doesn't help.

dynamic_cast_issue.zip sources are attached in archive build.bat contains commands to build

sbc100 commented 2 years ago

I think this would happen with gcc and clang too if you used -fvisibility=hidden wouldn't it?

Stuonts commented 1 year ago

We have a large project on Mac (built with clang) with the same codebase and some bugs occur on Emscripten while the same code (using dynamic_cast) works on Mac

Also, we checked basically the same small example on Mac and dynamic_cast works across modules

    CClass *c = dynamic_cast<CClass *>(i);
    if (c) 
        std::cout << "success" << std::endl;
    else
        std::cout << "fail" << std::endl;

this dynamic_cast from lib2.cpp works on Mac (built on clang) while fails on Emscripten