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