[PATCH] ld/pe-dll: Don't auto-export symbols from .tls section

LIU Hao lh_mouse@126.com
Tue Dec 9 12:00:38 GMT 2025
在 2025-12-9 19:18, Jan Beulich 写道:
> What would prevent .tls (without the $) to be used (e.g. by assembly code)?
> The linker script templates certainly cover that flavor of the section, too.
> Plus, do we need to go by name, i.e. is BSF_THREAD_LOCAL not suitably used?
> (Looks like except for cofflink.c COFF and PE source files really don't use
> the flag, including gas'es obj-coff.c.) At the very least that aspect
> would imo want ...

For an image, TLS template data must be consecutively placed in the range 
[`_tls_used.StartAddressOfRawData`, `_tls_used.EndAddressOfRawData`). In mingw-w64 `_tls_used` is defined 
in tlssup.c, and in Microsoft CRT it's in tlssup.cpp, same pattern.

Therefore, all TLS template data must be placed between these subsections:

    _CRTALLOC(".tls") char *_tls_start = NULL;
    _CRTALLOC(".tls$ZZZ") char *_tls_end = NULL;

A compiler should not generate a variable in `.tls` since it would be possibly sorted before 
`_tls_start`. Likewise, a compiler should not generate a variable in `.tls$_some_var` since it would be 
sorted after `_tls_end`.

When `-fdata-section` is not used, GCC 16 generates TLS data in `.tls$`; and when this option is used, 
GCC generates them in `.tls$$<symbol>` like Clang, which happen to be sorted before `tls$ZZZ`. It's not 
technically required that they be placed in a separate section, but due to the `@secrel` modifier, they 
must be in the beginning of a section. TLS template data are not otherwise special.




-- 
Best regards,
LIU Hao
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://sourceware.org/pipermail/binutils/attachments/20251209/30e80f92/attachment.sig>


More information about the Binutils mailing list