manual/llio.texi: update manual to document file-private locks
[jlayton/glibc.git] / csu / init-first.c
1 /* Initialization code run first thing by the ELF startup code.  Common version
2    Copyright (C) 1995-2014 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
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.
9
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.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #include <ctype.h>
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>
29
30 #include <ldsodefs.h>
31
32 /* Set nonzero if we have to be prepared for more than one libc being
33    used in the process.  Safe assumption if initializer never runs.  */
34 int __libc_multiple_libcs attribute_hidden = 1;
35
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;
40
41
42 void
43 __libc_init_first (int argc, char **argv, char **envp)
44 {
45 #ifdef SHARED
46   /* For DSOs we do not need __libc_init_first but instead _init.  */
47 }
48
49 void
50 attribute_hidden
51 _init (int argc, char **argv, char **envp)
52 {
53 #endif
54 #ifdef USE_NONOPTION_FLAGS
55   extern void __getopt_clean_environment (char **);
56 #endif
57
58   __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
59
60   /* Make sure we don't initialize twice.  */
61   if (!__libc_multiple_libcs)
62     {
63       /* Set the FPU control word to the proper default value if the
64          kernel would use a different value.  */
65       if (__fpu_control != GLRO(dl_fpu_control))
66         __setfpucw (__fpu_control);
67     }
68
69   /* Save the command-line arguments.  */
70   __libc_argc = argc;
71   __libc_argv = argv;
72   __environ = envp;
73
74 #ifndef SHARED
75   __libc_init_secure ();
76
77   /* First the initialization which normally would be done by the
78      dynamic linker.  */
79   _dl_non_dynamic_init ();
80 #endif
81
82 #ifdef VDSO_SETUP
83   VDSO_SETUP ();
84 #endif
85
86   __init_misc (argc, argv, envp);
87
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
92
93   /* Initialize ctype data.  */
94   __ctype_init ();
95
96 #if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
97   __libc_global_ctors ();
98 #endif
99 }
100
101 /* This function is defined here so that if this file ever gets into
102    ld.so we will get a link error.  Having this file silently included
103    in ld.so causes disaster, because the _init definition above will
104    cause ld.so to gain an init function, which is not a cool thing. */
105
106 extern void _dl_start (void) __attribute__ ((noreturn));
107
108 void
109 _dl_start (void)
110 {
111   abort ();
112 }