]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/init-first.c
update from main archive 970209
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / init-first.c
CommitLineData
2a072de4 1/* Initialization code run first thing by the ELF startup code. Linux version.
7cc27f44 2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
c6645251
UD
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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
0324daa0
RM
19
20#include <unistd.h>
41cfadd6 21#include <sysdep.h>
3776d592 22#include <fpu_control.h>
23396375 23#include <linux/personality.h>
a68b0d31 24#include <init-first.h>
7cc27f44 25#include <sys/types.h>
2a072de4 26
0324daa0
RM
27extern void __libc_init (int, char **, char **);
28extern void __libc_global_ctors (void);
29
3776d592 30/* The function is called from assembly stubs the compiler can't see. */
57ba7bb4 31static void init (int, char **, char **) __attribute__ ((unused));
0324daa0 32
39778c6c
UD
33extern int _dl_starting_up;
34weak_extern (_dl_starting_up)
35
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. */
38int __libc_multiple_libcs = 1;
23396375 39
dcf0671d
UD
40/* Remember the command line argument and enviroment contents for
41 later calls of initializers for dynamic libraries. */
42int __libc_argc;
43char **__libc_argv;
dcf0671d 44
7cc27f44
UD
45/* We often need the PID. Cache this value. */
46pid_t __libc_pid;
47
dcf0671d 48
0324daa0 49static void
57ba7bb4 50init (int argc, char **argv, char **envp)
0324daa0 51{
8d71c7b0 52 extern int __personality (int);
7cc27f44 53 extern void __getopt_clean_environment (void);
8d71c7b0 54
39778c6c
UD
55 /* We must not call `personality' twice. */
56 if (!__libc_multiple_libcs)
23396375 57 {
39778c6c
UD
58 /* The `personality' system call takes one argument that chooses
59 the "personality", i.e. the set of system calls and such. We
60 must make this call first thing to disable emulation of some
61 other system that might have been enabled by default based on
62 the executable format. */
63 __personality (PER_LINUX);
64
65 /* Set the FPU control word to the proper default value. */
66 __setfpucw (__fpu_control);
23396375 67 }
0324daa0 68
57ba7bb4
UD
69 /* Save the command-line arguments. */
70 __libc_argc = argc;
71 __libc_argv = argv;
72 __environ = envp;
73
74 __libc_init (argc, argv, envp);
3776d592 75
7cc27f44
UD
76 /* This is a hack to make the special getopt in GNU libc working. */
77 __getopt_clean_environment ();
78
3776d592
RM
79#ifdef PIC
80 __libc_global_ctors ();
81#endif
0324daa0
RM
82}
83
84#ifdef PIC
0324daa0 85
3776d592 86SYSDEP_CALL_INIT(_init, init);
0324daa0
RM
87
88void
3776d592 89__libc_init_first (void)
0324daa0 90{
0324daa0 91}
0324daa0 92
3776d592
RM
93#else
94
95SYSDEP_CALL_INIT(__libc_init_first, init);
0324daa0 96
0324daa0 97#endif
e320cbc9
UD
98
99
100/* This function is defined here so that if this file ever gets into
101 ld.so we will get a link error. Having this file silently included
102 in ld.so causes disaster, because the _init definition above will
103 cause ld.so to gain an init function, which is not a cool thing. */
104
105void
a68b0d31 106_dl_start (void)
e320cbc9
UD
107{
108 abort ();
109}