[PATCH 34/59] x86: Fix THREAD_GSCOPE_RESET_FLAG build on clang
Uros Bizjak
ubizjak@gmail.com
Sun Oct 19 15:21:56 GMT 2025
On 10/17/25 21:13, Adhemerval Zanella wrote:
> clang does not support __seg_fs in asm constraint.
> ---
> sysdeps/x86_64/nptl/tls.h | 21 +++++++++++++++++----
> 1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
> index abfeb88054..2c4b9aaa80 100644
> --- a/sysdeps/x86_64/nptl/tls.h
> +++ b/sysdeps/x86_64/nptl/tls.h
> @@ -198,13 +198,26 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80,
> # define THREAD_GSCOPE_FLAG_UNUSED 0
> # define THREAD_GSCOPE_FLAG_USED 1
> # define THREAD_GSCOPE_FLAG_WAIT 2
> +
> +/* clang does not support __seg_fs in asm constraint. */
> +# ifdef __clang__
> +# define XCHGL_GSCOPE(__r) \
> + asm volatile ("xchgl %0, %%fs:%P1" \
> + : "=r" (__r) \
> + : "i" (offsetof (struct pthread, header.gscope_flag)), \
> + "0" (THREAD_GSCOPE_FLAG_UNUSED))
This needs a "memory" clobber, because this asm hides memory access
from the compiler. Please see the "memory" special clobber argument
section in [1].
Also, please use the "c" operand modifier instead of "P". Clang allows
"c" with "i" constraint and also checks that operand fits "c".
Clang accepts __seg_fs prefixed addresses, it just "forgets" to emit
%fs: prefix in the generated code. While this could be considered a bug
with clang, the simplest solution is to just conditionally put "%%fs:"
prefix in the asm template for clang.
[1]
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers
Uros.
More information about the Libc-alpha
mailing list