link.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Data structure for communication from the run-time dynamic linker for
  2. loaded ELF shared objects.
  3. Copyright (C) 1995-1999, 2000, 2001 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. /* 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. /* 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; /* Base address shared object is loaded at. */
  72. char *l_name; /* Absolute file name object was found in. */
  73. ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
  74. struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
  75. };
  76. #ifdef __USE_GNU
  77. struct dl_phdr_info
  78. {
  79. ElfW(Addr) dlpi_addr;
  80. const char *dlpi_name;
  81. const ElfW(Phdr) *dlpi_phdr;
  82. ElfW(Half) dlpi_phnum;
  83. };
  84. __BEGIN_DECLS
  85. extern int dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info,
  86. size_t size, void *data),
  87. void *data) __THROW;
  88. __END_DECLS
  89. #endif
  90. #endif /* link.h */