Skip to content

Make sure -sSIDE_MODULE=1 passes --whole-archive to linker - #27430

Closed
hoodmane wants to merge 1 commit into
emscripten-core:mainfrom
hoodmane:side-module-1-whole-archive
Closed

hoodmane wants to merge 1 commit into
emscripten-core:mainfrom
hoodmane:side-module-1-whole-archive

Conversation

@hoodmane

Copy link
Copy Markdown
Collaborator

This fixes a regression introduced in #25930. Closes #27403.

@hoodmane

Copy link
Copy Markdown
Collaborator Author

Well that doesn't pass CI...

@sbc100

sbc100 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

So you are suggesting the -sSIDE_MODULE=1 should use --whole-archive and -sSIDE_MODULE=2 should not. That does indeed seem reasonable to me.

What kind of side modules are you building that require this? Could you switch to just using -shared instead? We are trying to make the semantics of -shared march the behaviour on native platforms.

@sbc100

sbc100 commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

I think I tracked down the issue and came up with an alternative fix: #28055

sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 23, 2026
In emscripten-core#25930, `-shared` was implemented by defaulting `SIDE_MODULE` to `1`
(which implies `LINKABLE=1`) and then special-casing `lld_flags` in
`tools/building.py` to avoid `--whole-archive`. That special case had
the unintended regression of also disabling `--whole-archive` for
explicit `-sSIDE_MODULE=1` builds, while still running `wasm-ld` twice
in `phase_link` for `-shared` due to `LINKABLE=1`.

Instead, default `SIDE_MODULE` to `2` when `-shared` is used so
`LINKABLE` remains disabled and `--whole-archive` is applied whenever
`LINKABLE` is set. This restores the pre-emscripten-core#25930 `--whole-archive`
behavior for `-sSIDE_MODULE=1` without enabling it for `-shared`.

To keep native linker semantics for `-shared`, avoid passing
`--no-export-dynamic` when `-shared` is specified so default-visibility
symbols in object files are still exported automatically (unlike
explicit `-sSIDE_MODULE=2`, which continues to DCE unexported symbols).

Supersedes emscripten-core#27430.

Fixes: emscripten-core#27403
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 23, 2026
In emscripten-core#25930, `-shared` was implemented by defaulting `SIDE_MODULE` to `1`
(which implies `LINKABLE=1`) and then special-casing `lld_flags` in
`tools/building.py` to avoid `--whole-archive`. That special case had
the unintended regression of also disabling `--whole-archive` for
explicit `-sSIDE_MODULE=1` builds, while still running `wasm-ld` twice
in `phase_link` for `-shared` due to `LINKABLE=1`.

Instead, default `SIDE_MODULE` to `2` when `-shared` is used so
`LINKABLE` remains disabled and `--whole-archive` is applied whenever
`LINKABLE` is set. This restores the pre-emscripten-core#25930 `--whole-archive`
behavior for `-sSIDE_MODULE=1` without enabling it for `-shared`.

To keep native linker semantics for `-shared`, avoid passing
`--no-export-dynamic` when `-shared` is specified so default-visibility
symbols in object files are still exported automatically (unlike
explicit `-sSIDE_MODULE=2`, which continues to DCE unexported symbols).

Supersedes emscripten-core#27430.

Fixes: emscripten-core#27403
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 23, 2026
In emscripten-core#25930, `-shared` was implemented by defaulting `SIDE_MODULE` to `1`
(which implies `LINKABLE=1`) and then special-casing `lld_flags` in
`tools/building.py` to avoid `--whole-archive`. That special case had
the unintended regression of also disabling `--whole-archive` for
explicit `-sSIDE_MODULE=1` builds, while still running `wasm-ld` twice
in `phase_link` for `-shared` due to `LINKABLE=1`.

Instead, default `SIDE_MODULE` to `2` when `-shared` is used so
`LINKABLE` remains disabled and `--whole-archive` is applied whenever
`LINKABLE` is set. This restores the pre-emscripten-core#25930 `--whole-archive`
behavior for `-sSIDE_MODULE=1` without enabling it for `-shared`.

To keep native linker semantics for `-shared`, avoid passing
`--no-export-dynamic` when `-shared` is specified so default-visibility
symbols in object files are still exported automatically (unlike
explicit `-sSIDE_MODULE=2`, which continues to DCE unexported symbols).

Supersedes emscripten-core#27430.

Fixes: emscripten-core#27403
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 23, 2026
In emscripten-core#25930, `-shared` was implemented by defaulting `SIDE_MODULE` to `1`
(which implies `LINKABLE=1`) and then special-casing `lld_flags` in
`tools/building.py` to avoid `--whole-archive`. That special case had
the unintended regression of also disabling `--whole-archive` for
explicit `-sSIDE_MODULE=1` builds, while still running `wasm-ld` twice
in `phase_link` for `-shared` due to `LINKABLE=1`.

Instead, default `SIDE_MODULE` to `2` when `-shared` is used so
`LINKABLE` remains disabled and `--whole-archive` is applied whenever
`LINKABLE` is set. This restores the pre-emscripten-core#25930 `--whole-archive`
behavior for `-sSIDE_MODULE=1` without enabling it for `-shared`.

To keep native linker semantics for `-shared`, avoid passing
`--no-export-dynamic` when `-shared` is specified so default-visibility
symbols in object files are still exported automatically (unlike
explicit `-sSIDE_MODULE=2`, which continues to DCE unexported symbols).

Supersedes emscripten-core#27430.

Fixes: emscripten-core#27403
sbc100 added a commit to sbc100/emscripten that referenced this pull request Oct 27, 2026
In emscripten-core#25930, `-shared` was implemented by defaulting `SIDE_MODULE` to `1`
(which implies `LINKABLE=1`) and then special-casing `lld_flags` in
`tools/building.py` to avoid `--whole-archive`. That special case had
the unintended regression of also disabling `--whole-archive` for
explicit `-sSIDE_MODULE=1` builds, while still running `wasm-ld` twice
in `phase_link` for `-shared` due to `LINKABLE=1`.

Instead, default `SIDE_MODULE` to `2` when `-shared` is used so
`LINKABLE` remains disabled and `--whole-archive` is applied whenever
`LINKABLE` is set. This restores the pre-emscripten-core#25930 `--whole-archive`
behavior for `-sSIDE_MODULE=1` without enabling it for `-shared`.

To keep native linker semantics for `-shared`, avoid passing
`--no-export-dynamic` when `-shared` is specified so default-visibility
symbols in object files are still exported automatically (unlike
explicit `-sSIDE_MODULE=2`, which continues to DCE unexported symbols).

Supersedes emscripten-core#27430.

Fixes: emscripten-core#27403
@sbc100

sbc100 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Closing in favor of #28055

@sbc100 sbc100 closed this Oct 27, 2026
sbc100 added a commit that referenced this pull request Oct 27, 2026
#28055)

In #25930, `-shared` was implemented by defaulting `SIDE_MODULE` to `1`
(which implies `LINKABLE=1`) and then special-casing `lld_flags` in
`tools/building.py` to avoid `--whole-archive`. That special case had
the unintended regression of also disabling `--whole-archive` for
explicit `-sSIDE_MODULE=1` builds, while still running `wasm-ld` twice
in `phase_link` for `-shared` due to `LINKABLE=1`.

Instead, default `SIDE_MODULE` to `2` when `-shared` is used so
`LINKABLE` remains disabled and `--whole-archive` is applied whenever
`LINKABLE` is set. This restores the pre-#25930 `--whole-archive`
behavior for `-sSIDE_MODULE=1` without enabling it for `-shared`.

To keep native linker semantics for `-shared`, avoid passing
`--no-export-dynamic` when `-shared` is specified so default-visibility
symbols in object files are still exported automatically (unlike
explicit `-sSIDE_MODULE=2`, which continues to DCE unexported symbols).

Supersedes #27430.

Fixes: #27403
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trouble with emcc 6.0.0 from #25930

2 participants