dl-hash.h 5.1 KB

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