LinuxThreads TLS adjustment for ARM/MIPS

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

LinuxThreads TLS adjustment for ARM/MIPS

Daniel Jacobowitz-2
I've had this patch in my tree for most of the year.  Here's what I
originally wrote about it on libc-alpha:

> The problem is that libc.so and libpthread.so both know the layout of
> struct _pthread_descr_struct, in order for __errno_location to use the
> thread-specific errno.  The initial members of that structure are
> guarded by a conditional:
>
>   #if !defined USE_TLS || !TLS_DTV_AT_TP
>
> For Alpha, ia64, PowerPC, SH, and the MIPS and ARM ports I'm working
> on, TLS_DTV_AT_TP is set.  So if libc.so and linuxthreads.so don't
> agree on the value of USE_TLS, the structure won't match.  Alpha, ia64,
> and PowerPC only require toolchain support in order to use TLS, so this
> isn't a problem; linuxthreads is built with USE_TLS defined.  For i386,
> more is required, but they meet the !TLS_DTV_AT_TP check so these
> members are never included.
>
> However, SH and ARM and MIPS require kernel support for TLS that we
> can't assume is present.  So, just like i386, they disable TLS while
> building libpthread.so unless the appropriate kernel is assumed.  This
> breaks __errno_location() in glibc.  This patch lets such ports request
> the initial elements to be consistently declared.

The relevant macro is already defined by MIPS and ARM (it leaked in when I
contributed them).  I can't test SH, so I'm leaving it alone, but I believe
that SH would need this in order for a LinuxThreads library for old
kernels (with --enable-tls --without-__thread) and an NPTL library for
new kernels to coexist.  Otherwise the LinuxThreads ld.so misses the NPTL
p_errno.

Tested on ARM, checked in.

--
Daniel Jacobowitz
CodeSourcery, LLC

2005-11-11  Daniel Jacobowitz  <[hidden email]>

        * descr.h (struct _pthread_descr_struct): Include padding if
        INCLUDE_TLS_PADDING.

Index: glibc/linuxthreads/descr.h
===================================================================
--- glibc.orig/linuxthreads/descr.h 2005-02-10 02:16:16.000000000 -0500
+++ glibc/linuxthreads/descr.h 2005-10-04 13:58:15.000000000 -0400
@@ -109,7 +109,7 @@ union dtv;
 
 struct _pthread_descr_struct
 {
-#if !defined USE_TLS || !TLS_DTV_AT_TP
+#if !defined USE_TLS || !TLS_DTV_AT_TP || INCLUDE_TLS_PADDING
   /* This overlaps tcbhead_t (see tls.h), as used for TLS without threads.  */
   union
   {
Reply | Threaded
Open this post in threaded view
|

Re: LinuxThreads TLS adjustment for ARM/MIPS

Kaz Kojima
Daniel Jacobowitz <[hidden email]> wrote:
> The relevant macro is already defined by MIPS and ARM (it leaked in when I
> contributed them).  I can't test SH, so I'm leaving it alone, but I believe
> that SH would need this in order for a LinuxThreads library for old
> kernels (with --enable-tls --without-__thread) and an NPTL library for
> new kernels to coexist.  Otherwise the LinuxThreads ld.so misses the NPTL
> p_errno.

I've tested the attached patch cut&patsted from ARM on SH.

Regards,
        kaz
--
2005-11-11  Kaz Kojima  <[hidden email]>

        * linuxthreads/sysdeps/sh/tls.h [!FLOATING_STACKS]
        (INCLUDE_TLS_PADDING): New macro.

diff -uprN ORIG/libc/ports/linuxthreads/sysdeps/sh/tls.h LOCAL/libc/ports/linuxthreads/sysdeps/sh/tls.h
--- ORIG/libc/ports/linuxthreads/sysdeps/sh/tls.h 2005-01-10 05:01:15.000000000 +0900
+++ LOCAL/libc/ports/linuxthreads/sysdeps/sh/tls.h 2005-11-12 07:55:01.000000000 +0900
@@ -51,6 +51,13 @@ typedef union dtv
 /* Signal that TLS support is available.  */
 # define USE_TLS 1
 
+/* Include padding in _pthread_descr_struct so that libc can find p_errno,
+   if libpthread will only include the padding because of the !IS_IN_libpthread
+   check.  */
+#ifndef FLOATING_STACKS
+# define INCLUDE_TLS_PADDING 1
+#endif
+
 # ifndef __ASSEMBLER__
 
 typedef struct
Reply | Threaded
Open this post in threaded view
|

Re: LinuxThreads TLS adjustment for ARM/MIPS

Daniel Jacobowitz-2
On Sat, Nov 12, 2005 at 09:45:44AM +0900, Kaz Kojima wrote:
> Daniel Jacobowitz <[hidden email]> wrote:
> > The relevant macro is already defined by MIPS and ARM (it leaked in when I
> > contributed them).  I can't test SH, so I'm leaving it alone, but I believe
> > that SH would need this in order for a LinuxThreads library for old
> > kernels (with --enable-tls --without-__thread) and an NPTL library for
> > new kernels to coexist.  Otherwise the LinuxThreads ld.so misses the NPTL
> > p_errno.
>
> I've tested the attached patch cut&patsted from ARM on SH.

Thanks for testing!  I've checked it in.

--
Daniel Jacobowitz
CodeSourcery, LLC