Commit eb6a878
Globally enable linker dead-code elimination on Unix (#128232)
-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.
`eng/native/configurecompiler.cmake`:
- **Compile**: add `-fdata-sections` alongside the existing
`-ffunction-sections` (Unix/WASI) so unreferenced data, not just
functions, can be stripped.
- **Link, Apple**: `-Wl,-dead_strip` for Checked / Release /
RelWithDebInfo.
- **Link, other Unix **:
`-Wl,--gc-sections` for the same three configurations.
- **Debug**: untouched, matching Windows configuration
Targets that need specific symbols retained can still opt out per-symbol
via `KEEP` / `__attribute__((used))` / export lists;
`-fvisibility=hidden` plus existing export lists already cover the
common cases.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: Elinor Fung <elfung@microsoft.com>
Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>1 parent a49d0cf commit eb6a878
1 file changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
740 | 740 | | |
741 | 741 | | |
742 | 742 | | |
743 | | - | |
| 743 | + | |
| 744 | + | |
744 | 745 | | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
745 | 752 | | |
746 | 753 | | |
747 | 754 | | |
| |||
0 commit comments