Globally enable linker dead-code elimination on Unix#128232
Conversation
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/runtime-infrastructure |
Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the native build configuration (eng/native/configurecompiler.cmake) to enable link-time dead-code elimination (section GC) by default on non-Windows Unix builds, and ensures compilation places both functions and data into separate sections to make that elimination effective.
Changes:
- Add global non-Debug linker flags to strip unused sections (
-Wl,-dead_stripon Apple,-Wl,--gc-sectionselsewhere). - Add
-fdata-sectionsalongside the existing-ffunction-sectionsfor Unix/WASI compilation. - Update nearby comments to describe the function/data sectioning intent.
Show a summary per file
| File | Description |
|---|---|
| eng/native/configurecompiler.cmake | Enables global link-time section GC on Unix non-Debug builds and adds -fdata-sections to support stripping unused data. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 3
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot what is the size delta on linux for runtime binaries (in particular coreclr and apphost) with this change? |
I'm unable to run a full Linux build in this environment to produce actual measurements. What I can say:
If you can kick off a CI build or a local linux-x64 Release build comparing |
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
-ffunction-sections is set globally for non-MSVC builds in eng/native/configurecompiler.cmake, but the matching -Wl,--gc-sections / -Wl,-dead_strip is never passed to the linker, so on Linux/macOS unreferenced sections are not actually stripped. Windows is unaffected because /OPT:REF is set globally. This became visible in #126367 when apphost picked up a dn-containers link dependency and grew unexpectedly.
cc @dotnet/appmodel @jkotas
eng/native/configurecompiler.cmake:-fdata-sectionsalongside the existing-ffunction-sections(Unix/WASI) so unreferenced data, not just functions, can be stripped.-Wl,-dead_stripfor Checked / Release / RelWithDebInfo.-Wl,--gc-sectionsfor the same three configurations.-Wl,--no-gc-sectionsdebug+sanitizers workaround.Targets that need specific symbols retained can still opt out per-symbol via
KEEP/__attribute__((used))/ export lists;-fvisibility=hiddenplus existing export lists already cover the common cases.