dl-elf.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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);
  59. static inline __attribute__((always_inline))
  60. void __dl_parse_dynamic_info(Elf32_Dyn *dpnt, unsigned long dynamic_info[], void *debug_addr)
  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. }
  90. /* Reloc type classes as returned by elf_machine_type_class().
  91. ELF_RTYPE_CLASS_PLT means this reloc should not be satisfied by
  92. some PLT symbol, ELF_RTYPE_CLASS_COPY means this reloc should not be
  93. satisfied by any symbol in the executable. Some architectures do
  94. not support copy relocations. In this case we define the macro to
  95. zero so that the code for handling them gets automatically optimized
  96. out. */
  97. #ifdef DL_NO_COPY_RELOCS
  98. # define ELF_RTYPE_CLASS_COPY (0x0)
  99. #else
  100. # define ELF_RTYPE_CLASS_COPY (0x2)
  101. #endif
  102. #define ELF_RTYPE_CLASS_PLT (0x1)
  103. /* Convert between the Linux flags for page protections and the
  104. ones specified in the ELF standard. */
  105. #define LXFLAGS(X) ( (((X) & PF_R) ? PROT_READ : 0) | \
  106. (((X) & PF_W) ? PROT_WRITE : 0) | \
  107. (((X) & PF_X) ? PROT_EXEC : 0))
  108. #endif /* LINUXELF_H */