dl-sysdep.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #define do_rem(result, n, base) ((result) = (n) % (base))
  17. /* 8192 bytes alignment */
  18. #define PAGE_ALIGN 0xffffe000
  19. #define ADDR_ALIGN 0x1fff
  20. #define OFFS_ALIGN 0xffffe000
  21. /* The union of reloc-type-classes where the reloc TYPE is a member.
  22. TYPE is in the class ELF_RTYPE_CLASS_PLT if it can describe a
  23. relocation for a PLT entry, that is, for which a PLT entry should not
  24. be allowed to define the value. The GNU linker for CRIS can merge a
  25. .got.plt entry (R_CRIS_JUMP_SLOT) with a .got entry (R_CRIS_GLOB_DAT),
  26. so we need to match both these reloc types.
  27. TYPE is in the class ELF_RTYPE_CLASS_NOCOPY if it should not be allowed
  28. to resolve to one of the main executable's symbols, as for a COPY
  29. reloc. */
  30. #define elf_machine_type_class(type) \
  31. ((((((type) == R_CRIS_JUMP_SLOT)) \
  32. || ((type) == R_CRIS_GLOB_DAT)) * ELF_RTYPE_CLASS_PLT) \
  33. | (((type) == R_CRIS_COPY) * ELF_RTYPE_CLASS_COPY))
  34. static inline Elf32_Addr
  35. elf_machine_dynamic(void)
  36. {
  37. /* Don't just set this to an asm variable "r0" since that's not logical
  38. (like, the variable is uninitialized and the register is fixed) and
  39. may make GCC trip over itself doing register allocation. Yes, I'm
  40. paranoid. Why do you ask? */
  41. Elf32_Addr *got;
  42. __asm__ ("move.d $r0,%0" : "=rm" (got));
  43. return *got;
  44. }
  45. /* Return the run-time load address of the shared object. We do it like
  46. m68k and i386, by taking an arbitrary local symbol, forcing a GOT entry
  47. for it, and peeking into the GOT table, which is set to the link-time
  48. file-relative symbol value (regardless of whether the target is REL or
  49. RELA). We subtract this link-time file-relative value from the "local"
  50. value we calculate from GOT position and GOT offset. FIXME: Perhaps
  51. there's some other symbol we could use, that we don't *have* to force a
  52. GOT entry for. */
  53. static inline Elf32_Addr
  54. elf_machine_load_address(void)
  55. {
  56. Elf32_Addr gotaddr_diff;
  57. __asm__ ("sub.d [$r0+_dl_start:GOT16],$r0,%0\n\t"
  58. "add.d _dl_start:GOTOFF,%0" : "=r" (gotaddr_diff));
  59. return gotaddr_diff;
  60. }
  61. static inline void
  62. elf_machine_relative(Elf32_Addr load_off, const Elf32_Addr rel_addr,
  63. Elf32_Word relative_count)
  64. {
  65. Elf32_Rela *rpnt = (void *)rel_addr;
  66. --rpnt;
  67. do {
  68. Elf32_Addr *const reloc_addr =
  69. (void *)(load_off + (++rpnt)->r_offset);
  70. *reloc_addr = load_off + rpnt->r_addend;
  71. } while (--relative_count);
  72. }