Updated to fedora-glibc-20050106T1443
[glibc.git] / sysdeps / unix / sysv / linux / init-first.c
blob7f0b963cb74c8dc67b0d0088219633944c6626f6
1 /* Initialization code run first thing by the ELF startup code. Linux version.
2 Copyright (C) 1995-2004, 2005 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
18 02111-1307 USA. */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <sysdep.h>
25 #include <fpu_control.h>
26 #include <sys/param.h>
27 #include <sys/types.h>
28 #include <libc-internal.h>
30 #include <ldsodefs.h>
32 /* Set nonzero if we have to be prepared for more then one libc being
33 used in the process. Safe assumption if initializer never runs. */
34 int __libc_multiple_libcs attribute_hidden = 1;
36 /* Remember the command line argument and enviroment contents for
37 later calls of initializers for dynamic libraries. */
38 int __libc_argc attribute_hidden;
39 char **__libc_argv attribute_hidden;
42 void
43 attribute_hidden
44 __libc_init_first (int argc, char **argv, char **envp)
46 #ifdef SHARED
47 /* For DSOs we do not need __libc_init_first but instead _init. */
50 void
51 attribute_hidden
52 _init (int argc, char **argv, char **envp)
54 #endif
55 #ifdef USE_NONOPTION_FLAGS
56 extern void __getopt_clean_environment (char **);
57 #endif
59 __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
61 /* Make sure we don't initialize twice. */
62 if (!__libc_multiple_libcs)
64 /* Set the FPU control word to the proper default value if the
65 kernel would use a different value. (In a static program we
66 don't have this information.) */
67 #ifdef SHARED
68 if (__fpu_control != GLRO(dl_fpu_control))
69 #endif
70 __setfpucw (__fpu_control);
73 /* Save the command-line arguments. */
74 __libc_argc = argc;
75 __libc_argv = argv;
76 __environ = envp;
78 #ifndef SHARED
79 __libc_init_secure ();
81 /* First the initialization which normally would be done by the
82 dynamic linker. */
83 _dl_non_dynamic_init ();
84 #endif
86 __init_misc (argc, argv, envp);
88 #ifdef USE_NONOPTION_FLAGS
89 /* This is a hack to make the special getopt in GNU libc working. */
90 __getopt_clean_environment (envp);
91 #endif
93 #ifdef SHARED
94 __libc_global_ctors ();
95 #endif
99 /* This function is defined here so that if this file ever gets into
100 ld.so we will get a link error. Having this file silently included
101 in ld.so causes disaster, because the _init definition above will
102 cause ld.so to gain an init function, which is not a cool thing. */
104 extern void _dl_start (void) __attribute__ ((noreturn));
106 void
107 _dl_start (void)
109 abort ();