link.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Data structure for communication from the run-time dynamic linker for
  2. loaded ELF shared objects.
  3. Copyright (C) 1995-1999, 2000, 2001, 2004 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, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 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. #if defined _LIBC && defined __UCLIBC_HAS_THREADS_NATIVE__
  24. #include <tls.h>
  25. #endif
  26. /* We use this macro to refer to ELF types independent of the native wordsize.
  27. `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
  28. #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
  29. #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
  30. #define _ElfW_1(e,w,t) e##w##t
  31. #include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
  32. /* Rendezvous structure used by the run-time dynamic linker to communicate
  33. details of shared object loading to the debugger. If the executable's
  34. dynamic section has a DT_DEBUG element, the run-time linker sets that
  35. element's value to the address where this structure can be found. */
  36. struct r_debug
  37. {
  38. int r_version; /* Version number for this protocol. */
  39. struct link_map *r_map; /* Head of the chain of loaded objects. */
  40. /* This is the address of a function internal to the run-time linker,
  41. that will always be called when the linker begins to map in a
  42. library or unmap it, and again when the mapping change is complete.
  43. The debugger can set a breakpoint at this address if it wants to
  44. notice shared object mapping changes. */
  45. ElfW(Addr) r_brk;
  46. enum
  47. {
  48. /* This state value describes the mapping change taking place when
  49. the `r_brk' address is called. */
  50. RT_CONSISTENT, /* Mapping change is complete. */
  51. RT_ADD, /* Beginning to add a new object. */
  52. RT_DELETE /* Beginning to remove an object mapping. */
  53. } r_state;
  54. ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
  55. };
  56. /* This is the instance of that structure used by the dynamic linker. */
  57. extern struct r_debug _r_debug;
  58. /* This symbol refers to the "dynamic structure" in the `.dynamic' section
  59. of whatever module refers to `_DYNAMIC'. So, to find its own
  60. `struct r_debug', a program could do:
  61. for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
  62. if (dyn->d_tag == DT_DEBUG)
  63. r_debug = (struct r_debug *) dyn->d_un.d_ptr;
  64. */
  65. extern ElfW(Dyn) _DYNAMIC[];
  66. /* Structure describing a loaded shared object. The `l_next' and `l_prev'
  67. members form a chain of all the shared objects loaded at startup.
  68. These data structures exist in space used by the run-time dynamic linker;
  69. modifying them may have disastrous results. */
  70. struct link_map
  71. {
  72. /* These first few members are part of the protocol with the debugger.
  73. This is the same format used in SVR4. */
  74. ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
  75. char *l_name; /* Absolute file name object was found in. */
  76. ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
  77. struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
  78. #ifdef USE_TLS
  79. /* Thread-local storage related info. */
  80. /* Start of the initialization image. */
  81. void *l_tls_initimage;
  82. /* Size of the initialization image. */
  83. size_t l_tls_initimage_size;
  84. /* Size of the TLS block. */
  85. size_t l_tls_blocksize;
  86. /* Alignment requirement of the TLS block. */
  87. size_t l_tls_align;
  88. /* Offset of first byte module alignment. */
  89. size_t l_tls_firstbyte_offset;
  90. # ifndef NO_TLS_OFFSET
  91. # define NO_TLS_OFFSET 0
  92. # endif
  93. /* For objects present at startup time: offset in the static TLS block. */
  94. ptrdiff_t l_tls_offset;
  95. /* Index of the module in the dtv array. */
  96. size_t l_tls_modid;
  97. /* Nonzero if _dl_init_static_tls should be called for this module */
  98. unsigned int l_need_tls_init:1;
  99. #endif
  100. };
  101. #ifdef __USE_GNU
  102. struct dl_phdr_info
  103. {
  104. ElfW(Addr) dlpi_addr;
  105. const char *dlpi_name;
  106. const ElfW(Phdr) *dlpi_phdr;
  107. ElfW(Half) dlpi_phnum;
  108. #if 0
  109. /* Note: the next two members were introduced after the first
  110. version of this structure was available. Check the SIZE
  111. argument passed to the dl_iterate_phdr() callback to determine
  112. whether or not they are provided. */
  113. /* Incremented when a new object may have been added. */
  114. unsigned long long int dlpi_adds;
  115. /* Incremented when an object may have been removed. */
  116. unsigned long long int dlpi_subs;
  117. #endif
  118. };
  119. __BEGIN_DECLS
  120. extern int dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
  121. size_t size, void *data),
  122. void *data);
  123. __END_DECLS
  124. #endif
  125. #endif /* link.h */