dl-trampoline.S 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* PLT trampolines. Nios II version.
  2. Copyright (C) 2005-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 <sysdep.h>
  16. #include <libc-symbols.h>
  17. .text
  18. .globl _dl_runtime_resolve
  19. cfi_startproc
  20. _dl_runtime_resolve:
  21. /* The runtime resolver receives the original function arguments in r4
  22. through r7, the shared library identifier from GOT[1]? in r14, and the
  23. relocation index times four in r15. It updates the corresponding PLT GOT
  24. entry so that the PLT entry will transfer control directly to the target
  25. in the future, and then transfers control to the target. */
  26. /* Save arguments and return address. */
  27. subi sp, sp, 28
  28. cfi_adjust_cfa_offset (28)
  29. stw r22, 24(sp)
  30. cfi_rel_offset (r22, 24)
  31. stw r8, 20(sp) /* save r8, because this might be a call to mcount */
  32. cfi_rel_offset (r8, 20)
  33. stw r7, 16(sp)
  34. cfi_rel_offset (r7, 16)
  35. stw r6, 12(sp)
  36. cfi_rel_offset (r6, 12)
  37. stw r5, 8(sp)
  38. cfi_rel_offset (r5, 8)
  39. stw r4, 4(sp)
  40. cfi_rel_offset (r4, 4)
  41. stw ra, 0(sp)
  42. cfi_rel_offset (ra, 0)
  43. /* Get pointer to linker struct. */
  44. mov r4, r14
  45. /* Get the relocation offset. We're given a multiple of 4 and
  46. need a multiple of 12, so multiply by 3. */
  47. slli r5, r15, 1
  48. add r5, r5, r15
  49. /* Call the fixup routine. */
  50. nextpc r22
  51. 1: movhi r2, %hiadj(_gp_got - 1b)
  52. addi r2, r2, %lo(_gp_got - 1b)
  53. add r22, r22, r2
  54. ldw r2, %call(_dl_fixup)(r22)
  55. callr r2
  56. /* Restore the arguments and return address. */
  57. ldw ra, 0(sp)
  58. ldw r4, 4(sp)
  59. ldw r5, 8(sp)
  60. ldw r6, 12(sp)
  61. ldw r7, 16(sp)
  62. ldw r8, 20(sp)
  63. ldw r22, 24(sp)
  64. addi sp, sp, 28
  65. cfi_adjust_cfa_offset (-28)
  66. /* Jump to the newly found address. */
  67. jmp r2
  68. cfi_endproc