dl-hash.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. ElfW(Addr) mapaddr; /* Address at which ELF segments (either main app and DSO) are mapped into */
  33. enum {elf_lib, elf_executable,program_interpreter, loaded_file} libtype;
  34. struct dyn_elf * symbol_scope;
  35. unsigned short usage_count;
  36. unsigned short int init_flag;
  37. unsigned long rtld_flags; /* RTLD_GLOBAL, RTLD_NOW etc. */
  38. Elf_Symndx nbucket;
  39. #ifdef __LDSO_GNU_HASH_SUPPORT__
  40. /* Data needed to support GNU hash style */
  41. Elf32_Word l_gnu_bitmask_idxbits;
  42. Elf32_Word l_gnu_shift;
  43. const ElfW(Addr) *l_gnu_bitmask;
  44. union
  45. {
  46. const Elf32_Word *l_gnu_chain_zero;
  47. const Elf_Symndx *elf_buckets;
  48. };
  49. #else
  50. Elf_Symndx *elf_buckets;
  51. #endif
  52. struct init_fini_list *init_fini;
  53. struct init_fini_list *rtld_local; /* keep tack of RTLD_LOCAL libs in same group */
  54. /*
  55. * These are only used with ELF style shared libraries
  56. */
  57. Elf_Symndx nchain;
  58. #ifdef __LDSO_GNU_HASH_SUPPORT__
  59. union
  60. {
  61. const Elf32_Word *l_gnu_buckets;
  62. const Elf_Symndx *chains;
  63. };
  64. #else
  65. Elf_Symndx *chains;
  66. #endif
  67. unsigned long dynamic_info[DYNAMIC_SIZE];
  68. unsigned long n_phent;
  69. ElfW(Phdr) * ppnt;
  70. ElfW(Addr) relro_addr;
  71. size_t relro_size;
  72. dev_t st_dev; /* device */
  73. ino_t st_ino; /* inode */
  74. #ifdef __powerpc__
  75. /* this is used to store the address of relocation data words, so
  76. * we don't have to calculate it every time, which requires a divide */
  77. unsigned long data_words;
  78. #endif
  79. #ifdef __FDPIC__
  80. /* Every loaded module holds a hashtable of function descriptors of
  81. functions defined in it, such that it's easy to release the
  82. memory when the module is dlclose()d. */
  83. struct funcdesc_ht *funcdesc_ht;
  84. #endif
  85. };
  86. #define RELOCS_DONE 0x000001
  87. #define JMP_RELOCS_DONE 0x000002
  88. #define INIT_FUNCS_CALLED 0x000004
  89. #define FINI_FUNCS_CALLED 0x000008
  90. #define DL_OPENED 0x000010
  91. extern struct dyn_elf * _dl_symbol_tables;
  92. extern struct elf_resolve * _dl_loaded_modules;
  93. extern struct dyn_elf * _dl_handles;
  94. extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname,
  95. DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info,
  96. unsigned long dynamic_addr, unsigned long dynamic_size);
  97. extern char * _dl_lookup_hash(const char * name, struct dyn_elf * rpnt,
  98. struct elf_resolve *mytpnt, int type_class
  99. #ifdef __FDPIC__
  100. , struct elf_resolve **tpntp
  101. #endif
  102. );
  103. static __always_inline char *_dl_find_hash(const char *name, struct dyn_elf *rpnt,
  104. struct elf_resolve *mytpnt, int type_class)
  105. {
  106. #ifdef __FDPIC__
  107. return _dl_lookup_hash(name, rpnt, mytpnt, type_class, NULL);
  108. #else
  109. return _dl_lookup_hash(name, rpnt, mytpnt, type_class);
  110. #endif
  111. }
  112. extern int _dl_linux_dynamic_link(void);
  113. extern char * _dl_library_path;
  114. extern char * _dl_not_lazy;
  115. static __inline__ int _dl_symbol(char * name)
  116. {
  117. if (name[0] != '_' || name[1] != 'd' || name[2] != 'l' || name[3] != '_')
  118. return 0;
  119. return 1;
  120. }
  121. #define LD_ERROR_NOFILE 1
  122. #define LD_ERROR_NOZERO 2
  123. #define LD_ERROR_NOTELF 3
  124. #define LD_ERROR_NOTMAGIC 4
  125. #define LD_ERROR_NOTDYN 5
  126. #define LD_ERROR_MMAP_FAILED 6
  127. #define LD_ERROR_NODYNAMIC 7
  128. #define LD_WRONG_RELOCS 8
  129. #define LD_BAD_HANDLE 9
  130. #define LD_NO_SYMBOL 10
  131. #endif /* _LD_HASH_H_ */