[PATCH] nptl: fix __builtin_thread_pointer detection on LoongArch

Florian Weimer fweimer@redhat.com
Mon Nov 4 06:28:17 GMT 2024


> This is the version 2, disscussed in https://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

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



More information about the Libc-alpha mailing list