link.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* Data structure for communication from the run-time dynamic linker for
  2. loaded ELF shared objects.
  3. Copyright (C) 1995-2001, 2004, 2005, 2006, 2010 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 Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the 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. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef _LINK_H
  17. #define _LINK_H 1
  18. #include <features.h>
  19. #include <elf.h>
  20. #ifdef __HAVE_SHARED__
  21. #include <dlfcn.h>
  22. #endif
  23. #include <sys/types.h>
  24. #if defined _LIBC && defined __UCLIBC_HAS_TLS__
  25. #include <tls.h>
  26. #endif
  27. /* We use this macro to refer to ELF types independent of the native wordsize.
  28. `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
  29. #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
  30. #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
  31. #define _ElfW_1(e,w,t) e##w##t
  32. #include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
  33. /* Rendezvous structure used by the run-time dynamic linker to communicate
  34. details of shared object loading to the debugger. If the executable's
  35. dynamic section has a DT_DEBUG element, the run-time linker sets that
  36. element's value to the address where this structure can be found. */
  37. struct r_debug
  38. {
  39. int r_version; /* Version number for this protocol. */
  40. struct link_map *r_map; /* Head of the chain of loaded objects. */
  41. /* This is the address of a function internal to the run-time linker,
  42. that will always be called when the linker begins to map in a
  43. library or unmap it, and again when the mapping change is complete.
  44. The debugger can set a breakpoint at this address if it wants to
  45. notice shared object mapping changes. */
  46. ElfW(Addr) r_brk;
  47. enum
  48. {
  49. /* This state value describes the mapping change taking place when
  50. the `r_brk' address is called. */
  51. RT_CONSISTENT, /* Mapping change is complete. */
  52. RT_ADD, /* Beginning to add a new object. */
  53. RT_DELETE /* Beginning to remove an object mapping. */
  54. } r_state;
  55. ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
  56. };
  57. /* This is the instance of that structure used by the dynamic linker. */
  58. extern struct r_debug _r_debug;
  59. /* This symbol refers to the "dynamic structure" in the `.dynamic' section
  60. of whatever module refers to `_DYNAMIC'. So, to find its own
  61. `struct r_debug', a program could do:
  62. for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
  63. if (dyn->d_tag == DT_DEBUG)
  64. r_debug = (struct r_debug *) dyn->d_un.d_ptr;
  65. */
  66. extern ElfW(Dyn) _DYNAMIC[];
  67. #if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__)
  68. # include <bits/elf-fdpic.h>
  69. #endif
  70. #ifdef __DSBT__
  71. # include <bits/elf-dsbt.h>
  72. #endif
  73. /* Structure describing a loaded shared object. The `l_next' and `l_prev'
  74. members form a chain of all the shared objects loaded at startup.
  75. These data structures exist in space used by the run-time dynamic linker;
  76. modifying them may have disastrous results. */
  77. struct link_map
  78. {
  79. /* These first few members are part of the protocol with the debugger.
  80. This is the same format used in SVR4. */
  81. #if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__)
  82. struct elf32_fdpic_loadaddr l_addr;
  83. #else
  84. #ifdef __DSBT__
  85. struct elf32_dsbt_loadaddr l_addr;
  86. #else
  87. ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
  88. #endif
  89. #endif
  90. char *l_name; /* Absolute file name object was found in. */
  91. ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
  92. struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
  93. #ifdef _LIBC
  94. #if defined(USE_TLS) && USE_TLS
  95. /* Thread-local storage related info. */
  96. /* Start of the initialization image. */
  97. void *l_tls_initimage;
  98. /* Size of the initialization image. */
  99. size_t l_tls_initimage_size;
  100. /* Size of the TLS block. */
  101. size_t l_tls_blocksize;
  102. /* Alignment requirement of the TLS block. */
  103. size_t l_tls_align;
  104. /* Offset of first byte module alignment. */
  105. size_t l_tls_firstbyte_offset;
  106. # ifndef NO_TLS_OFFSET
  107. # define NO_TLS_OFFSET 0
  108. # endif
  109. /* For objects present at startup time: offset in the static TLS block. */
  110. ptrdiff_t l_tls_offset;
  111. /* Index of the module in the dtv array. */
  112. size_t l_tls_modid;
  113. /* Nonzero if _dl_init_static_tls should be called for this module */
  114. unsigned int l_need_tls_init:1;
  115. /* Address of TLS descriptor hash table. */
  116. void *l_tlsdesc_table;
  117. #endif
  118. #endif
  119. };
  120. #ifdef __USE_GNU
  121. #if 0
  122. /* Version numbers for la_version handshake interface. */
  123. #define LAV_CURRENT 1
  124. /* Activity types signaled through la_activity. */
  125. enum
  126. {
  127. LA_ACT_CONSISTENT, /* Link map consistent again. */
  128. LA_ACT_ADD, /* New object will be added. */
  129. LA_ACT_DELETE /* Objects will be removed. */
  130. };
  131. /* Values representing origin of name for dynamic loading. */
  132. enum
  133. {
  134. LA_SER_ORIG = 0x01, /* Original name. */
  135. LA_SER_LIBPATH = 0x02, /* Directory from LD_LIBRARY_PATH. */
  136. LA_SER_RUNPATH = 0x04, /* Directory from RPATH/RUNPATH. */
  137. LA_SER_CONFIG = 0x08, /* Found through ldconfig. */
  138. LA_SER_DEFAULT = 0x40, /* Default directory. */
  139. LA_SER_SECURE = 0x80 /* Unused. */
  140. };
  141. /* Values for la_objopen return value. */
  142. enum
  143. {
  144. LA_FLG_BINDTO = 0x01, /* Audit symbols bound to this object. */
  145. LA_FLG_BINDFROM = 0x02 /* Audit symbols bound from this object. */
  146. };
  147. /* Values for la_symbind flags parameter. */
  148. enum
  149. {
  150. LA_SYMB_NOPLTENTER = 0x01, /* la_pltenter will not be called. */
  151. LA_SYMB_NOPLTEXIT = 0x02, /* la_pltexit will not be called. */
  152. LA_SYMB_STRUCTCALL = 0x04, /* Return value is a structure. */
  153. LA_SYMB_DLSYM = 0x08, /* Binding due to dlsym call. */
  154. LA_SYMB_ALTVALUE = 0x10 /* Value has been changed by a previous
  155. la_symbind call. */
  156. };
  157. #endif
  158. struct dl_phdr_info
  159. {
  160. #if defined(__FRV_FDPIC__) || defined(__BFIN_FDPIC__) || defined(__FDPIC__)
  161. struct elf32_fdpic_loadaddr dlpi_addr;
  162. #else
  163. #ifdef __DSBT__
  164. struct elf32_dsbt_loadaddr dlpi_addr;
  165. #else
  166. ElfW(Addr) dlpi_addr;
  167. #endif
  168. #endif
  169. const char *dlpi_name;
  170. const ElfW(Phdr) *dlpi_phdr;
  171. ElfW(Half) dlpi_phnum;
  172. #if 0
  173. /* Note: Following members were introduced after the first
  174. version of this structure was available. Check the SIZE
  175. argument passed to the dl_iterate_phdr callback to determine
  176. whether or not each later member is available. */
  177. /* Incremented when a new object may have been added. */
  178. unsigned long long int dlpi_adds;
  179. /* Incremented when an object may have been removed. */
  180. unsigned long long int dlpi_subs;
  181. /* If there is a PT_TLS segment, its module ID as used in
  182. TLS relocations, else zero. */
  183. size_t dlpi_tls_modid;
  184. /* The address of the calling thread's instance of this module's
  185. PT_TLS segment, if it has one and it has been allocated
  186. in the calling thread, otherwise a null pointer. */
  187. void *dlpi_tls_data;
  188. #endif
  189. };
  190. __BEGIN_DECLS
  191. extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *,
  192. size_t, void *),
  193. void *__data);
  194. #if 0
  195. /* Prototypes for the ld.so auditing interfaces. These are not
  196. defined anywhere in ld.so but instead have to be provided by the
  197. auditing DSO. */
  198. extern unsigned int la_version (unsigned int __version);
  199. extern void la_activity (uintptr_t *__cookie, unsigned int __flag);
  200. extern char *la_objsearch (const char *__name, uintptr_t *__cookie,
  201. unsigned int __flag);
  202. extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
  203. uintptr_t *__cookie);
  204. extern void la_preinit (uintptr_t *__cookie);
  205. extern uintptr_t la_symbind32 (Elf32_Sym *__sym, unsigned int __ndx,
  206. uintptr_t *__refcook, uintptr_t *__defcook,
  207. unsigned int *__flags, const char *__symname);
  208. extern uintptr_t la_symbind64 (Elf64_Sym *__sym, unsigned int __ndx,
  209. uintptr_t *__refcook, uintptr_t *__defcook,
  210. unsigned int *__flags, const char *__symname);
  211. extern unsigned int la_objclose (uintptr_t *__cookie);
  212. #endif
  213. __END_DECLS
  214. #endif
  215. #endif /* link.h */