https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96200
--- Comment #6 from Florian Weimer <fw at gcc dot gnu.org> --- (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.