resolve.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * This function is _not_ called directly. It is jumped to (so no return
  3. * address is on the stack) when attempting to use a symbol that has not yet
  4. * been resolved. The first time a jump symbol (such as a function call inside
  5. * a shared library) is used (before it gets resolved) it will jump here to
  6. * _dl_linux_resolve. When we get called the stack looks like this:
  7. * reloc_entry
  8. * tpnt
  9. *
  10. * This function saves all the registers, puts a copy of reloc_entry and tpnt
  11. * on the stack (as function arguments) then make the function call
  12. * _dl_linux_resolver(tpnt, reloc_entry). _dl_linux_resolver() figures out
  13. * where the jump symbol is _really_ supposed to have jumped to and returns
  14. * that to us. Once we have that, we overwrite tpnt with this fixed up
  15. * address. We then clean up after ourselves, put all the registers back how we
  16. * found them, then we jump to where the fixed up address, which is where the
  17. * jump symbol that got us here really wanted to jump to in the first place.
  18. * found them, then we jump to the fixed up address, which is where the jump
  19. * symbol that got us here really wanted to jump to in the first place.
  20. * -Erik Andersen
  21. */
  22. .text
  23. .globl _dl_linux_resolve
  24. .type _dl_linux_resolve,@function
  25. _dl_linux_resolve:
  26. pusha /* preserve all regs */
  27. lea 0x20(%esp),%eax /* eax = tpnt and reloc_entry params */
  28. pushl 4(%eax) /* push copy of reloc_entry param */
  29. pushl (%eax) /* push copy of tpnt param */
  30. #ifdef __PIC__
  31. call .L24
  32. .L24:
  33. popl %ebx
  34. addl $_GLOBAL_OFFSET_TABLE_+[.-.L24],%ebx
  35. movl _dl_linux_resolver@GOT(%ebx),%ebx /* eax = resolved func */
  36. call *%ebx
  37. #else
  38. call _dl_linux_resolver
  39. #endif
  40. movl %eax,0x28(%esp) /* store func addr over original
  41. * tpnt param */
  42. addl $0x8,%esp /* remove copy parameters */
  43. popa /* restore regs */
  44. ret $4 /* jump to func removing original
  45. * reloc_entry param from stack */
  46. .LFE2:
  47. .size _dl_linux_resolve,.LFE2-_dl_linux_resolve