This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: dlclose and TLS


Ulrich Drepper writes:

> I've checked in some code to fix dlclose of modules with static TLS
> for TLS_TCB_AT_TP platforms.  The existing code was completely broken
> but I thnk it should more or less work for TLS_DTV_AT_TP platforms.

As of this morning ppc and ppc64 linuxthreads are working but nplt is not. At the moment nptl-0.36 is out sync with glibc at cvs head.

The problem I fould was that (at glibc cvs head) TLS_TCB_SIZE (defined as 0) was removed from the TLS_TPREL_VALUE calculation (in sysdeps/powerpc/dl-tls.h). To compensate the size of tcbhead_t was rolled into TLS_PRE_TCB_SIZE (in linuxthreads/sysdeps/powerpc/tls.h). Also dtv addressing was changed to use (TCBP)[-1].dtv.

The nptl sysdeps/powerpc/tls.h is still using the old definition (TLS_PRE_TCB_SIZE does not include sizeof(tcbhead_t)) so all TPREL relocations are off by sizeof(tcbhead_t).

Unfortunately my attemps so far (by either changing powerpc/dl-tls.h (add TLS_TCB_SIZE back) or nptl's powerpc/tls.h (make it look like linuxthreads powerpc/tls.h) have successed in getting ppc32/64 nptl working. There seems to be dependences in glibc for TLS_TCB_SIZE to be 0 and in nptl-0.36 for it to be sizeof(tcbhead_t)

Is anyone else working on the corresponing nptl changes?

If not what are the generic glibc dependences on TLS_TCB_SIZE and TLS_PRE_TCB_SIZE for TLS_DTV_AT_TP platforms?



diff -urN nptl-0.36/nptl/sysdeps/powerpc/tls.h libc23/nptl/sysdeps/powerpc/tls.h
--- nptl-0.36/nptl/sysdeps/powerpc/tls.h	2003-03-20 02:53:01.000000000 -0600
+++ libc23/nptl/sysdeps/powerpc/tls.h	2003-04-28 13:58:43.000000000 -0500
@@ -69,19 +69,21 @@
 } 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)
+# define TLS_PRE_TCB_SIZE \
+  (sizeof (struct pthread)				      \
+   + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
 
 /* XXX if __alignof__ (struct pthread) > __alignof (tcbhead_t)
    we could be in trouble.  -- paulus */
@@ -98,37 +100,37 @@
 
 /* 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
+# define INSTALL_DTV(TCBP, DTVP) \
+  ((tcbhead_t *) (TCBP))[-1].dtv = (DTVP) + 1
 
 /* Install new dtv for current thread.  */
-# define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
+# 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)
+# define TLS_INIT_TP(TCBP, secondcall) \
+    (__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)
diff -urN libc23-cvstip-20030428/sysdeps/powerpc/dl-tls.h libc23/sysdeps/powerpc/dl-tls.h
--- libc23-cvstip-20030428/sysdeps/powerpc/dl-tls.h	2003-04-25 04:08:56.000000000 -0500
+++ libc23/sysdeps/powerpc/dl-tls.h	2003-04-28 17:34:28.000000000 -0500
@@ -35,7 +35,7 @@
 /* Compute the value for a @tprel reloc.  */
 #define TLS_TPREL_VALUE(sym_map, sym, reloc) \
   ((sym_map)->l_tls_offset + (sym)->st_value + (reloc)->r_addend \
-   - TLS_TP_OFFSET)
+   - TLS_TCB_SIZE - TLS_TP_OFFSET)
 
 /* Compute the value for a @dtprel reloc.  */
 #define TLS_DTPREL_VALUE(sym, reloc) \

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]