Force Clang to use __tls_get_addr in static libraries


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 uses %fs).

My question is: how can I force Clang to use __tls_get_addr() even in static libraries?

Compiling with `-fpic`, `-fpie` or `-ftls-model=global-dynamic` doesn't seem to work, neither does futzing around with extern or volatile. Also, I understand that this will cause performance degradation.

For reference, here ( is the code generated when compiling as Static Library, and here ( is the same with a Shared Library.

- Naman Dixit