crti.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Special .init and .fini section support for Alpha.
  2. Copyright (C) 2001-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. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The GNU Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. Note that people who make modified versions of this file are not
  17. obligated to grant this special exception for their modified
  18. versions; it is their choice whether to do so. The GNU Lesser
  19. General Public License gives permission to release a modified
  20. version without this exception; this exception also makes it
  21. possible to release a modified version which carries forward this
  22. exception.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library. If not, see
  29. <https://www.gnu.org/licenses/>. */
  30. /* crti.S puts a function prologue at the beginning of the .init and
  31. .fini sections and defines global symbols for those addresses, so
  32. they can be called as functions. The symbols _init and _fini are
  33. magic and cause the linker to emit DT_INIT and DT_FINI.
  34. This differs from what would be generated for ordinary code in that
  35. we save and restore the GP within the function. In order for linker
  36. relaxation to work, the value in the GP register on exit from a function
  37. must be valid for the function entry point. Normally, a function is
  38. contained within one object file and this is not an issue, provided
  39. that the function reloads the gp after making any function calls.
  40. However, _init and _fini are constructed from pieces of many object
  41. files, all of which may have different GP values. So we must reload
  42. the GP value from crti.o in crtn.o. */
  43. #include <libc-symbols.h>
  44. #include <sysdep.h>
  45. #ifndef PREINIT_FUNCTION
  46. # define PREINIT_FUNCTION __gmon_start__
  47. #endif
  48. #ifndef PREINIT_FUNCTION_WEAK
  49. # define PREINIT_FUNCTION_WEAK 1
  50. #endif
  51. #if PREINIT_FUNCTION_WEAK
  52. weak_extern (PREINIT_FUNCTION)
  53. #else
  54. .hidden PREINIT_FUNCTION
  55. #endif
  56. .section .init, "ax", @progbits
  57. .globl _init
  58. .hidden _init
  59. .type _init, @function
  60. .usepv _init, std
  61. _init:
  62. ldgp $29, 0($27)
  63. subq $30, 16, $30
  64. #if PREINIT_FUNCTION_WEAK
  65. lda $27, PREINIT_FUNCTION
  66. #endif
  67. stq $26, 0($30)
  68. stq $29, 8($30)
  69. #if PREINIT_FUNCTION_WEAK
  70. beq $27, 1f
  71. jsr $26, ($27), PREINIT_FUNCTION
  72. ldq $29, 8($30)
  73. 1:
  74. #else
  75. bsr $26, PREINIT_FUNCTION !samegp
  76. #endif
  77. .p2align 3
  78. .section .fini, "ax", @progbits
  79. .globl _fini
  80. .hidden _fini
  81. .type _fini,@function
  82. .usepv _fini,std
  83. _fini:
  84. ldgp $29, 0($27)
  85. subq $30, 16, $30
  86. stq $26, 0($30)
  87. stq $29, 8($30)
  88. .p2align 3