Skip to content

--no-entry is ignored when -sASSERTIONS is enabled #26047

@daniloarcidiacono

Description

@daniloarcidiacono

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:

  1. Create a C++ file containing a main function.
  2. Compile with em++ --no-entry -sASSERTIONS.
  3. The resulting Wasm binary/JS will still contain the main entry 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']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions