diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h index a78c4f4d01..a5bd245aa9 100644 --- a/sysdeps/x86_64/nptl/tls.h +++ b/sysdeps/x86_64/nptl/tls.h @@ -180,8 +180,20 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80, assignments like pthread_descr self = thread_self(); do not get optimized away. */ -# if __GNUC_PREREQ (6, 0) -# define THREAD_SELF \ + +# if __GNUC_PREREQ (12, 0) +/* Hide access to a hardwided address to avoid GCC -Warray-bounds. */ +static inline void *__thread_self (size_t __off) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" + return *(void *__seg_fs *) __off; +#pragma GCC diagnostic pop +} +# define THREAD_SELF \ + ((struct pthread *)__thread_self (offsetof (struct pthread, header.self))) +# elif __GNUC_PREREQ (6, 0) +# define THREAD_SELF \ (*(struct pthread *__seg_fs *) offsetof (struct pthread, header.self)) # else # define THREAD_SELF \