Back to index

glibc  2.9
init-first.c
Go to the documentation of this file.
00001 /* Initialization code run first thing by the XCOFF startup code.  AIX version.
00002    Copyright (C) 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 <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 #ifndef SHARED
00031 # include <ldsodefs.h>
00032 # include "dl-osinfo.h"
00033 #endif
00034 
00035 extern void __libc_init (int, char **, char **);
00036 
00037 /* The function is called from assembly stubs the compiler can't see.  */
00038 static void init (int, char **, char **) __attribute__ ((unused));
00039 
00040 /* Set nonzero if we have to be prepared for more then one libc being
00041    used in the process.  Safe assumption if initializer never runs.  */
00042 int __libc_multiple_libcs attribute_hidden = 1;
00043 
00044 /* Remember the command line argument and enviroment contents for
00045    later calls of initializers for dynamic libraries.  */
00046 int __libc_argc attribute_hidden;
00047 char **__libc_argv attribute_hidden;
00048 
00049 
00050 static void
00051 init (int argc, char **argv, char **envp)
00052 {
00053 #ifdef USE_NONOPTION_FLAGS
00054   extern void __getopt_clean_environment (char **);
00055 #endif
00056   /* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
00057      If the address would be taken inside the expression the optimizer
00058      would try to be too smart and throws it away.  Grrr.  */
00059 
00060   /* XXX disable dl for now
00061   __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up; */
00062 
00063   /* Save the command-line arguments.  */
00064   __libc_argc = argc;
00065   __libc_argv = argv;
00066   __environ = envp;
00067 
00068 #ifndef SHARED
00069   __libc_init_secure ();
00070 #endif
00071 
00072   __libc_init (argc, argv, envp);
00073 
00074 #ifdef USE_NONOPTION_FLAGS
00075   /* This is a hack to make the special getopt in GNU libc working.  */
00076   __getopt_clean_environment (envp);
00077 #endif
00078 
00079 #ifdef SHARED
00080   __libc_global_ctors ();
00081 #endif
00082 }
00083 
00084 #ifdef SHARED
00085 
00086 strong_alias (init, _init);
00087 
00088 extern void __libc_init_first (void);
00089 
00090 void
00091 __libc_init_first (void)
00092 {
00093 }
00094 
00095 #else
00096 extern void __libc_init_first (int argc, char **argv, char **envp);
00097 
00098 void
00099 __libc_init_first (int argc, char **argv, char **envp)
00100 {
00101   init (argc, argv, envp);
00102 }
00103 #endif