resolve.S 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Stolen from glibc-2.2.2 by David Schleef <ds@schleef.org>
  3. */
  4. .text
  5. .align 4
  6. .globl _dl_linux_resolver
  7. .globl _dl_linux_resolve
  8. .type _dl_linux_resolve,@function
  9. _dl_linux_resolve:
  10. // We need to save the registers used to pass parameters, and register 0,
  11. // which is used by _mcount; the registers are saved in a stack frame.
  12. stwu 1,-64(1)
  13. stw 0,12(1)
  14. stw 3,16(1)
  15. stw 4,20(1)
  16. // The code that calls this has put parameters for 'fixup' in r12 and r11.
  17. mr 3,12
  18. stw 5,24(1)
  19. mr 4,11
  20. stw 6,28(1)
  21. mflr 0
  22. // We also need to save some of the condition register fields.
  23. stw 7,32(1)
  24. stw 0,48(1)
  25. stw 8,36(1)
  26. mfcr 0
  27. stw 9,40(1)
  28. stw 10,44(1)
  29. stw 0,8(1)
  30. bl _dl_linux_resolver@local
  31. // 'fixup' returns the address we want to branch to.
  32. mtctr 3
  33. // Put the registers back...
  34. lwz 0,48(1)
  35. lwz 10,44(1)
  36. lwz 9,40(1)
  37. mtlr 0
  38. lwz 8,36(1)
  39. lwz 0,8(1)
  40. lwz 7,32(1)
  41. lwz 6,28(1)
  42. mtcrf 0xFF,0
  43. lwz 5,24(1)
  44. lwz 4,20(1)
  45. lwz 3,16(1)
  46. lwz 0,12(1)
  47. // ...unwind the stack frame, and jump to the PLT entry we updated.
  48. addi 1,1,64
  49. bctr
  50. .LFE2:
  51. .size _dl_linux_resolve,.LFE2-_dl_linux_resolve
  52. #if 0
  53. pusha /* preserve all regs */
  54. lea 0x20(%esp),%eax /* eax = tpnt and reloc_entry params */
  55. pushl 4(%eax) /* push copy of reloc_entry param */
  56. pushl (%eax) /* push copy of tpnt param */
  57. #ifdef __PIC__
  58. call .L24
  59. .L24:
  60. popl %ebx
  61. addl $_GLOBAL_OFFSET_TABLE_+[.-.L24],%ebx
  62. movl _dl_linux_resolver@GOT(%ebx),%ebx /* eax = resolved func */
  63. call *%ebx
  64. #else
  65. call _dl_linux_resolver
  66. #endif
  67. movl %eax,0x28(%esp) /* store func addr over original
  68. * tpnt param */
  69. addl $0x8,%esp /* remove copy parameters */
  70. popa /* restore regs */
  71. ret $4 /* jump to func removing original
  72. * reloc_entry param from stack */
  73. #endif