-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.22 (0f3d2e6)
clang version 22.0.0git (https:/github.com/llvm/llvm-project c7706d9472fe880ba1d3418919ad4185710c9559)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\opt\emsdk\upstream\bin
Description
In Emscripten 4.0+, the linker logic in phase_linker_setup contains a block intended to help users by force-exporting main in assertion builds so that a warning can be issued if it is missing. However, this block does not check if the user explicitly requested a build with no entry point via --no-entry.
By adding main to EXPORT_IF_DEFINED, the linker is forced to resolve the main symbol. If a main function exists in the object files (even if intended only for native tests), it is pulled into the Wasm binary, effectively ignoring the --no-entry flag.
Location:
tools/link.py (~line 1095):
elif settings.ASSERTIONS and not settings.STANDALONE_WASM:
settings.EXPORT_IF_DEFINED += ['main', '__main_argc_argv']Steps to Reproduce:
- Create a C++ file containing a
mainfunction. - Compile with
em++ --no-entry -sASSERTIONS. - The resulting Wasm binary/JS will still contain the
mainentry point logic.
Actual Behavior:
The linker treats main as a required export, pulling it into the binary despite --no-entry.
Expected Behavior:
If options.no_entry is set (which sets settings.EXPECT_MAIN = 0), the compiler should not force-export main for assertion warnings.
Suggested Fix:
Update the conditional in tools/link.py to respect settings.EXPECT_MAIN:
elif settings.ASSERTIONS and not settings.STANDALONE_WASM and settings.EXPECT_MAIN:
settings.EXPORT_IF_DEFINED += ['main', '__main_argc_argv']