* sysdeps/mach/hurd/i386/init-first.c (init1) [! SHARED]:
authorRoland McGrath <roland@gnu.org>
Sat, 11 Sep 2004 23:52:43 +0000 (23:52 +0000)
committerRoland McGrath <roland@gnu.org>
Sat, 11 Sep 2004 23:52:43 +0000 (23:52 +0000)
Set _dl_phdr and _dl_phnum.
(init1): When bootstrap task, bail early and never examine *D.

ChangeLog
sysdeps/mach/hurd/i386/init-first.c

index 311bd4e..682a38b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-09-11  Roland McGrath  <roland@frob.com>
+
+       * sysdeps/mach/hurd/i386/init-first.c (init1) [! SHARED]:
+       Set _dl_phdr and _dl_phnum.
+       (init1): When bootstrap task, bail early and never examine *D.
+
 2004-09-11  Alfred M. Szmidt  <ams@kemisten.nu>
 
        * sysdeps/mach/hurd/i386/tls.h (__i386_set_gdt) [!HAVE_I386_SET_GDT]:
index 14b6064..1b2dee5 100644 (file)
@@ -111,35 +111,51 @@ init1 (int argc, char *arg0, ...)
   /* 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])
     {
-      _hurd_init_dtable = d->dtable;
-      _hurd_init_dtablesize = d->dtablesize;
-
-      {
-       /* Check if the stack we are now on is different from
-          the one described by _hurd_stack_{base,size}.  */
-
-       char dummy;
-       const vm_address_t newsp = (vm_address_t) &dummy;
-
-       if (d->stack_size != 0 && (newsp < d->stack_base ||
-                                  newsp - d->stack_base > d->stack_size))
-         /* The new stack pointer does not intersect with the
-            stack the exec server set up for us, so free that stack.  */
-         __vm_deallocate (__mach_task_self (), d->stack_base, d->stack_size);
-      }
+#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;
+      _dl_phdr = (const ElfW(Phdr) *) ((const void *) ehdr + ehdr->e_phoff);
+      _dl_phnum = ehdr->e_phnum;
+      assert (ehdr->e_phentsize == sizeof (ElfW(Phdr)));
+#endif
+      return;
     }
 
-  if ((void *) d != argv[0] && (d->portarray || d->intarray))
+#ifndef SHARED
+  __libc_enable_secure = d->flags & EXEC_SECURE;
+
+  _dl_phdr = (const ElfW(Phdr) *) d->phdr;
+  _dl_phnum = d->phdr_size / sizeof (ElfW(Phdr));
+  assert (d->phdr_size % sizeof (ElfW(Phdr)) == 0);
+#endif
+
+  _hurd_init_dtable = d->dtable;
+  _hurd_init_dtablesize = d->dtablesize;
+
+  {
+    /* Check if the stack we are now on is different from
+       the one described by _hurd_stack_{base,size}.  */
+
+    char dummy;
+    const vm_address_t newsp = (vm_address_t) &dummy;
+
+    if (d->stack_size != 0 && (newsp < d->stack_base ||
+                              newsp - d->stack_base > d->stack_size))
+      /* The new stack pointer does not intersect with the
+        stack the exec server set up for us, so free that stack.  */
+      __vm_deallocate (__mach_task_self (), d->stack_base, d->stack_size);
+  }
+
+  if (d->portarray || d->intarray)
     /* Initialize library data structures, start signal processing, etc.  */
     _hurd_init (d->flags, argv,
                d->portarray, d->portarraysize,
                d->intarray, d->intarraysize);
-
-#ifndef SHARED
-  __libc_enable_secure = d->flags & EXEC_SECURE;
-#endif
 }