init-first.c 2.4 KB

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