2000-04-02 Roland McGrath <roland@baalperazim.frob.com>
+ * 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.
+
* stdio-common/tmpfile.c [! USE_IN_LIBIO]: No alias needed,
since we define the function with the name `tmpfile'.
/* 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
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\
.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)
/* 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
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;
/* 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);
__libc_argc = argc;
__libc_argv = argv;
- __environ = envp;
while (*envp)
++envp;
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
}
");
-#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,
}
/* 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. */
/* NOTREACHED */
}
- /* Initialize data structures so we can do RPCs. */
- __mach_init ();
-
- RUN_HOOK (_hurd_preinit_hook, ());
+ first_init ();
_hurd_startup ((void **) &argc, &doinit);
}