Update.
[platform/upstream/glibc.git] / sysdeps / unix / sysv / linux / init-first.c
1 /* Initialization code run first thing by the ELF startup code.  Linux version.
2    Copyright (C) 1995, 1996, 1997, 1998 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 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.  */
19
20 #include <unistd.h>
21 #include <sysdep.h>
22 #include <fpu_control.h>
23 #include <linux/personality.h>
24 #include <init-first.h>
25 #include <sys/types.h>
26
27 extern void __libc_init_secure (void);
28 extern void __libc_init (int, char **, char **);
29 extern void __libc_global_ctors (void);
30
31 /* The function is called from assembly stubs the compiler can't see.  */
32 static void init (int, char **, char **) __attribute__ ((unused));
33
34 extern int _dl_starting_up;
35 weak_extern (_dl_starting_up)
36
37 /* Set nonzero if we have to be prepared for more then one libc being
38    used in the process.  Safe assumption if initializer never runs.  */
39 int __libc_multiple_libcs = 1;
40
41 /* Remember the command line argument and enviroment contents for
42    later calls of initializers for dynamic libraries.  */
43 int __libc_argc;
44 char **__libc_argv;
45
46
47 static void
48 init (int argc, char **argv, char **envp)
49 {
50   extern int __personality (int);
51   extern void __getopt_clean_environment (char **);
52
53   /* We must not call `personality' twice.  */
54   if (!__libc_multiple_libcs)
55     {
56       /* The `personality' system call takes one argument that chooses
57          the "personality", i.e. the set of system calls and such.  We
58          must make this call first thing to disable emulation of some
59          other system that might have been enabled by default based on
60          the executable format.  */
61       __personality (PER_LINUX);
62
63       /* Set the FPU control word to the proper default value.  */
64       __setfpucw (__fpu_control);
65     }
66
67   /* Save the command-line arguments.  */
68   __libc_argc = argc;
69   __libc_argv = argv;
70   __environ = envp;
71
72 #ifndef PIC
73   __libc_init_secure ();
74 #endif
75
76   __libc_init (argc, argv, envp);
77
78   /* This is a hack to make the special getopt in GNU libc working.  */
79   __getopt_clean_environment (envp);
80
81 #ifdef PIC
82   __libc_global_ctors ();
83 #endif
84 }
85
86 #ifdef PIC
87
88 SYSDEP_CALL_INIT(_init, init);
89
90 void
91 __libc_init_first (void)
92 {
93 }
94
95 #else
96 void
97 __libc_init_first (int argc, char **argv, char **envp)
98 {
99   init (argc, argv, envp);
100 }
101 #endif
102
103
104 /* This function is defined here so that if this file ever gets into
105    ld.so we will get a link error.  Having this file silently included
106    in ld.so causes disaster, because the _init definition above will
107    cause ld.so to gain an init function, which is not a cool thing. */
108
109 void
110 _dl_start (void)
111 {
112   abort ();
113 }