]> git.ipfire.org Git - thirdparty/glibc.git/blame - csu/init-first.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / csu / init-first.c
CommitLineData
93c65d43 1/* Initialization code run first thing by the ELF startup code. Common version
bfff8b1b 2 Copyright (C) 1995-2017 Free Software Foundation, Inc.
7cc27f44 3 This file is part of the GNU C Library.
e4448b6f 4
7cc27f44 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
e4448b6f 9
7cc27f44
UD
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
41bdb6e2 13 Lesser General Public License for more details.
e4448b6f 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
e4448b6f 18
228c019e 19#include <ctype.h>
93c65d43
RM
20#include <stdio.h>
21#include <stdlib.h>
22#include <fcntl.h>
e4448b6f 23#include <unistd.h>
93c65d43
RM
24#include <sysdep.h>
25#include <fpu_control.h>
26#include <sys/param.h>
0413b54c 27#include <sys/types.h>
93c65d43
RM
28#include <libc-internal.h>
29
30#include <ldsodefs.h>
e4448b6f 31
f24a6d08 32/* Set nonzero if we have to be prepared for more than one libc being
9ae10332 33 used in the process. Safe assumption if initializer never runs. */
ab26a24a 34int __libc_multiple_libcs attribute_hidden = 1;
548330d3 35
93c65d43
RM
36/* Remember the command line argument and enviroment contents for
37 later calls of initializers for dynamic libraries. */
38int __libc_argc attribute_hidden;
39char **__libc_argv attribute_hidden;
40
e4448b6f 41
e4448b6f 42void
93c65d43 43__libc_init_first (int argc, char **argv, char **envp)
e4448b6f 44{
93c65d43
RM
45#ifdef SHARED
46 /* For DSOs we do not need __libc_init_first but instead _init. */
e4448b6f 47}
93c65d43
RM
48
49void
50attribute_hidden
51_init (int argc, char **argv, char **envp)
52{
53#endif
54#ifdef USE_NONOPTION_FLAGS
55 extern void __getopt_clean_environment (char **);
e4448b6f
RM
56#endif
57
93c65d43
RM
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
95e7cf29 64 kernel would use a different value. */
93c65d43 65 if (__fpu_control != GLRO(dl_fpu_control))
93c65d43
RM
66 __setfpucw (__fpu_control);
67 }
e4448b6f 68
93c65d43
RM
69 /* Save the command-line arguments. */
70 __libc_argc = argc;
71 __libc_argv = argv;
e4448b6f 72 __environ = envp;
93c65d43
RM
73
74#ifndef SHARED
93c65d43
RM
75 /* First the initialization which normally would be done by the
76 dynamic linker. */
77 _dl_non_dynamic_init ();
78#endif
79
80#ifdef VDSO_SETUP
81 VDSO_SETUP ();
82#endif
83
84 __init_misc (argc, argv, envp);
7cc27f44 85
0ed24bc6 86#ifdef USE_NONOPTION_FLAGS
7cc27f44 87 /* This is a hack to make the special getopt in GNU libc working. */
2604afb1 88 __getopt_clean_environment (envp);
0ed24bc6 89#endif
228c019e
TS
90
91 /* Initialize ctype data. */
92 __ctype_init ();
93c65d43
RM
93
94#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
95 __libc_global_ctors ();
96#endif
97}
98
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. */
103
104extern void _dl_start (void) __attribute__ ((noreturn));
105
106void
107_dl_start (void)
108{
109 abort ();
e4448b6f 110}