dl-sysdep.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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) * ELF_RTYPE_CLASS_PLT \
  30. | ((type) == R_OR1K_COPY) * ELF_RTYPE_CLASS_COPY)
  31. static inline Elf32_Addr *
  32. or1k_get_got (void)
  33. {
  34. Elf32_Addr *got;
  35. Elf32_Addr linkreg;
  36. __asm__("l.ori %0, r9, 0\n"
  37. "l.jal .LPC1\n"
  38. #ifndef __OR1K_NODELAY__
  39. "l.nop\n"
  40. #endif
  41. ".LPC1:\n"
  42. "l.movhi %1, gotpchi(_GLOBAL_OFFSET_TABLE_+(.-.LPC1))\n"
  43. "l.ori %1, %1, gotpclo(_GLOBAL_OFFSET_TABLE_+(.-.LPC1))\n"
  44. "l.add %1, %1, r9\n"
  45. "l.ori r9, %0, 0\n"
  46. : "=r" (linkreg), "=r" (got));
  47. return got;
  48. }
  49. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  50. first element of the GOT. */
  51. static inline Elf32_Addr
  52. elf_machine_dynamic (void)
  53. {
  54. Elf32_Addr *got = or1k_get_got();
  55. return *got;
  56. }
  57. /* Return the run-time load address of the shared object. */
  58. static inline Elf32_Addr
  59. elf_machine_load_address (void)
  60. {
  61. /* Compute the difference between the runtime address of _DYNAMIC as seen
  62. by a GOTOFF reference, and the link-time address found in the special
  63. unrelocated first GOT entry. */
  64. Elf32_Addr dyn;
  65. Elf32_Addr *got = or1k_get_got();
  66. __asm__ __volatile__ (
  67. "l.movhi %0, gotoffhi(_DYNAMIC);"
  68. "l.ori %0, %0, gotofflo(_DYNAMIC);"
  69. "l.add %0, %0, %1;"
  70. : "=r"(dyn), "=r"(got)
  71. );
  72. return dyn - *got;
  73. }
  74. static __always_inline void
  75. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  76. Elf32_Word relative_count)
  77. {
  78. Elf32_Rela * rpnt = (void *) rel_addr;
  79. --rpnt;
  80. do {
  81. Elf32_Addr *const reloc_addr = (void *) (load_off +
  82. (++rpnt)->r_offset);
  83. *reloc_addr += load_off;
  84. } while (--relative_count);
  85. }