Hello,

Does MinGW-w64 builds support native thread-local storage (TLS),
i.e. placing TLS variables to the array pointed via TEB?
I'm trying to find a way to use TLS from a shared library,
even if through a macro, that will work for both MinGW-w64 and clang
at the same time (i.e. no #ifdef when accessing).

Currently the following gives large, dynamic results for "index",
while one would expect it to be static and small.
With clang, "index" can be later used to access the "var" thread-local value
in other threads, while with MinGW it crashes.

extern unsigned long _tls_index; // filled by loader
__thread int var;
char *base = ((char **)__readgsqword(0x58))[_tls_index]; // TLS array in TEB
ptrdiff_t index = (char *)&var - base;

// access in any other thread:
*(int *)((char **)__readgsqword(0x58)[saved_tls_index]) + index) // == var


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to