link.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* Data structure for communication from the run-time dynamic linker for
  2. loaded ELF shared objects.
  3. Copyright (C) 1995-2026 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. <https://www.gnu.org/licenses/>. */
  16. #ifndef _LINK_H
  17. #define _LINK_H 1
  18. #include <features.h>
  19. #include <elf.h>
  20. #include <dlfcn.h>
  21. #include <sys/types.h>
  22. /* We use this macro to refer to ELF types independent of the native wordsize.
  23. `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
  24. #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
  25. #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
  26. #define _ElfW_1(e,w,t) e##w##t
  27. #include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
  28. #include <bits/link.h>
  29. /* The legacy rendezvous structure used by the run-time dynamic linker to
  30. communicate details of shared object loading to the debugger. */
  31. struct r_debug
  32. {
  33. /* Version number for this protocol. It should be greater than 0. */
  34. int r_version;
  35. struct link_map *r_map; /* Head of the chain of loaded objects. */
  36. /* This is the address of a function internal to the run-time linker,
  37. that will always be called when the linker begins to map in a
  38. library or unmap it, and again when the mapping change is complete.
  39. The debugger can set a breakpoint at this address if it wants to
  40. notice shared object mapping changes. */
  41. ElfW(Addr) r_brk;
  42. enum
  43. {
  44. /* This state value describes the mapping change taking place when
  45. the `r_brk' address is called. */
  46. RT_CONSISTENT, /* Mapping change is complete. */
  47. RT_ADD, /* Beginning to add a new object. */
  48. RT_DELETE /* Beginning to remove an object mapping. */
  49. } r_state;
  50. ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
  51. };
  52. /* This is the symbol of that structure provided by the dynamic linker. */
  53. extern struct r_debug _r_debug;
  54. /* The extended rendezvous structure used by the run-time dynamic linker
  55. to communicate details of shared object loading to the debugger. If
  56. the executable's dynamic section has a DT_DEBUG element, the run-time
  57. linker sets that element's value to the address where this structure
  58. can be found. */
  59. struct r_debug_extended
  60. {
  61. struct r_debug base;
  62. /* The following field is added by r_version == 2. */
  63. /* Link to the next r_debug_extended structure. Each r_debug_extended
  64. structure represents a different namespace. The first
  65. r_debug_extended structure is for the default namespace. */
  66. struct r_debug_extended *r_next;
  67. };
  68. /* This symbol refers to the "dynamic structure" in the `.dynamic' section
  69. of whatever module refers to `_DYNAMIC'. So, to find its own
  70. `struct r_debug_extended', a program could do:
  71. for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
  72. if (dyn->d_tag == DT_DEBUG)
  73. r_debug_extended = (struct r_debug_extended *) dyn->d_un.d_ptr;
  74. */
  75. extern ElfW(Dyn) _DYNAMIC[];
  76. /* Structure describing a loaded shared object. The `l_next' and `l_prev'
  77. members form a chain of all the shared objects loaded at startup.
  78. These data structures exist in space used by the run-time dynamic linker;
  79. modifying them may have disastrous results. */
  80. struct link_map
  81. {
  82. /* These first few members are part of the protocol with the debugger.
  83. This is the same format used in SVR4. */
  84. ElfW(Addr) l_addr; /* Difference between the address in the ELF
  85. file and the addresses in memory. */
  86. char *l_name; /* Absolute file name object was found in. */
  87. ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
  88. struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
  89. };
  90. #ifdef __USE_GNU
  91. /* Version numbers for la_version handshake interface. */
  92. #include <bits/link_lavcurrent.h>
  93. /* Activity types signaled through la_activity. */
  94. enum
  95. {
  96. LA_ACT_CONSISTENT, /* Link map consistent again. */
  97. LA_ACT_ADD, /* New object will be added. */
  98. LA_ACT_DELETE /* Objects will be removed. */
  99. };
  100. /* Values representing origin of name for dynamic loading. */
  101. enum
  102. {
  103. LA_SER_ORIG = 0x01, /* Original name. */
  104. LA_SER_LIBPATH = 0x02, /* Directory from LD_LIBRARY_PATH. */
  105. LA_SER_RUNPATH = 0x04, /* Directory from RPATH/RUNPATH. */
  106. LA_SER_CONFIG = 0x08, /* Found through ldconfig. */
  107. LA_SER_DEFAULT = 0x40, /* Default directory. */
  108. LA_SER_SECURE = 0x80 /* Unused. */
  109. };
  110. /* Values for la_objopen return value. */
  111. enum
  112. {
  113. LA_FLG_BINDTO = 0x01, /* Audit symbols bound to this object. */
  114. LA_FLG_BINDFROM = 0x02 /* Audit symbols bound from this object. */
  115. };
  116. /* Values for la_symbind flags parameter. */
  117. enum
  118. {
  119. LA_SYMB_NOPLTENTER = 0x01, /* la_pltenter will not be called. */
  120. LA_SYMB_NOPLTEXIT = 0x02, /* la_pltexit will not be called. */
  121. LA_SYMB_STRUCTCALL = 0x04, /* Return value is a structure. */
  122. LA_SYMB_DLSYM = 0x08, /* Binding due to dlsym call. */
  123. LA_SYMB_ALTVALUE = 0x10 /* Value has been changed by a previous
  124. la_symbind call. */
  125. };
  126. struct dl_phdr_info
  127. {
  128. ElfW(Addr) dlpi_addr;
  129. const char *dlpi_name;
  130. const ElfW(Phdr) *dlpi_phdr;
  131. ElfW(Half) dlpi_phnum;
  132. /* Note: Following members were introduced after the first
  133. version of this structure was available. Check the SIZE
  134. argument passed to the dl_iterate_phdr callback to determine
  135. whether or not each later member is available. */
  136. /* Incremented when a new object may have been added. */
  137. __extension__ unsigned long long int dlpi_adds;
  138. /* Incremented when an object may have been removed. */
  139. __extension__ unsigned long long int dlpi_subs;
  140. /* If there is a PT_TLS segment, its module ID as used in
  141. TLS relocations, else zero. */
  142. size_t dlpi_tls_modid;
  143. /* The address of the calling thread's instance of this module's
  144. PT_TLS segment, if it has one and it has been allocated
  145. in the calling thread, otherwise a null pointer. */
  146. void *dlpi_tls_data;
  147. };
  148. __BEGIN_DECLS
  149. extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *,
  150. size_t, void *),
  151. void *__data);
  152. /* Prototypes for the ld.so auditing interfaces. These are not
  153. defined anywhere in ld.so but instead have to be provided by the
  154. auditing DSO. */
  155. extern unsigned int la_version (unsigned int __version);
  156. extern void la_activity (uintptr_t *__cookie, unsigned int __flag);
  157. extern char *la_objsearch (const char *__name, uintptr_t *__cookie,
  158. unsigned int __flag);
  159. extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
  160. uintptr_t *__cookie);
  161. extern void la_preinit (uintptr_t *__cookie);
  162. extern uintptr_t la_symbind32 (Elf32_Sym *__sym, unsigned int __ndx,
  163. uintptr_t *__refcook, uintptr_t *__defcook,
  164. unsigned int *__flags, const char *__symname);
  165. extern uintptr_t la_symbind64 (Elf64_Sym *__sym, unsigned int __ndx,
  166. uintptr_t *__refcook, uintptr_t *__defcook,
  167. unsigned int *__flags, const char *__symname);
  168. extern unsigned int la_objclose (uintptr_t *__cookie);
  169. __END_DECLS
  170. #endif
  171. #endif /* link.h */