emscripten-core / emscripten-core/emscripten
IF YOU ARE EXPERIENCING SYMBOLS BEING STRIPPED NO MATTER WHAT YOU DO AND ARE GETTING LINKER ERRORS, READ THIS
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I've been creating an empscripten WASM target for FastLED.
earlier this week today i've been intensively investigating symbols not showing up.
### Let me just skip right to the point
Clang is stripping out your symbols *before* they are getting to the linker. Our exports were in one .cpp file.
Here's what's happening: clang is really aggressive in *eliminating* object files that aren't being referenced by other objects/libs (as of trzeci/emscripten:1.39.17-upstream).
EMSCRIPTEN_KEEPALIVE appears to be powerless here.. Telling the linker the symbols exist does nothing in orphaned object files. Clang will tree shake the exports out.
Here's a quick solution that worked for *this* project.
* Put all your exports into a *.hpp.
* Include this exports.hpp into one of your main cpp files.
Happy coding!
### Repro Case
git clone github.com/fastled/fastled
Check out this commit.
5d0c06e3e8e2a6dc19b21263c2360839ac818c2c
Then run this command:
`uv run ci/wasm_compile.py -b examples/wasm`
When the build is done a browser window will pop open and you'll see this, missing symbols for extern_setup and extern_loop:

Anytime after we applied the fix, you should see something like this:

Previous issue(s): https://github.com/emscripten-core/emscripten/issues/6233
Contributor guide
Assessment
This issue has not been assessed yet.