1 | /* Initialization code run first thing by the ELF startup code. Common version |
2 | Copyright (C) 1995-2024 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 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. |
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 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <stdio.h> |
20 | #include <stdlib.h> |
21 | #include <fcntl.h> |
22 | #include <unistd.h> |
23 | #include <sysdep.h> |
24 | #include <fpu_control.h> |
25 | #include <sys/param.h> |
26 | #include <sys/types.h> |
27 | #include <libc-internal.h> |
28 | |
29 | #include <ldsodefs.h> |
30 | |
31 | /* Remember the command line argument and environment contents for |
32 | later calls of initializers for dynamic libraries. */ |
33 | int __libc_argc attribute_hidden; |
34 | char **__libc_argv attribute_hidden; |
35 | |
36 | |
37 | void |
38 | __libc_init_first (int argc, char **argv, char **envp) |
39 | { |
40 | #ifdef SHARED |
41 | /* For DSOs we do not need __libc_init_first but an ELF constructor. */ |
42 | } |
43 | |
44 | static void __attribute__ ((constructor)) |
45 | _init_first (int argc, char **argv, char **envp) |
46 | { |
47 | #endif |
48 | |
49 | /* Make sure we don't initialize twice. */ |
50 | #ifdef SHARED |
51 | if (__libc_initial) |
52 | { |
53 | /* Set the FPU control word to the proper default value if the |
54 | kernel would use a different value. */ |
55 | if (__fpu_control != GLRO(dl_fpu_control)) |
56 | __setfpucw (__fpu_control); |
57 | } |
58 | #endif |
59 | |
60 | /* Save the command-line arguments. */ |
61 | __libc_argc = argc; |
62 | __libc_argv = argv; |
63 | __environ = envp; |
64 | |
65 | #ifndef SHARED |
66 | /* First the initialization which normally would be done by the |
67 | dynamic linker. */ |
68 | _dl_non_dynamic_init (); |
69 | #endif |
70 | |
71 | __init_misc (argc, argv, envp); |
72 | } |
73 | |
74 | /* This function is defined here so that if this file ever gets into |
75 | ld.so we will get a link error. Having this file silently included |
76 | in ld.so causes disaster, because the _init_first definition above |
77 | will cause ld.so to gain an ELF constructor, which is not a cool |
78 | thing. */ |
79 | |
80 | extern void _dl_start (void) __attribute__ ((noreturn)); |
81 | |
82 | void |
83 | _dl_start (void) |
84 | { |
85 | abort (); |
86 | } |
87 | |