Globally enable linker dead-code elimination on Unix#128232
Draft
Copilot wants to merge 3 commits into
Draft
Conversation
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
elinor-fung
May 14, 2026 22:26
View session
Contributor
|
Tagging subscribers to this area: @dotnet/runtime-infrastructure |
am11
reviewed
May 14, 2026
Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Contributor
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
Comment on lines
+324
to
+333
| # Strip unreferenced sections at link time, paired with -ffunction-sections/-fdata-sections | ||
| # (set in the Unix/WASI compile-options block below). Gated to non-Debug builds so Debug | ||
| # keeps full symbols and incremental linking. Windows uses /OPT:REF, configured above. | ||
| if(CLR_CMAKE_HOST_UNIX) | ||
| if(CLR_CMAKE_HOST_APPLE) | ||
| add_linker_flag($<$<CONFIG:CHECKED,RELEASE,RELWITHDEBINFO>:-Wl,-dead_strip>) | ||
| else() | ||
| add_linker_flag($<$<CONFIG:CHECKED,RELEASE,RELWITHDEBINFO>:-Wl,--gc-sections>) | ||
| endif() | ||
| endif() |
This was referenced May 15, 2026
Open
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+327
to
+333
| if(CLR_CMAKE_HOST_UNIX) | ||
| if(CLR_CMAKE_HOST_APPLE) | ||
| add_linker_flag(-Wl,-dead_strip CHECKED RELEASE RELWITHDEBINFO) | ||
| else() | ||
| add_linker_flag(-Wl,--gc-sections CHECKED RELEASE RELWITHDEBINFO) | ||
| endif() | ||
| endif() |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #128228 per this review comment: flip
--gc-sections/-dead_stripglobally inconfigurecompiler.cmakeinstead of opting in per binary, mirroring the existing global/OPT:REFon Windows.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.Goes broader than #128228 (which scoped this to
apphost/dotnet/nethost). Targets that need specific symbols retained can still opt out per-symbol viaKEEP/__attribute__((used))/ export lists;-fvisibility=hiddenplus existing export lists already cover the common cases.