dl-sysdep.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* CRIS can never use Elf32_Rel relocations. */
  2. #define ELF_USES_RELOCA
  3. #include <elf.h>
  4. /* Initialization sequence for the GOT. */
  5. #define INIT_GOT(GOT_BASE,MODULE) \
  6. { \
  7. GOT_BASE[1] = (unsigned long) MODULE; \
  8. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  9. }
  10. /* Defined some magic numbers that this ld.so should accept. */
  11. #define MAGIC1 EM_CRIS
  12. #undef MAGIC2
  13. #define ELF_TARGET "CRIS"
  14. struct elf_resolve;
  15. extern unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry);
  16. /* 8192 bytes alignment */
  17. #define PAGE_ALIGN 0xffffe000
  18. #define ADDR_ALIGN 0x1fff
  19. #define OFFS_ALIGN 0xffffe000
  20. /* The union of reloc-type-classes where the reloc TYPE is a member.
  21. TYPE is in the class ELF_RTYPE_CLASS_PLT if it can describe a
  22. relocation for a PLT entry, that is, for which a PLT entry should not
  23. be allowed to define the value. The GNU linker for CRIS can merge a
  24. .got.plt entry (R_CRIS_JUMP_SLOT) with a .got entry (R_CRIS_GLOB_DAT),
  25. so we need to match both these reloc types.
  26. TYPE is in the class ELF_RTYPE_CLASS_NOCOPY if it should not be allowed
  27. to resolve to one of the main executable's symbols, as for a COPY
  28. reloc. */
  29. #define elf_machine_type_class(type) \
  30. ((((((type) == R_CRIS_JUMP_SLOT)) \
  31. || ((type) == R_CRIS_GLOB_DAT)) * ELF_RTYPE_CLASS_PLT) \
  32. | (((type) == R_CRIS_COPY) * ELF_RTYPE_CLASS_COPY))
  33. static __inline__ Elf32_Addr
  34. elf_machine_dynamic(void)
  35. {
  36. /* Don't just set this to an asm variable "r0" since that's not logical
  37. (like, the variable is uninitialized and the register is fixed) and
  38. may make GCC trip over itself doing register allocation. Yes, I'm
  39. paranoid. Why do you ask? */
  40. Elf32_Addr *got;
  41. __asm__ ("move.d $r0,%0" : "=rm" (got));
  42. return *got;
  43. }
  44. /* Return the run-time load address of the shared object. We do it like
  45. m68k and i386, by taking an arbitrary local symbol, forcing a GOT entry
  46. for it, and peeking into the GOT table, which is set to the link-time
  47. file-relative symbol value (regardless of whether the target is REL or
  48. RELA). We subtract this link-time file-relative value from the "local"
  49. value we calculate from GOT position and GOT offset. FIXME: Perhaps
  50. there's some other symbol we could use, that we don't *have* to force a
  51. GOT entry for. */
  52. static __inline__ Elf32_Addr
  53. elf_machine_load_address(void)
  54. {
  55. Elf32_Addr gotaddr_diff;
  56. #ifdef __arch_v32
  57. extern char ___CRISv32_dummy[] __asm__ ("_dl_start");
  58. __asm__ ("addo.w _dl_start:GOT16,$r0,$acr\n\t"
  59. "lapc _dl_start,%0\n\t"
  60. "sub.d [$acr],%0"
  61. /* For v32, we need to force GCC to have R0 loaded with
  62. _GLOBAL_OFFSET_TABLE_ at this point, which might not
  63. otherwise have happened in the caller. (For v10, it's
  64. loaded for non-global variables too, so we don't need
  65. anything special there.) We accomplish this by faking the
  66. address of a global variable (as seen by GCC) as input to
  67. the asm; that address calculation goes through the GOT.
  68. Use of this function happens before we've filled in the
  69. GOT, so the address itself will not be correctly
  70. calculated, therefore we don't use any symbol whose
  71. address may be re-used later on. Let's just reuse the
  72. _dl_start symbol, faking it as a global by renaming it as
  73. another variable through an asm. */
  74. : "=r" (gotaddr_diff)
  75. : "g" (___CRISv32_dummy)
  76. : "acr");
  77. #else
  78. __asm__ ("sub.d [$r0+_dl_start:GOT16],$r0,%0\n\t"
  79. "add.d _dl_start:GOTOFF,%0" : "=r" (gotaddr_diff));
  80. #endif
  81. return gotaddr_diff;
  82. }
  83. static __inline__ void
  84. elf_machine_relative(Elf32_Addr load_off, const Elf32_Addr rel_addr,
  85. Elf32_Word relative_count)
  86. {
  87. Elf32_Rela *rpnt = (void *)rel_addr;
  88. --rpnt;
  89. do {
  90. Elf32_Addr *const reloc_addr =
  91. (void *)(load_off + (++rpnt)->r_offset);
  92. *reloc_addr = load_off + rpnt->r_addend;
  93. } while (--relative_count);
  94. }