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.  For i386/Unix.
00002    Copyright (C) 1995,1996,1997,2000,2001,2002 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 <unistd.h>
00021 
00022 extern void __libc_init (int, char **, char **);
00023 #ifdef USE_NONOPTION_FLAGS
00024 extern void __getopt_clean_environment (char **);
00025 #endif
00026 extern void __libc_global_ctors (void);
00027 
00028 int __libc_multiple_libcs attribute_hidden = 1;
00029 
00030 static void
00031 init (int *data)
00032 {
00033   int argc = *data;
00034   char **argv = (void *) (data + 1);
00035   char **envp = &argv[argc + 1];
00036 
00037   __environ = envp;
00038   __libc_init (argc, argv, envp);
00039 
00040 #ifdef USE_NONOPTION_FLAGS
00041   /* This is a hack to make the special getopt in GNU libc working.  */
00042   __getopt_clean_environment (envp);
00043 #endif
00044 }
00045 
00046 #ifdef SHARED
00047 /* This function is called to initialize the shared C library.
00048    It is called just before the user _start code from i386/elf/start.S,
00049    with the stack set up as that code gets it.  */
00050 
00051 /* NOTE!  The linker notices the magical name `_init' and sets the DT_INIT
00052    pointer in the dynamic section based solely on that.  It is convention
00053    for this function to be in the `.init' section, but the symbol name is
00054    the only thing that really matters!!  */
00055 /*void _init (int argc, ...) __attribute__ ((unused, section (".init")));*/
00056 
00057 void
00058 _init (int argc, ...)
00059 {
00060   init (&argc);
00061 
00062   __libc_global_ctors ();
00063 }
00064 #endif
00065 
00066 
00067 void
00068 __libc_init_first (int argc __attribute__ ((unused)), ...)
00069 {
00070 #ifndef SHARED
00071   init (&argc);
00072 #endif
00073 }