about summary refs log tree commit diff
path: root/nptl
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-04-25 09:12:43 +0000
committerUlrich Drepper <drepper@redhat.com>2003-04-25 09:12:43 +0000
commit299601a1ef8df4532ded24194c4556e294ab1e6e (patch)
tree7e7338ca0004ce7fdba3e7429677ef0a5786ad8f /nptl
parent29bfc9453e2945b476cec5545f8409fd2a2ba886 (diff)
downloadglibc-299601a1ef8df4532ded24194c4556e294ab1e6e.tar.gz
glibc-299601a1ef8df4532ded24194c4556e294ab1e6e.tar.xz
glibc-299601a1ef8df4532ded24194c4556e294ab1e6e.zip
Update.
2003-04-22  Jakub Jelinek  <jakub@redhat.com>

	* include/link.h (NO_TLS_OFFSET): Define to 0 if not defined.
	* elf/dl-close.c (_dl_close): Use NO_TLS_OFFSET.
	* elf/dl-object.c (_dl_new_object): Initialize l_tls_offset to
	NO_TLS_OFFSET.
	* elf/rtld.c (_dl_start_final, _dl_start): Likewise.
	* elf/dl-reloc.c (CHECK_STATIC_TLS): Use NO_TLS_OFFSET.
	* sysdeps/generic/dl-tls.c (_dl_allocate_tls_init): Likewise.
	* sysdeps/powerpc/dl-tls.h (TLS_TPREL_VALUE): Don't subtract
	TLS_TCB_SIZE.
Diffstat (limited to 'nptl')
-rw-r--r--nptl/ChangeLog38
-rw-r--r--nptl/allocatestack.c16
-rw-r--r--nptl/descr.h21
-rw-r--r--nptl/sysdeps/ia64/tcb-offsets.sym2
-rw-r--r--nptl/sysdeps/powerpc/tcb-offsets.sym11
-rw-r--r--nptl/sysdeps/powerpc/tls.h31
-rw-r--r--nptl/sysdeps/pthread/createthread.c8
-rw-r--r--nptl/sysdeps/sh/tcb-offsets.sym2
-rw-r--r--nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h2
-rw-r--r--nptl/sysdeps/unix/sysv/linux/powerpc/createthread.c2
-rw-r--r--nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h3
-rw-r--r--nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h3
-rw-r--r--nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h3
13 files changed, 95 insertions, 47 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index b1b68b4b3e..8e76d9e417 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,41 @@
+2003-04-22  Jakub Jelinek  <jakub@redhat.com>
+
+	* descr.h (p_multiple_threads): Define.
+	(struct pthread) [TLS_MULTIPLE_THREADS_IN_TCB]: Move
+	multiple_threads to last int in the structure.
+	* allocatestack.c (TLS_TPADJ): Add TLS_PRE_TCB_SIZE instead of
+	sizeof (struct pthread).
+	(allocate_stack): Subtract TLS_PRE_TCB_SIZE bytes instead of
+	1 struct pthread.  Use p_multiple_threads macro.
+	* sysdeps/pthread/createthread.c (create_thread): Use
+	p_multiple_threads macro if TLS_DTV_AT_TP.
+	* sysdeps/powerpc/tls.h (TLS_INIT_TCB_SIZE, TLS_TCB_SIZE): Define
+	to 0.
+	(TLS_INIT_TCB_ALIGN, TLS_TCB_ALIGN): Define to alignment of
+	struct pthread.
+	(TLS_PRE_TCB_SIZE): Increase to cover tcbhead_t preceeded by pad
+	to 32-bit bytes.
+	(INSTALL_DTV, GET_DTV, THREAD_DTV): tcbhead_t is immediately before
+	tcbp.
+	(TLS_INIT_TP, THREAD_SELF, INIT_THREAD_SELF): Don't add TLS_TCB_SIZE
+	unneccessarily.
+	(NO_TLS_OFFSET): Define.
+	* sysdeps/powerpc/tcb-offsets.sym (MULTIPLE_THREADS): Use
+	p_multiple_threads macro.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
+	(SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
+	(SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/createthread.c (TLS_VALUE): Don't
+	add TLS_TCB_SIZE unnecessarily.
+	* sysdeps/ia64/tcb-offsets.sym (MULTIPLE_THREADS): Define to
+	-sizeof(int).
+	* sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (SINGLE_THREAD_P):
+	Use p_multiple_threads macro.
+	* sysdeps/sh/tcb-offsets.sym (MULTIPLE_THREADS): Likewise.
+	* sysdeps/unix/sysv/linux/sh/sysdep-cancel.h (SINGLE_THREAD_P):
+	Likewise.
+
 2003-04-22  Roland McGrath  <roland@redhat.com>
 
 	* Makeconfig (shared-thread-library): Reverse link order to work
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index c199cf21d4..c6b89d873e 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -81,7 +81,7 @@
 #if TLS_TCB_AT_TP
 # define TLS_TPADJ(pd) (pd)
 #elif TLS_DTV_AT_TP
-# define TLS_TPADJ(pd) ((pd) + 1)
+# define TLS_TPADJ(pd) ((struct pthread *)((char *) (pd) + TLS_PRE_TCB_SIZE))
 #endif
 
 /* Cache handling for not-yet free stacks.  */
@@ -296,8 +296,9 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
       pd = (struct pthread *) ((uintptr_t) attr->stackaddr
 			       - TLS_TCB_SIZE - adj);
 #elif TLS_DTV_AT_TP
-      pd = (struct pthread *) ((uintptr_t) attr->stackaddr
-			       - __static_tls_size - adj) - 1;
+      pd = (struct pthread *) (((uintptr_t) attr->stackaddr
+			        - __static_tls_size - adj)
+			       - TLS_PRE_TCB_SIZE);
 #endif
 
       /* The user provided stack memory needs to be cleared.  */
@@ -321,7 +322,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 
 #ifdef TLS_MULTIPLE_THREADS_IN_TCB
       /* This is at least the second thread.  */
-      pd->header.multiple_threads = 1;
+      p_multiple_threads (pd) = 1;
 #else
       __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;
 #endif
@@ -426,9 +427,10 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 #if TLS_TCB_AT_TP
 	  pd = (struct pthread *) ((char *) mem + size - coloring) - 1;
 #elif TLS_DTV_AT_TP
-	  pd = (struct pthread *) (((uintptr_t) mem + size - coloring
+	  pd = (struct pthread *) ((((uintptr_t) mem + size - coloring
 				    - __static_tls_size)
-				   & ~__static_tls_align_m1) - 1;
+				    & ~__static_tls_align_m1)
+				   - TLS_PRE_TCB_SIZE);
 #endif
 
 	  /* Remember the stack-related values.  */
@@ -447,7 +449,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 
 #ifdef TLS_MULTIPLE_THREADS_IN_TCB
 	  /* This is at least the second thread.  */
-	  pd->header.multiple_threads = 1;
+	  p_multiple_threads (pd) = 1;
 #else
 	  __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;
 #endif
diff --git a/nptl/descr.h b/nptl/descr.h
index efb25c7479..7fd64ecb39 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -99,11 +99,7 @@ struct pthread
 #if !TLS_DTV_AT_TP
     /* This overlaps the TCB as used for TLS without threads (see tls.h).  */
     tcbhead_t header;
-#elif TLS_MULTIPLE_THREADS_IN_TCB
-    struct
-    {
-      int multiple_threads;
-    } header;
+# define p_multiple_threads(descr) (descr)->header.multiple_threads
 #endif
 
     /* This extra padding has no special purpose, and this structure layout
@@ -232,6 +228,21 @@ struct pthread
   size_t stackblock_size;
   /* Size of the included guard area.  */
   size_t guardsize;
+
+#if TLS_DTV_AT_TP && TLS_MULTIPLE_THREADS_IN_TCB
+  /* Must come last.  */
+  int __multiple_threads;
+# define p_multiple_threads(descr) \
+  ((union							\
+    {								\
+      struct pthread s;						\
+      struct							\
+	{							\
+	  char dummy[sizeof (struct pthread) - sizeof (int)];   \
+	  int multiple_threads;					\
+	} m;							\
+    } *)(descr)->m.multiple_threads)
+#endif
 } __attribute ((aligned (TCB_ALIGNMENT)));
 
 
diff --git a/nptl/sysdeps/ia64/tcb-offsets.sym b/nptl/sysdeps/ia64/tcb-offsets.sym
index 11cc06ab31..9f92bb62cd 100644
--- a/nptl/sysdeps/ia64/tcb-offsets.sym
+++ b/nptl/sysdeps/ia64/tcb-offsets.sym
@@ -1,4 +1,4 @@
 #include <sysdep.h>
 #include <tls.h>
 
-MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) - sizeof (struct pthread)
+MULTIPLE_THREADS_OFFSET -sizeof(int)
diff --git a/nptl/sysdeps/powerpc/tcb-offsets.sym b/nptl/sysdeps/powerpc/tcb-offsets.sym
index d6b7560b8e..58ee03072e 100644
--- a/nptl/sysdeps/powerpc/tcb-offsets.sym
+++ b/nptl/sysdeps/powerpc/tcb-offsets.sym
@@ -1,13 +1,4 @@
 #include <sysdep.h>
 #include <tls.h>
 
---
-
--- Abuse tls.h macros to derive offsets relative to the thread register.
-# undef __thread_register
-# define __thread_register	((void *) 0)
-# define thread_offsetof(mem)	((void *) &THREAD_SELF->mem - (void *) 0)
-
-#if TLS_MULTIPLE_THREADS_IN_TCB
-MULTIPLE_THREADS_OFFSET		thread_offsetof (header.multiple_threads)
-#endif
+MULTIPLE_THREADS_OFFSET	((void *) &p_multiple_threads ((struct pthread) ((void *) 0 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)) - (void *) 0)
diff --git a/nptl/sysdeps/powerpc/tls.h b/nptl/sysdeps/powerpc/tls.h
index 0ef5655b8d..e3e0424fe0 100644
--- a/nptl/sysdeps/powerpc/tls.h
+++ b/nptl/sysdeps/powerpc/tls.h
@@ -69,22 +69,19 @@ typedef struct
 } tcbhead_t;
 
 /* This is the size of the initial TCB.  */
-# define TLS_INIT_TCB_SIZE	sizeof (tcbhead_t)
+# define TLS_INIT_TCB_SIZE	0
 
 /* Alignment requirements for the initial TCB.  */
-# define TLS_INIT_TCB_ALIGN	__alignof__ (tcbhead_t)
+# define TLS_INIT_TCB_ALIGN	__alignof__ (struct pthread)
 
 /* This is the size of the TCB.  */
-# define TLS_TCB_SIZE		sizeof (tcbhead_t)
+# define TLS_TCB_SIZE		0
 
 /* Alignment requirements for the TCB.  */
-# define TLS_TCB_ALIGN		__alignof__ (tcbhead_t)
+# define TLS_TCB_ALIGN		__alignof__ (struct pthread)
 
 /* This is the size we need before TCB.  */
-# define TLS_PRE_TCB_SIZE	sizeof (struct pthread)
-
-/* XXX if __alignof__ (struct pthread) > __alignof (tcbhead_t)
-   we could be in trouble.  -- paulus */
+# define TLS_PRE_TCB_SIZE	(sizeof (struct pthread) + 32)
 
 # ifndef __powerpc64__
 /* Register r2 (tp) is reserved by the ABI as "thread pointer". */
@@ -98,37 +95,37 @@ register void *__thread_register __asm__ ("r13");
 
 /* The following assumes that TP (R2 or R13) points to the end of the
    TCB + 0x7000 (per the ABI).  This implies that TCB address is
-   TP-(TLS_TCB_SIZE + 0x7000).  As we define TLS_DTV_AT_TP we can
+   TP - 0x7000.  As we define TLS_DTV_AT_TP we can
    assume that the pthread struct is allocated immediately ahead of the
    TCB.  This implies that the pthread_descr address is
-   TP-(TLS_PRE_TCB_SIZE + TLS_TCB_SIZE + 0x7000).  */
+   TP - (TLS_PRE_TCB_SIZE + 0x7000).  */
 # define TLS_TCB_OFFSET	0x7000
 
 /* Install the dtv pointer.  The pointer passed is to the element with
    index -1 which contain the length.  */
 # define INSTALL_DTV(tcbp, dtvp) \
-  ((tcbhead_t *) (tcbp))->dtv = dtvp + 1
+  ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
 
 /* Install new dtv for current thread.  */
 # define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
 
 /* Return dtv of given thread descriptor.  */
-# define GET_DTV(tcbp)	(((tcbhead_t *) (tcbp))->dtv)
+# define GET_DTV(tcbp)	(((tcbhead_t *) (tcbp))[-1].dtv)
 
 /* Code to initially initialize the thread pointer.  This might need
    special attention since 'errno' is not yet available and if the
    operation can cause a failure 'errno' must not be touched.  */
 # define TLS_INIT_TP(tcbp, secondcall) \
-    (__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET + TLS_TCB_SIZE, NULL)
+    (__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET, NULL)
 
 /* Return the address of the dtv for the current thread.  */
 # define THREAD_DTV() \
-     (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET - TLS_TCB_SIZE))->dtv)
+     (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET))[-1].dtv)
 
 /* Return the thread descriptor for the current thread.  */
 # define THREAD_SELF \
     ((struct pthread *) (__thread_register \
-			 - TLS_TCB_OFFSET - TLS_TCB_SIZE - TLS_PRE_TCB_SIZE))
+			 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
 
 /* Read member of the thread descriptor directly.  */
 # define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
@@ -145,6 +142,10 @@ register void *__thread_register __asm__ ("r13");
 # define THREAD_SETMEM_NC(descr, member, idx, value) \
     ((void)(descr), (THREAD_SELF)->member[idx] = (value))
 
+/* l_tls_offset == 0 is perfectly valid on PPC, so we have to use some
+   different value to mean unset l_tls_offset.  */
+# define NO_TLS_OFFSET		-1
+
 #endif /* __ASSEMBLER__ */
 
 #endif	/* tls.h */
diff --git a/nptl/sysdeps/pthread/createthread.c b/nptl/sysdeps/pthread/createthread.c
index 9d00e4e135..f5c640607a 100644
--- a/nptl/sysdeps/pthread/createthread.c
+++ b/nptl/sysdeps/pthread/createthread.c
@@ -87,7 +87,11 @@ create_thread (struct pthread *pd, STACK_VARIABLES_PARMS)
 	     thread might not yet have the flag set.  No need to set
 	     the global variable again if this is what we use.  */
 #ifdef TLS_MULTIPLE_THREADS_IN_TCB
+# if TLS_DTV_AT_TP
+	  p_multiple_threads (THREAD_SELF) = 1;
+# else
 	  THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1);
+# endif
 #endif
 
 	  /* Now fill in the information about the new thread in
@@ -159,7 +163,11 @@ create_thread (struct pthread *pd, STACK_VARIABLES_PARMS)
      not yet have the flag set.  No need to set the global variable
      again if this is what we use.  */
 #ifdef TLS_MULTIPLE_THREADS_IN_TCB
+# if TLS_DTV_AT_TP
+  p_multiple_threads (THREAD_SELF) = 1;
+# else
   THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1);
+# endif
 #endif
 
   return 0;
diff --git a/nptl/sysdeps/sh/tcb-offsets.sym b/nptl/sysdeps/sh/tcb-offsets.sym
index 3386f1d056..940c933edf 100644
--- a/nptl/sysdeps/sh/tcb-offsets.sym
+++ b/nptl/sysdeps/sh/tcb-offsets.sym
@@ -1,5 +1,5 @@
 #include <sysdep.h>
 #include <tls.h>
 
-MULTIPLE_THREADS_OFFSET		offsetof (struct pthread, header.multiple_threads)
+MULTIPLE_THREADS_OFFSET		((char *) &p_multiple_threads ((struct pthread *)0) - (char *) 0)
 TLS_PRE_TCB_SIZE		sizeof (struct pthread)
diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h b/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
index 667abce340..930cc14e45 100644
--- a/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
+++ b/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
@@ -101,7 +101,7 @@ __syscall_error_##args:							      \
 
 # ifndef __ASSEMBLER__
 #  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, header.multiple_threads) == 0, 1)
+  __builtin_expect (p_multiple_threads (THREAD_SELF) == 0, 1)
 # else
 #  define SINGLE_THREAD_P \
   adds r14 = MULTIPLE_THREADS_OFFSET, r13 ;; ld4 r14 = [r14] ;; cmp4.ne p6, p7 = 0, r14
diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/createthread.c b/nptl/sysdeps/unix/sysv/linux/powerpc/createthread.c
index bcbcdd724b..e811ad74eb 100644
--- a/nptl/sysdeps/unix/sysv/linux/powerpc/createthread.c
+++ b/nptl/sysdeps/unix/sysv/linux/powerpc/createthread.c
@@ -19,7 +19,7 @@
 
 /* Value passed to 'clone' for initialization of the thread register.  */
 #define TLS_VALUE ((void *) (pd) \
-		   + TLS_TCB_OFFSET + TLS_TCB_SIZE + TLS_PRE_TCB_SIZE)
+		   + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
 
 /* Get the real implementation.	 */
 #include <nptl/sysdeps/pthread/createthread.c>
diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
index d256f8d8b2..f82addb3ad 100644
--- a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
+++ b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
@@ -86,8 +86,7 @@
 
 # ifndef __ASSEMBLER__
 #  define SINGLE_THREAD_P						\
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
-				   header.multiple_threads) == 0, 1)
+  __builtin_expect (p_multiple_threads (THREAD_SELF) == 0, 1)
 # else
 #  define SINGLE_THREAD_P						\
   lwz 10,MULTIPLE_THREADS_OFFSET(2);					\
diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
index 5483586c7b..00dc3a2a6a 100644
--- a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
+++ b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
@@ -86,8 +86,7 @@
 
 # ifndef __ASSEMBLER__
 #  define SINGLE_THREAD_P						\
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
-				   header.multiple_threads) == 0, 1)
+  __builtin_expect (p_multiple_threads (THREAD_SELF) == 0, 1)
 # else
 #   define SINGLE_THREAD_P						\
   lwz   10,MULTIPLE_THREADS_OFFSET(13);				\
diff --git a/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h b/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
index 16f8ad5e0f..10189a49b5 100644
--- a/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
+++ b/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
@@ -117,8 +117,7 @@
 
 # ifndef __ASSEMBLER__
 #  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
+  __builtin_expect (p_multiple_threads (THREAD_SELF) == 0, 1)
 # else
 #  define SINGLE_THREAD_P \
 	stc gbr,r0; \