dl-sysdep.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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; see the file COPYING.LIB. If
  13. not, see <http://www.gnu.org/licenses/>.  */
  14. /* Use reloca */
  15. #define ELF_USES_RELOCA
  16. #include <elf.h>
  17. /* Initialise the GOT */
  18. #define INIT_GOT(GOT_BASE,MODULE) \
  19. do { \
  20. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  21. GOT_BASE[1] = (unsigned long) MODULE; \
  22. } while(0)
  23. /* Here we define the magic numbers that this dynamic loader should accept */
  24. #define MAGIC1 EM_OR1K
  25. #undef MAGIC2
  26. /* Used for error messages */
  27. #define ELF_TARGET "or1k"
  28. #define elf_machine_type_class(type) \
  29. (((type) == R_OR1K_JMP_SLOT || (type) == R_OR1K_TLS_DTPMOD || \
  30. (type) == R_OR1K_TLS_DTPOFF || \
  31. (type) == R_OR1K_TLS_TPOFF) * ELF_RTYPE_CLASS_PLT \
  32. | ((type) == R_OR1K_COPY) * ELF_RTYPE_CLASS_COPY)
  33. static inline Elf32_Addr *
  34. or1k_get_got (void)
  35. {
  36. Elf32_Addr *got;
  37. Elf32_Addr linkreg;
  38. __asm__("l.ori %0, r9, 0\n"
  39. "l.jal .LPC1\n"
  40. #ifndef __OR1K_NODELAY__
  41. "l.nop\n"
  42. #endif
  43. ".LPC1:\n"
  44. "l.movhi %1, gotpchi(_GLOBAL_OFFSET_TABLE_+(.-.LPC1))\n"
  45. "l.ori %1, %1, gotpclo(_GLOBAL_OFFSET_TABLE_+(.-.LPC1))\n"
  46. "l.add %1, %1, r9\n"
  47. "l.ori r9, %0, 0\n"
  48. : "=r" (linkreg), "=r" (got));
  49. return got;
  50. }
  51. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  52. first element of the GOT. */
  53. static inline Elf32_Addr
  54. elf_machine_dynamic (void)
  55. {
  56. Elf32_Addr *got = or1k_get_got();
  57. return *got;
  58. }
  59. /* Return the run-time load address of the shared object. */
  60. static inline Elf32_Addr
  61. elf_machine_load_address (void)
  62. {
  63. /* Compute the difference between the runtime address of _DYNAMIC as seen
  64. by a GOTOFF reference, and the link-time address found in the special
  65. unrelocated first GOT entry. */
  66. Elf32_Addr dyn;
  67. Elf32_Addr *got = or1k_get_got();
  68. __asm__ __volatile__ (
  69. "l.movhi %0, gotoffhi(_DYNAMIC);"
  70. "l.ori %0, %0, gotofflo(_DYNAMIC);"
  71. "l.add %0, %0, %1;"
  72. : "=r"(dyn), "=r"(got)
  73. );
  74. return dyn - *got;
  75. }
  76. static __always_inline void
  77. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  78. Elf32_Word relative_count)
  79. {
  80. Elf32_Rela * rpnt = (void *) rel_addr;
  81. --rpnt;
  82. do {
  83. Elf32_Addr *const reloc_addr = (void *) (load_off +
  84. (++rpnt)->r_offset);
  85. *reloc_addr += load_off;
  86. } while (--relative_count);
  87. }