gconstructor: Add attribute used for TLS callback pointer

This is needed to ensure that the pointer is not removed
by an optimization pass. Theoretically, we'd have to add
both 'used' and 'retain' attributes, however for PE targets
'used' includes the effect of 'retain' [1], and GCC warns
if 'retain' is used in PE targets.

Fixes the constructor test in LTO builds.

[1] https://reviews.llvm.org/D96838
This commit is contained in:
Luca Bacci
2025-08-20 14:00:38 +02:00
parent 99886f2d66
commit 004ff59828

View File

@@ -60,7 +60,7 @@ __pragma (comment (linker, "/INCLUDE:" G_MSVC_SYMBOL_PREFIX "_ptr_" #func))
static void NTAPI func (PVOID, DWORD, PVOID); \
\
G_BEGIN_DECLS \
__attribute__ ((section (".CRT$XLCE"))) \
__attribute__ ((section (".CRT$XLCE"), used)) \
G_EXTERN_CONST PIMAGE_TLS_CALLBACK _ptr_##func = func; \
G_END_DECLS