emscripten-core / emscripten-core/emscripten

Remove `_` prefix/name mangling for native symbols

Open
#12,844 4 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

With the original JS compiler native symbols historically got prefixed with an `_`.

With fastcomp this tradition was continued with `JSBackend.cpp` adding extra `_` to all its exports.

With the llvm backend we still continue this mangling but only in the JS wrapper code. The actual exports from the wam module do not have this mangling but the wrapper code added this. See:

https://github.com/emscripten-core/emscripten/blob/119980fe4839b943599edf5cc222131db41c22ff/tools/shared.py#L736

and also the runtime equivalent:

https://github.com/emscripten-core/emscripten/blob/119980fe4839b943599edf5cc222131db41c22ff/src/jsifier.js#L27
https://github.com/emscripten-core/emscripten/blob/119980fe4839b943599edf5cc222131db41c22ff/src/jsifier.js#L32

We should try to phase this out over time.

I suggest we add a new setting called `MANGLE_NATIVE_SYMBOLS` which defaults to 1. We can then default this to `0 in STRICT mode and one day change the default for everyone.

Alternative names for this setting:

- `MANGLE_EXPORTS`
- `MANGLED_EXPORTS`
- `PREFIX_EXPORTS`

When this setting is enabled, EXPORTED_FUNCTIONS should also not contain the mangling so users would have to move from `EXPORTED_FUNCTIONS=[_main]` to `EXPORTED_FUNCTIONS=[main]`

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.