Prevent TLS and load config symbols from being garbage collected
Prevents `_tls_used` and `_load_config_used` symbols from being removed by garbage collection in PE executables.
This change prevents the linker from garbage-collecting _tls_used and _load_config_used symbols in PE executables. These symbols are crucial for optional TLS directory linking in mingw-w64. Without this change, data sections containing these symbols could be removed if not otherwise referenced, leading to broken executables when TLS is used.
In Details
The PE linker emulation in ld/emultempl/pe.em and ld/emultempl/pep.em has been modified to prevent garbage collection of __tls_used and _load_config_used. These symbols are necessary for the mingw-w64 TLS directory to be linked on demand. By ensuring these symbols are not stripped, executables relying on this mechanism will function correctly. This addresses a potential issue where otherwise unused data sections containing these symbols could be removed by --gc-sections.
- TLS
- Thread-Local Storage. A mechanism that provides each thread in a process with its own private copy of data.
- PE executable
- Portable Executable. The file format used for executables, DLLs, and object files on 32-bit and 64-bit versions of Windows.
- `_tls_used`
- A symbol that indicates the presence of Thread-Local Storage in an executable. It is used by the linker to ensure that the TLS directory is properly included in the PE header.
- `_load_config_used`
- A symbol related to the Load Configuration Directory in PE executables, which contains information about security and other runtime configurations.
- garbage collection (GC)
- A memory management technique where the runtime automatically reclaims memory that is no longer in use. In the context of linkers,
--gc-sectionsremoves unused sections of code or data.