Commit b1a9061ff489 ("winpthreads: Fix thread-local storage callbacks on
MSVC") already fixed it for MSVC. For GNU linker it is needed to explicitly
reference that variable and store its reference to some other variable
marked with __attribute__((used)) to prevent LTO compiler discarding it.
---
mingw-w64-libraries/winpthreads/src/thread.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/mingw-w64-libraries/winpthreads/src/thread.c
b/mingw-w64-libraries/winpthreads/src/thread.c
index 73d4329c19ad..b1d9cb92933f 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -520,13 +520,15 @@ __dyn_tls_pthread (HANDLE hDllHandle, DWORD dwReason,
LPVOID lpreserved)
/* TLS-runtime section variable. */
-#if defined(_MSC_VER)
/* Force a reference to _tls_used to make the linker create the TLS
* directory if it's not already there. (e.g. if __declspec(thread)
* is not used).
* Force a reference to __xl_f to prevent whole program optimization
* from discarding the variable. */
-
+#if defined(__GNUC__)
+extern const IMAGE_TLS_DIRECTORY _tls_used;
+static __attribute__((used)) const IMAGE_TLS_DIRECTORY *const
_include_tls_used = &_tls_used;
+#elif defined(_MSC_VER)
/* On x86, symbols are prefixed with an underscore. */
# if defined(_M_IX86)
# pragma comment(linker, "/include:__tls_used")
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public