resolve.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Meta dynamic resolver
  3. *
  4. * Copyright (C) 2013 Imagination Technologies Ltd.
  5. *
  6. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  7. *
  8. * This function is _not_ called directly. It is jumped to (so no return
  9. * address is on the stack) when attempting to use a symbol that has not yet
  10. * been resolved. The first time a jump symbol (such as a function call inside
  11. * a shared library) is used (before it gets resolved) it will jump here to
  12. * _dl_linux_resolve. When we get called the stack looks like this:
  13. * reloc_entry
  14. * tpnt
  15. *
  16. * This function saves all the registers then makes the function call
  17. * _dl_linux_resolver(tpnt, reloc_entry). _dl_linux_resolver() figures out
  18. * where the jump symbol is _really_ supposed to have jumped to and returns
  19. * that to us. Once we have that, we overwrite tpnt with this fixed up
  20. * address. We then clean up after ourselves, put all the registers back how we
  21. * found them, then we jump to the fixed up address, which is where the jump
  22. * symbol that got us here really wanted to jump to in the first place.
  23. * -Erik Andersen
  24. */
  25. .text
  26. .global __dl_linux_resolve
  27. .type __dl_linux_resolve,@function
  28. __dl_linux_resolve:
  29. !! Save registers on the stack. Do we need to save any more here?
  30. MSETL [A0StP++],D0Ar6,D0Ar4,D0Ar2,D0FrT
  31. SETL [A0StP++],A0FrP,A1LbP
  32. !! Get the args for _dl_linux_resolver off the stack
  33. GETL D0Re0,D1Re0,[A0StP+#-(6*8)]
  34. GETD D1Ar1,[D0Re0]
  35. MOV D0Ar2,D1Re0
  36. !! Multiply plt_index by sizeof(Elf32_Rela)
  37. MULW D0Ar2,D0Ar2,#12
  38. !! Call the resolver
  39. CALLR D1RtP,__dl_linux_resolver
  40. !! Restore the registers from the stack
  41. SUB A0.2,A0StP,#(1*8)
  42. GETL A0FrP,A1LbP,[A0.2]
  43. SUB A0.2,A0.2,#(4*8)
  44. MGETL D0Ar6,D0Ar4,D0Ar2,D0FrT,[A0.2]
  45. !! Also take into account args pushed by PLT
  46. SUB A0StP,A0StP,#(6*8)
  47. !! Jump to the resolved address
  48. MOV PC,D0Re0
  49. .size __dl_linux_resolve, .-__dl_linux_resolve