ld: Prevent `_tls_used` and `_load_config_used` from being garbage-collected
Project / Subsystem
binutils / ld
Date
2026-07-27
Proposer
LIU Hao <lh_mouse@126.com>
Source type
public_inbox
Consensus
Proposed
Sentiment
8/10
Technical tradeoffs
- • Prevents executable corruption on Windows by retaining essential symbols.
- • Slightly increases executable size by ensuring `_tls_used` and `_load_config_used` are not garbage collected.
All attributes
- project
- binutils
- subsystem
- ld
- patch_id
- —
- discussion_id
- 8eb0155d-cbb3-4780-a81f-c360aa27bdde@126.com
- source_type
- public_inbox
- title
- ld: Prevent `_tls_used` and `_load_config_used` from being garbage-collected
- headline
- ld: Prevent `_tls_used` and `_load_config_used` from being garbage-collected
- tldr
- Prevents linker garbage collection of `_tls_used` and `_load_config_used` symbols on Windows, fixing broken executables.
- proposer
- LIU Hao <lh_mouse@126.com>
- consensus
- Proposed
- outcome
- proposed
- sentiment_score
- 8
- technical_tradeoffs
-
- • Prevents executable corruption on Windows by retaining essential symbols.
- • Slightly increases executable size by ensuring `_tls_used` and `_load_config_used` are not garbage collected.
- series_id
- —
- series_role
- standalone
- series_parts
- []
- tags
-
- • ld
- • linker
- • windows
- • mingw
- • gc-sections
- bugzilla_url
- —
- date
- 2026-07-27T00:00:00.000Z
ld: Prevent `_tls_used` and `_load_config_used` from being garbage-collected
This patch prevents the ld linker from garbage-collecting the _tls_used and _load_config_used symbols when the --gc-sections option is used. These symbols are crucial for the PE executable format on Windows, as their Relative Virtual Addresses (RVAs) are written into the PE header. Recent changes in mingw-w64 made these symbols only linked on demand, leading to their removal by garbage collection and resulting in broken executables. The patch adds these symbols to a list that ld will not garbage-collect, ensuring correct executable generation.