[PATCH 1/2] x86_64: Use __seg_fs qualifier to cast access to TCB in THREAD_GSCOPE_RESET_FLAG()

H.J. Lu hjl.tools@gmail.com
Sun Sep 14 19:28:20 GMT 2025


On Wed, Sep 10, 2025 at 12:01 PM Uros Bizjak <ubizjak@gmail.com> wrote:

> Use the __seg_fs named address space qualifier to cast access to the
> gscope_flag in the TCB as a %fs: prefixed address.  This enables the
> use of the "m" operand constraint, which informs the compiler about
> memory access in the inline assembly.
>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: H.J.Lu <hjl.tools@gmail.com>
> Cc: Florian Weimer <fweimer@redhat.com>
> Cc: Carlos O'Donell <carlos@redhat.com>
> ---
>  sysdeps/x86_64/nptl/tls.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
> index 683f8bfdfc..cf41430050 100644
> --- a/sysdeps/x86_64/nptl/tls.h
> +++ b/sysdeps/x86_64/nptl/tls.h
> @@ -201,9 +201,10 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2)
> == 0x80,
>  # define THREAD_GSCOPE_RESET_FLAG() \
>    do
>    \
>      { int __res;
>    \
> -      asm volatile ("xchgl %0, %%fs:%P1"
>    \
> +      asm volatile ("xchgl %1, %0"
>    \
>                     : "=r" (__res)
>     \
> -                   : "i" (offsetof (struct pthread,
> header.gscope_flag)),    \
> +                   : "m" (*(int __seg_fs *)
>     \
> +                          offsetof (struct pthread,
> header.gscope_flag)),    \
>                       "0" (THREAD_GSCOPE_FLAG_UNUSED));
>    \
>        if (__res == THREAD_GSCOPE_FLAG_WAIT)
>     \
>         lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1,
> LLL_PRIVATE);    \
> --
> 2.51.0
>
>
LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.

-- 
H.J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250914/826bb003/attachment.htm>


More information about the Libc-alpha mailing list