| 1 | /* Initialization code run first thing by the ELF startup code.  Common version | 
|---|
| 2 | Copyright (C) 1995-2020 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 | /* Set nonzero if we have to be prepared for more than one libc being | 
|---|
| 32 | used in the process.  Safe assumption if initializer never runs.  */ | 
|---|
| 33 | int __libc_multiple_libcs attribute_hidden = 1; | 
|---|
| 34 |  | 
|---|
| 35 | /* Remember the command line argument and enviroment contents for | 
|---|
| 36 | later calls of initializers for dynamic libraries.  */ | 
|---|
| 37 | int __libc_argc attribute_hidden; | 
|---|
| 38 | char **__libc_argv attribute_hidden; | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | void | 
|---|
| 42 | __libc_init_first (int argc, char **argv, char **envp) | 
|---|
| 43 | { | 
|---|
| 44 | #ifdef SHARED | 
|---|
| 45 | /* For DSOs we do not need __libc_init_first but an ELF constructor.  */ | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | static void __attribute__ ((constructor)) | 
|---|
| 49 | _init_first (int argc, char **argv, char **envp) | 
|---|
| 50 | { | 
|---|
| 51 | #endif | 
|---|
| 52 |  | 
|---|
| 53 | __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up; | 
|---|
| 54 |  | 
|---|
| 55 | /* Make sure we don't initialize twice.  */ | 
|---|
| 56 | if (!__libc_multiple_libcs) | 
|---|
| 57 | { | 
|---|
| 58 | /* Set the FPU control word to the proper default value if the | 
|---|
| 59 | kernel would use a different value.  */ | 
|---|
| 60 | if (__fpu_control != GLRO(dl_fpu_control)) | 
|---|
| 61 | __setfpucw (__fpu_control); | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | /* Save the command-line arguments.  */ | 
|---|
| 65 | __libc_argc = argc; | 
|---|
| 66 | __libc_argv = argv; | 
|---|
| 67 | __environ = envp; | 
|---|
| 68 |  | 
|---|
| 69 | #ifndef SHARED | 
|---|
| 70 | /* First the initialization which normally would be done by the | 
|---|
| 71 | dynamic linker.  */ | 
|---|
| 72 | _dl_non_dynamic_init (); | 
|---|
| 73 | #endif | 
|---|
| 74 |  | 
|---|
| 75 | __init_misc (argc, argv, envp); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | /* This function is defined here so that if this file ever gets into | 
|---|
| 79 | ld.so we will get a link error.  Having this file silently included | 
|---|
| 80 | in ld.so causes disaster, because the _init_first definition above | 
|---|
| 81 | will cause ld.so to gain an ELF constructor, which is not a cool | 
|---|
| 82 | thing. */ | 
|---|
| 83 |  | 
|---|
| 84 | extern void _dl_start (void) __attribute__ ((noreturn)); | 
|---|
| 85 |  | 
|---|
| 86 | void | 
|---|
| 87 | _dl_start (void) | 
|---|
| 88 | { | 
|---|
| 89 | abort (); | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|