bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #17644] glibc: support for TLS


From: Samuel Thibault
Subject: Re: [bug #17644] glibc: support for TLS
Date: Sun, 24 Jun 2007 17:45:35 +0200
User-agent: Mutt/1.5.12-2006-07-14

Hi,

I updated my TLS patches on savannah.  Neal, can you have a look at
the hurd part?  It is relatively straight forward, it shouldn't be a
problem. As I said earlier, the -transitional version is only meant for
a debian transition package.

Now, here is the glibc part inline for discussion:

First I had to make MACHINE_THREAD_STATE_FLAVOR defined to
i386_REGS_SEGS_STATE instead of i386_THREAD_STATE_COUNT, because in many
places, we need to save/restore the segment registers as well.  However,
this breaks some places that create new contexts and don't want to
know about segments, so I added MACHINE_NEW_THREAD_STATE_FLAVOR which
is defined to i386_THREAD_STATE_COUNT, and used that instead in those
places.

The second part is composed of two initialization fixups:
- when using cthreads, init() copies argc, argv and envp to a new stack,
  add a hurd_startup_data structure, and switches to it. However,
  argv[0], ... are not copied, so that the test ((void *) d == argv[0])
  always evaluates to false. A simple way to fix it is after finding out
  that ((void *) d != argv[0]) (which means we have a hurd_startup_data
  structure in d), to check that phdr was provided by the exec server
  or was zeroed by init().
- _start points on the first instruction, not on the elf header.
  __executable_start does point on the elf header.

Samuel

Index: hurd/hurdfault.c
===================================================================
RCS file: /cvs/glibc/libc/hurd/hurdfault.c,v
retrieving revision 1.21
diff -u -p -r1.21 hurdfault.c
--- hurd/hurdfault.c    21 Dec 2005 22:16:20 -0000      1.21
+++ hurd/hurdfault.c    12 Jun 2007 00:02:53 -0000
@@ -214,7 +214,7 @@ _hurdsig_fault_init(void)
      __proc_handle_exceptions (port,
                               sigexc,
                               forward_sigexc, MACH_MSG_TYPE_MAKE_SEND,
-                              MACHINE_THREAD_STATE_FLAVOR,
+                              MACHINE_NEW_THREAD_STATE_FLAVOR,
                               (natural_t *) &state,
                               MACHINE_THREAD_STATE_COUNT));
   assert_perror (err);
Index: mach/setup-thread.c
===================================================================
RCS file: /cvs/glibc/libc/mach/setup-thread.c,v
retrieving revision 1.19
--- mach/setup-thread.c 22 Dec 2005 11:31:24 -0000      1.19
+++ mach/setup-thread.c 12 Jun 2007 00:02:54 -0000
@@ -73,7 +73,7 @@ __mach_setup_thread()
   if (error = __vm_protect (task, stack, __vm_page_size, 0, VM_PROT_NONE))
     return error;
 
-  return __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
+  return __thread_set_state (thread, MACHINE_NEW_THREAD_STATE_FLAVOR,
                             (natural_t *) &ts, tssize);
 }
 
Index: sysdeps/generic/thread_state.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/generic/thread_state.h,v
retrieving revision 1.2
--- sysdeps/generic/thread_state.h      6 Jul 2001 04:55:50 -0000       1.2
+++ sysdeps/generic/thread_state.h      12 Jun 2007 00:02:54 -0000
@@ -23,6 +23,7 @@
 
 /* Replace <machine> with "i386" or "mips" or whatever.  */
 
+#define MACHINE_NEW_THREAD_STATE_FLAVOR        <machine>_NEW_THREAD_STATE
 #define MACHINE_THREAD_STATE_FLAVOR    <machine>_THREAD_STATE
 #define MACHINE_THREAD_STATE_COUNT     <machine>_THREAD_STATE_COUNT
 
Index: sysdeps/mach/alpha/thread_state.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/mach/alpha/thread_state.h,v
retrieving revision 1.5
--- sysdeps/mach/alpha/thread_state.h   6 Jul 2001 04:55:56 -0000       1.5
+++ sysdeps/mach/alpha/thread_state.h   12 Jun 2007 00:02:54 -0000
@@ -19,6 +19,7 @@
 
 #include <mach/machine/thread_status.h>
 
+#define MACHINE_NEW_THREAD_STATE_FLAVOR        ALPHA_THREAD_STATE
 #define MACHINE_THREAD_STATE_FLAVOR    ALPHA_THREAD_STATE
 #define MACHINE_THREAD_STATE_COUNT     ALPHA_THREAD_STATE_COUNT
 
Index: sysdeps/mach/i386/thread_state.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/mach/i386/thread_state.h,v
retrieving revision 1.14
--- sysdeps/mach/i386/thread_state.h    6 Jul 2001 04:56:00 -0000       1.14
+++ sysdeps/mach/i386/thread_state.h    12 Jun 2007 00:02:54 -0000
@@ -19,7 +19,8 @@
 
 #include <mach/machine/thread_status.h>
 
-#define MACHINE_THREAD_STATE_FLAVOR    i386_THREAD_STATE
+#define MACHINE_NEW_THREAD_STATE_FLAVOR        i386_THREAD_STATE
+#define MACHINE_THREAD_STATE_FLAVOR    i386_REGS_SEGS_STATE
 #define MACHINE_THREAD_STATE_COUNT     i386_THREAD_STATE_COUNT
 
 #define machine_thread_state i386_thread_state
Index: sysdeps/mach/powerpc/thread_state.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/mach/powerpc/thread_state.h,v
retrieving revision 1.2
--- sysdeps/mach/powerpc/thread_state.h 26 Aug 2002 22:39:44 -0000      1.2
+++ sysdeps/mach/powerpc/thread_state.h 12 Jun 2007 00:02:54 -0000
@@ -19,6 +19,7 @@
 
 #include <mach/machine/thread_status.h>
 
+#define MACHINE_NEW_THREAD_STATE_FLAVOR        PPC_THREAD_STATE
 #define MACHINE_THREAD_STATE_FLAVOR    PPC_THREAD_STATE
 #define MACHINE_THREAD_STATE_COUNT     PPC_THREAD_STATE_COUNT
 
--- sysdeps/mach/hurd/i386/init-first.c.orig    2007-06-23 19:27:14.000000000 
+0000
+++ sysdeps/mach/hurd/i386/init-first.c 2007-06-23 21:41:40.000000000 +0000
@@ -116,14 +116,14 @@
   /* If we are the bootstrap task started by the kernel,
      then after the environment pointers there is no Hurd
      data block; the argument strings start there.  */
-  if ((void *) d == argv[0])
+  if ((void *) d == argv[0] || !d->phdr)
     {
 #ifndef SHARED
       /* We may need to see our own phdrs, e.g. for TLS setup.
          Try the usual kludge to find the headers without help from
         the exec server.  */
-      extern const void _start;
-      const ElfW(Ehdr) *const ehdr = &_start;
+      extern const void __executable_start;
+      const ElfW(Ehdr) *const ehdr = &__executable_start;
       _dl_phdr = (ElfW(Phdr) *) ((const void *) ehdr + ehdr->e_phoff);
       _dl_phnum = ehdr->e_phnum;
       assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));





reply via email to

[Prev in Thread] Current Thread [Next in Thread]