dl-hash.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 _DL_HASH_H
  8. #define _DL_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 symbol_ref {
  24. const ElfW(Sym) *sym;
  25. struct elf_resolve *tpnt;
  26. };
  27. /* Structure to describe a single list of scope elements. The lookup
  28. functions get passed an array of pointers to such structures. */
  29. struct r_scope_elem {
  30. struct elf_resolve **r_list; /* Array of maps for the scope. */
  31. unsigned int r_nlist; /* Number of entries in the scope. */
  32. struct r_scope_elem *next;
  33. };
  34. struct elf_resolve {
  35. /* These entries must be in this order to be compatible with the interface used
  36. by gdb to obtain the list of symbols. */
  37. DL_LOADADDR_TYPE loadaddr; /* Base address shared object is loaded at. */
  38. char *libname; /* Absolute file name object was found in. */
  39. ElfW(Dyn) *dynamic_addr; /* Dynamic section of the shared object. */
  40. struct elf_resolve * next;
  41. struct elf_resolve * prev;
  42. /* Nothing after this address is used by gdb. */
  43. #if defined(USE_TLS) && USE_TLS
  44. /* Thread-local storage related info. */
  45. /* Start of the initialization image. */
  46. void *l_tls_initimage;
  47. /* Size of the initialization image. */
  48. size_t l_tls_initimage_size;
  49. /* Size of the TLS block. */
  50. size_t l_tls_blocksize;
  51. /* Alignment requirement of the TLS block. */
  52. size_t l_tls_align;
  53. /* Offset of first byte module alignment. */
  54. size_t l_tls_firstbyte_offset;
  55. # ifndef NO_TLS_OFFSET
  56. # define NO_TLS_OFFSET 0
  57. # endif
  58. /* For objects present at startup time: offset in the static TLS block. */
  59. ptrdiff_t l_tls_offset;
  60. /* Index of the module in the dtv array. */
  61. size_t l_tls_modid;
  62. /* Nonzero if _dl_init_static_tls should be called for this module */
  63. unsigned int l_need_tls_init:1;
  64. /* Address of TLS descriptor hash table. */
  65. void *l_tlsdesc_table;
  66. #endif
  67. ElfW(Addr) mapaddr;
  68. #ifdef __LDSO_STANDALONE_SUPPORT__
  69. /* Store the entry point from the ELF header (e_entry) */
  70. ElfW(Addr) l_entry;
  71. #endif
  72. enum {elf_lib, elf_executable,program_interpreter, loaded_file} libtype;
  73. /* This is the local scope of the shared object */
  74. struct r_scope_elem symbol_scope;
  75. unsigned short usage_count;
  76. unsigned short int init_flag;
  77. unsigned long rtld_flags; /* RTLD_GLOBAL, RTLD_NOW etc. */
  78. Elf_Symndx nbucket;
  79. #ifdef __LDSO_GNU_HASH_SUPPORT__
  80. /* Data needed to support GNU hash style */
  81. Elf32_Word l_gnu_bitmask_idxbits;
  82. Elf32_Word l_gnu_shift;
  83. const ElfW(Addr) *l_gnu_bitmask;
  84. union
  85. {
  86. const Elf32_Word *l_gnu_chain_zero;
  87. const Elf_Symndx *elf_buckets;
  88. };
  89. #else
  90. Elf_Symndx *elf_buckets;
  91. #endif
  92. struct init_fini_list *init_fini;
  93. struct init_fini_list *rtld_local; /* keep tack of RTLD_LOCAL libs in same group */
  94. /*
  95. * These are only used with ELF style shared libraries
  96. */
  97. Elf_Symndx nchain;
  98. #ifdef __LDSO_GNU_HASH_SUPPORT__
  99. union
  100. {
  101. const Elf32_Word *l_gnu_buckets;
  102. const Elf_Symndx *chains;
  103. };
  104. #else
  105. Elf_Symndx *chains;
  106. #endif
  107. unsigned long dynamic_info[DYNAMIC_SIZE];
  108. unsigned long n_phent;
  109. ElfW(Phdr) * ppnt;
  110. ElfW(Addr) relro_addr;
  111. size_t relro_size;
  112. dev_t st_dev; /* device */
  113. ino_t st_ino; /* inode */
  114. #ifdef __powerpc__
  115. /* this is used to store the address of relocation data words, so
  116. * we don't have to calculate it every time, which requires a divide */
  117. unsigned long data_words;
  118. #endif
  119. #ifdef __FDPIC__
  120. /* Every loaded module holds a hashtable of function descriptors of
  121. functions defined in it, such that it's easy to release the
  122. memory when the module is dlclose()d. */
  123. struct funcdesc_ht *funcdesc_ht;
  124. #endif
  125. #ifdef __DSBT__
  126. /* Information for DSBT */
  127. void **dsbt_table;
  128. unsigned long dsbt_size;
  129. unsigned long dsbt_index;
  130. #endif
  131. };
  132. #define RELOCS_DONE 0x000001
  133. #define JMP_RELOCS_DONE 0x000002
  134. #define INIT_FUNCS_CALLED 0x000004
  135. #define FINI_FUNCS_CALLED 0x000008
  136. #define DL_OPENED 0x000010
  137. #define DL_RESERVED 0x000020
  138. extern struct dyn_elf * _dl_symbol_tables;
  139. extern struct elf_resolve * _dl_loaded_modules;
  140. extern struct dyn_elf * _dl_handles;
  141. extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname,
  142. DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info,
  143. unsigned long dynamic_addr, unsigned long dynamic_size);
  144. extern char *_dl_find_hash(const char *name, struct r_scope_elem *scope,
  145. struct elf_resolve *mytpnt, int type_class,
  146. struct symbol_ref *symbol);
  147. extern char * _dl_library_path;
  148. #define LD_ERROR_NOFILE 1
  149. #define LD_ERROR_NOZERO 2
  150. #define LD_ERROR_NOTELF 3
  151. #define LD_ERROR_NOTMAGIC 4
  152. #define LD_ERROR_NOTDYN 5
  153. #define LD_ERROR_MMAP_FAILED 6
  154. #define LD_ERROR_NODYNAMIC 7
  155. #define LD_ERROR_TLS_FAILED 8
  156. #define LD_WRONG_RELOCS 9
  157. #define LD_BAD_HANDLE 10
  158. #define LD_NO_SYMBOL 11
  159. #endif /* _DL_HASH_H */