From 004ff59828607ccfe3b28aa9ee79bffdcae5bf48 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Wed, 20 Aug 2025 14:00:38 +0200 Subject: [PATCH] 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 --- glib/gconstructorprivate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/gconstructorprivate.h b/glib/gconstructorprivate.h index 1c8e64ce6..3d2252cb3 100644 --- a/glib/gconstructorprivate.h +++ b/glib/gconstructorprivate.h @@ -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