From what I understand, if I have some code that contains a _Thread_local
variable, and I compile it to a shared library, then all accesses to the variable go through __tls_get_addr()
. However, if I compile it to a static library, the access happens without that function (on x64, it used %fs
).
My question is: how can I force GCC/Clang to use __tls_get_addr()
even in static libraries?
Compiling with -fpic
or -fpie
doesn't seem to work, neither does futzing around with extern
or volatile
. Also, I understand that this will cause performance degradation, please refrain from asking me to justify my reasons behind this question.