link.h revision 1.3 1 1.1 pk /*
2 1.3 pk * Copyright (c) 1993 Paul Kranenburg
3 1.3 pk * All rights reserved.
4 1.3 pk *
5 1.3 pk * Redistribution and use in source and binary forms, with or without
6 1.3 pk * modification, are permitted provided that the following conditions
7 1.3 pk * are met:
8 1.3 pk * 1. Redistributions of source code must retain the above copyright
9 1.3 pk * notice, this list of conditions and the following disclaimer.
10 1.3 pk * 2. Redistributions in binary form must reproduce the above copyright
11 1.3 pk * notice, this list of conditions and the following disclaimer in the
12 1.3 pk * documentation and/or other materials provided with the distribution.
13 1.3 pk * 3. All advertising materials mentioning features or use of this software
14 1.3 pk * must display the following acknowledgement:
15 1.3 pk * This product includes software developed by Paul Kranenburg.
16 1.3 pk * 4. The name of the author may not be used to endorse or promote products
17 1.3 pk * derived from this software withough specific prior written permission
18 1.3 pk *
19 1.3 pk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 1.3 pk * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 1.3 pk * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.3 pk * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.3 pk * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 1.3 pk * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 1.3 pk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 1.3 pk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.3 pk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 1.3 pk * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.3 pk *
30 1.3 pk * $Id: link.h,v 1.3 1994/01/28 20:26:52 pk Exp $
31 1.3 pk */
32 1.3 pk
33 1.3 pk /*
34 1.1 pk * RRS section definitions.
35 1.1 pk *
36 1.3 pk * The layout of some data structures defined in this header file is
37 1.3 pk * such that we can provide compatibility with the SunOS 4.x shared
38 1.3 pk * library scheme.
39 1.1 pk */
40 1.1 pk
41 1.1 pk #ifndef _LINK_H_
42 1.1 pk #define _LINK_H_
43 1.1 pk
44 1.1 pk /*
45 1.3 pk * A `Shared Object Descriptor' descibes a shared object that is needed
46 1.1 pk * to complete the link edit process of the object containing it.
47 1.3 pk * A list of such objects (chained through `sod_next') is pointed at
48 1.3 pk * by `sdt_sods' in the section_dispatch_table structure.
49 1.1 pk */
50 1.1 pk
51 1.3 pk struct sod { /* Shared Object Descriptor */
52 1.3 pk long sod_name; /* name (relative to load address) */
53 1.3 pk u_int sod_library : 1, /* Searched for by library rules */
54 1.3 pk sod_reserved : 31;
55 1.3 pk short sod_major; /* major version number */
56 1.3 pk short sod_minor; /* minor version number */
57 1.3 pk long sod_next; /* next sod */
58 1.1 pk };
59 1.1 pk
60 1.1 pk /*
61 1.3 pk * `Shared Object Map's are used by the run-time link editor (ld.so) to
62 1.3 pk * keep track of all shared objects loaded into a process' address space.
63 1.1 pk * These structures are only used at run-time and do not occur within
64 1.1 pk * the text or data segment of an executable or shared library.
65 1.1 pk */
66 1.3 pk struct so_map { /* Shared Object Map */
67 1.3 pk caddr_t som_addr; /* Address at which object mapped */
68 1.3 pk char *som_path; /* Path to mmap'ed file */
69 1.3 pk struct so_map *som_next; /* Next map in chain */
70 1.3 pk struct sod *som_sod; /* Sod responsible for this map */
71 1.3 pk caddr_t som_sodbase; /* Base address of this sod */
72 1.3 pk u_int som_write : 1; /* Text is currently writable */
73 1.3 pk struct _dynamic *som_dynamic; /* _dynamic structure */
74 1.3 pk caddr_t som_spd; /* Private data */
75 1.1 pk };
76 1.1 pk
77 1.1 pk /*
78 1.1 pk * Symbol description with size. This is simply an `nlist' with
79 1.1 pk * one field (nz_size) added.
80 1.1 pk * Used to convey size information on items in the data segment
81 1.1 pk * of shared objects. An array of these live in the shared object's
82 1.3 pk * text segment and is addressed by the `sdt_nzlist' field.
83 1.1 pk */
84 1.1 pk struct nzlist {
85 1.1 pk struct nlist nlist;
86 1.1 pk u_long nz_size;
87 1.1 pk #define nz_un nlist.n_un
88 1.1 pk #define nz_strx nlist.n_un.n_strx
89 1.1 pk #define nz_name nlist.n_un.n_name
90 1.1 pk #define nz_type nlist.n_type
91 1.1 pk #define nz_value nlist.n_value
92 1.1 pk #define nz_desc nlist.n_desc
93 1.1 pk #define nz_other nlist.n_other
94 1.1 pk };
95 1.1 pk
96 1.3 pk #define N_AUX(p) ((p)->n_other & 0xf)
97 1.3 pk #define N_RESERVED(p) (((unsigned int)(p)->n_other >> 4) & 0xf)
98 1.3 pk #define N_OTHER(r, v) (((unsigned int)(r) << 4) | ((v) & 0xf))
99 1.3 pk
100 1.3 pk #define AUX_OBJECT 1
101 1.3 pk #define AUX_FUNC 2
102 1.3 pk
103 1.3 pk
104 1.1 pk /*
105 1.3 pk * The `section_dispatch_table' structure contains offsets to various data
106 1.1 pk * structures needed to do run-time relocation.
107 1.1 pk */
108 1.3 pk struct section_dispatch_table {
109 1.3 pk struct so_map *sdt_loaded; /* List of loaded objects */
110 1.3 pk long sdt_sods; /* List of shared objects descriptors */
111 1.3 pk long sdt_filler1; /* Unused (was: search rules) */
112 1.3 pk long sdt_got; /* Global offset table */
113 1.3 pk long sdt_plt; /* Procedure linkage table */
114 1.3 pk long sdt_rel; /* Relocation table */
115 1.3 pk long sdt_hash; /* Symbol hash table */
116 1.3 pk long sdt_nzlist; /* Symbol table itself */
117 1.3 pk long sdt_filler2; /* Unused (was: stab_hash) */
118 1.3 pk long sdt_buckets; /* Number of hash buckets */
119 1.3 pk long sdt_strings; /* Symbol strings */
120 1.3 pk long sdt_str_sz; /* Size of symbol strings */
121 1.3 pk long sdt_text_sz; /* Size of text area */
122 1.3 pk long sdt_plt_sz; /* Size of procedure linkage table */
123 1.1 pk };
124 1.1 pk
125 1.1 pk /*
126 1.3 pk * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table.
127 1.1 pk * Used to quickly lookup symbols of the shared object by hashing
128 1.1 pk * on the symbol's name. `rh_symbolnum' is the index of the symbol
129 1.3 pk * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is
130 1.1 pk * the next symbol in the hash bucket (in case of collisions).
131 1.1 pk */
132 1.1 pk struct rrs_hash {
133 1.3 pk int rh_symbolnum; /* Symbol number */
134 1.3 pk int rh_next; /* Next hash entry */
135 1.1 pk };
136 1.1 pk
137 1.1 pk /*
138 1.1 pk * `rt_symbols' is used to keep track of run-time allocated commons
139 1.1 pk * and data items copied from shared objects.
140 1.1 pk */
141 1.1 pk struct rt_symbol {
142 1.3 pk struct nzlist *rt_sp; /* The symbol */
143 1.3 pk struct rt_symbol *rt_next; /* Next in linear list */
144 1.3 pk struct rt_symbol *rt_link; /* Next in bucket */
145 1.3 pk caddr_t rt_srcaddr; /* Address of "master" copy */
146 1.3 pk struct so_map *rt_smp; /* Originating map */
147 1.1 pk };
148 1.1 pk
149 1.1 pk /*
150 1.1 pk * Debugger interface structure.
151 1.1 pk */
152 1.3 pk struct so_debug {
153 1.3 pk int dd_version; /* Version # of interface */
154 1.3 pk int dd_in_debugger; /* Set when run by debugger */
155 1.3 pk int dd_sym_loaded; /* Run-time linking brought more
156 1.3 pk symbols into scope */
157 1.3 pk char *dd_bpt_addr; /* Address of rtld-generated bpt */
158 1.3 pk int dd_bpt_shadow; /* Original contents of bpt */
159 1.3 pk struct rt_symbol *dd_cc; /* Allocated commons/copied data */
160 1.1 pk };
161 1.1 pk
162 1.1 pk /*
163 1.1 pk * Entry points into ld.so - user interface to the run-time linker.
164 1.1 pk */
165 1.1 pk struct ld_entry {
166 1.3 pk void *(*dlopen) __P((char *, int));
167 1.3 pk int (*dlclose) __P((void *));
168 1.3 pk void *(*dlsym) __P((void *, char *));
169 1.3 pk int (*dlctl) __P((void *, int, void *));
170 1.1 pk };
171 1.1 pk
172 1.1 pk /*
173 1.3 pk * dlctl() commands
174 1.3 pk */
175 1.3 pk #define DL_GETERRNO 1
176 1.3 pk #define DL_SETSRCHPATH x
177 1.3 pk #define DL_GETLIST x
178 1.3 pk #define DL_GETREFCNT x
179 1.3 pk #define DL_GETLOADADDR x
180 1.3 pk
181 1.3 pk #if 0 /* In separate header file */
182 1.3 pk /*
183 1.3 pk * dl*() prototypes.
184 1.3 pk */
185 1.3 pk extern void *dlopen __P((char *, int));
186 1.3 pk extern int dlclose __P((void *));
187 1.3 pk extern void *dlsym __P((void *, char *));
188 1.3 pk extern int dlctl __P((void *, int, void *));
189 1.3 pk #endif
190 1.3 pk
191 1.3 pk
192 1.3 pk /*
193 1.1 pk * This is the structure pointed at by the __DYNAMIC symbol if an
194 1.1 pk * executable requires the attention of the run-time link editor.
195 1.1 pk * __DYNAMIC is given the value zero if no run-time linking needs to
196 1.1 pk * be done (it is always present in shared objects).
197 1.3 pk * The union `d_un' provides for different versions of the dynamic
198 1.3 pk * linking mechanism (switched on by `d_version'). The last version
199 1.1 pk * used by Sun is 3. We leave some room here and go to version number
200 1.1 pk * 8 for NetBSD, the main difference lying in the support for the
201 1.1 pk * `nz_list' type of symbols.
202 1.1 pk */
203 1.1 pk
204 1.3 pk struct _dynamic {
205 1.3 pk int d_version; /* version # of this interface */
206 1.3 pk struct so_debug *d_debug;
207 1.1 pk union {
208 1.3 pk struct section_dispatch_table *d_sdt;
209 1.3 pk } d_un;
210 1.3 pk struct ld_entry *d_entry;
211 1.1 pk };
212 1.1 pk
213 1.1 pk #define LD_VERSION_SUN (3)
214 1.1 pk #define LD_VERSION_BSD (8)
215 1.1 pk #define LD_VERSION_NZLIST_P(v) ((v) >= 8)
216 1.1 pk
217 1.3 pk #define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got)
218 1.3 pk #define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt)
219 1.3 pk #define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel)
220 1.3 pk #define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist)
221 1.3 pk #define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash)
222 1.3 pk #define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings)
223 1.3 pk #define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods)
224 1.3 pk #define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets)
225 1.3 pk
226 1.3 pk #define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got)
227 1.3 pk #define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel)
228 1.3 pk #define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash)
229 1.3 pk #define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist)
230 1.3 pk #define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz)
231 1.3 pk #define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz)
232 1.3 pk #define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz)
233 1.1 pk
234 1.1 pk /*
235 1.3 pk * Interface to ld.so
236 1.1 pk */
237 1.1 pk struct crt_ldso {
238 1.1 pk int crt_ba; /* Base address of ld.so */
239 1.1 pk int crt_dzfd; /* "/dev/zero" file decriptor (SunOS) */
240 1.1 pk int crt_ldfd; /* ld.so file descriptor */
241 1.3 pk struct _dynamic *crt_dp; /* Main's __DYNAMIC */
242 1.1 pk char **crt_ep; /* environment strings */
243 1.1 pk caddr_t crt_bp; /* Breakpoint if run from debugger */
244 1.3 pk char *crt_prog; /* Program name */
245 1.1 pk };
246 1.1 pk
247 1.1 pk /*
248 1.1 pk * Version passed from crt0 to ld.so (1st argument to _rtld()).
249 1.1 pk */
250 1.1 pk #define CRT_VERSION_SUN 1
251 1.3 pk #define CRT_VERSION_BSD_2 2
252 1.3 pk #define CRT_VERSION_BSD_3 3
253 1.2 pk
254 1.2 pk
255 1.2 pk /*
256 1.2 pk * Maximum number of recognized shared object version numbers.
257 1.2 pk */
258 1.2 pk #define MAXDEWEY 8
259 1.2 pk
260 1.2 pk /*
261 1.2 pk * Header of the hints file.
262 1.2 pk */
263 1.2 pk struct hints_header {
264 1.2 pk long hh_magic;
265 1.2 pk #define HH_MAGIC 011421044151
266 1.2 pk long hh_version; /* Interface version number */
267 1.2 pk #define LD_HINTS_VERSION_1 1
268 1.2 pk long hh_hashtab; /* Location of hash table */
269 1.2 pk long hh_nbucket; /* Number of buckets in hashtab */
270 1.2 pk long hh_strtab; /* Location of strings */
271 1.2 pk long hh_strtab_sz; /* Size of strings */
272 1.2 pk long hh_ehints; /* End of hints (max offset in file) */
273 1.2 pk };
274 1.2 pk
275 1.2 pk #define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC)
276 1.2 pk
277 1.2 pk /*
278 1.2 pk * Hash table element in hints file.
279 1.2 pk */
280 1.2 pk struct hints_bucket {
281 1.2 pk /* namex and pathx are indices into the string table */
282 1.2 pk int hi_namex; /* Library name */
283 1.2 pk int hi_pathx; /* Full path */
284 1.2 pk int hi_dewey[MAXDEWEY]; /* The versions */
285 1.2 pk int hi_ndewey; /* Number of version numbers */
286 1.2 pk #define hi_major hi_dewey[0]
287 1.2 pk #define hi_minor hi_dewey[1]
288 1.2 pk int hi_next; /* Next in this bucket */
289 1.2 pk };
290 1.2 pk
291 1.2 pk #define _PATH_LD_HINTS "/var/run/ld.so.hints"
292 1.1 pk
293 1.1 pk #endif /* _LINK_H_ */
294 1.1 pk
295