1
/* Initialization code run first thing by the ELF startup code.
2
Copyright (C) 1995-2004, 2005, 2007 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
26
#include <fpu_control.h>
27
#include <sys/param.h>
28
#include <sys/types.h>
29
#include <libc-internal.h>
33
extern int __syscall_sigaction (int __sig, const struct sigaction *__act, struct sigaction *__oact) __THROW;
34
libc_hidden_proto (__syscall_sigaction)
36
/* Set nonzero if we have to be prepared for more then one libc being
37
used in the process. Safe assumption if initializer never runs. */
38
int __libc_multiple_libcs attribute_hidden = 1;
40
/* Remember the command line argument and enviroment contents for
41
later calls of initializers for dynamic libraries. */
42
int __libc_argc attribute_hidden;
43
char **__libc_argv attribute_hidden;
47
__libc_init_first (int argc, char **argv, char **envp)
50
/* For DSOs we do not need __libc_init_first but instead _init. */
55
_init (int argc, char **argv, char **envp)
58
#ifdef USE_NONOPTION_FLAGS
59
extern void __getopt_clean_environment (char **);
62
__libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
64
/* Make sure we don't initialize twice. */
65
if (!__libc_multiple_libcs)
67
/* Set the FPU control word to the proper default value if the
68
kernel would use a different value. (In a static program we
69
don't have this information.) */
71
/* at least on kFreeBSD set it even if SHARED,
72
fixes "make check" failures like math/test-fpucw.out */
74
if (__fpu_control != GLRO(dl_fpu_control))
77
__setfpucw (__fpu_control);
80
/* By default on kFreeBSD when a call to non existing syscall is
81
made, the program is terminated. As we want to be able to detect
82
missing syscalls and provide a fallback code, we ignore the SIGSYS
87
act.sa_handler = SIG_IGN;
88
__sigemptyset (&act.sa_mask);
91
INLINE_SYSCALL (sigaction, 3, SIGSYS, &act, NULL);
94
/* Save the command-line arguments. */
100
__libc_init_secure ();
102
/* First the initialization which normally would be done by the
104
_dl_non_dynamic_init ();
111
__init_misc (argc, argv, envp);
113
#ifdef USE_NONOPTION_FLAGS
114
/* This is a hack to make the special getopt in GNU libc working. */
115
__getopt_clean_environment (envp);
118
#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
119
__libc_global_ctors ();
124
/* This function is defined here so that if this file ever gets into
125
ld.so we will get a link error. Having this file silently included
126
in ld.so causes disaster, because the _init definition above will
127
cause ld.so to gain an init function, which is not a cool thing. */
129
extern void _dl_start (void) __attribute__ ((noreturn));