[PATCH v2 19/28] x86: Fix THREAD_GSCOPE_RESET_FLAG build on clang

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Oct 30 18:27:35 GMT 2025



On 29/10/25 04:13, Uros Bizjak wrote:
> 
> 
> On 10/28/25 18:08, Adhemerval Zanella wrote:
>> clang does not support __seg_fs in asm constraint.
>> ---
>>   sysdeps/x86_64/nptl/tls.h | 22 ++++++++++++++++++----
>>   1 file changed, 18 insertions(+), 4 deletions(-)
>>
>> diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
>> index abfeb88054..809d90875a 100644
>> --- a/sysdeps/x86_64/nptl/tls.h
>> +++ b/sysdeps/x86_64/nptl/tls.h
>> @@ -198,13 +198,27 @@ _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 %%fs:%c1, %0"                          \
>> +                 : "=r" (__r)                              \
>> +                 : "i" (offsetof (struct pthread, header.gscope_flag)),          \
>> +           "0" (THREAD_GSCOPE_FLAG_UNUSED)                  \
>> +         : "memory")
> 
> Does:
> 
>    asm volatile ("xchgl %%fs:%1, %0"                \
>          : "=r" (__r)                \
>          : "m" (((struct pthread __seg_fs *)0)->header.gscope_flag),  \
>            "0" (THREAD_GSCOPE_FLAG_UNUSED))
> 
> work with clang?

It does, although clang seems to just ignore __seg_fs qualifier [1]. I will
change to this, clang might eventually add similar gcc support.


[1] https://godbolt.org/z/4q9jr4G5G


More information about the Libc-alpha mailing list