update to 2.17
[platform/upstream/glibc.git] / csu / init-first.c
index fa21274..b3bacdd 100644 (file)
@@ -1,5 +1,5 @@
-/* Initialization code run first thing by the ELF startup code.  Stub version.
-   Copyright (C) 1995, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
+/* Initialization code run first thing by the ELF startup code.  Common version
+   Copyright (C) 1995-2015 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
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
 #include <unistd.h>
+#include <sysdep.h>
+#include <fpu_control.h>
+#include <sys/param.h>
 #include <sys/types.h>
+#include <libc-internal.h>
 
-/* Set nonzero if we have to be prepared for more then one libc being
+#include <ldsodefs.h>
+
+/* Set nonzero if we have to be prepared for more than one libc being
    used in the process.  Safe assumption if initializer never runs.  */
 int __libc_multiple_libcs attribute_hidden = 1;
 
-extern void __libc_init (int, char **, char **);
-#ifdef USE_NONOPTION_FLAGS
-extern void __getopt_clean_environment (char **);
-#endif
+/* Remember the command line argument and enviroment contents for
+   later calls of initializers for dynamic libraries.  */
+int __libc_argc attribute_hidden;
+char **__libc_argv attribute_hidden;
+
 
-#ifdef SHARED
 void
-__libc_init_first (void)
+__libc_init_first (int argc, char **argv, char **envp)
 {
+#ifdef SHARED
+  /* For DSOs we do not need __libc_init_first but instead _init.  */
 }
-#endif
 
-#ifdef SHARED
-/* 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
-#else
-void __libc_init_first
-#endif
-(int argc, char *arg0, ...)
+void
+attribute_hidden
+_init (int argc, char **argv, char **envp)
 {
-  char **argv = &arg0, **envp = &argv[argc + 1];
+#endif
+#ifdef USE_NONOPTION_FLAGS
+  extern void __getopt_clean_environment (char **);
+#endif
+
+  __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
+
+  /* Make sure we don't initialize twice.  */
+  if (!__libc_multiple_libcs)
+    {
+      /* Set the FPU control word to the proper default value if the
+        kernel would use a different value.  */
+      if (__fpu_control != GLRO(dl_fpu_control))
+       __setfpucw (__fpu_control);
+    }
 
+  /* Save the command-line arguments.  */
+  __libc_argc = argc;
+  __libc_argv = argv;
   __environ = envp;
-  __libc_init (argc, argv, envp);
+
+#ifndef SHARED
+  __libc_init_secure ();
+
+  /* First the initialization which normally would be done by the
+     dynamic linker.  */
+  _dl_non_dynamic_init ();
+#endif
+
+#ifdef VDSO_SETUP
+  VDSO_SETUP ();
+#endif
+
+  __init_misc (argc, argv, envp);
 
 #ifdef USE_NONOPTION_FLAGS
   /* This is a hack to make the special getopt in GNU libc working.  */
   __getopt_clean_environment (envp);
 #endif
+
+  /* Initialize ctype data.  */
+  __ctype_init ();
+
+#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
+  __libc_global_ctors ();
+#endif
+}
+
+/* This function is defined here so that if this file ever gets into
+   ld.so we will get a link error.  Having this file silently included
+   in ld.so causes disaster, because the _init definition above will
+   cause ld.so to gain an init function, which is not a cool thing. */
+
+extern void _dl_start (void) __attribute__ ((noreturn));
+
+void
+_dl_start (void)
+{
+  abort ();
 }