1 /* Initialization code run first thing by the ELF startup code. Linux version.
2 Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 #include <fpu_control.h>
26 #include <sys/param.h>
27 #include <sys/types.h>
28 #include "kernel-features.h"
29 #include <libc-internal.h>
33 # include "dl-osinfo.h"
36 /* The function is called from assembly stubs the compiler can't see. */
37 static void init (int, char **, char **) __attribute__ ((unused
));
39 extern int _dl_starting_up
;
40 weak_extern (_dl_starting_up
)
42 /* Set nonzero if we have to be prepared for more then one libc being
43 used in the process. Safe assumption if initializer never runs. */
44 int __libc_multiple_libcs attribute_hidden
= 1;
46 /* Remember the command line argument and enviroment contents for
47 later calls of initializers for dynamic libraries. */
48 int __libc_argc attribute_hidden
;
49 char **__libc_argv attribute_hidden
;
53 init (int argc
, char **argv
, char **envp
)
55 #ifdef USE_NONOPTION_FLAGS
56 extern void __getopt_clean_environment (char **);
58 /* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
59 If the address would be taken inside the expression the optimizer
60 would try to be too smart and throws it away. Grrr. */
61 int *dummy_addr
= &_dl_starting_up
;
63 __libc_multiple_libcs
= dummy_addr
&& !_dl_starting_up
;
65 /* Make sure we don't initialize twice. */
66 if (!__libc_multiple_libcs
)
69 DL_SYSDEP_OSCHECK (__libc_fatal
);
72 /* Set the FPU control word to the proper default value if the
73 kernel would use a different value. (In a static program we
74 don't have this information.) */
76 if (__fpu_control
!= GL(dl_fpu_control
))
78 __setfpucw (__fpu_control
);
81 /* Save the command-line arguments. */
87 __libc_init_secure ();
89 /* First the initialization which normally would be done by the
91 _dl_non_dynamic_init ();
94 __init_misc (argc
, argv
, envp
);
96 #ifdef USE_NONOPTION_FLAGS
97 /* This is a hack to make the special getopt in GNU libc working. */
98 __getopt_clean_environment (envp
);
102 __libc_global_ctors ();
108 strong_alias (init
, _init
);
110 extern void __libc_init_first (void);
113 __libc_init_first (void)
118 extern void __libc_init_first (int argc
, char **argv
, char **envp
);
121 __libc_init_first (int argc
, char **argv
, char **envp
)
123 init (argc
, argv
, envp
);
128 /* This function is defined here so that if this file ever gets into
129 ld.so we will get a link error. Having this file silently included
130 in ld.so causes disaster, because the _init definition above will
131 cause ld.so to gain an init function, which is not a cool thing. */
133 extern void _dl_start (void) __attribute__ ((noreturn
));