(_hurd_intr_rpc_mach_msg): New declaration.
[glibc.git] / elf / link.h
blobbdcfcf27f494cc90cb9e8b016620b521a35f1f4b
1 /* Run-time dynamic linker data structures for loaded ELF shared objects.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3 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.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #ifndef _LINK_H
21 #define _LINK_H 1
23 #include <elf.h>
26 /* Rendezvous structure used by the run-time dynamic linker to communicate
27 details of shared object loading to the debugger. If the executable's
28 dynamic section has a DT_DEBUG element, the run-time linker sets that
29 element's value to the address where this structure can be found. */
31 struct r_debug
33 int r_version; /* Version number for this protocol. */
35 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 Elf32_Addr r_brk;
43 enum
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;
52 Elf32_Addr r_ldbase; /* Base address the linker is loaded at. */
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)
59 if (dyn->d_tag == DT_DEBUG) r_debug = (struct r_debug) dyn->d_un.d_ptr;
62 extern Elf32_Dyn _DYNAMIC[];
65 /* Structure describing a loaded shared object. The `l_next' and `l_prev'
66 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. */
71 struct link_map
73 /* These first few members are part of the protocol with the debugger.
74 This is the same format used in SVR4. */
76 Elf32_Addr l_addr; /* Base address shared object is loaded at. */
77 char *l_name; /* Absolute file name object was found in. */
78 Elf32_Dyn *l_ld; /* Dynamic section of the shared object. */
79 struct link_map *l_next, *l_prev; /* Chain of loaded objects. */
81 /* All following members are internal to the dynamic linker.
82 They may change without notice. */
84 const char *l_libname; /* Name requested (before search). */
85 /* Indexed pointers to dynamic section.
86 [0,DT_NUM) are indexed by the processor-independent tags.
87 [DT_NUM,DT_NUM+DT_PROCNUM] are indexed by the tag minus DT_LOPROC. */
88 Elf32_Dyn *l_info[DT_NUM + DT_PROCNUM];
89 const Elf32_Phdr *l_phdr; /* Pointer to program header table in core. */
90 Elf32_Word l_phnum; /* Number of program header entries. */
91 Elf32_Addr l_entry; /* Entry point location. */
93 /* Symbol hash table. */
94 Elf32_Word l_nbuckets;
95 const Elf32_Word *l_buckets, *l_chain;
97 unsigned int l_opencount; /* Reference count for dlopen/dlclose. */
98 enum /* Where this object came from. */
100 lt_executable, /* The main executable program. */
101 lt_interpreter, /* The interpreter: the dynamic linker. */
102 lt_library, /* Library needed by main executable. */
103 lt_loaded, /* Extra run-time loaded shared object. */
104 } l_type:2;
105 unsigned int l_deps_loaded:1; /* Nonzero if DT_NEEDED items loaded. */
106 unsigned int l_relocated:1; /* Nonzero if object's relocations done. */
107 unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */
108 unsigned int l_init_running:1; /* Nonzero while DT_INIT function runs. */
111 /* Internal functions of the run-time dynamic linker.
112 These can be accessed if you link again the dynamic linker
113 as a shared library, as in `-lld' or `/lib/ld.so' explicitly;
114 but are not normally of interest to user programs.
116 The `-ldl' library functions in <dlfcn.h> provide a simple
117 user interface to run-time dynamic linking. */
120 /* File descriptor referring to the zero-fill device. */
121 extern int _dl_zerofd;
123 /* OS-dependent function to open the zero-fill device. */
124 extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
126 /* OS-dependent function to write a message on the standard output.
127 All arguments are `const char *'; args until a null pointer
128 are concatenated to form the message to print. */
129 extern void _dl_sysdep_message (const char *string, ...);
131 /* OS-dependent function to give a fatal error message and exit
132 when the dynamic linker fails before the program is fully linked.
133 All arguments are `const char *'; args until a null pointer
134 are concatenated to form the message to print. */
135 extern void _dl_sysdep_fatal (const char *string, ...)
136 __attribute__ ((__noreturn__));
138 /* Nonzero if the program should be "secure" (i.e. it's setuid or somesuch).
139 This tells the dynamic linker to ignore environment variables. */
140 extern int _dl_secure;
142 /* This function is called by all the internal dynamic linker functions
143 when they encounter an error. ERRCODE is either an `errno' code or
144 zero; OBJECT is the name of the problematical shared object, or null if
145 it is a general problem; ERRSTRING is a string describing the specific
146 problem. */
148 extern void _dl_signal_error (int errcode,
149 const char *object,
150 const char *errstring)
151 __attribute__ ((__noreturn__));
153 /* Call OPERATE, catching errors from `dl_signal_error'. If there is no
154 error, *ERRSTRING is set to null. If there is an error, *ERRSTRING and
155 *OBJECT are set to the strings passed to _dl_signal_error, and the error
156 code passed is the return value. */
157 extern int _dl_catch_error (const char **errstring,
158 const char **object,
159 void (*operate) (void));
162 /* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
163 _dl_catch_error. Returns zero for success, nonzero for failure; and
164 arranges for `dlerror' to return the error details. */
165 extern int _dlerror_run (void (*operate) (void));
168 /* Open the shared object NAME and map in its segments.
169 LOADER's DT_RPATH is used in searching for NAME.
170 If the object is already opened, returns its existing map. */
171 extern struct link_map *_dl_map_object (struct link_map *loader,
172 const char *name);
174 /* Similar, but file found at REALNAME and opened on FD.
175 REALNAME must malloc'd storage and is used in internal data structures. */
176 extern struct link_map *_dl_map_object_from_fd (const char *name,
177 int fd, char *realname);
179 /* Cache the locations of MAP's hash table. */
180 extern void _dl_setup_hash (struct link_map *map);
183 /* Search loaded objects' symbol tables for a definition of the symbol
184 referred to by UNDEF. *SYM is the symbol table entry containing the
185 reference; it is replaced with the defining symbol, and the base load
186 address of the defining object is returned. SYMBOL_SCOPE is the head of
187 the chain used for searching. REFERENCE_NAME should name the object
188 containing the reference; it is used in error messages. If NOSELF is
189 nonzero, them *SYM itself cannot define the value; another binding must
190 be found. */
191 extern Elf32_Addr _dl_lookup_symbol (const char *undef,
192 const Elf32_Sym **sym,
193 struct link_map *symbol_scope,
194 const char *reference_name,
195 int noself);
198 /* List of objects currently loaded. */
199 extern struct link_map *_dl_loaded;
201 /* Tail of that list which were loaded at startup. */
202 extern struct link_map *_dl_startup_loaded;
204 /* Allocate a `struct link_map' for a new object being loaded,
205 and enter it into the _dl_loaded list. */
206 extern struct link_map *_dl_new_object (char *realname, const char *libname,
207 int type);
209 /* Relocate the given object (if it hasn't already been).
210 If LAZY is nonzero, don't relocate its PLT. */
211 extern void _dl_relocate_object (struct link_map *map, int lazy);
213 /* Return the address of the next initializer function not yet run.
214 When there are no more initializers to be run, this returns zero.
215 The functions are returned in the order they should be called. */
216 extern Elf32_Addr _dl_init_next (void);
218 /* Call the finalizer functions of all shared objects whose
219 initializer functions have completed. */
220 extern void _dl_fini (void);
222 /* The dynamic linker calls this function before and having changing
223 any shared object mappings. The `r_state' member of `struct r_debug'
224 says what change is taking place. This function's address is
225 the value of the `r_brk' member. */
226 extern void _dl_r_debug_state (void);
229 #endif /* link.h */