ld_sysdep.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* vi: set sw=4 ts=4: */
  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. /*
  7. * Define this if the system uses RELOCA.
  8. */
  9. #undef ELF_USES_RELOCA
  10. /*
  11. * Get a pointer to the argv array. On many platforms this can be just
  12. * the address if the first argument, on other platforms we need to
  13. * do something a little more subtle here.
  14. */
  15. #define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *) ARGS)
  16. /*
  17. * Initialization sequence for the application/library GOT.
  18. */
  19. #define INIT_GOT(GOT_BASE,MODULE) \
  20. do { \
  21. unsigned long i; \
  22. \
  23. /* Check if this is the dynamic linker itself */ \
  24. if (MODULE->libtype == program_interpreter) \
  25. continue; \
  26. \
  27. /* Fill in first two GOT entries according to the ABI */ \
  28. GOT_BASE[0] = (unsigned long) _dl_linux_resolve; \
  29. GOT_BASE[1] = (unsigned long) MODULE; \
  30. \
  31. /* Add load address displacement to all local GOT entries */ \
  32. i = 2; \
  33. while (i < MODULE->mips_local_gotno) \
  34. GOT_BASE[i++] += (unsigned long) MODULE->loadaddr; \
  35. \
  36. } while (0)
  37. /*
  38. * Here is a macro to perform the GOT relocation. This is only
  39. * used when bootstrapping the dynamic loader.
  40. */
  41. #define PERFORM_BOOTSTRAP_GOT(got) \
  42. do { \
  43. Elf32_Sym *sym; \
  44. unsigned long i; \
  45. \
  46. /* Add load address displacement to all local GOT entries */ \
  47. i = 2; \
  48. while (i < tpnt->mips_local_gotno) \
  49. got[i++] += load_addr; \
  50. \
  51. /* Handle global GOT entries */ \
  52. got += tpnt->mips_local_gotno; \
  53. sym = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + \
  54. load_addr) + tpnt->mips_gotsym; \
  55. i = tpnt->mips_symtabno - tpnt->mips_gotsym; \
  56. \
  57. while (i--) { \
  58. if (sym->st_shndx == SHN_UNDEF || \
  59. sym->st_shndx == SHN_COMMON) \
  60. *got = load_addr + sym->st_value; \
  61. else if (ELF32_ST_TYPE(sym->st_info) == STT_FUNC && \
  62. *got != sym->st_value) \
  63. *got += load_addr; \
  64. else if (ELF32_ST_TYPE(sym->st_info) == STT_SECTION) { \
  65. if (sym->st_other == 0) \
  66. *got += load_addr; \
  67. } \
  68. else \
  69. *got = load_addr + sym->st_value; \
  70. \
  71. got++; \
  72. sym++; \
  73. } \
  74. } while (0)
  75. /*
  76. * Here is a macro to perform a relocation. This is only used when
  77. * bootstrapping the dynamic loader.
  78. */
  79. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  80. switch(ELF32_R_TYPE((RELP)->r_info)) { \
  81. case R_MIPS_REL32: \
  82. if (symtab_index) { \
  83. if (symtab_index < tpnt->mips_gotsym) \
  84. *REL += SYMBOL; \
  85. } \
  86. else { \
  87. *REL += LOAD; \
  88. } \
  89. break; \
  90. case R_MIPS_NONE: \
  91. break; \
  92. default: \
  93. SEND_STDERR("Aiieeee!"); \
  94. _dl_exit(1); \
  95. }
  96. /*
  97. * Transfer control to the user's application, once the dynamic loader
  98. * is done. This routine has to exit the current function, then
  99. * call the _dl_elf_main function. For MIPS, we do it in assembly
  100. * because the stack doesn't get properly restored otherwise. Got look
  101. * at boot1_arch.h
  102. */
  103. #define START()
  104. /* Here we define the magic numbers that this dynamic loader should accept */
  105. #define MAGIC1 EM_MIPS
  106. #define MAGIC2 EM_MIPS_RS3_LE
  107. /* Used for error messages */
  108. #define ELF_TARGET "MIPS"
  109. unsigned long _dl_linux_resolver(unsigned long sym_index,
  110. unsigned long old_gpreg);
  111. #define do_rem(result, n, base) result = (n % base)
  112. /* 4096 bytes alignment */
  113. #define PAGE_ALIGN 0xfffff000
  114. #define ADDR_ALIGN 0xfff
  115. #define OFFS_ALIGN 0x7ffff000