]> sourceware.org Git - glibc.git/blame - sysdeps/unix/sysv/linux/init-first.c
Update.
[glibc.git] / sysdeps / unix / sysv / linux / init-first.c
CommitLineData
2a072de4
RM
1/* Initialization code run first thing by the ELF startup code. Linux version.
2Copyright (C) 1995, 1996 Free Software Foundation, Inc.
0324daa0
RM
3This file is part of the GNU C Library.
4
5The GNU C Library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Library General Public License as
7published by the Free Software Foundation; either version 2 of the
8License, or (at your option) any later version.
9
10The GNU C Library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Library General Public License for more details.
14
15You should have received a copy of the GNU Library General Public
16License along with the GNU C Library; see the file COPYING.LIB. If
17not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18Cambridge, MA 02139, USA. */
19
20#include <unistd.h>
41cfadd6 21#include <sysdep.h>
3776d592 22#include <fpu_control.h>
23396375 23#include <linux/personality.h>
3776d592 24#include "init-first.h"
2a072de4 25
0324daa0
RM
26extern void __libc_init (int, char **, char **);
27extern void __libc_global_ctors (void);
28
3776d592
RM
29/* The function is called from assembly stubs the compiler can't see. */
30static void init (void *) __attribute__ ((unused));
0324daa0 31
23396375
UD
32extern int __libc_is_static;
33#ifdef PIC
34weak_extern (__libc_is_static)
35#endif
36
0324daa0 37static void
3776d592 38init (void *data)
0324daa0 39{
8d71c7b0
RM
40 extern int __personality (int);
41
3776d592
RM
42 int argc = *(long *)data;
43 char **argv = (char **)data + 1;
0324daa0
RM
44 char **envp = &argv[argc + 1];
45
a8922de8
UD
46 /* XXX Another gcc bug. We marked the function as `unused' but it
47 is still optimized away. */
48 volatile void *foo __attribute__ ((unused)) = &init;
49
23396375
UD
50#ifdef PIC
51 if (&__libc_is_static != NULL)
52#endif
53 {
54#ifdef PIC
55 /* We must not call `personality' twice. */
56 if (__libc_is_static == 0)
57#endif
58 {
59 /* The `personality' system call takes one argument that
60 chooses the "personality", i.e. the set of system calls
61 and such. We must make this call first thing to disable
62 emulation of some other system that might have been
63 enabled by default based on the executable format. */
64 __personality (PER_LINUX);
65
66 /* Set the FPU control word to the proper default value. */
67 __setfpucw (__fpu_control);
68 }
69
70 /* We set LIBC_IS_STATIC to a value > 0 for the static library
71 and < 0 for the shared library. This information might be
72 useful for the running program but it is mainly necessary for
73 the above `if' statement. */
74#ifdef PIC
75 __libc_is_static = -1;
76#else
77 __libc_is_static = 1;
78#endif
79 }
0324daa0
RM
80
81 __environ = envp;
82 __libc_init (argc, argv, envp);
3776d592
RM
83
84#ifdef PIC
85 __libc_global_ctors ();
86#endif
0324daa0
RM
87}
88
89#ifdef PIC
0324daa0 90
3776d592 91SYSDEP_CALL_INIT(_init, init);
0324daa0
RM
92
93void
3776d592 94__libc_init_first (void)
0324daa0 95{
0324daa0 96}
0324daa0 97
3776d592
RM
98#else
99
100SYSDEP_CALL_INIT(__libc_init_first, init);
0324daa0 101
0324daa0 102#endif
This page took 0.083672 seconds and 5 git commands to generate.