about summary refs log tree commit diff
path: root/sysdeps/generic/libc-start.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/generic/libc-start.c')
-rw-r--r--sysdeps/generic/libc-start.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/sysdeps/generic/libc-start.c b/sysdeps/generic/libc-start.c
index d6fd3d3581..d32e54f162 100644
--- a/sysdeps/generic/libc-start.c
+++ b/sysdeps/generic/libc-start.c
@@ -16,29 +16,58 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
+#include <link.h>
 #include <stdlib.h>
 #include <unistd.h>
 
+extern void __libc_init_first (int argc, char **argv, char **envp);
+
+extern int _dl_starting_up;
+weak_extern (_dl_starting_up)
+extern int __libc_multiple_libcs;
+
 int
 __libc_start_main (int (*main) (int, char **, char **), int argc,
 		   char **argv, void (*init) (void), void (*fini) (void),
 		   void (*rtld_fini) (void))
 {
+#ifndef PIC
+  /* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
+     If the address would be taken inside the expression the optimizer
+     would try to be too smart and throws it away.  Grrr.  */
+  int *dummy_addr = &_dl_starting_up;
+
+  __libc_multiple_libcs = dummy_addr && !_dl_starting_up;
+#endif
+
   /* Register the destructor of the dynamic linker if there is any.  */
   if (rtld_fini != NULL)
     atexit (rtld_fini);
 
-  /* Call the initializer of the libc.  */
-  __libc_init_first ();
-
   /* Set the global _environ variable correctly.  */
   __environ = &argv[argc + 1];
 
+  /* Call the initializer of the libc.  */
+#ifdef PIC
+  if (_dl_debug_impcalls)
+    _dl_debug_message (1, "\ninitialize libc\n\n", NULL);
+#endif
+  __libc_init_first (argc, argv, __environ);
+
   /* Call the initializer of the program.  */
+#ifdef PIC
+  if (_dl_debug_impcalls)
+    _dl_debug_message (1, "\ninitialize program: ", argv[0], "\n\n", NULL);
+#endif
   (*init) ();
 
   /* Register the destructor of the program.  */
   atexit (fini);
 
-  exit ((*main) (argc, argv, envp));
+#ifdef PIC
+  if (_dl_debug_impcalls)
+    _dl_debug_message (1, "\ntransferring control: ", argv[0], "\n\n", NULL);
+#endif
+
+  exit ((*main) (argc, argv, __environ));
 }