[cfe-users] Force Clang to use __tls_get_addr in static libraries

Naman Dixit via cfe-users cfe-users at lists.llvm.org
Thu Jun 18 20:51:52 PDT 2020


>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 (https://pastebin.com/raw/xUZyAk2h) is the code generated when compiling as Static Library, and here (https://pastebin.com/raw/9Ys6Ey60) is the same with a Shared Library.

- Naman Dixit

More information about the cfe-users mailing list