link.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Data structure for communication from the run-time dynamic linker for
  2. loaded ELF shared objects.
  3. Copyright (C) 1995-1999, 2000 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 Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. 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. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. Boston, MA 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. #endif /* link.h */