aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2000-04-02 22:01:23 +0000
committerRoland McGrath <roland@gnu.org>2000-04-02 22:01:23 +0000
commit5879ee9fa107553df828f71fd8e6633d3032370a (patch)
tree184e7f19b623b4ddf26ea256b80e11ec350bc884 /sysdeps
parente1724cd7ef4da860e8a1bfbe8adf0e0ec4d0e90f (diff)
downloadglibc-5879ee9fa107553df828f71fd8e6633d3032370a.tar
glibc-5879ee9fa107553df828f71fd8e6633d3032370a.tar.gz
glibc-5879ee9fa107553df828f71fd8e6633d3032370a.tar.bz2
glibc-5879ee9fa107553df828f71fd8e6633d3032370a.zip
* sysdeps/mach/hurd/i386/init-first.c: Replace PIC #ifdefs with SHARED.
(init1): Don't initialize __environ here, since init already does it. (first_init): New function, broken out of _init. (_hurd_stack_setup): Use it. [SHARED] (_dl_init_first): New function, renamed from old _init. (init1) [SHARED]: Don't call posixland_init here. (posixland_init): Take ENVP arg, so signature is usual for initializer. [SHARED] (_init): Define as alias for posixland_init. [! SHARED] (__libc_first_init): Define as alias for posixland_init. * sysdeps/i386/dl-machine.h (RTLD_START): Insert the macro RTLD_START_SPECIAL_INIT before calling initializers. (RTLD_START_SPECIAL_INIT): Define to empty if undefined. * sysdeps/mach/hurd/i386/dl-machine.h: New file. * sysdeps/mach/hurd/dl-sysdep.c (_dl_init_first): New weak function. * elf/Versions ({libc,ld.so}: GLIBC_2.2): Add _dl_init_first.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/i386/dl-machine.h21
-rw-r--r--sysdeps/mach/hurd/dl-sysdep.c6
-rw-r--r--sysdeps/mach/hurd/i386/dl-machine.h7
-rw-r--r--sysdeps/mach/hurd/i386/init-first.c65
4 files changed, 63 insertions, 36 deletions
diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
index 507a69d338..753f12678f 100644
--- a/sysdeps/i386/dl-machine.h
+++ b/sysdeps/i386/dl-machine.h
@@ -1,5 +1,5 @@
/* Machine-dependent ELF dynamic relocation inline functions. i386 version.
- Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,97,98,99,2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -223,19 +223,24 @@ _dl_start_user:\n\
popl %esi\n\
# Adjust the stack pointer to skip _dl_skip_args words.\n\
leal (%esp,%eax,4), %esp\n\
- # Subtract _dl_skip_args from it.\n\
+ # Subtract _dl_skip_args from argc.\n\
subl %eax, %esi\n\
+ # Push argc back on the stack.\n\
+ push %esi\n\
+ # The special initializer gets called with the stack just\n\
+ # as the application's entry point will see it; it can\n\
+ # switch stacks if it moves these contents over.\n\
+" RTLD_START_SPECIAL_INIT "\n\
# Load the parameters again.\n\
- leal 4(%esp,%esi,4), %edx\n\
- movl %esp, %ecx\n\
+ # (eax, edx, ecx, *--esp) = (_dl_loaded, argc, argv, envp)\n\
+ leal 8(%esp,%esi,4), %edx\n\
+ leal 4(%esp), %ecx\n\
pushl %edx\n\
movl %esi, %edx\n\
movl _dl_loaded@GOT(%ebx), %eax\n\
movl (%eax), %eax\n\
# Call the function to run the initializers.\n\
call _dl_init@PLT\n\
- # Push argc back on the stack.\n\
- push %esi\n\
# Pass our finalizer function to the user in %edx, as per ELF ABI.\n\
movl _dl_fini@GOT(%ebx), %edx\n\
# Jump to the user's entry point.\n\
@@ -243,6 +248,10 @@ _dl_start_user:\n\
.previous\n\
");
+#ifndef RTLD_START_SPECIAL_INIT
+#define RTLD_START_SPECIAL_INIT /* nothing */
+#endif
+
/* Nonzero iff TYPE should not be allowed to resolve to one of
the main executable's symbols, as for a COPY reloc. */
#define elf_machine_lookup_noexec_p(type) ((type) == R_386_COPY)
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index a1f4565869..9083ca0350 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -730,3 +730,9 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
*sz = 1;
return result;
}
+
+void weak_function
+_dl_init_first (int argc, ...)
+{
+ /* This no-op definition only gets used if libc is not linked in. */
+}
diff --git a/sysdeps/mach/hurd/i386/dl-machine.h b/sysdeps/mach/hurd/i386/dl-machine.h
new file mode 100644
index 0000000000..153abba48f
--- /dev/null
+++ b/sysdeps/mach/hurd/i386/dl-machine.h
@@ -0,0 +1,7 @@
+/* Dynamic linker magic for Hurd/i386.
+ This file just gets us a call to _dl_first_init inserted
+ into the asm in sysdeps/i386/dl-machine.h that contains
+ the initializer code. */
+
+#define RTLD_START_SPECIAL_INIT "call _dl_init_first@PLT"
+#include_next "dl-machine.h"
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index ee7b90252b..505c9ca328 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -1,5 +1,5 @@
/* Initialization code run first thing by the ELF startup code. For i386/Hurd.
- Copyright (C) 1995, 96, 97, 98, 99 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,97,98,99,2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -35,7 +35,7 @@ unsigned int __hurd_threadvar_max;
unsigned long int __hurd_threadvar_stack_offset;
unsigned long int __hurd_threadvar_stack_mask;
-#ifndef PIC
+#ifndef SHARED
int __libc_enable_secure;
#endif
int __libc_multiple_libcs = 1;
@@ -53,8 +53,8 @@ DEFINE_HOOK (_hurd_preinit_hook, (void));
/* We call this once the Hurd magic is all set up and we are ready to be a
Posixoid program. This does the same things the generic version does. */
-static void internal_function
-posixland_init (int argc, char **argv)
+static void
+posixland_init (int argc, char **argv, char **envp)
{
__libc_init (argc, argv, __environ);
@@ -76,7 +76,6 @@ init1 (int argc, char *arg0, ...)
__libc_argc = argc;
__libc_argv = argv;
- __environ = envp;
while (*envp)
++envp;
@@ -111,10 +110,8 @@ init1 (int argc, char *arg0, ...)
d->portarray, d->portarraysize,
d->intarray, d->intarraysize);
-#ifndef PIC
+#ifndef SHARED
__libc_enable_secure = d->flags & EXEC_SECURE;
-#else
- posixland_init(argc, argv);
#endif
}
@@ -247,38 +244,49 @@ asm ("
");
-#ifdef PIC
-/* This function is called to initialize the shared C library.
- It is called just before the user _start code from i386/elf/start.S,
- with the stack set up as that code gets it. */
-
-/* NOTE! The linker notices the magical name `_init' and sets the DT_INIT
- pointer in the dynamic section based solely on that. It is convention
- for this function to be in the `.init' section, but the symbol name is
- the only thing that really matters!! */
-void
-_init (int argc, ...)
+/* Do the first essential initializations that must precede all else. */
+static inline void
+first_init (void)
{
/* Initialize data structures so we can do RPCs. */
__mach_init ();
RUN_HOOK (_hurd_preinit_hook, ());
+}
+
+#ifdef SHARED
+/* This function is called specially by the dynamic linker to do early
+ initialization of the shared C library before normal initializers
+ expecting a Posixoid environment can run. It gets called with the
+ stack set up just as the user will see it, so it can switch stacks. */
+
+void
+_dl_init_first (int argc, ...)
+{
+ first_init ();
init (&argc);
}
#endif
+#ifdef SHARED
+/* The regular posixland initialization is what goes into libc's
+ normal initializer. */
+/* NOTE! The linker notices the magical name `_init' and sets the DT_INIT
+ pointer in the dynamic section based solely on that. It is convention
+ for this function to be in the `.init' section, but the symbol name is
+ the only thing that really matters!! */
+strong_alias (posixland_init, _init);
+
void
__libc_init_first (int argc, char **argv, char **envp)
-#ifdef PIC
{
/* Everything was done in the shared library initializer, _init. */
}
#else
-{
- posixland_init(argc, argv);
-}
+strong_alias (posixland_init, __libc_init_first);
+
/* XXX This is all a crock and I am not happy with it.
This poorly-named function is called by static-start.S,
@@ -295,9 +303,9 @@ _hurd_stack_setup (int argc __attribute__ ((unused)), ...)
}
/* Push the user return address after the argument data, and then
- jump to `doinit1' (above), so it is as if __libc_init_first's
- caller had called `doinit1' with the argument data already on the
- stack. */
+ jump to `doinit1' (above), so it is as if __libc_init_first's
+ caller had called `doinit1' with the argument data already on the
+ stack. */
*--data = (&argc)[-1];
asm volatile ("movl %0, %%esp\n" /* Switch to new outermost stack. */
"movl $0, %%ebp\n" /* Clear outermost frame pointer. */
@@ -305,10 +313,7 @@ _hurd_stack_setup (int argc __attribute__ ((unused)), ...)
/* NOTREACHED */
}
- /* Initialize data structures so we can do RPCs. */
- __mach_init ();
-
- RUN_HOOK (_hurd_preinit_hook, ());
+ first_init ();
_hurd_startup ((void **) &argc, &doinit);
}