resolve.S 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. .align 4
  24. .globl _dl_linux_resolve
  25. .type _dl_linux_resolve,@function
  26. _dl_linux_resolve:
  27. pusha /* preserve all regs */
  28. lea 0x20(%esp),%eax /* eax = tpnt and reloc_entry params */
  29. pushl 4(%eax) /* push copy of reloc_entry param */
  30. pushl (%eax) /* push copy of tpnt param */
  31. #ifdef __PIC__
  32. call .L24
  33. .L24:
  34. popl %ebx
  35. addl $_GLOBAL_OFFSET_TABLE_+[.-.L24],%ebx
  36. movl _dl_linux_resolver@GOT(%ebx),%ebx /* eax = resolved func */
  37. call *%ebx
  38. #else
  39. call _dl_linux_resolver
  40. #endif
  41. movl %eax,0x28(%esp) /* store func addr over original
  42. * tpnt param */
  43. addl $0x8,%esp /* remove copy parameters */
  44. popa /* restore regs */
  45. ret $4 /* jump to func removing original
  46. * reloc_entry param from stack */
  47. .LFE2:
  48. .size _dl_linux_resolve,.LFE2-_dl_linux_resolve