link.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* Data structure for communication from the run-time dynamic linker for
  2. loaded ELF shared objects.
  3. Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. Boston, MA 02111-1307, USA. */
  17. #ifndef _LINK_H
  18. #define _LINK_H 1
  19. #include <features.h>
  20. #include <elf.h>
  21. #include <dlfcn.h>
  22. #include <sys/types.h>
  23. /* We use this macro to refer to ELF types independent of the native wordsize.
  24. `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
  25. #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
  26. #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
  27. #define _ElfW_1(e,w,t) e##w##t
  28. #include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
  29. /* Rendezvous structure used by the run-time dynamic linker to communicate
  30. details of shared object loading to the debugger. If the executable's
  31. dynamic section has a DT_DEBUG element, the run-time linker sets that
  32. element's value to the address where this structure can be found. */
  33. struct r_debug
  34. {
  35. int r_version; /* Version number for this protocol. */
  36. struct link_map *r_map; /* Head of the chain of loaded objects. */
  37. /* This is the address of a function internal to the run-time linker,
  38. that will always be called when the linker begins to map in a
  39. library or unmap it, and again when the mapping change is complete.
  40. The debugger can set a breakpoint at this address if it wants to
  41. notice shared object mapping changes. */
  42. ElfW(Addr) r_brk;
  43. enum
  44. {
  45. /* This state value describes the mapping change taking place when
  46. the `r_brk' address is called. */
  47. RT_CONSISTENT, /* Mapping change is complete. */
  48. RT_ADD, /* Beginning to add a new object. */
  49. RT_DELETE /* Beginning to remove an object mapping. */
  50. } r_state;
  51. ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
  52. };
  53. /* This is the instance of that structure used by the dynamic linker. */
  54. extern struct r_debug _r_debug;
  55. /* This symbol refers to the "dynamic structure" in the `.dynamic' section
  56. of whatever module refers to `_DYNAMIC'. So, to find its own
  57. `struct r_debug', a program could do:
  58. for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
  59. if (dyn->d_tag == DT_DEBUG)
  60. r_debug = (struct r_debug *) dyn->d_un.d_ptr;
  61. */
  62. extern ElfW(Dyn) _DYNAMIC[];
  63. /* Some internal data structures of the dynamic linker used in the
  64. linker map. We only provide forward declarations. */
  65. struct libname_list;
  66. struct r_found_version;
  67. struct r_search_path_elem;
  68. /* Forward declaration. */
  69. struct link_map;
  70. /* Structure to describe a single list of scope elements. The lookup
  71. functions get passed an array of pointers to such structures. */
  72. struct r_scope_elem
  73. {
  74. /* Array of maps for the scope. */
  75. struct link_map **r_list;
  76. /* Number of entries in the scope. */
  77. unsigned int r_nlist;
  78. /* Array of maps which also includes duplicates. */
  79. struct link_map **r_duplist;
  80. /* Number of elements in this list. */
  81. unsigned int r_nduplist;
  82. };
  83. /* Structure describing a loaded shared object. The `l_next' and `l_prev'
  84. members form a chain of all the shared objects loaded at startup.
  85. These data structures exist in space used by the run-time dynamic linker;
  86. modifying them may have disastrous results.
  87. This data structure might change in future, if necessary. User-level
  88. programs must avoid defining objects of this type. */
  89. struct link_map
  90. {
  91. /* These first few members are part of the protocol with the debugger.
  92. This is the same format used in SVR4. */
  93. ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
  94. char *l_name; /* Absolute file name object was found in. */
  95. ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
  96. struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
  97. /* All following members are internal to the dynamic linker.
  98. They may change without notice. */
  99. struct libname_list *l_libname;
  100. /* Indexed pointers to dynamic section.
  101. [0,DT_NUM) are indexed by the processor-independent tags.
  102. [DT_NUM,DT_NUM+DT_PROCNUM) are indexed by the tag minus DT_LOPROC.
  103. [DT_NUM+DT_PROCNUM,DT_NUM+DT_PROCNUM+DT_EXTRANUM) are indexed
  104. by DT_EXTRATAGIDX(tagvalue) and
  105. [DT_NUM+DT_PROCNUM+DT_VERSIONTAGNUM,
  106. DT_NUM+DT_PROCNUM+DT_VERSIONTAGNUM+DT_EXTRANUM)
  107. are indexed by DT_EXTRATAGIDX(tagvalue) (see <elf.h>). */
  108. ElfW(Dyn) *l_info[DT_NUM + DT_PROCNUM + DT_VERSIONTAGNUM + DT_EXTRANUM];
  109. const ElfW(Phdr) *l_phdr; /* Pointer to program header table in core. */
  110. ElfW(Addr) l_entry; /* Entry point location. */
  111. ElfW(Half) l_phnum; /* Number of program header entries. */
  112. /* Array of DT_NEEDED dependencies and their dependencies, in
  113. dependency order for symbol lookup (with and without
  114. duplicates). There is no entry before the dependencies have
  115. been loaded. */
  116. struct r_scope_elem l_searchlist;
  117. /* We need a special searchlist to process objects marked with
  118. DT_SYMBOLIC. */
  119. struct r_scope_elem l_symbolic_searchlist;
  120. /* Dependent object that first caused this object to be loaded. */
  121. struct link_map *l_loader;
  122. /* Symbol hash table. */
  123. ElfW(Symndx) l_nbuckets;
  124. const ElfW(Symndx) *l_buckets, *l_chain;
  125. unsigned int l_opencount; /* Reference count for dlopen/dlclose. */
  126. enum /* Where this object came from. */
  127. {
  128. lt_executable, /* The main executable program. */
  129. lt_library, /* Library needed by main executable. */
  130. lt_loaded /* Extra run-time loaded shared object. */
  131. } l_type:2;
  132. unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
  133. unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
  134. unsigned int l_init_running:1; /* Nonzero while DT_INIT function runs. */
  135. unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */
  136. unsigned int l_reserved:2; /* Reserved for internal use. */
  137. /* Array with version names. */
  138. unsigned int l_nversions;
  139. struct r_found_version *l_versions;
  140. /* Collected information about own RPATH directories. */
  141. struct r_search_path_elem **l_rpath_dirs;
  142. /* Collected results of relocation while profiling. */
  143. ElfW(Addr) *l_reloc_result;
  144. /* Pointer to the version information if available. */
  145. ElfW(Half) *l_versyms;
  146. /* String specifying the path where this object was found. */
  147. const char *l_origin;
  148. /* Start and finish of memory map for this object. l_map_start
  149. need not be the same as l_addr. */
  150. ElfW(Addr) l_map_start, l_map_end;
  151. /* This is an array defining the lookup scope for this link map.
  152. There are at most three different scope lists. */
  153. struct r_scope_elem *l_scope[4];
  154. /* A similar array, this time only with the local scope. This is
  155. used occasionally. */
  156. struct r_scope_elem *l_local_scope[2];
  157. /* This information is kept to check for sure whether a shared
  158. object is the same as one already loaded. */
  159. dev_t l_dev;
  160. ino_t l_ino;
  161. /* Nonzero if the data structure pointed to by `l_phdr' is allocated. */
  162. int l_phdr_allocated;
  163. };
  164. #endif /* link.h */