about summary refs log tree commit diff
path: root/linuxthreads
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2003-03-02 11:45:12 +0000
committerRoland McGrath <roland@gnu.org>2003-03-02 11:45:12 +0000
commitbb0ddc2f1eca652aa8af56825b2ba3182498cc5a (patch)
tree8b03305facff745ff0bd14c50e811dfd77cef343 /linuxthreads
parent3093b1c70cd227c3329d2bbb77cd59ce2cbdcbd4 (diff)
downloadglibc-bb0ddc2f1eca652aa8af56825b2ba3182498cc5a.tar.gz
glibc-bb0ddc2f1eca652aa8af56825b2ba3182498cc5a.tar.xz
glibc-bb0ddc2f1eca652aa8af56825b2ba3182498cc5a.zip
* sysdeps/powerpc/powerpc64/dl-machine.h (elf_machine_fixup_plt):
	Don't use weak_extern for dl_rtld_map.  Instead check only if [SHARED].
	(elf_machine_rela): Clean up.

	* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela): Clean up.

	PowerPC TLS support contributed by Paul Mackerras <paulus@samba.org>.
	* sysdeps/powerpc/powerpc32/elf/configure.in: New file.
	* sysdeps/powerpc/powerpc32/elf/configure: New generated file.
	* elf/tls-macros.h [__powerpc__ && !__powerpc64__]
	(TLS_LE, TLS_IE, TLS_LD, TLS_GD): Define them.
	* sysdeps/powerpc/powerpc32/dl-machine.h (elf_machine_rela): Support
	new relocs for TLS.

	* sysdeps/powerpc/dl-tls.h (TLS_TP_OFFSET, TLS_DTV_OFFSET): Move these
	macros out of [SHARED].
	(TLS_TPREL_VALUE, TLS_DTPREL_VALUE): New macros.

	* elf/elf.h: Define R_PPC_* relocs for TLS support.
	Clean up R_PPC64_* macro definition comments.
Diffstat (limited to 'linuxthreads')
-rw-r--r--linuxthreads/ChangeLog30
-rw-r--r--linuxthreads/descr.h19
-rw-r--r--linuxthreads/manager.c10
-rw-r--r--linuxthreads/pthread.c10
-rw-r--r--linuxthreads/sysdeps/ia64/tcb-offsets.sym2
-rw-r--r--linuxthreads/sysdeps/ia64/tls.h2
-rw-r--r--linuxthreads/sysdeps/powerpc/powerpc64/pt-machine.h12
-rw-r--r--linuxthreads/sysdeps/powerpc/tcb-offsets.sym22
-rw-r--r--linuxthreads/sysdeps/powerpc/tls.h63
-rw-r--r--linuxthreads/sysdeps/sh/tcb-offsets.sym2
-rw-r--r--linuxthreads/sysdeps/sh/tls.h2
-rw-r--r--linuxthreads/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h3
-rw-r--r--linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h3
-rw-r--r--linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h3
14 files changed, 131 insertions, 52 deletions
diff --git a/linuxthreads/ChangeLog b/linuxthreads/ChangeLog
index 6ab0613fa0..c9d18a9632 100644
--- a/linuxthreads/ChangeLog
+++ b/linuxthreads/ChangeLog
@@ -1,4 +1,32 @@
-2003-02-27  Roland McGrath  <roland@redhat.com>
+2003-03-01  Roland McGrath  <roland@redhat.com>
+
+	* sysdeps/powerpc/powerpc64/pt-machine.h
+	(THREAD_GETMEM, THREAD_GETMEM_NC, THREAD_SETMEM, THREAD_SETMEM_NC):
+	New macros.
+	* sysdeps/powerpc/tls.h: Don't define those here.
+
+	* sysdeps/powerpc/tls.h [! USE_TLS && !__powerpc64__]: Define
+	tcbhead_t with multiple_threads member.
+	[USE_TLS] (tcbhead_t): Define minimal one-word version.
+	[USE_TLS && !__powerpc64__] (TLS_MULTIPLE_THREADS_IN_TCB): Define.
+	* sysdeps/powerpc/tcb-offsets.sym [USE_TLS]: Use tls.h macros to
+	derive thread register offset of p_multiple_threads member.
+
+	* descr.h (struct _pthread_descr_struct) [!USE_TLS || !TLS_DTV_AT_TP]:
+	Conditionalize p_header member on this.
+	[TLS_MULTIPLE_THREADS_IN_TCB]: Add p_multiple_threads alternatively.
+	* sysdeps/ia64/tls.h [USE_TLS] (TLS_MULTIPLE_THREADS_IN_TCB): Define.
+	* sysdeps/sh/tls.h: Likewise.
+	* sysdeps/ia64/tcb-offsets.sym [USE_TLS]: Use p_multiple_threads.
+	* sysdeps/sh/tcb-offsets.sym: Likewise.
+	* sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
+	(SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
+	(SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
+	(SINGLE_THREAD_P): Likewise.
+	* pthread.c (__pthread_initialize_manager): Likewise.
+	* manager.c (pthread_handle_create): Likewise.
 
 	* sysdeps/powerpc/tls.h [HAVE_TLS_SUPPORT]: Define USE_TLS and all
 	related macros.
diff --git a/linuxthreads/descr.h b/linuxthreads/descr.h
index d266ffb126..2dcb37642a 100644
--- a/linuxthreads/descr.h
+++ b/linuxthreads/descr.h
@@ -23,6 +23,7 @@
 #include <stdint.h>
 #include <sys/types.h>
 #include <hp-timing.h>
+#include <tls.h>
 
 /* Fast thread-specific data internal to libc.  */
 enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0,
@@ -106,11 +107,14 @@ typedef struct _pthread_rwlock_info {
 
 union dtv;
 
-
-struct _pthread_descr_struct {
-  /* XXX Remove this union for IA-64 style TLS module */
-  union {
-    struct {
+struct _pthread_descr_struct
+{
+#if !defined USE_TLS || !TLS_DTV_AT_TP
+  /* This overlaps tcbhead_t (see tls.h), as used for TLS without threads.  */
+  union
+  {
+    struct
+    {
       void *tcb;		/* Pointer to the TCB.  This is not always
 				   the address of this thread descriptor.  */
       union dtv *dtvp;
@@ -122,6 +126,11 @@ struct _pthread_descr_struct {
     } data;
     void *__padding[16];
   } p_header;
+# define p_multiple_threads p_header.data.multiple_threads
+#elif TLS_MULTIPLE_THREADS_IN_TCB
+  int p_multiple_threads;
+#endif
+
   pthread_descr p_nextlive, p_prevlive;
                                 /* Double chaining of active threads */
   pthread_descr p_nextwaiting;  /* Next element in the queue holding the thr */
diff --git a/linuxthreads/manager.c b/linuxthreads/manager.c
index 8f9b23841b..3ecf7d16f8 100644
--- a/linuxthreads/manager.c
+++ b/linuxthreads/manager.c
@@ -638,13 +638,13 @@ static int pthread_handle_create(pthread_t *thread, const pthread_attr_t *attr,
   new_thread_id = sseg + pthread_threads_counter;
   /* Initialize the thread descriptor.  Elements which have to be
      initialized to zero already have this value.  */
-#if defined USE_TLS && TLS_DTV_AT_TP
-  new_thread->p_header.data.tcb = new_thread + 1;
-#else
+#if !defined USE_TLS || !TLS_DTV_AT_TP
   new_thread->p_header.data.tcb = new_thread;
-#endif
   new_thread->p_header.data.self = new_thread;
-  new_thread->p_header.data.multiple_threads = 1;
+#endif
+#if TLS_MULTIPLE_THREADS_IN_TCB || !defined USE_TLS || !TLS_DTV_AT_TP
+  new_thread->p_multiple_threads = 1;
+#endif
   new_thread->p_tid = new_thread_id;
   new_thread->p_lock = &(__pthread_handles[sseg].h_lock);
   new_thread->p_cancelstate = PTHREAD_CANCEL_ENABLE;
diff --git a/linuxthreads/pthread.c b/linuxthreads/pthread.c
index 2888a6a2f7..01be30ba12 100644
--- a/linuxthreads/pthread.c
+++ b/linuxthreads/pthread.c
@@ -566,8 +566,10 @@ int __pthread_initialize_manager(void)
 #endif
 
   __pthread_multiple_threads = 1;
-  __pthread_main_thread->p_header.data.multiple_threads = 1;
-  * __libc_multiple_threads_ptr = 1;
+#if TLS_MULTIPLE_THREADS_IN_TCB || !defined USE_TLS || !TLS_DTV_AT_TP
+  __pthread_main_thread->p_multiple_threads = 1;
+#endif
+  *__libc_multiple_threads_ptr = 1;
 
 #ifndef HAVE_Z_NODELETE
   if (__builtin_expect (&__dso_handle != NULL, 1))
@@ -611,9 +613,13 @@ int __pthread_initialize_manager(void)
   __pthread_handles[1].h_descr = manager_thread = mgr;
 
   /* Initialize the descriptor.  */
+#if !defined USE_TLS || !TLS_DTV_AT_TP
   mgr->p_header.data.tcb = tcbp;
   mgr->p_header.data.self = mgr;
   mgr->p_header.data.multiple_threads = 1;
+#elif TLS_MULTIPLE_THREADS_IN_TCB
+  mgr->p_multiple_threads = 1;
+#endif
   mgr->p_lock = &__pthread_handles[1].h_lock;
 # ifndef HAVE___THREAD
   mgr->p_errnop = &mgr->p_errno;
diff --git a/linuxthreads/sysdeps/ia64/tcb-offsets.sym b/linuxthreads/sysdeps/ia64/tcb-offsets.sym
index 2b677f5abb..f7793f7665 100644
--- a/linuxthreads/sysdeps/ia64/tcb-offsets.sym
+++ b/linuxthreads/sysdeps/ia64/tcb-offsets.sym
@@ -3,7 +3,7 @@
 
 --
 #ifdef USE_TLS
-MULTIPLE_THREADS_OFFSET offsetof (struct _pthread_descr_struct, p_header.data.multiple_threads) - sizeof (struct _pthread_descr_struct)
+MULTIPLE_THREADS_OFFSET offsetof (struct _pthread_descr_struct, p_multiple_threads) - sizeof (struct _pthread_descr_struct)
 #else
 MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads)
 #endif
diff --git a/linuxthreads/sysdeps/ia64/tls.h b/linuxthreads/sysdeps/ia64/tls.h
index 238ea08399..7aec4f4f8a 100644
--- a/linuxthreads/sysdeps/ia64/tls.h
+++ b/linuxthreads/sysdeps/ia64/tls.h
@@ -98,6 +98,8 @@ typedef struct
 #  define INIT_THREAD_SELF(descr, nr) \
   (__thread_self = (struct _pthread_descr_struct *)(descr) + 1)
 
+# define TLS_MULTIPLE_THREADS_IN_TCB 1
+
 /* Get the thread descriptor definition.  */
 #  include <linuxthreads/descr.h>
 
diff --git a/linuxthreads/sysdeps/powerpc/powerpc64/pt-machine.h b/linuxthreads/sysdeps/powerpc/powerpc64/pt-machine.h
index a3dc26fe21..e3a153af14 100644
--- a/linuxthreads/sysdeps/powerpc/powerpc64/pt-machine.h
+++ b/linuxthreads/sysdeps/powerpc/powerpc64/pt-machine.h
@@ -1,6 +1,6 @@
 /* Machine-dependent pthreads configuration and inline functions.
    powerpc version.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -57,6 +57,16 @@ register struct _pthread_descr_struct *__thread_self __asm__("r13");
 /* Initialize the thread-unique value.  */
 #define INIT_THREAD_SELF(descr, nr)  (__thread_self = (descr))
 
+/* Access to data in the thread descriptor is easy.  */
+#define THREAD_GETMEM(descr, member) \
+  ((void) (descr), THREAD_SELF->member)
+#define THREAD_GETMEM_NC(descr, member) \
+  ((void) (descr), THREAD_SELF->member)
+#define THREAD_SETMEM(descr, member, value) \
+  ((void) (descr), THREAD_SELF->member = (value))
+#define THREAD_SETMEM_NC(descr, member, value) \
+  ((void) (descr), THREAD_SELF->member = (value))
+
 /* Compare-and-swap for semaphores. */
 /* note that test-and-set(x) is the same as !compare-and-swap(x, 0, 1) */
 
diff --git a/linuxthreads/sysdeps/powerpc/tcb-offsets.sym b/linuxthreads/sysdeps/powerpc/tcb-offsets.sym
index aee6be2570..bb4226fb3a 100644
--- a/linuxthreads/sysdeps/powerpc/tcb-offsets.sym
+++ b/linuxthreads/sysdeps/powerpc/tcb-offsets.sym
@@ -1,4 +1,24 @@
 #include <sysdep.h>
 #include <tls.h>
 
-MULTIPLE_THREADS_OFFSET		offsetof (tcbhead_t, multiple_threads)
+--
+
+-- This could go into powerpc32/ instead and conditionalize #include of it.
+#ifndef __powerpc64__
+
+# ifdef USE_TLS
+
+-- 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->p_##mem - (void *) 0)
+
+# else
+
+#  define thread_offsetof(mem)	offsetof (tcbhead_t, mem)
+
+# endif
+
+MULTIPLE_THREADS_OFFSET		thread_offsetof (multiple_threads)
+
+#endif
diff --git a/linuxthreads/sysdeps/powerpc/tls.h b/linuxthreads/sysdeps/powerpc/tls.h
index 1c34a3b7b5..d946d06fae 100644
--- a/linuxthreads/sysdeps/powerpc/tls.h
+++ b/linuxthreads/sysdeps/powerpc/tls.h
@@ -32,15 +32,6 @@ typedef union dtv
   void *pointer;
 } dtv_t;
 
-typedef struct
-{
-  void *tcb;		/* Pointer to the TCB.  Not necessary the
-			   thread descriptor used by libpthread.  */
-  dtv_t *dtv;
-  void *self;		/* Pointer to the thread descriptor.  */
-  int multiple_threads;
-} tcbhead_t;
-
 #else /* __ASSEMBLER__ */
 # include <tcb-offsets.h>
 #endif /* __ASSEMBLER__ */
@@ -52,6 +43,14 @@ typedef struct
 
 # ifndef __ASSEMBLER__
 
+/* This layout is actually wholly private and not affected by the ABI.
+   Nor does it overlap the pthread data structure, so we need nothing
+   extra here at all.  */
+typedef struct
+{
+  dtv_t *dtv;
+} tcbhead_t;
+
 /* This is the size of the initial TCB.  */
 #  define TLS_INIT_TCB_SIZE	sizeof (tcbhead_t)
 
@@ -67,12 +66,12 @@ typedef struct
 /* This is the size we need before TCB.  */
 #  define TLS_PRE_TCB_SIZE	sizeof (struct _pthread_descr_struct)
 
-/* The following assumes that TP (R13) is points to the end of the
+/* The following assumes that TP (R2 or R13) is points to the end of the
    TCB + 0x7000 (per the ABI).  This implies that TCB address is
-   R13-(TLS_TCB_SIZE + 0x7000).  As we define TLS_DTV_AT_TP we can
+   TP-(TLS_TCB_SIZE + 0x7000).  As we define TLS_DTV_AT_TP we can
    assume that the pthread_descr is allocated immediately ahead of the
    TCB.  This implies that the pthread_descr address is
-   R13-(TLS_PRE_TCB_SIZE + TLS_TCB_SIZE + 0x7000).  */
+   TP-(TLS_PRE_TCB_SIZE + TLS_TCB_SIZE + 0x7000).  */
 #  define TLS_TCB_OFFSET	0x7000
 
 /* The DTV is allocated at the TP; the TCB is placed elsewhere.  */
@@ -99,7 +98,7 @@ typedef struct
    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, 0)
+    (__thread_register = (void *) (TCBP) + TLS_TCB_OFFSET + TLS_TCB_SIZE, NULL)
 
 /* Return the address of the dtv for the current thread.  */
 #  define THREAD_DTV() \
@@ -116,30 +115,36 @@ typedef struct
      (__thread_register = ((void *) (DESCR) \
 		           + TLS_TCB_OFFSET + TLS_TCB_SIZE + TLS_PRE_TCB_SIZE))
 
+/* Make sure we have the p_multiple_threads member in the thread structure.
+   See below.  */
+#  ifndef __powerpc64__
+#   define TLS_MULTIPLE_THREADS_IN_TCB 1
+#  endif
+
 /* Get the thread descriptor definition.  */
 #  include <linuxthreads/descr.h>
 
-/* Generic bits of LinuxThreads may call these macros with
-   DESCR set to NULL.  We are expected to be able to reference
-   the "current" value.  */
-
-#  define THREAD_GETMEM(descr, member) \
-     ((void) sizeof (descr), THREAD_SELF->member)
-#  define THREAD_SETMEM(descr, member, value) \
-     ((void) sizeof (descr), THREAD_SELF->member = (value))
-
-#define THREAD_GETMEM_NC(descr, member) THREAD_GETMEM (descr, member)
-#define THREAD_SETMEM_NC(descr, member, value) \
-  THREAD_SETMEM ((descr), member, (value))
-
 # endif /* __ASSEMBLER__ */
 
-#else /* Not HAVE_TLS_SUPPORT.  */
+#elif !defined __ASSEMBLER__ && !defined __powerpc64__
+
+/* This overlaps the start of the pthread_descr.  On PPC32, system
+   calls and such use this to find the multiple_threads flag and need
+   to use the same offset relative to the thread register in both
+   single-threaded and multi-threaded code.  On PPC64, the global
+   variable is always used, so single-threaded code without TLS
+   never needs to initialize the thread register at all.  */
+typedef struct
+{
+  void *tcb;			/* Never used.  */
+  dtv_t *dtv;			/* Never used.  */
+  void *self;			/* Used only if multithreaded, and rarely.  */
+  int multiple_threads;		/* Only this member is really used.  */
+} tcbhead_t;
 
 #define NONTLS_INIT_TP							\
   do {									\
-    static const tcbhead_t nontls_init_tp				\
-      = { .multiple_threads = 0 };					\
+    static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 };	\
     __thread_self = (__typeof (__thread_self)) &nontls_init_tp;		\
   } while (0)
 
diff --git a/linuxthreads/sysdeps/sh/tcb-offsets.sym b/linuxthreads/sysdeps/sh/tcb-offsets.sym
index d74292b1c2..328eb05738 100644
--- a/linuxthreads/sysdeps/sh/tcb-offsets.sym
+++ b/linuxthreads/sysdeps/sh/tcb-offsets.sym
@@ -3,7 +3,7 @@
 
 --
 #ifdef USE_TLS
-MULTIPLE_THREADS_OFFSET offsetof (struct _pthread_descr_struct, p_header.data.multiple_threads)
+MULTIPLE_THREADS_OFFSET offsetof (struct _pthread_descr_struct, p_multiple_threads)
 TLS_PRE_TCB_SIZE	sizeof (struct _pthread_descr_struct)
 #else
 MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads)
diff --git a/linuxthreads/sysdeps/sh/tls.h b/linuxthreads/sysdeps/sh/tls.h
index af67a8eded..17a247c6b6 100644
--- a/linuxthreads/sysdeps/sh/tls.h
+++ b/linuxthreads/sysdeps/sh/tls.h
@@ -112,6 +112,8 @@ typedef struct
      __asm __volatile ("ldc %0,gbr" : : "r" (__self + 1));		      \
      0; })
 
+# define TLS_MULTIPLE_THREADS_IN_TCB 1
+
 /* Get the thread descriptor definition.  This must be after the
    the definition of THREAD_SELF for TLS.  */
 #  include <linuxthreads/descr.h>
diff --git a/linuxthreads/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h b/linuxthreads/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
index ec9451775d..af45b19356 100644
--- a/linuxthreads/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
+++ b/linuxthreads/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
@@ -101,8 +101,7 @@ __syscall_error_##args:							      \
 
 # ifndef __ASSEMBLER__
 #  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				      \
-				   p_header.data.multiple_threads) == 0, 1)
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, p_multiple_threads) == 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/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h b/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
index 155ea47d84..2d191d115c 100644
--- a/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
+++ b/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
@@ -85,8 +85,7 @@
 
 # ifndef __ASSEMBLER__
 #  define SINGLE_THREAD_P						\
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
-				     p_header.data.multiple_threads) == 0, 1)
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, p_multiple_threads) == 0, 1)
 # else
 #  define SINGLE_THREAD_P						\
   lwz 10,MULTIPLE_THREADS_OFFSET(2);					\
diff --git a/linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h b/linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
index 57db351735..e6d0cca252 100644
--- a/linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
+++ b/linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
@@ -121,8 +121,7 @@
 # ifndef __ASSEMBLER__
 #  if defined FLOATING_STACKS && USE___THREAD && defined PIC
 #   define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				      \
-				   p_header.data.multiple_threads) == 0, 1)
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, p_multiple_threads) == 0, 1)
 #  else
 extern int __local_multiple_threads attribute_hidden;
 #   define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)