Back to index

glibc  2.9
init-first.c
Go to the documentation of this file.
00001 /* Initialization code run first thing by the ELF startup code.  Linux version.
00002    Copyright (C) 1995-2004, 2005, 2007 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <fcntl.h>
00023 #include <unistd.h>
00024 #include <sysdep.h>
00025 #include <fpu_control.h>
00026 #include <sys/param.h>
00027 #include <sys/types.h>
00028 #include <libc-internal.h>
00029 
00030 #include <ldsodefs.h>
00031 
00032 /* Set nonzero if we have to be prepared for more then one libc being
00033    used in the process.  Safe assumption if initializer never runs.  */
00034 int __libc_multiple_libcs attribute_hidden = 1;
00035 
00036 /* Remember the command line argument and enviroment contents for
00037    later calls of initializers for dynamic libraries.  */
00038 int __libc_argc attribute_hidden;
00039 char **__libc_argv attribute_hidden;
00040 
00041 
00042 void
00043 __libc_init_first (int argc, char **argv, char **envp)
00044 {
00045 #ifdef SHARED
00046   /* For DSOs we do not need __libc_init_first but instead _init.  */
00047 }
00048 
00049 void
00050 attribute_hidden
00051 _init (int argc, char **argv, char **envp)
00052 {
00053 #endif
00054 #ifdef USE_NONOPTION_FLAGS
00055   extern void __getopt_clean_environment (char **);
00056 #endif
00057 
00058   __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
00059 
00060   /* Make sure we don't initialize twice.  */
00061   if (!__libc_multiple_libcs)
00062     {
00063       /* Set the FPU control word to the proper default value if the
00064         kernel would use a different value.  (In a static program we
00065         don't have this information.)  */
00066 #ifdef SHARED
00067       if (__fpu_control != GLRO(dl_fpu_control))
00068 #endif
00069        __setfpucw (__fpu_control);
00070     }
00071 
00072   /* Save the command-line arguments.  */
00073   __libc_argc = argc;
00074   __libc_argv = argv;
00075   __environ = envp;
00076 
00077 #ifndef SHARED
00078   __libc_init_secure ();
00079 
00080   /* First the initialization which normally would be done by the
00081      dynamic linker.  */
00082   _dl_non_dynamic_init ();
00083 #endif
00084 
00085 #ifdef VDSO_SETUP
00086   VDSO_SETUP ();
00087 #endif
00088 
00089   __init_misc (argc, argv, envp);
00090 
00091 #ifdef USE_NONOPTION_FLAGS
00092   /* This is a hack to make the special getopt in GNU libc working.  */
00093   __getopt_clean_environment (envp);
00094 #endif
00095 
00096 #ifdef SHARED
00097   __libc_global_ctors ();
00098 #endif
00099 }
00100 
00101 
00102 /* This function is defined here so that if this file ever gets into
00103    ld.so we will get a link error.  Having this file silently included
00104    in ld.so causes disaster, because the _init definition above will
00105    cause ld.so to gain an init function, which is not a cool thing. */
00106 
00107 extern void _dl_start (void) __attribute__ ((noreturn));
00108 
00109 void
00110 _dl_start (void)
00111 {
00112   abort ();
00113 }