dl-trampoline.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /* PLT trampolines. ARM version.
  2. Copyright (C) 2005-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. /* ??? Needs more rearrangement for the LDM to handle thumb mode. */
  16. #define NO_THUMB
  17. #include <sysdep.h>
  18. #include <libc-symbols.h>
  19. .text
  20. .globl _dl_runtime_resolve
  21. .type _dl_runtime_resolve, #function
  22. CFI_SECTIONS
  23. cfi_startproc
  24. .align 2
  25. _dl_runtime_resolve:
  26. cfi_adjust_cfa_offset (4)
  27. cfi_rel_offset (lr, 0)
  28. @ we get called with
  29. @ stack[0] contains the return address from this call
  30. @ ip contains &GOT[n+3] (pointer to function)
  31. @ lr points to &GOT[2]
  32. @ Save arguments. We save r4 to realign the stack.
  33. push {r0-r4}
  34. cfi_adjust_cfa_offset (20)
  35. cfi_rel_offset (r0, 0)
  36. cfi_rel_offset (r1, 4)
  37. cfi_rel_offset (r2, 8)
  38. cfi_rel_offset (r3, 12)
  39. @ get pointer to linker struct
  40. ldr r0, [lr, #-4]
  41. @ prepare to call _dl_fixup()
  42. @ change &GOT[n+3] into 8*n NOTE: reloc are 8 bytes each
  43. sub r1, ip, lr
  44. sub r1, r1, #4
  45. add r1, r1, r1
  46. @ call fixup routine
  47. bl _dl_fixup
  48. @ save the return
  49. mov ip, r0
  50. @ get arguments and return address back. We restore r4
  51. @ only to realign the stack.
  52. pop {r0-r4,lr}
  53. cfi_adjust_cfa_offset (-24)
  54. @ jump to the newly found address
  55. BX(ip)
  56. cfi_endproc
  57. .size _dl_runtime_resolve, .-_dl_runtime_resolve
  58. #if !defined PROF && defined SHARED
  59. .globl _dl_runtime_profile
  60. .type _dl_runtime_profile, #function
  61. CFI_SECTIONS
  62. cfi_startproc
  63. .align 2
  64. _dl_runtime_profile:
  65. cfi_adjust_cfa_offset (4)
  66. cfi_rel_offset (lr, 0)
  67. @ we get called with
  68. @ stack[0] contains the return address from this call
  69. @ ip contains &GOT[n+3] (pointer to function)
  70. @ lr points to &GOT[2]
  71. @ Stack layout:
  72. @ 212 - saved lr
  73. @ 208 - framesize returned from pltenter
  74. @ 16 - La_arm_regs
  75. @ 8 - Saved two arguments to _dl_profile_fixup
  76. @ 4 - Saved result of _dl_profile_fixup
  77. @ 0 - outgoing argument to _dl_profile_fixup
  78. @ For now, we only save the general purpose registers.
  79. sub sp, sp, #196
  80. cfi_adjust_cfa_offset (196)
  81. stmia sp, {r0-r3}
  82. cfi_rel_offset (r0, 0)
  83. cfi_rel_offset (r1, 4)
  84. cfi_rel_offset (r2, 8)
  85. cfi_rel_offset (r3, 12)
  86. sub sp, sp, #16
  87. cfi_adjust_cfa_offset (16)
  88. @ Save sp and lr.
  89. add r0, sp, #216
  90. str r0, [sp, #32]
  91. ldr r2, [sp, #212]
  92. str r2, [sp, #36]
  93. @ get pointer to linker struct
  94. ldr r0, [lr, #-4]
  95. @ prepare to call _dl_profile_fixup()
  96. @ change &GOT[n+3] into 8*n NOTE: reloc are 8 bytes each
  97. sub r1, ip, lr
  98. sub r1, r1, #4
  99. add r1, r1, r1
  100. @ Save these two arguments for pltexit.
  101. add r3, sp, #8
  102. stmia r3!, {r0,r1}
  103. @ Set up extra args for _dl_profile_fixup.
  104. @ r2 and r3 are already loaded.
  105. add ip, sp, #208
  106. str ip, [sp, #0]
  107. @ call profiling fixup routine
  108. bl _dl_profile_fixup
  109. @ The address to call is now in r0.
  110. @ Check whether we're wrapping this function.
  111. ldr ip, [sp, #208]
  112. cmp ip, #0
  113. bge 1f
  114. cfi_remember_state
  115. @ save the return
  116. mov ip, r0
  117. @ get arguments and return address back
  118. add sp, sp, #16
  119. cfi_adjust_cfa_offset (-16)
  120. ldmia sp, {r0-r3,sp,lr}
  121. cfi_adjust_cfa_offset (-200)
  122. @ jump to the newly found address
  123. BX(ip)
  124. cfi_restore_state
  125. 1:
  126. @ The new frame size is in ip.
  127. @ New stack layout:
  128. @ 268 - saved r7
  129. @ 264 - saved result of _dl_profile_fixup
  130. @ 72 - La_arm_regs
  131. @ 64 - Saved two arguments to _dl_profile_fixup
  132. @ 0 - La_arm_retval
  133. @ For now, we only save the general purpose registers.
  134. @ Build the new frame.
  135. str r7, [sp, #212]
  136. cfi_rel_offset (r7, 212)
  137. sub r7, sp, #56
  138. cfi_def_cfa_register (r7)
  139. cfi_adjust_cfa_offset (56)
  140. sub sp, sp, ip
  141. bic sp, sp, #7
  142. @ Save the _dl_profile_fixup result around the call to memcpy.
  143. str r0, [r7, #264]
  144. @ Copy the stack arguments.
  145. mov r0, sp
  146. add r1, r7, #272
  147. mov r2, ip
  148. bl memcpy
  149. @ Call the function.
  150. add ip, r7, #72
  151. ldmia ip, {r0-r3}
  152. ldr ip, [r7, #264]
  153. BLX(ip)
  154. stmia r7, {r0-r3}
  155. @ Call pltexit.
  156. add ip, r7, #64
  157. ldmia ip, {r0,r1}
  158. add r2, r7, #72
  159. add r3, r7, #0
  160. bl _dl_audit_pltexit
  161. @ Return to caller.
  162. ldmia r7, {r0-r3}
  163. mov sp, r7
  164. cfi_def_cfa_register (sp)
  165. ldr r7, [sp, #268]
  166. ldr lr, [sp, #92]
  167. add sp, sp, #272
  168. cfi_adjust_cfa_offset (-272)
  169. BX(lr)
  170. cfi_endproc
  171. .size _dl_runtime_profile, .-_dl_runtime_profile
  172. #endif
  173. .previous