93dc2d
commit ce2248ab91b2ea09a378f85012f251f31ac65e31
93dc2d
Author: Florian Weimer <fweimer@redhat.com>
93dc2d
Date:   Thu Dec 9 09:49:32 2021 +0100
93dc2d
93dc2d
    nptl: Introduce <tcb-access.h> for THREAD_* accessors
93dc2d
    
93dc2d
    These are common between most architectures.  Only the x86 targets
93dc2d
    are outliers.
93dc2d
    
93dc2d
    Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
93dc2d
93dc2d
diff --git a/sysdeps/aarch64/nptl/tls.h b/sysdeps/aarch64/nptl/tls.h
93dc2d
index 6e896207a659514f..cd9abb5d1d073593 100644
93dc2d
--- a/sysdeps/aarch64/nptl/tls.h
93dc2d
+++ b/sysdeps/aarch64/nptl/tls.h
93dc2d
@@ -98,15 +98,7 @@ typedef struct
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   CONST_THREAD_AREA (64, sizeof (struct pthread))
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Get and set the global scope generation counter in struct pthread.  */
93dc2d
 # define THREAD_GSCOPE_IN_TCB      1
93dc2d
diff --git a/sysdeps/alpha/nptl/tls.h b/sysdeps/alpha/nptl/tls.h
93dc2d
index 4dbccc5249539325..5f4843b28e7f1ad1 100644
93dc2d
--- a/sysdeps/alpha/nptl/tls.h
93dc2d
+++ b/sysdeps/alpha/nptl/tls.h
93dc2d
@@ -92,15 +92,7 @@ typedef struct
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   REGISTER (64, 64, 32 * 8, -sizeof (struct pthread))
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-#define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-#define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-#define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-#define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Get and set the global scope generation counter in struct pthread.  */
93dc2d
 #define THREAD_GSCOPE_IN_TCB      1
93dc2d
diff --git a/sysdeps/arc/nptl/tls.h b/sysdeps/arc/nptl/tls.h
93dc2d
index 95300fdd2159dc53..d9ada2f38089e6cd 100644
93dc2d
--- a/sysdeps/arc/nptl/tls.h
93dc2d
+++ b/sysdeps/arc/nptl/tls.h
93dc2d
@@ -100,15 +100,7 @@ typedef struct
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   CONST_THREAD_AREA (32, sizeof (struct pthread))
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Get and set the global scope generation counter in struct pthread.  */
93dc2d
 #define THREAD_GSCOPE_IN_TCB      1
93dc2d
diff --git a/sysdeps/arm/nptl/tls.h b/sysdeps/arm/nptl/tls.h
93dc2d
index 1bd11307ce0a7f0a..354aae3318291395 100644
93dc2d
--- a/sysdeps/arm/nptl/tls.h
93dc2d
+++ b/sysdeps/arm/nptl/tls.h
93dc2d
@@ -89,15 +89,7 @@ typedef struct
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   CONST_THREAD_AREA (32, sizeof (struct pthread))
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-#define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-#define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-#define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-#define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Get and set the global scope generation counter in struct pthread.  */
93dc2d
 #define THREAD_GSCOPE_IN_TCB      1
93dc2d
diff --git a/sysdeps/csky/nptl/tls.h b/sysdeps/csky/nptl/tls.h
93dc2d
index 7a234041ed0bff39..f3fa3fcb02748776 100644
93dc2d
--- a/sysdeps/csky/nptl/tls.h
93dc2d
+++ b/sysdeps/csky/nptl/tls.h
93dc2d
@@ -116,15 +116,7 @@ typedef struct
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   CONST_THREAD_AREA (32, sizeof (struct pthread))
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Get and set the global scope generation counter in struct pthread.  */
93dc2d
 # define THREAD_GSCOPE_IN_TCB      1
93dc2d
diff --git a/sysdeps/hppa/nptl/tls.h b/sysdeps/hppa/nptl/tls.h
93dc2d
index 857003a7d35073eb..f0e274c45fb5e91e 100644
93dc2d
--- a/sysdeps/hppa/nptl/tls.h
93dc2d
+++ b/sysdeps/hppa/nptl/tls.h
93dc2d
@@ -107,15 +107,7 @@ typedef struct
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   REGISTER (32, 32, 53 * 4, -sizeof (struct pthread))
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 static inline struct pthread *__get_cr27(void)
93dc2d
 {
93dc2d
diff --git a/sysdeps/i386/nptl/tcb-access.h b/sysdeps/i386/nptl/tcb-access.h
93dc2d
new file mode 100644
93dc2d
index 0000000000000000..6c6d561e394817c7
93dc2d
--- /dev/null
93dc2d
+++ b/sysdeps/i386/nptl/tcb-access.h
93dc2d
@@ -0,0 +1,123 @@
93dc2d
+/* THREAD_* accessors.  i386 version.
93dc2d
+   Copyright (C) 2002-2021 Free Software Foundation, Inc.
93dc2d
+   This file is part of the GNU C Library.
93dc2d
+
93dc2d
+   The GNU C Library is free software; you can redistribute it and/or
93dc2d
+   modify it under the terms of the GNU Lesser General Public
93dc2d
+   License as published by the Free Software Foundation; either
93dc2d
+   version 2.1 of the License, or (at your option) any later version.
93dc2d
+
93dc2d
+   The GNU C Library is distributed in the hope that it will be useful,
93dc2d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
93dc2d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
93dc2d
+   Lesser General Public License for more details.
93dc2d
+
93dc2d
+   You should have received a copy of the GNU Lesser General Public
93dc2d
+   License along with the GNU C Library; if not, see
93dc2d
+   <https://www.gnu.org/licenses/>.  */
93dc2d
+
93dc2d
+/* Read member of the thread descriptor directly.  */
93dc2d
+#define THREAD_GETMEM(descr, member) \
93dc2d
+  ({ __typeof (descr->member) __value;					      \
93dc2d
+     _Static_assert (sizeof (__value) == 1				      \
93dc2d
+		     || sizeof (__value) == 4				      \
93dc2d
+		     || sizeof (__value) == 8,				      \
93dc2d
+		     "size of per-thread data");			      \
93dc2d
+     if (sizeof (__value) == 1)						      \
93dc2d
+       asm volatile ("movb %%gs:%P2,%b0"				      \
93dc2d
+		     : "=q" (__value)					      \
93dc2d
+		     : "0" (0), "i" (offsetof (struct pthread, member)));     \
93dc2d
+     else if (sizeof (__value) == 4)					      \
93dc2d
+       asm volatile ("movl %%gs:%P1,%0"					      \
93dc2d
+		     : "=r" (__value)					      \
93dc2d
+		     : "i" (offsetof (struct pthread, member)));	      \
93dc2d
+     else /* 8 */								      \
93dc2d
+       {								      \
93dc2d
+	 asm volatile ("movl %%gs:%P1,%%eax\n\t"			      \
93dc2d
+		       "movl %%gs:%P2,%%edx"				      \
93dc2d
+		       : "=A" (__value)					      \
93dc2d
+		       : "i" (offsetof (struct pthread, member)),	      \
93dc2d
+			 "i" (offsetof (struct pthread, member) + 4));	      \
93dc2d
+       }								      \
93dc2d
+     __value; })
93dc2d
+
93dc2d
+
93dc2d
+/* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
93dc2d
+#define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
+  ({ __typeof (descr->member[0]) __value;				      \
93dc2d
+     _Static_assert (sizeof (__value) == 1				      \
93dc2d
+		     || sizeof (__value) == 4				      \
93dc2d
+		     || sizeof (__value) == 8,				      \
93dc2d
+		     "size of per-thread data");			      \
93dc2d
+     if (sizeof (__value) == 1)						      \
93dc2d
+       asm volatile ("movb %%gs:%P2(%3),%b0"				      \
93dc2d
+		     : "=q" (__value)					      \
93dc2d
+		     : "0" (0), "i" (offsetof (struct pthread, member[0])),   \
93dc2d
+		     "r" (idx));					      \
93dc2d
+     else if (sizeof (__value) == 4)					      \
93dc2d
+       asm volatile ("movl %%gs:%P1(,%2,4),%0"				      \
93dc2d
+		     : "=r" (__value)					      \
93dc2d
+		     : "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
+		       "r" (idx));					      \
93dc2d
+     else /* 8 */							      \
93dc2d
+       {								      \
93dc2d
+	 asm volatile  ("movl %%gs:%P1(,%2,8),%%eax\n\t"		      \
93dc2d
+			"movl %%gs:4+%P1(,%2,8),%%edx"			      \
93dc2d
+			: "=&A" (__value)				      \
93dc2d
+			: "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
+			  "r" (idx));					      \
93dc2d
+       }								      \
93dc2d
+     __value; })
93dc2d
+
93dc2d
+
93dc2d
+
93dc2d
+/* Set member of the thread descriptor directly.  */
93dc2d
+#define THREAD_SETMEM(descr, member, value) \
93dc2d
+  ({									      \
93dc2d
+     _Static_assert (sizeof (descr->member) == 1			      \
93dc2d
+		     || sizeof (descr->member) == 4			      \
93dc2d
+		     || sizeof (descr->member) == 8,			      \
93dc2d
+		     "size of per-thread data");			      \
93dc2d
+     if (sizeof (descr->member) == 1)					      \
93dc2d
+       asm volatile ("movb %b0,%%gs:%P1" :				      \
93dc2d
+		     : "iq" (value),					      \
93dc2d
+		       "i" (offsetof (struct pthread, member)));	      \
93dc2d
+     else if (sizeof (descr->member) == 4)				      \
93dc2d
+       asm volatile ("movl %0,%%gs:%P1" :				      \
93dc2d
+		     : "ir" (value),					      \
93dc2d
+		       "i" (offsetof (struct pthread, member)));	      \
93dc2d
+     else /* 8 */							      \
93dc2d
+       {								      \
93dc2d
+	 asm volatile ("movl %%eax,%%gs:%P1\n\t"			      \
93dc2d
+		       "movl %%edx,%%gs:%P2" :				      \
93dc2d
+		       : "A" ((uint64_t) cast_to_integer (value)),	      \
93dc2d
+			 "i" (offsetof (struct pthread, member)),	      \
93dc2d
+			 "i" (offsetof (struct pthread, member) + 4));	      \
93dc2d
+       }})
93dc2d
+
93dc2d
+
93dc2d
+/* Same as THREAD_SETMEM, but the member offset can be non-constant.  */
93dc2d
+#define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
+  ({									      \
93dc2d
+     _Static_assert (sizeof (descr->member[0]) == 1			      \
93dc2d
+		     || sizeof (descr->member[0]) == 4			      \
93dc2d
+		     || sizeof (descr->member[0]) == 8,			      \
93dc2d
+		     "size of per-thread data");			      \
93dc2d
+     if (sizeof (descr->member[0]) == 1)				      \
93dc2d
+       asm volatile ("movb %b0,%%gs:%P1(%2)" :				      \
93dc2d
+		     : "iq" (value),					      \
93dc2d
+		       "i" (offsetof (struct pthread, member)),		      \
93dc2d
+		       "r" (idx));					      \
93dc2d
+     else if (sizeof (descr->member[0]) == 4)				      \
93dc2d
+       asm volatile ("movl %0,%%gs:%P1(,%2,4)" :			      \
93dc2d
+		     : "ir" (value),					      \
93dc2d
+		       "i" (offsetof (struct pthread, member)),		      \
93dc2d
+		       "r" (idx));					      \
93dc2d
+     else /* 8 */							      \
93dc2d
+       {								      \
93dc2d
+	 asm volatile ("movl %%eax,%%gs:%P1(,%2,8)\n\t"			      \
93dc2d
+		       "movl %%edx,%%gs:4+%P1(,%2,8)" :			      \
93dc2d
+		       : "A" ((uint64_t) cast_to_integer (value)),	      \
93dc2d
+			 "i" (offsetof (struct pthread, member)),	      \
93dc2d
+			 "r" (idx));					      \
93dc2d
+       }})
93dc2d
diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
93dc2d
index 86ee1ef30270f960..111c9ee59df30bc3 100644
93dc2d
--- a/sysdeps/i386/nptl/tls.h
93dc2d
+++ b/sysdeps/i386/nptl/tls.h
93dc2d
@@ -250,113 +250,7 @@ tls_fill_user_desc (union user_desc_init *desc,
93dc2d
   REGISTER_THREAD_AREA (32, offsetof (struct user_regs_struct, xgs), 3) \
93dc2d
   REGISTER_THREAD_AREA (64, 26 * 8, 3) /* x86-64's user_regs_struct->gs */
93dc2d
 
93dc2d
-
93dc2d
-/* Read member of the thread descriptor directly.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  ({ __typeof (descr->member) __value;					      \
93dc2d
-     _Static_assert (sizeof (__value) == 1				      \
93dc2d
-		     || sizeof (__value) == 4				      \
93dc2d
-		     || sizeof (__value) == 8,				      \
93dc2d
-		     "size of per-thread data");			      \
93dc2d
-     if (sizeof (__value) == 1)						      \
93dc2d
-       asm volatile ("movb %%gs:%P2,%b0"				      \
93dc2d
-		     : "=q" (__value)					      \
93dc2d
-		     : "0" (0), "i" (offsetof (struct pthread, member)));     \
93dc2d
-     else if (sizeof (__value) == 4)					      \
93dc2d
-       asm volatile ("movl %%gs:%P1,%0"					      \
93dc2d
-		     : "=r" (__value)					      \
93dc2d
-		     : "i" (offsetof (struct pthread, member)));	      \
93dc2d
-     else /* 8 */								      \
93dc2d
-       {								      \
93dc2d
-	 asm volatile ("movl %%gs:%P1,%%eax\n\t"			      \
93dc2d
-		       "movl %%gs:%P2,%%edx"				      \
93dc2d
-		       : "=A" (__value)					      \
93dc2d
-		       : "i" (offsetof (struct pthread, member)),	      \
93dc2d
-			 "i" (offsetof (struct pthread, member) + 4));	      \
93dc2d
-       }								      \
93dc2d
-     __value; })
93dc2d
-
93dc2d
-
93dc2d
-/* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  ({ __typeof (descr->member[0]) __value;				      \
93dc2d
-     _Static_assert (sizeof (__value) == 1				      \
93dc2d
-		     || sizeof (__value) == 4				      \
93dc2d
-		     || sizeof (__value) == 8,				      \
93dc2d
-		     "size of per-thread data");			      \
93dc2d
-     if (sizeof (__value) == 1)						      \
93dc2d
-       asm volatile ("movb %%gs:%P2(%3),%b0"				      \
93dc2d
-		     : "=q" (__value)					      \
93dc2d
-		     : "0" (0), "i" (offsetof (struct pthread, member[0])),   \
93dc2d
-		     "r" (idx));					      \
93dc2d
-     else if (sizeof (__value) == 4)					      \
93dc2d
-       asm volatile ("movl %%gs:%P1(,%2,4),%0"				      \
93dc2d
-		     : "=r" (__value)					      \
93dc2d
-		     : "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
-		       "r" (idx));					      \
93dc2d
-     else /* 8 */							      \
93dc2d
-       {								      \
93dc2d
-	 asm volatile  ("movl %%gs:%P1(,%2,8),%%eax\n\t"		      \
93dc2d
-			"movl %%gs:4+%P1(,%2,8),%%edx"			      \
93dc2d
-			: "=&A" (__value)				      \
93dc2d
-			: "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
-			  "r" (idx));					      \
93dc2d
-       }								      \
93dc2d
-     __value; })
93dc2d
-
93dc2d
-
93dc2d
-
93dc2d
-/* Set member of the thread descriptor directly.  */
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  ({									      \
93dc2d
-     _Static_assert (sizeof (descr->member) == 1			      \
93dc2d
-		     || sizeof (descr->member) == 4			      \
93dc2d
-		     || sizeof (descr->member) == 8,			      \
93dc2d
-		     "size of per-thread data");			      \
93dc2d
-     if (sizeof (descr->member) == 1)					      \
93dc2d
-       asm volatile ("movb %b0,%%gs:%P1" :				      \
93dc2d
-		     : "iq" (value),					      \
93dc2d
-		       "i" (offsetof (struct pthread, member)));	      \
93dc2d
-     else if (sizeof (descr->member) == 4)				      \
93dc2d
-       asm volatile ("movl %0,%%gs:%P1" :				      \
93dc2d
-		     : "ir" (value),					      \
93dc2d
-		       "i" (offsetof (struct pthread, member)));	      \
93dc2d
-     else /* 8 */							      \
93dc2d
-       {								      \
93dc2d
-	 asm volatile ("movl %%eax,%%gs:%P1\n\t"			      \
93dc2d
-		       "movl %%edx,%%gs:%P2" :				      \
93dc2d
-		       : "A" ((uint64_t) cast_to_integer (value)),	      \
93dc2d
-			 "i" (offsetof (struct pthread, member)),	      \
93dc2d
-			 "i" (offsetof (struct pthread, member) + 4));	      \
93dc2d
-       }})
93dc2d
-
93dc2d
-
93dc2d
-/* Same as THREAD_SETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  ({									      \
93dc2d
-     _Static_assert (sizeof (descr->member[0]) == 1			      \
93dc2d
-		     || sizeof (descr->member[0]) == 4			      \
93dc2d
-		     || sizeof (descr->member[0]) == 8,			      \
93dc2d
-		     "size of per-thread data");			      \
93dc2d
-     if (sizeof (descr->member[0]) == 1)				      \
93dc2d
-       asm volatile ("movb %b0,%%gs:%P1(%2)" :				      \
93dc2d
-		     : "iq" (value),					      \
93dc2d
-		       "i" (offsetof (struct pthread, member)),		      \
93dc2d
-		       "r" (idx));					      \
93dc2d
-     else if (sizeof (descr->member[0]) == 4)				      \
93dc2d
-       asm volatile ("movl %0,%%gs:%P1(,%2,4)" :			      \
93dc2d
-		     : "ir" (value),					      \
93dc2d
-		       "i" (offsetof (struct pthread, member)),		      \
93dc2d
-		       "r" (idx));					      \
93dc2d
-     else /* 8 */							      \
93dc2d
-       {								      \
93dc2d
-	 asm volatile ("movl %%eax,%%gs:%P1(,%2,8)\n\t"			      \
93dc2d
-		       "movl %%edx,%%gs:4+%P1(,%2,8)" :			      \
93dc2d
-		       : "A" ((uint64_t) cast_to_integer (value)),	      \
93dc2d
-			 "i" (offsetof (struct pthread, member)),	      \
93dc2d
-			 "r" (idx));					      \
93dc2d
-       }})
93dc2d
-
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Set the stack guard field in TCB head.  */
93dc2d
 #define THREAD_SET_STACK_GUARD(value) \
93dc2d
diff --git a/sysdeps/ia64/nptl/tls.h b/sysdeps/ia64/nptl/tls.h
93dc2d
index 66d9bf3189f0b727..26fe555cb4b5e164 100644
93dc2d
--- a/sysdeps/ia64/nptl/tls.h
93dc2d
+++ b/sysdeps/ia64/nptl/tls.h
93dc2d
@@ -128,15 +128,7 @@ register struct pthread *__thread_self __asm__("r13");
93dc2d
 /* Magic for libthread_db to know how to do THREAD_SELF.  */
93dc2d
 # define DB_THREAD_SELF REGISTER (64, 64, 13 * 8, -TLS_PRE_TCB_SIZE)
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-#define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-#define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-#define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-#define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Set the stack guard field in TCB head.  */
93dc2d
 #define THREAD_SET_STACK_GUARD(value) \
93dc2d
diff --git a/sysdeps/m68k/nptl/tls.h b/sysdeps/m68k/nptl/tls.h
93dc2d
index cfcd6d2b7b59321c..9f562c38288df200 100644
93dc2d
--- a/sysdeps/m68k/nptl/tls.h
93dc2d
+++ b/sysdeps/m68k/nptl/tls.h
93dc2d
@@ -118,15 +118,7 @@ extern void * __m68k_read_tp (void);
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   CONST_THREAD_AREA (32, TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* l_tls_offset == 0 is perfectly valid on M68K, so we have to use some
93dc2d
    different value to mean unset l_tls_offset.  */
93dc2d
diff --git a/sysdeps/microblaze/nptl/tls.h b/sysdeps/microblaze/nptl/tls.h
93dc2d
index c93d90b11bfe4c74..bfa6efa78049bb2d 100644
93dc2d
--- a/sysdeps/microblaze/nptl/tls.h
93dc2d
+++ b/sysdeps/microblaze/nptl/tls.h
93dc2d
@@ -100,20 +100,7 @@ typedef struct
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   CONST_THREAD_AREA (32, sizeof (struct pthread))
93dc2d
 
93dc2d
-/* Read member of the thread descriptor directly.  */
93dc2d
-# define THREAD_GETMEM(descr, member) (descr->member)
93dc2d
-
93dc2d
-/* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  (descr->member[idx])
93dc2d
-
93dc2d
-/* Set member of the thread descriptor directly.  */
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  (descr->member = (value))
93dc2d
-
93dc2d
-/* Same as THREAD_SETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  (descr->member[idx] = (value))
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Get and set the global scope generation counter in struct pthread.  */
93dc2d
 # define THREAD_GSCOPE_IN_TCB      1
93dc2d
diff --git a/sysdeps/mips/nptl/tls.h b/sysdeps/mips/nptl/tls.h
93dc2d
index c09f49071cf3b5b9..ef99aa646c898e76 100644
93dc2d
--- a/sysdeps/mips/nptl/tls.h
93dc2d
+++ b/sysdeps/mips/nptl/tls.h
93dc2d
@@ -144,14 +144,7 @@ typedef struct
93dc2d
   CONST_THREAD_AREA (32, TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
93dc2d
 
93dc2d
 /* Access to data in the thread descriptor is easy.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* l_tls_offset == 0 is perfectly valid on MIPS, so we have to use some
93dc2d
    different value to mean unset l_tls_offset.  */
93dc2d
diff --git a/sysdeps/nios2/nptl/tls.h b/sysdeps/nios2/nptl/tls.h
93dc2d
index 02a05b4e741092bf..7110cfccad7131f4 100644
93dc2d
--- a/sysdeps/nios2/nptl/tls.h
93dc2d
+++ b/sysdeps/nios2/nptl/tls.h
93dc2d
@@ -112,15 +112,7 @@ register struct pthread *__thread_self __asm__("r23");
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   REGISTER (32, 32, 23 * 4, -TLS_PRE_TCB_SIZE - TLS_TCB_OFFSET)
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 # define THREAD_GET_POINTER_GUARD()				\
93dc2d
   (((tcbhead_t *) (READ_THREAD_POINTER ()			\
93dc2d
diff --git a/sysdeps/nptl/tcb-access.h b/sysdeps/nptl/tcb-access.h
93dc2d
new file mode 100644
93dc2d
index 0000000000000000..b4137b8ab8067915
93dc2d
--- /dev/null
93dc2d
+++ b/sysdeps/nptl/tcb-access.h
93dc2d
@@ -0,0 +1,30 @@
93dc2d
+/* THREAD_* accessors.  Generic version based on struct pthread pointers.
93dc2d
+   Copyright (C) 2002-2021 Free Software Foundation, Inc.
93dc2d
+   This file is part of the GNU C Library.
93dc2d
+
93dc2d
+   The GNU C Library is free software; you can redistribute it and/or
93dc2d
+   modify it under the terms of the GNU Lesser General Public
93dc2d
+   License as published by the Free Software Foundation; either
93dc2d
+   version 2.1 of the License, or (at your option) any later version.
93dc2d
+
93dc2d
+   The GNU C Library is distributed in the hope that it will be useful,
93dc2d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
93dc2d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
93dc2d
+   Lesser General Public License for more details.
93dc2d
+
93dc2d
+   You should have received a copy of the GNU Lesser General Public
93dc2d
+   License along with the GNU C Library; if not, see
93dc2d
+   <https://www.gnu.org/licenses/>.  */
93dc2d
+
93dc2d
+/* Note: These are for accessing the TCB of the *current* thread.
93dc2d
+   descr can be disregarded on some targets as an optimization.  See
93dc2d
+   i386 for an example.  */
93dc2d
+
93dc2d
+#define THREAD_GETMEM(descr, member) \
93dc2d
+  descr->member
93dc2d
+#define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
+  descr->member[idx]
93dc2d
+#define THREAD_SETMEM(descr, member, value) \
93dc2d
+  descr->member = (value)
93dc2d
+#define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
+  descr->member[idx] = (value)
93dc2d
diff --git a/sysdeps/powerpc/nptl/tls.h b/sysdeps/powerpc/nptl/tls.h
93dc2d
index 6c779b6609147d54..110d085d30c86302 100644
93dc2d
--- a/sysdeps/powerpc/nptl/tls.h
93dc2d
+++ b/sysdeps/powerpc/nptl/tls.h
93dc2d
@@ -176,20 +176,7 @@ typedef struct
93dc2d
   REGISTER (64, 64, PT_THREAD_POINTER * 8,				      \
93dc2d
 	    - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
93dc2d
 
93dc2d
-/* Read member of the thread descriptor directly.  */
93dc2d
-# define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
93dc2d
-
93dc2d
-/* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-    ((void)(descr), (THREAD_SELF)->member[idx])
93dc2d
-
93dc2d
-/* Set member of the thread descriptor directly.  */
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-    ((void)(descr), (THREAD_SELF)->member = (value))
93dc2d
-
93dc2d
-/* Same as THREAD_SETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-    ((void)(descr), (THREAD_SELF)->member[idx] = (value))
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Set the stack guard field in TCB head.  */
93dc2d
 # define THREAD_SET_STACK_GUARD(value) \
93dc2d
diff --git a/sysdeps/riscv/nptl/tls.h b/sysdeps/riscv/nptl/tls.h
93dc2d
index 5350bcc0498bab69..bdc0a3a6f91b51e8 100644
93dc2d
--- a/sysdeps/riscv/nptl/tls.h
93dc2d
+++ b/sysdeps/riscv/nptl/tls.h
93dc2d
@@ -105,14 +105,7 @@ typedef struct
93dc2d
   REGISTER (64, 64, 4 * 8, - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
93dc2d
 
93dc2d
 /* Access to data in the thread descriptor is easy.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* l_tls_offset == 0 is perfectly valid, so we have to use some different
93dc2d
    value to mean unset l_tls_offset.  */
93dc2d
diff --git a/sysdeps/s390/nptl/tls.h b/sysdeps/s390/nptl/tls.h
93dc2d
index efb52515e05c06a9..2cdd18eb2907c060 100644
93dc2d
--- a/sysdeps/s390/nptl/tls.h
93dc2d
+++ b/sysdeps/s390/nptl/tls.h
93dc2d
@@ -135,15 +135,7 @@ typedef struct
93dc2d
 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
93dc2d
 			REGISTER (64, __WORDSIZE, 18 * 8, 0)
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-#define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-#define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-#define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-#define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Set the stack guard field in TCB head.  */
93dc2d
 #define THREAD_SET_STACK_GUARD(value) \
93dc2d
diff --git a/sysdeps/sh/nptl/tls.h b/sysdeps/sh/nptl/tls.h
93dc2d
index ac3c9a9e856ee686..390640020e45f716 100644
93dc2d
--- a/sysdeps/sh/nptl/tls.h
93dc2d
+++ b/sysdeps/sh/nptl/tls.h
93dc2d
@@ -113,19 +113,7 @@ typedef struct
93dc2d
 # define DB_THREAD_SELF \
93dc2d
   REGISTER (32, 32, REG_GBR * 4, -sizeof (struct pthread))
93dc2d
 
93dc2d
-/* Read member of the thread descriptor directly.  */
93dc2d
-# define THREAD_GETMEM(descr, member) (descr->member)
93dc2d
-
93dc2d
-/* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) (descr->member[idx])
93dc2d
-
93dc2d
-/* Set member of the thread descriptor directly.  */
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-    descr->member = (value)
93dc2d
-
93dc2d
-/* Same as THREAD_SETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-    descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 #define THREAD_GET_POINTER_GUARD() \
93dc2d
   ({ tcbhead_t *__tcbp;							      \
93dc2d
diff --git a/sysdeps/sparc/nptl/tls.h b/sysdeps/sparc/nptl/tls.h
93dc2d
index dd1eb82a595619a9..376d729989e35660 100644
93dc2d
--- a/sysdeps/sparc/nptl/tls.h
93dc2d
+++ b/sysdeps/sparc/nptl/tls.h
93dc2d
@@ -112,15 +112,7 @@ register struct pthread *__thread_self __asm__("%g7");
93dc2d
   REGISTER (32, 32, 10 * 4, 0) \
93dc2d
   REGISTER (64, __WORDSIZE, (6 * 8) + (__WORDSIZE==64?0:4), 0)
93dc2d
 
93dc2d
-/* Access to data in the thread descriptor is easy.  */
93dc2d
-#define THREAD_GETMEM(descr, member) \
93dc2d
-  descr->member
93dc2d
-#define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  descr->member[idx]
93dc2d
-#define THREAD_SETMEM(descr, member, value) \
93dc2d
-  descr->member = (value)
93dc2d
-#define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  descr->member[idx] = (value)
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Set the stack guard field in TCB head.  */
93dc2d
 #define THREAD_SET_STACK_GUARD(value) \
93dc2d
diff --git a/sysdeps/x86_64/nptl/tcb-access.h b/sysdeps/x86_64/nptl/tcb-access.h
93dc2d
new file mode 100644
93dc2d
index 0000000000000000..18848a729d16a4f5
93dc2d
--- /dev/null
93dc2d
+++ b/sysdeps/x86_64/nptl/tcb-access.h
93dc2d
@@ -0,0 +1,130 @@
93dc2d
+/* THREAD_* accessors.  x86_64 version.
93dc2d
+   Copyright (C) 2002-2021 Free Software Foundation, Inc.
93dc2d
+   This file is part of the GNU C Library.
93dc2d
+
93dc2d
+   The GNU C Library is free software; you can redistribute it and/or
93dc2d
+   modify it under the terms of the GNU Lesser General Public
93dc2d
+   License as published by the Free Software Foundation; either
93dc2d
+   version 2.1 of the License, or (at your option) any later version.
93dc2d
+
93dc2d
+   The GNU C Library is distributed in the hope that it will be useful,
93dc2d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
93dc2d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
93dc2d
+   Lesser General Public License for more details.
93dc2d
+
93dc2d
+   You should have received a copy of the GNU Lesser General Public
93dc2d
+   License along with the GNU C Library; if not, see
93dc2d
+   <https://www.gnu.org/licenses/>.  */
93dc2d
+
93dc2d
+/* Read member of the thread descriptor directly.  */
93dc2d
+# define THREAD_GETMEM(descr, member) \
93dc2d
+  ({ __typeof (descr->member) __value;					      \
93dc2d
+     _Static_assert (sizeof (__value) == 1				      \
93dc2d
+		     || sizeof (__value) == 4				      \
93dc2d
+		     || sizeof (__value) == 8,				      \
93dc2d
+		     "size of per-thread data");			      \
93dc2d
+     if (sizeof (__value) == 1)						      \
93dc2d
+       asm volatile ("movb %%fs:%P2,%b0"				      \
93dc2d
+		     : "=q" (__value)					      \
93dc2d
+		     : "0" (0), "i" (offsetof (struct pthread, member)));     \
93dc2d
+     else if (sizeof (__value) == 4)					      \
93dc2d
+       asm volatile ("movl %%fs:%P1,%0"					      \
93dc2d
+		     : "=r" (__value)					      \
93dc2d
+		     : "i" (offsetof (struct pthread, member)));	      \
93dc2d
+     else /* 8 */								      \
93dc2d
+       {								      \
93dc2d
+	 asm volatile ("movq %%fs:%P1,%q0"				      \
93dc2d
+		       : "=r" (__value)					      \
93dc2d
+		       : "i" (offsetof (struct pthread, member)));	      \
93dc2d
+       }								      \
93dc2d
+     __value; })
93dc2d
+
93dc2d
+
93dc2d
+/* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
93dc2d
+# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
+  ({ __typeof (descr->member[0]) __value;				      \
93dc2d
+     _Static_assert (sizeof (__value) == 1				      \
93dc2d
+		     || sizeof (__value) == 4				      \
93dc2d
+		     || sizeof (__value) == 8,				      \
93dc2d
+		     "size of per-thread data");			      \
93dc2d
+     if (sizeof (__value) == 1)						      \
93dc2d
+       asm volatile ("movb %%fs:%P2(%q3),%b0"				      \
93dc2d
+		     : "=q" (__value)					      \
93dc2d
+		     : "0" (0), "i" (offsetof (struct pthread, member[0])),   \
93dc2d
+		       "r" (idx));					      \
93dc2d
+     else if (sizeof (__value) == 4)					      \
93dc2d
+       asm volatile ("movl %%fs:%P1(,%q2,4),%0"				      \
93dc2d
+		     : "=r" (__value)					      \
93dc2d
+		     : "i" (offsetof (struct pthread, member[0])), "r" (idx));\
93dc2d
+     else /* 8 */							      \
93dc2d
+       {								      \
93dc2d
+	 asm volatile ("movq %%fs:%P1(,%q2,8),%q0"			      \
93dc2d
+		       : "=r" (__value)					      \
93dc2d
+		       : "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
+			 "r" (idx));					      \
93dc2d
+       }								      \
93dc2d
+     __value; })
93dc2d
+
93dc2d
+
93dc2d
+/* Loading addresses of objects on x86-64 needs to be treated special
93dc2d
+   when generating PIC code.  */
93dc2d
+#ifdef __pic__
93dc2d
+# define IMM_MODE "nr"
93dc2d
+#else
93dc2d
+# define IMM_MODE "ir"
93dc2d
+#endif
93dc2d
+
93dc2d
+
93dc2d
+/* Set member of the thread descriptor directly.  */
93dc2d
+# define THREAD_SETMEM(descr, member, value) \
93dc2d
+  ({									      \
93dc2d
+     _Static_assert (sizeof (descr->member) == 1			      \
93dc2d
+		     || sizeof (descr->member) == 4			      \
93dc2d
+		     || sizeof (descr->member) == 8,			      \
93dc2d
+		     "size of per-thread data");			      \
93dc2d
+     if (sizeof (descr->member) == 1)					      \
93dc2d
+       asm volatile ("movb %b0,%%fs:%P1" :				      \
93dc2d
+		     : "iq" (value),					      \
93dc2d
+		       "i" (offsetof (struct pthread, member)));	      \
93dc2d
+     else if (sizeof (descr->member) == 4)				      \
93dc2d
+       asm volatile ("movl %0,%%fs:%P1" :				      \
93dc2d
+		     : IMM_MODE (value),				      \
93dc2d
+		       "i" (offsetof (struct pthread, member)));	      \
93dc2d
+     else /* 8 */							      \
93dc2d
+       {								      \
93dc2d
+	 /* Since movq takes a signed 32-bit immediate or a register source   \
93dc2d
+	    operand, use "er" constraint for 32-bit signed integer constant   \
93dc2d
+	    or register.  */						      \
93dc2d
+	 asm volatile ("movq %q0,%%fs:%P1" :				      \
93dc2d
+		       : "er" ((uint64_t) cast_to_integer (value)),	      \
93dc2d
+			 "i" (offsetof (struct pthread, member)));	      \
93dc2d
+       }})
93dc2d
+
93dc2d
+
93dc2d
+/* Same as THREAD_SETMEM, but the member offset can be non-constant.  */
93dc2d
+# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
+  ({									      \
93dc2d
+     _Static_assert (sizeof (descr->member[0]) == 1			      \
93dc2d
+		     || sizeof (descr->member[0]) == 4			      \
93dc2d
+		     || sizeof (descr->member[0]) == 8,			      \
93dc2d
+		     "size of per-thread data");			      \
93dc2d
+     if (sizeof (descr->member[0]) == 1)				      \
93dc2d
+       asm volatile ("movb %b0,%%fs:%P1(%q2)" :				      \
93dc2d
+		     : "iq" (value),					      \
93dc2d
+		       "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
+		       "r" (idx));					      \
93dc2d
+     else if (sizeof (descr->member[0]) == 4)				      \
93dc2d
+       asm volatile ("movl %0,%%fs:%P1(,%q2,4)" :			      \
93dc2d
+		     : IMM_MODE (value),				      \
93dc2d
+		       "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
+		       "r" (idx));					      \
93dc2d
+     else /* 8 */							      \
93dc2d
+       {								      \
93dc2d
+	 /* Since movq takes a signed 32-bit immediate or a register source   \
93dc2d
+	    operand, use "er" constraint for 32-bit signed integer constant   \
93dc2d
+	    or register.  */						      \
93dc2d
+	 asm volatile ("movq %q0,%%fs:%P1(,%q2,8)" :			      \
93dc2d
+		       : "er" ((uint64_t) cast_to_integer (value)),	      \
93dc2d
+			 "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
+			 "r" (idx));					      \
93dc2d
+       }})
93dc2d
diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
93dc2d
index a78c4f4d016002fa..3af1836e28b26fdb 100644
93dc2d
--- a/sysdeps/x86_64/nptl/tls.h
93dc2d
+++ b/sysdeps/x86_64/nptl/tls.h
93dc2d
@@ -195,119 +195,7 @@ _Static_assert (offsetof (tcbhead_t, __glibc_unused2) == 0x80,
93dc2d
 # define DB_THREAD_SELF_INCLUDE  <sys/reg.h> /* For the FS constant.  */
93dc2d
 # define DB_THREAD_SELF CONST_THREAD_AREA (64, FS)
93dc2d
 
93dc2d
-/* Read member of the thread descriptor directly.  */
93dc2d
-# define THREAD_GETMEM(descr, member) \
93dc2d
-  ({ __typeof (descr->member) __value;					      \
93dc2d
-     _Static_assert (sizeof (__value) == 1				      \
93dc2d
-		     || sizeof (__value) == 4				      \
93dc2d
-		     || sizeof (__value) == 8,				      \
93dc2d
-		     "size of per-thread data");			      \
93dc2d
-     if (sizeof (__value) == 1)						      \
93dc2d
-       asm volatile ("movb %%fs:%P2,%b0"				      \
93dc2d
-		     : "=q" (__value)					      \
93dc2d
-		     : "0" (0), "i" (offsetof (struct pthread, member)));     \
93dc2d
-     else if (sizeof (__value) == 4)					      \
93dc2d
-       asm volatile ("movl %%fs:%P1,%0"					      \
93dc2d
-		     : "=r" (__value)					      \
93dc2d
-		     : "i" (offsetof (struct pthread, member)));	      \
93dc2d
-     else /* 8 */								      \
93dc2d
-       {								      \
93dc2d
-	 asm volatile ("movq %%fs:%P1,%q0"				      \
93dc2d
-		       : "=r" (__value)					      \
93dc2d
-		       : "i" (offsetof (struct pthread, member)));	      \
93dc2d
-       }								      \
93dc2d
-     __value; })
93dc2d
-
93dc2d
-
93dc2d
-/* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_GETMEM_NC(descr, member, idx) \
93dc2d
-  ({ __typeof (descr->member[0]) __value;				      \
93dc2d
-     _Static_assert (sizeof (__value) == 1				      \
93dc2d
-		     || sizeof (__value) == 4				      \
93dc2d
-		     || sizeof (__value) == 8,				      \
93dc2d
-		     "size of per-thread data");			      \
93dc2d
-     if (sizeof (__value) == 1)						      \
93dc2d
-       asm volatile ("movb %%fs:%P2(%q3),%b0"				      \
93dc2d
-		     : "=q" (__value)					      \
93dc2d
-		     : "0" (0), "i" (offsetof (struct pthread, member[0])),   \
93dc2d
-		       "r" (idx));					      \
93dc2d
-     else if (sizeof (__value) == 4)					      \
93dc2d
-       asm volatile ("movl %%fs:%P1(,%q2,4),%0"				      \
93dc2d
-		     : "=r" (__value)					      \
93dc2d
-		     : "i" (offsetof (struct pthread, member[0])), "r" (idx));\
93dc2d
-     else /* 8 */							      \
93dc2d
-       {								      \
93dc2d
-	 asm volatile ("movq %%fs:%P1(,%q2,8),%q0"			      \
93dc2d
-		       : "=r" (__value)					      \
93dc2d
-		       : "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
-			 "r" (idx));					      \
93dc2d
-       }								      \
93dc2d
-     __value; })
93dc2d
-
93dc2d
-
93dc2d
-/* Loading addresses of objects on x86-64 needs to be treated special
93dc2d
-   when generating PIC code.  */
93dc2d
-#ifdef __pic__
93dc2d
-# define IMM_MODE "nr"
93dc2d
-#else
93dc2d
-# define IMM_MODE "ir"
93dc2d
-#endif
93dc2d
-
93dc2d
-
93dc2d
-/* Set member of the thread descriptor directly.  */
93dc2d
-# define THREAD_SETMEM(descr, member, value) \
93dc2d
-  ({									      \
93dc2d
-     _Static_assert (sizeof (descr->member) == 1			      \
93dc2d
-		     || sizeof (descr->member) == 4			      \
93dc2d
-		     || sizeof (descr->member) == 8,			      \
93dc2d
-		     "size of per-thread data");			      \
93dc2d
-     if (sizeof (descr->member) == 1)					      \
93dc2d
-       asm volatile ("movb %b0,%%fs:%P1" :				      \
93dc2d
-		     : "iq" (value),					      \
93dc2d
-		       "i" (offsetof (struct pthread, member)));	      \
93dc2d
-     else if (sizeof (descr->member) == 4)				      \
93dc2d
-       asm volatile ("movl %0,%%fs:%P1" :				      \
93dc2d
-		     : IMM_MODE (value),				      \
93dc2d
-		       "i" (offsetof (struct pthread, member)));	      \
93dc2d
-     else /* 8 */							      \
93dc2d
-       {								      \
93dc2d
-	 /* Since movq takes a signed 32-bit immediate or a register source   \
93dc2d
-	    operand, use "er" constraint for 32-bit signed integer constant   \
93dc2d
-	    or register.  */						      \
93dc2d
-	 asm volatile ("movq %q0,%%fs:%P1" :				      \
93dc2d
-		       : "er" ((uint64_t) cast_to_integer (value)),	      \
93dc2d
-			 "i" (offsetof (struct pthread, member)));	      \
93dc2d
-       }})
93dc2d
-
93dc2d
-
93dc2d
-/* Same as THREAD_SETMEM, but the member offset can be non-constant.  */
93dc2d
-# define THREAD_SETMEM_NC(descr, member, idx, value) \
93dc2d
-  ({									      \
93dc2d
-     _Static_assert (sizeof (descr->member[0]) == 1			      \
93dc2d
-		     || sizeof (descr->member[0]) == 4			      \
93dc2d
-		     || sizeof (descr->member[0]) == 8,			      \
93dc2d
-		     "size of per-thread data");			      \
93dc2d
-     if (sizeof (descr->member[0]) == 1)				      \
93dc2d
-       asm volatile ("movb %b0,%%fs:%P1(%q2)" :				      \
93dc2d
-		     : "iq" (value),					      \
93dc2d
-		       "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
-		       "r" (idx));					      \
93dc2d
-     else if (sizeof (descr->member[0]) == 4)				      \
93dc2d
-       asm volatile ("movl %0,%%fs:%P1(,%q2,4)" :			      \
93dc2d
-		     : IMM_MODE (value),				      \
93dc2d
-		       "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
-		       "r" (idx));					      \
93dc2d
-     else /* 8 */							      \
93dc2d
-       {								      \
93dc2d
-	 /* Since movq takes a signed 32-bit immediate or a register source   \
93dc2d
-	    operand, use "er" constraint for 32-bit signed integer constant   \
93dc2d
-	    or register.  */						      \
93dc2d
-	 asm volatile ("movq %q0,%%fs:%P1(,%q2,8)" :			      \
93dc2d
-		       : "er" ((uint64_t) cast_to_integer (value)),	      \
93dc2d
-			 "i" (offsetof (struct pthread, member[0])),	      \
93dc2d
-			 "r" (idx));					      \
93dc2d
-       }})
93dc2d
-
93dc2d
+# include <tcb-access.h>
93dc2d
 
93dc2d
 /* Set the stack guard field in TCB head.  */
93dc2d
 # define THREAD_SET_STACK_GUARD(value) \