Initializing threads to local storage is part of the startup code provided by libc. With static binding, your linker should add TLS initialization to the startup code associated with your program.
For example, glibc has __libc_setup_tls and _dl_tls_setup (among other things, related things) in libc.a , which will be added to the initialization code of your program if you link, say, gcc -static . (For dynamically linked programs, the _dl_ ... functions are part of the ELF dynamic linker-loader, ld-linux.so , which is not used to run a statically linked program.)
Proper TLS initialization in a statically linked executable is the result of the collaboration of your C library (which provides the code) and your toolchain (which should understand how to properly link all the necessary launch codes).
Kernel involvement in TLS initialization is negligible. (Basically, you just need to make sure that the .tdata section is accessible to libc for initialization.) For more information, see TFS files and LOAD files of an ELF file .
user3113526
source share