Repository navigation
[dylink] Restore --whole-archive when linking with -sSIDE_MODULE=1 - #28055
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the behavior of the -shared flag in Emscripten to better match native linker behavior regarding static archives and symbol exports, distinguishing it from -sSIDE_MODULE=1 and -sSIDE_MODULE=2. It updates documentation, changes the default SIDE_MODULE setting from 1 to 2 when linking shared libraries, and adds comprehensive tests. Feedback on the changes suggests adding a defensive check for cmdline.options in tools/building.py to avoid a potential AttributeError in environments where command-line options are not initialized.
bb2be82 to
203a550
Compare
|
What happens if |
Sure, that sounds reasonable. |
849e531 to
6f27d59
Compare
|
|
||
| if options.shared and not settings.FAKE_DYLIBS: | ||
| default_setting('SIDE_MODULE', 1) | ||
| default_setting('SIDE_MODULE', 2) |
There was a problem hiding this comment.
Doesn't this cause a large change in behavior? I mean, aside from the whole-archive stuff, can't things now break if they aren't exported and we dce them away?
There was a problem hiding this comment.
We export all dynamic symbols in options.shared mode (because we don't pass --no-export-dynamic like we do in -sSIDE_MODULE=2 mode).
I've tried to document this behaviour. Basically -shared works like it does on native platforms which is kind of half way between our =1 and =2 modes.
This change restores =1 the behaviour to before #25930 while keeping the -shared behaviour constant IIUC.
There was a problem hiding this comment.
I see, thanks. Well, no objections from me, but I am not an expert on our dynamic linking code - lgtm if @hoodmane approves
|
@hoodmane OK to land this? |
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
6f27d59 to
7cd837f
Compare
hoodmane
left a comment
There was a problem hiding this comment.
Yeah makes sense to me. Thanks!
In #25930,
-sharedwas implemented by defaultingSIDE_MODULEto1(which impliesLINKABLE=1) and then special-casinglld_flagsintools/building.pyto avoid--whole-archive. That special case had the unintended regression of also disabling--whole-archivefor explicit-sSIDE_MODULE=1builds, while still runningwasm-ldtwice inphase_linkfor-shareddue toLINKABLE=1.Instead, default
SIDE_MODULEto2when-sharedis used soLINKABLEremains disabled and--whole-archiveis applied wheneverLINKABLEis set. This restores the pre-#25930--whole-archivebehavior for-sSIDE_MODULE=1without enabling it for-shared.To keep native linker semantics for
-shared, avoid passing--no-export-dynamicwhen-sharedis 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