dl-sysdep.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* elf reloc code for the or1k platform, based on glibc 2.3.6, dl-machine.h */
  2. /*
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /* Use reloca */
  16. #define ELF_USES_RELOCA
  17. #include <elf.h>
  18. /* Initialise the GOT */
  19. #define INIT_GOT(GOT_BASE,MODULE) \
  20. do { \
  21. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  22. GOT_BASE[1] = (unsigned long) MODULE; \
  23. } while(0)
  24. /* Here we define the magic numbers that this dynamic loader should accept */
  25. #define MAGIC1 EM_OR1K
  26. #undef MAGIC2
  27. /* Used for error messages */
  28. #define ELF_TARGET "or1k"
  29. #define elf_machine_type_class(type) \
  30. (((type) == R_OR1K_JMP_SLOT) * ELF_RTYPE_CLASS_PLT \
  31. | ((type) == R_OR1K_COPY) * ELF_RTYPE_CLASS_COPY)
  32. static inline Elf32_Addr *
  33. or1k_get_got (void)
  34. {
  35. Elf32_Addr *got;
  36. Elf32_Addr linkreg;
  37. __asm__("l.ori %0, r9, 0\n"
  38. "l.jal .LPC1\n"
  39. #ifndef __OR1K_NODELAY__
  40. "l.nop\n"
  41. #endif
  42. ".LPC1:\n"
  43. "l.movhi %1, gotpchi(_GLOBAL_OFFSET_TABLE_+(.-.LPC1))\n"
  44. "l.ori %1, %1, gotpclo(_GLOBAL_OFFSET_TABLE_+(.-.LPC1))\n"
  45. "l.add %1, %1, r9\n"
  46. "l.ori r9, %0, 0\n"
  47. : "=r" (linkreg), "=r" (got));
  48. return got;
  49. }
  50. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  51. first element of the GOT. */
  52. static inline Elf32_Addr
  53. elf_machine_dynamic (void)
  54. {
  55. Elf32_Addr *got = or1k_get_got();
  56. return *got;
  57. }
  58. /* Return the run-time load address of the shared object. */
  59. static inline Elf32_Addr
  60. elf_machine_load_address (void)
  61. {
  62. /* Compute the difference between the runtime address of _DYNAMIC as seen
  63. by a GOTOFF reference, and the link-time address found in the special
  64. unrelocated first GOT entry. */
  65. Elf32_Addr dyn;
  66. Elf32_Addr *got = or1k_get_got();
  67. __asm__ __volatile__ (
  68. "l.movhi %0, gotoffhi(_DYNAMIC);"
  69. "l.ori %0, %0, gotofflo(_DYNAMIC);"
  70. "l.add %0, %0, %1;"
  71. : "=r"(dyn), "=r"(got)
  72. );
  73. return dyn - *got;
  74. }
  75. static __always_inline void
  76. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  77. Elf32_Word relative_count)
  78. {
  79. Elf32_Rela * rpnt = (void *) rel_addr;
  80. --rpnt;
  81. do {
  82. Elf32_Addr *const reloc_addr = (void *) (load_off +
  83. (++rpnt)->r_offset);
  84. *reloc_addr += load_off;
  85. } while (--relative_count);
  86. }