dl-sysdep.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* vi: set sw=8 ts=8: */
  2. /*
  3. * Various assmbly language/system dependent hacks that are required
  4. * so that we can minimize the amount of platform specific code.
  5. */
  6. /* Define this if the system uses RELOCA. */
  7. #undef ELF_USES_RELOCA
  8. #include <elf.h>
  9. #include <link.h>
  10. #define ARCH_NUM 3
  11. #define DT_MIPS_GOTSYM_IDX (DT_NUM + OS_NUM)
  12. #define DT_MIPS_LOCAL_GOTNO_IDX (DT_NUM + OS_NUM +1)
  13. #define DT_MIPS_SYMTABNO_IDX (DT_NUM + OS_NUM +2)
  14. #define ARCH_DYNAMIC_INFO(dpnt, dynamic, debug_addr) \
  15. do { \
  16. if (dpnt->d_tag == DT_MIPS_GOTSYM) \
  17. dynamic[DT_MIPS_GOTSYM_IDX] = dpnt->d_un.d_val; \
  18. else if (dpnt->d_tag == DT_MIPS_LOCAL_GOTNO) \
  19. dynamic[DT_MIPS_LOCAL_GOTNO_IDX] = dpnt->d_un.d_val; \
  20. else if (dpnt->d_tag == DT_MIPS_SYMTABNO) \
  21. dynamic[DT_MIPS_SYMTABNO_IDX] = dpnt->d_un.d_val; \
  22. else if (dpnt->d_tag == DT_MIPS_RLD_MAP) \
  23. *(Elf32_Addr *)(dpnt->d_un.d_ptr) = (Elf32_Addr) debug_addr; \
  24. } while (0)
  25. /* Initialization sequence for the application/library GOT. */
  26. #define INIT_GOT(GOT_BASE,MODULE) \
  27. do { \
  28. unsigned long idx; \
  29. \
  30. /* Check if this is the dynamic linker itself */ \
  31. if (MODULE->libtype == program_interpreter) \
  32. continue; \
  33. \
  34. /* Fill in first two GOT entries according to the ABI */ \
  35. GOT_BASE[0] = (unsigned long) _dl_runtime_resolve; \
  36. GOT_BASE[1] = (unsigned long) MODULE; \
  37. \
  38. /* Add load address displacement to all local GOT entries */ \
  39. idx = 2; \
  40. while (idx < MODULE->dynamic_info[DT_MIPS_LOCAL_GOTNO_IDX]) \
  41. GOT_BASE[idx++] += (unsigned long) MODULE->loadaddr; \
  42. \
  43. } while (0)
  44. /* Here we define the magic numbers that this dynamic loader should accept */
  45. #define MAGIC1 EM_MIPS
  46. #define MAGIC2 EM_MIPS_RS3_LE
  47. /* Used for error messages */
  48. #define ELF_TARGET "MIPS"
  49. unsigned long __dl_runtime_resolve(unsigned long sym_index,
  50. unsigned long old_gpreg);
  51. struct elf_resolve;
  52. void _dl_perform_mips_global_got_relocations(struct elf_resolve *tpnt, int lazy);
  53. /* 4096 bytes alignment */
  54. #define PAGE_ALIGN 0xfffff000
  55. #define ADDR_ALIGN 0xfff
  56. #define OFFS_ALIGN 0x7ffff000
  57. #define elf_machine_type_class(type) ELF_RTYPE_CLASS_PLT
  58. /* MIPS does not have COPY relocs */
  59. #define DL_NO_COPY_RELOCS
  60. #define OFFSET_GP_GOT 0x7ff0
  61. static inline ElfW(Addr) *
  62. elf_mips_got_from_gpreg (ElfW(Addr) gpreg)
  63. {
  64. /* FIXME: the offset of gp from GOT may be system-dependent. */
  65. return (ElfW(Addr) *) (gpreg - OFFSET_GP_GOT);
  66. }
  67. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  68. first element of the GOT. This must be inlined in a function which
  69. uses global data. We assume its $gp points to the primary GOT. */
  70. static inline ElfW(Addr)
  71. elf_machine_dynamic (void)
  72. {
  73. register ElfW(Addr) gp __asm__ ("$28");
  74. return *elf_mips_got_from_gpreg (gp);
  75. }
  76. #define STRINGXP(X) __STRING(X)
  77. #define STRINGXV(X) STRINGV_(X)
  78. #define STRINGV_(...) # __VA_ARGS__
  79. #define PTR_LA la
  80. #define PTR_SUBU subu
  81. /* Return the run-time load address of the shared object. */
  82. static inline ElfW(Addr)
  83. elf_machine_load_address (void)
  84. {
  85. ElfW(Addr) addr;
  86. asm (" .set noreorder\n"
  87. " " STRINGXP (PTR_LA) " %0, 0f\n"
  88. " bltzal $0, 0f\n"
  89. " nop\n"
  90. "0: " STRINGXP (PTR_SUBU) " %0, $31, %0\n"
  91. " .set reorder\n"
  92. : "=r" (addr)
  93. : /* No inputs */
  94. : "$31");
  95. return addr;
  96. }
  97. static inline void
  98. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  99. Elf32_Word relative_count)
  100. {
  101. /* No REALTIVE relocs in MIPS? */
  102. }