[PATCH 1/2] x86_64: Use __seg_fs qualifiers in NPTL accessors

H.J. Lu hjl.tools@gmail.com
Thu Aug 14 20:11:49 GMT 2025


On Thu, Aug 14, 2025 at 9:38 AM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> Use __seg_fs named address space qualifiers to cast NPTL accessors
> to %fs: prefixed addresses.  Use volatile access only where
> strictly necessary.
>
> Also remove stalled __GNUC_PREREQ (6, 0) condition.  Currenty GCC-12
> is required as the minimum supported compiler version.
>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> ---

> diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
> index 551d342d52..29b028cdcd 100644
> --- a/sysdeps/x86_64/nptl/tls.h
> +++ b/sysdeps/x86_64/nptl/tls.h
> @@ -168,22 +168,9 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80,
>       THREAD_GETMEM (__pd, header.dtv); })
>
>
> -/* Return the thread descriptor for the current thread.
> -
> -   The contained asm must *not* be marked volatile since otherwise
> -   assignments like
> -       pthread_descr self = thread_self();
> -   do not get optimized away.  */
> -# if __GNUC_PREREQ (6, 0)
> +/* Return the thread descriptor for the current thread.  */
>  #  define THREAD_SELF \
>    (*(struct pthread *__seg_fs *) offsetof (struct pthread, header.self))
> -# else
> -#  define THREAD_SELF \
> -  ({ struct pthread *__self;                                                 \
> -     asm ("mov %%fs:%c1,%0" : "=r" (__self)                                  \
> -         : "i" (offsetof (struct pthread, header.self)));                    \
> -     __self;})
> -# endif

Please create a separate patch to just drop the __GNUC_PREREQ (6, 0)
check for both i386 and x86-64.

Thanks.

-- 
H.J.


More information about the Libc-alpha mailing list