emscripten-core / emscripten-core/emscripten

IF YOU ARE EXPERIENCING SYMBOLS BEING STRIPPED NO MATTER WHAT YOU DO AND ARE GETTING LINKER ERRORS, READ THIS

Open
#22,730 2 comments 0 reactions 0 assignees View on GitHub
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:

![image](https://github.com/user-attachments/assets/022b6d4d-23dd-4f7a-a0fd-5d47802ca97d)

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

![image](https://github.com/user-attachments/assets/bfedb78b-8359-49c3-877f-29f6fd9815ae)

Previous issue(s): https://github.com/emscripten-core/emscripten/issues/6233

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.