Message ID | 20241101183523.118619-1-mjeanson@efficios.com |
---|---|
State | New |
Headers | show |
Series | nptl: fix __builtin_thread_pointer detection on LoongArch | expand |
i think the following is better, like powerpc. 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 */ 在 2024/11/2 上午2:35, Michael Jeanson 写道: > Unfortunatly, __has_builtin can't reliably detect [1] if > __builtin_thread_pointer is implemented in the backend which results in > build failures with some older GCC versions. Use __GNUC_PREREQ / > __glibc_clang_prereq instead. > > [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96952 > > Signed-off-by: Michael Jeanson <mjeanson@efficios.com> > --- > Cc: Yinyu Cai <caiyinyu@loongson.cn> > Cc: mengqinggang <mengqinggang@loongson.cn> > Cc: Arjun Shankar <arjun@redhat.com> > --- > sysdeps/loongarch/nptl/thread_pointer.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/sysdeps/loongarch/nptl/thread_pointer.h b/sysdeps/loongarch/nptl/thread_pointer.h > index 5dec2ef4c6..4ab63b5d1f 100644 > --- a/sysdeps/loongarch/nptl/thread_pointer.h > +++ b/sysdeps/loongarch/nptl/thread_pointer.h > @@ -19,12 +19,12 @@ > #ifndef _SYS_THREAD_POINTER_H > #define _SYS_THREAD_POINTER_H > > -#include <sys/cdefs.h> > +#include <features.h> > > static inline void * > __thread_pointer (void) > { > -#if __glibc_has_builtin (__builtin_thread_pointer) > +#if __GNUC_PREREQ (13, 3) || __glibc_clang_prereq (16, 0) > return __builtin_thread_pointer (); > #else > void *__thread_register;
On Sat, 2024-11-02 at 16:33 +0800, caiyinyu wrote: > i think the following is better, like powerpc. > > 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 */ I agree. To me the only advantage of __builtin_thread_pointer is we can use something like void * __thread_pointer (void) { return __builtin_thread_pointer (); } w/o considering the architecture. But now we have to consider the architecture anyway, so I can see no benefit from using __builtin_thread_pointer.
diff --git a/sysdeps/loongarch/nptl/thread_pointer.h b/sysdeps/loongarch/nptl/thread_pointer.h index 5dec2ef4c6..4ab63b5d1f 100644 --- a/sysdeps/loongarch/nptl/thread_pointer.h +++ b/sysdeps/loongarch/nptl/thread_pointer.h @@ -19,12 +19,12 @@ #ifndef _SYS_THREAD_POINTER_H #define _SYS_THREAD_POINTER_H -#include <sys/cdefs.h> +#include <features.h> static inline void * __thread_pointer (void) { -#if __glibc_has_builtin (__builtin_thread_pointer) +#if __GNUC_PREREQ (13, 3) || __glibc_clang_prereq (16, 0) return __builtin_thread_pointer (); #else void *__thread_register;
Unfortunatly, __has_builtin can't reliably detect [1] if __builtin_thread_pointer is implemented in the backend which results in build failures with some older GCC versions. Use __GNUC_PREREQ / __glibc_clang_prereq instead. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96952 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> --- Cc: Yinyu Cai <caiyinyu@loongson.cn> Cc: mengqinggang <mengqinggang@loongson.cn> Cc: Arjun Shankar <arjun@redhat.com> --- sysdeps/loongarch/nptl/thread_pointer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)