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

  • Preventing garbage collection of these symbols ensures correctness for PE executables but may slightly increase the size of executables that do not use TLS or specific load configurations.
  • Correctly handling symbol garbage collection in conjunction with indirect references and specific file formats is complex.

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 and load config symbols from GC
tldr
Patch prevents linker garbage collection of `_tls_used` and `_load_config_used` symbols for mingw-w64 PE targets.
proposer
LIU Hao <lh_mouse@126.com>
consensus
Proposed
outcome
proposed
sentiment_score
8
technical_tradeoffs
  • Preventing garbage collection of these symbols ensures correctness for PE executables but may slightly increase the size of executables that do not use TLS or specific load configurations.
  • Correctly handling symbol garbage collection in conjunction with indirect references and specific file formats is complex.
series_id
series_role
standalone
series_parts
[]
tags
  • linker
  • mingw
  • pe
  • tls
  • 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 addresses an issue where the linker (ld) with --gc-sections would garbage-collect symbols like _tls_used and _load_config_used on mingw-w64 PE targets. These symbols are necessary for the PE header at runtime and must not be collected. The change adds these symbols to the list of names that should not be garbage-collected, ensuring executables remain functional.