resolve.S 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2016 by Waldemar Brodkorb <wbx@uclibc-ng.org>
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. * ported from GNU libc
  5. */
  6. /* Copyright (C) 2005-2016 Free Software Foundation, Inc.
  7. This file is part of the GNU C Library.
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public License as
  10. published by the Free Software Foundation; either version 2.1 of the
  11. License, or (at your option) any later version.
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with the GNU C Library. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #include <features.h>
  20. #define PTR_REG(n) x##n
  21. #define PTR_LOG_SIZE 3
  22. #define PTR_SIZE (1<<PTR_LOG_SIZE)
  23. #define ip0 x16
  24. #define ip0l PTR_REG (16)
  25. #define ip1 x17
  26. #define lr x30
  27. /* RELA relocatons are 3 pointers */
  28. #define RELA_SIZE (PTR_SIZE * 3)
  29. .text
  30. .globl _dl_linux_resolve
  31. .type _dl_linux_resolve, %function
  32. .align 2
  33. _dl_linux_resolve:
  34. /* AArch64 we get called with:
  35. ip0 &PLTGOT[2]
  36. ip1 temp(dl resolver entry point)
  37. [sp, #8] lr
  38. [sp, #0] &PLTGOT[n]
  39. */
  40. /* Save arguments. */
  41. stp x8, x9, [sp, #-(80+8*16)]!
  42. stp x6, x7, [sp, #16]
  43. stp x4, x5, [sp, #32]
  44. stp x2, x3, [sp, #48]
  45. stp x0, x1, [sp, #64]
  46. stp q0, q1, [sp, #(80+0*16)]
  47. stp q2, q3, [sp, #(80+2*16)]
  48. stp q4, q5, [sp, #(80+4*16)]
  49. stp q6, q7, [sp, #(80+6*16)]
  50. /* Get pointer to linker struct. */
  51. ldr PTR_REG (0), [ip0, #-PTR_SIZE]
  52. /* Prepare to call _dl_linux_resolver(). */
  53. ldr x1, [sp, 80+8*16] /* Recover &PLTGOT[n] */
  54. sub x1, x1, ip0
  55. add x1, x1, x1, lsl #1
  56. lsl x1, x1, #3
  57. sub x1, x1, #(RELA_SIZE<<3)
  58. lsr x1, x1, #3
  59. /* Call resolver routine. */
  60. bl _dl_linux_resolver
  61. /* Save the return. */
  62. mov ip0, x0
  63. /* Get arguments and return address back. */
  64. ldp q0, q1, [sp, #(80+0*16)]
  65. ldp q2, q3, [sp, #(80+2*16)]
  66. ldp q4, q5, [sp, #(80+4*16)]
  67. ldp q6, q7, [sp, #(80+6*16)]
  68. ldp x0, x1, [sp, #64]
  69. ldp x2, x3, [sp, #48]
  70. ldp x4, x5, [sp, #32]
  71. ldp x6, x7, [sp, #16]
  72. ldp x8, x9, [sp], #(80+8*16)
  73. ldp ip1, lr, [sp], #16
  74. /* Jump to the newly found address. */
  75. br ip0
  76. .size _dl_linux_resolve, .-_dl_linux_resolve