update from main archive 970202
[glibc/history.git] / sysdeps / unix / sysv / linux / init-first.c
blob7c5b510956ea12eda2d664f7c4b1c8c34671ae7f
1 /* Initialization code run first thing by the ELF startup code. Linux version.
2 Copyright (C) 1995, 1996 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 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.
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.
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. */
20 #include <unistd.h>
21 #include <sysdep.h>
22 #include <fpu_control.h>
23 #include <linux/personality.h>
24 #include <init-first.h>
26 extern void __libc_init (int, char **, char **);
27 extern void __libc_global_ctors (void);
29 /* The function is called from assembly stubs the compiler can't see. */
30 static void init (int, char **, char **) __attribute__ ((unused));
32 extern int _dl_starting_up;
33 weak_extern (_dl_starting_up)
35 /* Set nonzero if we have to be prepared for more then one libc being
36 used in the process. Safe assumption if initializer never runs. */
37 int __libc_multiple_libcs = 1;
39 /* Remember the command line argument and enviroment contents for
40 later calls of initializers for dynamic libraries. */
41 int __libc_argc;
42 char **__libc_argv;
45 static void
46 init (int argc, char **argv, char **envp)
48 extern int __personality (int);
50 /* We must not call `personality' twice. */
51 if (!__libc_multiple_libcs)
53 /* The `personality' system call takes one argument that chooses
54 the "personality", i.e. the set of system calls and such. We
55 must make this call first thing to disable emulation of some
56 other system that might have been enabled by default based on
57 the executable format. */
58 __personality (PER_LINUX);
60 /* Set the FPU control word to the proper default value. */
61 __setfpucw (__fpu_control);
64 /* Save the command-line arguments. */
65 __libc_argc = argc;
66 __libc_argv = argv;
67 __environ = envp;
69 __libc_init (argc, argv, envp);
71 #ifdef PIC
72 __libc_global_ctors ();
73 #endif
76 #ifdef PIC
78 SYSDEP_CALL_INIT(_init, init);
80 void
81 __libc_init_first (void)
85 #else
87 SYSDEP_CALL_INIT(__libc_init_first, init);
89 #endif
92 /* This function is defined here so that if this file ever gets into
93 ld.so we will get a link error. Having this file silently included
94 in ld.so causes disaster, because the _init definition above will
95 cause ld.so to gain an init function, which is not a cool thing. */
97 void
98 _dl_start (void)
100 abort ();