init-first.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Initialization code run first thing by the ELF startup code. Common version
  2. Copyright (C) 1995-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <ctype.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <fcntl.h>
  19. #include <unistd.h>
  20. #include <sysdep.h>
  21. #include <fpu_control.h>
  22. #include <sys/param.h>
  23. #include <sys/types.h>
  24. #include <libc-internal.h>
  25. #include <ldsodefs.h>
  26. /* Set nonzero if we have to be prepared for more than one libc being
  27. used in the process. Safe assumption if initializer never runs. */
  28. int __libc_multiple_libcs attribute_hidden = 1;
  29. /* Remember the command line argument and enviroment contents for
  30. later calls of initializers for dynamic libraries. */
  31. int __libc_argc attribute_hidden;
  32. char **__libc_argv attribute_hidden;
  33. void
  34. __libc_init_first (int argc, char **argv, char **envp)
  35. {
  36. #ifdef SHARED
  37. /* For DSOs we do not need __libc_init_first but instead _init. */
  38. }
  39. void
  40. attribute_hidden
  41. _init (int argc, char **argv, char **envp)
  42. {
  43. #endif
  44. __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
  45. /* Make sure we don't initialize twice. */
  46. if (!__libc_multiple_libcs)
  47. {
  48. /* Set the FPU control word to the proper default value if the
  49. kernel would use a different value. */
  50. if (__fpu_control != GLRO(dl_fpu_control))
  51. __setfpucw (__fpu_control);
  52. }
  53. /* Save the command-line arguments. */
  54. __libc_argc = argc;
  55. __libc_argv = argv;
  56. __environ = envp;
  57. #ifndef SHARED
  58. /* First the initialization which normally would be done by the
  59. dynamic linker. */
  60. _dl_non_dynamic_init ();
  61. #endif
  62. #ifdef VDSO_SETUP
  63. VDSO_SETUP ();
  64. #endif
  65. __init_misc (argc, argv, envp);
  66. /* Initialize ctype data. */
  67. __ctype_init ();
  68. #if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
  69. __libc_global_ctors ();
  70. #endif
  71. }
  72. /* This function is defined here so that if this file ever gets into
  73. ld.so we will get a link error. Having this file silently included
  74. in ld.so causes disaster, because the _init definition above will
  75. cause ld.so to gain an init function, which is not a cool thing. */
  76. extern void _dl_start (void) __attribute__ ((noreturn));
  77. void
  78. _dl_start (void)
  79. {
  80. abort ();
  81. }