https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96200
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Florian Weimer from comment #6) > (In reply to H.J. Lu from comment #4) > > On Linux/i386 and Linux/x86-64, thread pointer access is done via syscall. > > On Linux/x86-64, __builtin_thread_pointer and __builtin_set_thread_pointer > > may be implemented with FSGSBASE ISA. Is it possible to implement these > > builtins on Linux/i386 and Linux/x86-64 for all processors? > > It's effectively part of the x86-64 ABI, but I think it's currently > undocumented. On x86-64, it looks like this: > > static inline void * > thread_pointer (void) > { > void *result; > asm ("mov %%fs:0, %0" : "=r" (result)); > return result; > } > > i386 is similar, but with %gs, I think. > > This is ABI since the early NPTL days, and GCC knows about this very > explicitly, to implement the -mno-tls-direct-seg-refs option. It is documented, see https://akkadia.org/drepper/tls.pdf "The only requirement about this register is that the actual thread pointer tpt can be loaded from the absolute address 0 via the %gs register. The following code would load the thread pointer in the %eax register: movl %gs:0, %eax" for ia32. For x86_64, it is not spelled explicitly, but it is implicit from: "The x86-64 ABI is at its base virtually the same as the IA-32 ABI. The difference is mainly in different size of variables containing pointers and that it only provides one variant which closely matches the IA-32 GNU variant. Instead of segment register %gs it uses the %fs segment register." as well as all the explicit insn sequences that use it. The psABI doesn't have TLS details I believe, so Ulrich's tls.pdf is the ABI document that covers that.