dl-elf.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef LINUXELF_H
  2. #define LINUXELF_H
  3. #include <dl-string.h> /* before elf.h to get ELF_USES_RELOCA right */
  4. #include <elf.h>
  5. #include <link.h>
  6. /* Forward declarations for stuff defined in ld_hash.h */
  7. struct dyn_elf;
  8. struct elf_resolve;
  9. #include <dl-defs.h>
  10. #ifdef __LDSO_CACHE_SUPPORT__
  11. extern int _dl_map_cache(void);
  12. extern int _dl_unmap_cache(void);
  13. #else
  14. static inline void _dl_map_cache(void) { }
  15. static inline void _dl_unmap_cache(void) { }
  16. #endif
  17. /* Function prototypes for non-static stuff in readelflib1.c */
  18. extern void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt,
  19. unsigned long rel_addr, unsigned long rel_size);
  20. extern int _dl_parse_relocation_information(struct dyn_elf *rpnt,
  21. unsigned long rel_addr, unsigned long rel_size);
  22. extern struct elf_resolve * _dl_load_shared_library(int secure,
  23. struct dyn_elf **rpnt, struct elf_resolve *tpnt, char *full_libname,
  24. int trace_loaded_objects);
  25. extern struct elf_resolve * _dl_load_elf_shared_library(int secure,
  26. struct dyn_elf **rpnt, char *libname);
  27. extern struct elf_resolve *_dl_check_if_named_library_is_loaded(const char *full_libname,
  28. int trace_loaded_objects);
  29. extern int _dl_linux_resolve(void);
  30. extern int _dl_fixup(struct dyn_elf *rpnt, int flag);
  31. extern void _dl_protect_relro (struct elf_resolve *l);
  32. /*
  33. * Datatype of a relocation on this platform
  34. */
  35. #ifdef ELF_USES_RELOCA
  36. # define ELF_RELOC ElfW(Rela)
  37. # define DT_RELOC_TABLE_ADDR DT_RELA
  38. # define DT_RELOC_TABLE_SIZE DT_RELASZ
  39. # define DT_RELOCCOUNT DT_RELACOUNT
  40. # define UNSUPPORTED_RELOC_TYPE DT_REL
  41. # define UNSUPPORTED_RELOC_STR "REL"
  42. #else
  43. # define ELF_RELOC ElfW(Rel)
  44. # define DT_RELOC_TABLE_ADDR DT_REL
  45. # define DT_RELOC_TABLE_SIZE DT_RELSZ
  46. # define DT_RELOCCOUNT DT_RELCOUNT
  47. # define UNSUPPORTED_RELOC_TYPE DT_RELA
  48. # define UNSUPPORTED_RELOC_STR "RELA"
  49. #endif
  50. /* OS and/or GNU dynamic extensions */
  51. #define OS_NUM 1
  52. #define DT_RELCONT_IDX DT_NUM
  53. #ifndef ARCH_DYNAMIC_INFO
  54. /* define in arch specific code, if needed */
  55. # define ARCH_NUM 0
  56. #endif
  57. #define DYNAMIC_SIZE (DT_NUM+OS_NUM+ARCH_NUM)
  58. extern void _dl_parse_dynamic_info(Elf32_Dyn *dpnt, unsigned long dynamic_info[], void *debug_addr, Elf32_Addr load_off);
  59. static inline __attribute__((always_inline))
  60. void __dl_parse_dynamic_info(Elf32_Dyn *dpnt, unsigned long dynamic_info[], void *debug_addr, Elf32_Addr load_off)
  61. {
  62. for (; dpnt->d_tag; dpnt++) {
  63. if (dpnt->d_tag < DT_NUM) {
  64. dynamic_info[dpnt->d_tag] = dpnt->d_un.d_val;
  65. #ifndef __mips__
  66. if (dpnt->d_tag == DT_DEBUG)
  67. dpnt->d_un.d_val = (unsigned long)debug_addr;
  68. #endif
  69. if (dpnt->d_tag == DT_BIND_NOW)
  70. dynamic_info[DT_BIND_NOW] = 1;
  71. if (dpnt->d_tag == DT_FLAGS &&
  72. (dpnt->d_un.d_val & DF_BIND_NOW))
  73. dynamic_info[DT_BIND_NOW] = 1;
  74. if (dpnt->d_tag == DT_TEXTREL)
  75. dynamic_info[DT_TEXTREL] = 1;
  76. } else if (dpnt->d_tag < DT_LOPROC) {
  77. if (dpnt->d_tag == DT_RELOCCOUNT)
  78. dynamic_info[DT_RELCONT_IDX] = dpnt->d_un.d_val;
  79. if (dpnt->d_tag == DT_FLAGS_1 &&
  80. (dpnt->d_un.d_val & DF_1_NOW))
  81. dynamic_info[DT_BIND_NOW] = 1;
  82. }
  83. #ifdef ARCH_DYNAMIC_INFO
  84. else {
  85. ARCH_DYNAMIC_INFO(dpnt, dynamic_info, debug_addr);
  86. }
  87. #endif
  88. }
  89. # define ADJUST_DYN_INFO(tag, load_off) \
  90. do { \
  91. if (dynamic_info[tag]) \
  92. dynamic_info[tag] += load_off; \
  93. } while(0)
  94. ADJUST_DYN_INFO (DT_HASH, load_off);
  95. ADJUST_DYN_INFO (DT_PLTGOT, load_off);
  96. ADJUST_DYN_INFO (DT_STRTAB, load_off);
  97. ADJUST_DYN_INFO (DT_SYMTAB, load_off);
  98. ADJUST_DYN_INFO (DT_RELOC_TABLE_ADDR, load_off);
  99. ADJUST_DYN_INFO (DT_JMPREL, load_off);
  100. # undef ADJUST_DYN_INFO
  101. }
  102. /* Reloc type classes as returned by elf_machine_type_class().
  103. ELF_RTYPE_CLASS_PLT means this reloc should not be satisfied by
  104. some PLT symbol, ELF_RTYPE_CLASS_COPY means this reloc should not be
  105. satisfied by any symbol in the executable. Some architectures do
  106. not support copy relocations. In this case we define the macro to
  107. zero so that the code for handling them gets automatically optimized
  108. out. */
  109. #ifdef DL_NO_COPY_RELOCS
  110. # define ELF_RTYPE_CLASS_COPY (0x0)
  111. #else
  112. # define ELF_RTYPE_CLASS_COPY (0x2)
  113. #endif
  114. #define ELF_RTYPE_CLASS_PLT (0x1)
  115. /* Convert between the Linux flags for page protections and the
  116. ones specified in the ELF standard. */
  117. #define LXFLAGS(X) ( (((X) & PF_R) ? PROT_READ : 0) | \
  118. (((X) & PF_W) ? PROT_WRITE : 0) | \
  119. (((X) & PF_X) ? PROT_EXEC : 0))
  120. #endif /* LINUXELF_H */