dl-elf.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifdef DEBUG
  7. # define LDSO_CONF "../util/ld.so.conf"
  8. # define LDSO_CACHE "../util/ld.so.cache"
  9. # define LDSO_PRELOAD "../util/ld.so.preload"
  10. #else
  11. # define LDSO_CONF UCLIBC_RUNTIME_PREFIX "etc/ld.so.conf"
  12. # define LDSO_CACHE UCLIBC_RUNTIME_PREFIX "etc/ld.so.cache"
  13. # define LDSO_PRELOAD UCLIBC_RUNTIME_PREFIX "etc/ld.so.preload"
  14. #endif
  15. #define LIB_ANY -1
  16. #define LIB_DLL 0
  17. #define LIB_ELF 1
  18. #define LIB_ELF64 0x80
  19. #define LIB_ELF_LIBC5 2
  20. #define LIB_ELF_LIBC6 3
  21. #define LIB_ELF_LIBC0 4
  22. /* Forward declarations for stuff defined in ld_hash.h */
  23. struct dyn_elf;
  24. struct elf_resolve;
  25. /* Definitions and prototypes for cache stuff */
  26. #ifdef USE_CACHE
  27. extern int _dl_map_cache(void);
  28. extern int _dl_unmap_cache(void);
  29. #define LDSO_CACHE_MAGIC "ld.so-"
  30. #define LDSO_CACHE_MAGIC_LEN (sizeof LDSO_CACHE_MAGIC -1)
  31. #define LDSO_CACHE_VER "1.7.0"
  32. #define LDSO_CACHE_VER_LEN (sizeof LDSO_CACHE_VER -1)
  33. typedef struct {
  34. char magic [LDSO_CACHE_MAGIC_LEN];
  35. char version [LDSO_CACHE_VER_LEN];
  36. int nlibs;
  37. } header_t;
  38. typedef struct {
  39. int flags;
  40. int sooffset;
  41. int liboffset;
  42. } libentry_t;
  43. #else
  44. static inline void _dl_map_cache(void) { }
  45. static inline void _dl_unmap_cache(void) { }
  46. #endif
  47. /* Function prototypes for non-static stuff in readelflib1.c */
  48. extern int _dl_parse_copy_information(struct dyn_elf *rpnt,
  49. unsigned long rel_addr, unsigned long rel_size, int type);
  50. extern void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt,
  51. unsigned long rel_addr, unsigned long rel_size, int type);
  52. extern int _dl_parse_relocation_information(struct dyn_elf *rpnt,
  53. unsigned long rel_addr, unsigned long rel_size, int type);
  54. extern struct elf_resolve * _dl_load_shared_library(int secure,
  55. struct dyn_elf **rpnt, struct elf_resolve *tpnt, char *full_libname,
  56. int trace_loaded_objects);
  57. extern struct elf_resolve * _dl_load_elf_shared_library(int secure,
  58. struct dyn_elf **rpnt, char *libname);
  59. extern struct elf_resolve *_dl_check_if_named_library_is_loaded(const char *full_libname,
  60. int trace_loaded_objects);
  61. extern int _dl_linux_resolve(void);
  62. extern int _dl_fixup(struct dyn_elf *rpnt, int flag);
  63. /*
  64. * Datatype of a relocation on this platform
  65. */
  66. #ifdef ELF_USES_RELOCA
  67. # define ELF_RELOC ElfW(Rela)
  68. # define DT_RELOC_TABLE_ADDR DT_RELA
  69. # define DT_RELOC_TABLE_SIZE DT_RELASZ
  70. # define UNSUPPORTED_RELOC_TYPE DT_REL
  71. # define UNSUPPORTED_RELOC_STR "REL"
  72. #else
  73. # define ELF_RELOC ElfW(Rel)
  74. # define DT_RELOC_TABLE_ADDR DT_REL
  75. # define DT_RELOC_TABLE_SIZE DT_RELSZ
  76. # define UNSUPPORTED_RELOC_TYPE DT_RELA
  77. # define UNSUPPORTED_RELOC_STR "RELA"
  78. #endif
  79. /* Reloc type classes as returned by elf_machine_type_class().
  80. ELF_RTYPE_CLASS_PLT means this reloc should not be satisfied by
  81. some PLT symbol, ELF_RTYPE_CLASS_COPY means this reloc should not be
  82. satisfied by any symbol in the executable. Some architectures do
  83. not support copy relocations. In this case we define the macro to
  84. zero so that the code for handling them gets automatically optimized
  85. out. */
  86. #ifdef DL_NO_COPY_RELOCS
  87. # define ELF_RTYPE_CLASS_COPY (0x0)
  88. #else
  89. # define ELF_RTYPE_CLASS_COPY (0x2)
  90. #endif
  91. #define ELF_RTYPE_CLASS_PLT (0x1)
  92. /* Convert between the Linux flags for page protections and the
  93. ones specified in the ELF standard. */
  94. #define LXFLAGS(X) ( (((X) & PF_R) ? PROT_READ : 0) | \
  95. (((X) & PF_W) ? PROT_WRITE : 0) | \
  96. (((X) & PF_X) ? PROT_EXEC : 0))
  97. #endif /* LINUXELF_H */