link.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* Data structure for communication from the run-time dynamic linker for
  2. loaded ELF shared objects.
  3. Copyright (C) 1995-2020 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. /* 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. /* Structure describing a loaded shared object. The `l_next' and `l_prev'
  64. members form a chain of all the shared objects loaded at startup.
  65. These data structures exist in space used by the run-time dynamic linker;
  66. modifying them may have disastrous results. */
  67. struct link_map
  68. {
  69. /* These first few members are part of the protocol with the debugger.
  70. This is the same format used in SVR4. */
  71. ElfW(Addr) l_addr; /* Difference between the address in the ELF
  72. file and the addresses in memory. */
  73. char *l_name; /* Absolute file name object was found in. */
  74. ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
  75. struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
  76. };
  77. #ifdef __USE_GNU
  78. /* Version numbers for la_version handshake interface. */
  79. #define LAV_CURRENT 1
  80. /* Activity types signaled through la_activity. */
  81. enum
  82. {
  83. LA_ACT_CONSISTENT, /* Link map consistent again. */
  84. LA_ACT_ADD, /* New object will be added. */
  85. LA_ACT_DELETE /* Objects will be removed. */
  86. };
  87. /* Values representing origin of name for dynamic loading. */
  88. enum
  89. {
  90. LA_SER_ORIG = 0x01, /* Original name. */
  91. LA_SER_LIBPATH = 0x02, /* Directory from LD_LIBRARY_PATH. */
  92. LA_SER_RUNPATH = 0x04, /* Directory from RPATH/RUNPATH. */
  93. LA_SER_CONFIG = 0x08, /* Found through ldconfig. */
  94. LA_SER_DEFAULT = 0x40, /* Default directory. */
  95. LA_SER_SECURE = 0x80 /* Unused. */
  96. };
  97. /* Values for la_objopen return value. */
  98. enum
  99. {
  100. LA_FLG_BINDTO = 0x01, /* Audit symbols bound to this object. */
  101. LA_FLG_BINDFROM = 0x02 /* Audit symbols bound from this object. */
  102. };
  103. /* Values for la_symbind flags parameter. */
  104. enum
  105. {
  106. LA_SYMB_NOPLTENTER = 0x01, /* la_pltenter will not be called. */
  107. LA_SYMB_NOPLTEXIT = 0x02, /* la_pltexit will not be called. */
  108. LA_SYMB_STRUCTCALL = 0x04, /* Return value is a structure. */
  109. LA_SYMB_DLSYM = 0x08, /* Binding due to dlsym call. */
  110. LA_SYMB_ALTVALUE = 0x10 /* Value has been changed by a previous
  111. la_symbind call. */
  112. };
  113. struct dl_phdr_info
  114. {
  115. ElfW(Addr) dlpi_addr;
  116. const char *dlpi_name;
  117. const ElfW(Phdr) *dlpi_phdr;
  118. ElfW(Half) dlpi_phnum;
  119. /* Note: Following members were introduced after the first
  120. version of this structure was available. Check the SIZE
  121. argument passed to the dl_iterate_phdr callback to determine
  122. whether or not each later member is available. */
  123. /* Incremented when a new object may have been added. */
  124. __extension__ unsigned long long int dlpi_adds;
  125. /* Incremented when an object may have been removed. */
  126. __extension__ unsigned long long int dlpi_subs;
  127. /* If there is a PT_TLS segment, its module ID as used in
  128. TLS relocations, else zero. */
  129. size_t dlpi_tls_modid;
  130. /* The address of the calling thread's instance of this module's
  131. PT_TLS segment, if it has one and it has been allocated
  132. in the calling thread, otherwise a null pointer. */
  133. void *dlpi_tls_data;
  134. };
  135. __BEGIN_DECLS
  136. extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *,
  137. size_t, void *),
  138. void *__data);
  139. /* Prototypes for the ld.so auditing interfaces. These are not
  140. defined anywhere in ld.so but instead have to be provided by the
  141. auditing DSO. */
  142. extern unsigned int la_version (unsigned int __version);
  143. extern void la_activity (uintptr_t *__cookie, unsigned int __flag);
  144. extern char *la_objsearch (const char *__name, uintptr_t *__cookie,
  145. unsigned int __flag);
  146. extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
  147. uintptr_t *__cookie);
  148. extern void la_preinit (uintptr_t *__cookie);
  149. extern uintptr_t la_symbind32 (Elf32_Sym *__sym, unsigned int __ndx,
  150. uintptr_t *__refcook, uintptr_t *__defcook,
  151. unsigned int *__flags, const char *__symname);
  152. extern uintptr_t la_symbind64 (Elf64_Sym *__sym, unsigned int __ndx,
  153. uintptr_t *__refcook, uintptr_t *__defcook,
  154. unsigned int *__flags, const char *__symname);
  155. extern unsigned int la_objclose (uintptr_t *__cookie);
  156. __END_DECLS
  157. #endif
  158. #endif /* link.h */