2005-12-27 Roland McGrath <roland@redhat.com>
[glibc.git] / elf / link.h
blobfdda019cbefb04d4c2531b46a0cde54688f11ebe
1 /* Data structure for communication from the run-time dynamic linker for
2 loaded ELF shared objects.
3 Copyright (C) 1995-2001, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _LINK_H
22 #define _LINK_H 1
24 #include <features.h>
25 #include <elf.h>
26 #include <dlfcn.h>
27 #include <sys/types.h>
29 /* We use this macro to refer to ELF types independent of the native wordsize.
30 `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
31 #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type)
32 #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t)
33 #define _ElfW_1(e,w,t) e##w##t
35 #include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
36 #include <bits/link.h>
38 /* Rendezvous structure used by the run-time dynamic linker to communicate
39 details of shared object loading to the debugger. If the executable's
40 dynamic section has a DT_DEBUG element, the run-time linker sets that
41 element's value to the address where this structure can be found. */
43 struct r_debug
45 int r_version; /* Version number for this protocol. */
47 struct link_map *r_map; /* Head of the chain of loaded objects. */
49 /* This is the address of a function internal to the run-time linker,
50 that will always be called when the linker begins to map in a
51 library or unmap it, and again when the mapping change is complete.
52 The debugger can set a breakpoint at this address if it wants to
53 notice shared object mapping changes. */
54 ElfW(Addr) r_brk;
55 enum
57 /* This state value describes the mapping change taking place when
58 the `r_brk' address is called. */
59 RT_CONSISTENT, /* Mapping change is complete. */
60 RT_ADD, /* Beginning to add a new object. */
61 RT_DELETE /* Beginning to remove an object mapping. */
62 } r_state;
64 ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
67 /* This is the instance of that structure used by the dynamic linker. */
68 extern struct r_debug _r_debug;
70 /* This symbol refers to the "dynamic structure" in the `.dynamic' section
71 of whatever module refers to `_DYNAMIC'. So, to find its own
72 `struct r_debug', a program could do:
73 for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; ++dyn)
74 if (dyn->d_tag == DT_DEBUG)
75 r_debug = (struct r_debug *) dyn->d_un.d_ptr;
77 extern ElfW(Dyn) _DYNAMIC[];
79 /* Structure describing a loaded shared object. The `l_next' and `l_prev'
80 members form a chain of all the shared objects loaded at startup.
82 These data structures exist in space used by the run-time dynamic linker;
83 modifying them may have disastrous results. */
85 struct link_map
87 /* These first few members are part of the protocol with the debugger.
88 This is the same format used in SVR4. */
90 ElfW(Addr) l_addr; /* Base address shared object is loaded at. */
91 char *l_name; /* Absolute file name object was found in. */
92 ElfW(Dyn) *l_ld; /* Dynamic section of the shared object. */
93 struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
96 #ifdef __USE_GNU
98 /* Version numbers for la_version handshake interface. */
99 #define LAV_CURRENT 1
101 /* Activity types signaled through la_activity. */
102 enum
104 LA_ACT_CONSISTENT, /* Link map consistent again. */
105 LA_ACT_ADD, /* New object will be added. */
106 LA_ACT_DELETE /* Objects will be removed. */
109 /* Values representing origin of name for dynamic loading. */
110 enum
112 LA_SER_ORIG = 0x01, /* Original name. */
113 LA_SER_LIBPATH = 0x02, /* Directory from LD_LIBRARY_PATH. */
114 LA_SER_RUNPATH = 0x04, /* Directory from RPATH/RUNPATH. */
115 LA_SER_CONFIG = 0x08, /* Found through ldconfig. */
116 LA_SER_DEFAULT = 0x40, /* Default directory. */
117 LA_SER_SECURE = 0x80 /* Unused. */
120 /* Values for la_objopen return value. */
121 enum
123 LA_FLG_BINDTO = 0x01, /* Audit symbols bound to this object. */
124 LA_FLG_BINDFROM = 0x02 /* Audit symbols bound from this object. */
127 /* Values for la_symbind flags parameter. */
128 enum
130 LA_SYMB_NOPLTENTER = 0x01, /* la_pltenter will not be called. */
131 LA_SYMB_NOPLTEXIT = 0x02, /* la_pltexit will not be called. */
132 LA_SYMB_STRUCTCALL = 0x04, /* Return value is a structure. */
133 LA_SYMB_DLSYM = 0x08, /* Binding due to dlsym call. */
134 LA_SYMB_ALTVALUE = 0x10 /* Value has been changed by a previous
135 la_symbind call. */
139 struct dl_phdr_info
141 ElfW(Addr) dlpi_addr;
142 const char *dlpi_name;
143 const ElfW(Phdr) *dlpi_phdr;
144 ElfW(Half) dlpi_phnum;
146 /* Note: the next two members were introduced after the first
147 version of this structure was available. Check the SIZE
148 argument passed to the dl_iterate_phdr() callback to determine
149 whether or not they are provided. */
151 /* Incremented when a new object may have been added. */
152 unsigned long long int dlpi_adds;
153 /* Incremented when an object may have been removed. */
154 unsigned long long int dlpi_subs;
157 __BEGIN_DECLS
159 extern int dl_iterate_phdr (int (*__callback) (struct dl_phdr_info *,
160 size_t, void *),
161 void *__data);
164 /* Prototypes for the ld.so auditing interfaces. These are not
165 defined anywhere in ld.so but instead have to be provided by the
166 auditing DSO. */
167 extern unsigned int la_version (unsigned int __version);
168 extern void la_activity (uintptr_t *__cookie, unsigned int __flag);
169 extern char *la_objsearch (const char *__name, uintptr_t *__cookie,
170 unsigned int __flag);
171 extern unsigned int la_objopen (struct link_map *__map, Lmid_t __lmid,
172 uintptr_t *__cookie);
173 extern void la_preinit (uintptr_t *__cookie);
174 extern uintptr_t la_symbind32 (Elf32_Sym *__sym, unsigned int __ndx,
175 uintptr_t *__refcook, uintptr_t *__defcook,
176 unsigned int *__flags, const char *__symname);
177 extern uintptr_t la_symbind64 (Elf64_Sym *__sym, unsigned int __ndx,
178 uintptr_t *__refcook, uintptr_t *__defcook,
179 unsigned int *__flags, const char *__symname);
180 extern unsigned int la_objclose (uintptr_t *__cookie);
182 __END_DECLS
184 #endif
186 #endif /* link.h */