[PATCH] nptl: fix __builtin_thread_pointer detection on LoongArch
caiyinyu
caiyinyu@loongson.cn
Tue Nov 5 02:43:01 GMT 2024
sorry for the mess on libalpha :( this is re-send.
see https://sourceware.org/pipermail/libc-alpha/2024-November/161237.html
在 2024/11/5 上午10:28, caiyinyu 写道:
>
>
> 在 2024/11/4 下午2:28, Florian Weimer 写道:
>>> This is the version 2, disscussed inhttps://sourceware.org/pipermail/libc-alpha/2024-November/161208.html
>>> v1:https://sourceware.org/pipermail/libc-alpha/2024-November/161185.html
>>> ---
>>> sysdeps/loongarch/nptl/thread_pointer.h | 8 +-------
>>> 1 file changed, 1 insertion(+), 7 deletions(-)
>>>
>>> diff --git a/sysdeps/loongarch/nptl/thread_pointer.h b/sysdeps/loongarch/nptl/thread_pointer.h
>>> index 5dec2ef4c6..96ac47ecbf 100644
>>> --- a/sysdeps/loongarch/nptl/thread_pointer.h
>>> +++ b/sysdeps/loongarch/nptl/thread_pointer.h
>>> @@ -19,18 +19,12 @@
>>> #ifndef _SYS_THREAD_POINTER_H
>>> #define _SYS_THREAD_POINTER_H
>>>
>>> -#include <sys/cdefs.h>
>>> +register void *__thread_register asm ("$tp");
>>>
>>> static inline void *
>>> __thread_pointer (void)
>>> {
>>> -#if __glibc_has_builtin (__builtin_thread_pointer)
>>> - return __builtin_thread_pointer ();
>>> -#else
>>> - void *__thread_register;
>>> - __asm__ ("move %0, $tp" : "=r" (__thread_register));
>>> return __thread_register;
>>> -#endif
>>> }
>>>
>>> #endif /* _SYS_THREAD_POINTER_H */
>> This may result in:
>>
>> warning: register of ‘tp’ used for multiple global register variables
> Indeed, a warning has been generated.
> we use " register void *__thread_self asm ("$tp"); " in
> sysdeps/loongarch/nptl/tls.h like riscv or1k ...
>
> So let's go with the following: (ps: When using the |-O2|optimization
> level during compilation, all implementations have no differences at
> the assembly level. )
>
> diff --git a/sysdeps/loongarch/nptl/thread_pointer.h
> b/sysdeps/loongarch/nptl/thread_pointer.h index 5dec2ef4c6..3c5367af24
> 100644 --- a/sysdeps/loongarch/nptl/thread_pointer.h +++
> b/sysdeps/loongarch/nptl/thread_pointer.h @@ -19,18 +19,12 @@ #ifndef
> _SYS_THREAD_POINTER_H #define _SYS_THREAD_POINTER_H -#include
> <sys/cdefs.h> - static inline void * __thread_pointer (void) { -#if
> __glibc_has_builtin (__builtin_thread_pointer) - return
> __builtin_thread_pointer (); -#else void *__thread_register; __asm__
> ("move %0, $tp" : "=r" (__thread_register)); return __thread_register;
> -#endif } #endif /* _SYS_THREAD_POINTER_H */
>
>> with GCC if the application already uses a similar construct. I don't
>> know if the warning is just cosmetic, or results in code generation
>> problems.
>>
>> Thanks,
>> Florian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20241105/d9debb1a/attachment-0001.htm>
More information about the Libc-alpha
mailing list