dl-hash.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright (C) 2000-2006 by Erik Andersen <andersen@codepoet.org>
  4. *
  5. * GNU Lesser General Public License version 2.1 or later.
  6. */
  7. #ifndef _LD_HASH_H_
  8. #define _LD_HASH_H_
  9. #ifndef RTLD_NEXT
  10. #define RTLD_NEXT ((void*)-1)
  11. #endif
  12. struct init_fini {
  13. struct elf_resolve **init_fini;
  14. unsigned long nlist; /* Number of entries in init_fini */
  15. };
  16. struct dyn_elf {
  17. struct elf_resolve * dyn;
  18. struct dyn_elf * next_handle; /* Used by dlopen et al. */
  19. struct init_fini init_fini;
  20. struct dyn_elf * next;
  21. struct dyn_elf * prev;
  22. };
  23. struct elf_resolve {
  24. /* These entries must be in this order to be compatible with the interface used
  25. by gdb to obtain the list of symbols. */
  26. DL_LOADADDR_TYPE loadaddr; /* Base address shared object is loaded at. */
  27. char *libname; /* Absolute file name object was found in. */
  28. ElfW(Dyn) *dynamic_addr; /* Dynamic section of the shared object. */
  29. struct elf_resolve * next;
  30. struct elf_resolve * prev;
  31. /* Nothing after this address is used by gdb. */
  32. #if defined(USE_TLS) && USE_TLS
  33. /* Thread-local storage related info. */
  34. /* Start of the initialization image. */
  35. void *l_tls_initimage;
  36. /* Size of the initialization image. */
  37. size_t l_tls_initimage_size;
  38. /* Size of the TLS block. */
  39. size_t l_tls_blocksize;
  40. /* Alignment requirement of the TLS block. */
  41. size_t l_tls_align;
  42. /* Offset of first byte module alignment. */
  43. size_t l_tls_firstbyte_offset;
  44. # ifndef NO_TLS_OFFSET
  45. # define NO_TLS_OFFSET 0
  46. # endif
  47. /* For objects present at startup time: offset in the static TLS block. */
  48. ptrdiff_t l_tls_offset;
  49. /* Index of the module in the dtv array. */
  50. size_t l_tls_modid;
  51. /* Nonzero if _dl_init_static_tls should be called for this module */
  52. unsigned int l_need_tls_init:1;
  53. #endif
  54. ElfW(Addr) mapaddr;
  55. enum {elf_lib, elf_executable,program_interpreter, loaded_file} libtype;
  56. struct dyn_elf * symbol_scope;
  57. unsigned short usage_count;
  58. unsigned short int init_flag;
  59. unsigned long rtld_flags; /* RTLD_GLOBAL, RTLD_NOW etc. */
  60. Elf_Symndx nbucket;
  61. #ifdef __LDSO_GNU_HASH_SUPPORT__
  62. /* Data needed to support GNU hash style */
  63. Elf32_Word l_gnu_bitmask_idxbits;
  64. Elf32_Word l_gnu_shift;
  65. const ElfW(Addr) *l_gnu_bitmask;
  66. union
  67. {
  68. const Elf32_Word *l_gnu_chain_zero;
  69. const Elf_Symndx *elf_buckets;
  70. };
  71. #else
  72. Elf_Symndx *elf_buckets;
  73. #endif
  74. struct init_fini_list *init_fini;
  75. struct init_fini_list *rtld_local; /* keep tack of RTLD_LOCAL libs in same group */
  76. /*
  77. * These are only used with ELF style shared libraries
  78. */
  79. Elf_Symndx nchain;
  80. #ifdef __LDSO_GNU_HASH_SUPPORT__
  81. union
  82. {
  83. const Elf32_Word *l_gnu_buckets;
  84. const Elf_Symndx *chains;
  85. };
  86. #else
  87. Elf_Symndx *chains;
  88. #endif
  89. unsigned long dynamic_info[DYNAMIC_SIZE];
  90. unsigned long n_phent;
  91. ElfW(Phdr) * ppnt;
  92. ElfW(Addr) relro_addr;
  93. size_t relro_size;
  94. dev_t st_dev; /* device */
  95. ino_t st_ino; /* inode */
  96. #ifdef __powerpc__
  97. /* this is used to store the address of relocation data words, so
  98. * we don't have to calculate it every time, which requires a divide */
  99. unsigned long data_words;
  100. #endif
  101. #ifdef __FDPIC__
  102. /* Every loaded module holds a hashtable of function descriptors of
  103. functions defined in it, such that it's easy to release the
  104. memory when the module is dlclose()d. */
  105. struct funcdesc_ht *funcdesc_ht;
  106. #endif
  107. };
  108. #define RELOCS_DONE 0x000001
  109. #define JMP_RELOCS_DONE 0x000002
  110. #define INIT_FUNCS_CALLED 0x000004
  111. #define FINI_FUNCS_CALLED 0x000008
  112. #define DL_OPENED 0x000010
  113. extern struct dyn_elf * _dl_symbol_tables;
  114. extern struct elf_resolve * _dl_loaded_modules;
  115. extern struct dyn_elf * _dl_handles;
  116. extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname,
  117. DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info,
  118. unsigned long dynamic_addr, unsigned long dynamic_size);
  119. /* Only need extra arg with some configurations */
  120. #if !((defined(USE_TLS) && USE_TLS) || defined __FDPIC__)
  121. # define _dl_lookup_hash(n, r, m, c, t) _dl_lookup_hash(n, r, m, c)
  122. #endif
  123. extern char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt,
  124. struct elf_resolve *mytpnt, int type_class,
  125. struct elf_resolve **tpntp);
  126. static __always_inline char *_dl_find_hash(const char *name, struct dyn_elf *rpnt,
  127. struct elf_resolve *mytpnt, int type_class,
  128. struct elf_resolve **tpntp)
  129. {
  130. return _dl_lookup_hash(name, rpnt, mytpnt, type_class, tpntp);
  131. }
  132. extern int _dl_linux_dynamic_link(void);
  133. extern char * _dl_library_path;
  134. extern char * _dl_not_lazy;
  135. static __inline__ int _dl_symbol(char * name)
  136. {
  137. if (name[0] != '_' || name[1] != 'd' || name[2] != 'l' || name[3] != '_')
  138. return 0;
  139. return 1;
  140. }
  141. #define LD_ERROR_NOFILE 1
  142. #define LD_ERROR_NOZERO 2
  143. #define LD_ERROR_NOTELF 3
  144. #define LD_ERROR_NOTMAGIC 4
  145. #define LD_ERROR_NOTDYN 5
  146. #define LD_ERROR_MMAP_FAILED 6
  147. #define LD_ERROR_NODYNAMIC 7
  148. #define LD_ERROR_TLS_FAILED 8
  149. #define LD_WRONG_RELOCS 9
  150. #define LD_BAD_HANDLE 10
  151. #define LD_NO_SYMBOL 11
  152. #endif /* _LD_HASH_H_ */