about summary refs log tree commit diff
path: root/sysdeps/mach
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2004-09-11 23:52:43 +0000
committerRoland McGrath <roland@gnu.org>2004-09-11 23:52:43 +0000
commit9d78d122725a52bd5389921bba9e36e99879f8d4 (patch)
tree9e54f4b16c4967ab02393dc906d3679d0b697b8d /sysdeps/mach
parentfc58d3523597f7e9253fd9e11837f8d8b014a891 (diff)
downloadglibc-9d78d122725a52bd5389921bba9e36e99879f8d4.tar.gz
glibc-9d78d122725a52bd5389921bba9e36e99879f8d4.tar.xz
glibc-9d78d122725a52bd5389921bba9e36e99879f8d4.zip
* 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.
Diffstat (limited to 'sysdeps/mach')
-rw-r--r--sysdeps/mach/hurd/i386/init-first.c60
1 files changed, 38 insertions, 22 deletions
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index 14b606494e..1b2dee5c9d 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -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
 }