/[gentoo]/xml/htdocs/proj/en/hardened/link.5.html
Gentoo

Contents of /xml/htdocs/proj/en/hardened/link.5.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download) (as text)
Sun Oct 9 06:00:38 2005 UTC (8 years, 11 months ago) by vapier
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/html
add html-ified version of netbsd manpage

1 <html>
2 <head><title>link(5) man page</title></head>
3 <body>
4 <pre>
5 LINK(5) BSD File Formats Manual LINK(5)
6
7 NAME
8 link -- dynamic loader and link editor interface
9
10 SYNOPSIS
11 #include &lt;link.h&gt;
12
13 DESCRIPTION
14 The include file &lt;link.h&gt; declares several structures that are present in
15 dynamically linked programs and libraries. The structures define the
16 interface between several components of the link-editor and loader mecha-
17 nism. The layout of a number of these structures within the binaries
18 resembles the a.out(5) format in many places as it serves such similar
19 functions as symbol definitions (including the accompanying string table)
20 and relocation records needed to resolve references to external entities.
21
22 It also records a number of data structures unique to the dynamic loading
23 and linking process. These include references to other objects that are
24 required to complete the link-editing process and indirection tables to
25 facilitate Position Independent Code (PIC) to improve sharing of code
26 pages among different processes.
27
28 The collection of data structures described here will be referred to as
29 the Run-time Relocation Section (RRS) and is embedded in the standard
30 text and data segments of the dynamically linked program or shared object
31 image as the existing a.out(5) format offers no room for it elsewhere.
32
33 Several utilities cooperate to ensure that the task of getting a program
34 ready to run can complete successfully in a way that optimizes the use of
35 system resources. The compiler emits PIC code from which shared
36 libraries can be built by ld(1). The compiler also includes size infor-
37 mation of any initialized data items through the .size assembler direc-
38 tive.
39
40 PIC code differs from conventional code in that it accesses data vari-
41 ables through an indirection table, the Global Offset Table, by conven-
42 tion accessible by the reserved name _GLOBAL_OFFSET_TABLE_. The exact
43 mechanism used for this is machine dependent, usually a machine register
44 is reserved for the purpose. The rational behind this construct is to
45 generate code that is independent of the actual load address. Only the
46 values contained in the Global Offset Table may need updating at run-time
47 depending on the load addresses of the various shared objects in the
48 address space.
49
50 Likewise, procedure calls to globally defined functions are redirected
51 through the Procedure Linkage Table (PLT) residing in the data segment of
52 the core image. Again, this is done to avoid run-time modifications to
53 the text segment.
54
55 The linker-editor allocates the Global Offset Table and Procedure Linkage
56 Table when combining PIC object files into an image suitable for mapping
57 into the process address space. It also collects all symbols that may be
58 needed by the run-time link-editor and stores these along with the
59 image's text and data bits. Another reserved symbol, _DYNAMIC is used to
60 indicate the presence of the run-time linker structures. Whenever
61 _DYNAMIC is relocated to 0, there is no need to invoke the run-time link-
62 editor. If this symbol is non-zero, it points at a data structure from
63 which the location of the necessary relocation- and symbol information
64 can be derived. This is most notably used by the start-up module, crt0.
65 The _DYNAMIC structure is conventionally located at the start of the data
66 segment of the image to which it pertains.
67
68 DATA STRUCTURES
69 The data structures supporting dynamic linking and run-time relocation
70 reside both in the text and data segments of the image they apply to.
71 The text segments contain read-only data such as symbols descriptions and
72 names, while the data segments contain the tables that need to be modi-
73 fied by during the relocation process.
74
75 The _DYNAMIC symbol references a _dynamic structure:
76
77 struct _dynamic {
78 int d_version;
79 struct so_debug *d_debug;
80 union {
81 struct section_dispatch_table *d_sdt;
82 } d_un;
83 struct ld_entry *d_entry;
84 };
85
86 d_version This field provides for different versions of the dynamic
87 linking implementation. The current version numbers under-
88 stood by ld and ld.so are LD_VERSION_SUN (3), which is used by
89 the SunOS 4.x releases, and LD_VERSION_BSD (8), which is cur-
90 rently in use by NetBSD.
91
92 d_un Refers to a d_version dependent data structure.
93
94 d_debug this field provides debuggers with a hook to access symbol
95 tables of shared objects loaded as a result of the actions of
96 the run-time link-editor.
97
98 d_entry this field is obsoleted by CRT interface version CRT_VER-
99 SION_BSD4, and is replaced by the crt_ldentry in crt_ldso.
100
101 The section_dispatch_table structure is the main ``dispatcher'' table,
102 containing offsets into the image's segments where various symbol and
103 relocation information is located.
104
105 struct section_dispatch_table {
106 struct so_map *sdt_loaded;
107 long sdt_sods;
108 long sdt_paths;
109 long sdt_got;
110 long sdt_plt;
111 long sdt_rel;
112 long sdt_hash;
113 long sdt_nzlist;
114 long sdt_filler2;
115 long sdt_buckets;
116 long sdt_strings;
117 long sdt_str_sz;
118 long sdt_text_sz;
119 long sdt_plt_sz;
120 };
121
122 sdt_loaded A pointer to the first link map loaded (see below). This
123 field is set by ld.so(1) for the benefit of debuggers that
124 may use it to load a shared object's symbol table.
125
126 sdt_sods The start of a (linked) list of shared object descriptors
127 needed by this object.
128
129 sdt_paths Library search rules. A colon separated list of directories
130 corresponding to the -R option of ld(1).
131
132 sdt_got The location of the Global Offset Table within this image.
133
134 sdt_plt The location of the Procedure Linkage Table within this
135 image.
136
137 sdt_rel The location of an array of relocation_info structures (see
138 a.out(5)) specifying run-time relocations.
139
140 sdt_hash The location of the hash table for fast symbol lookup in this
141 object's symbol table.
142
143 sdt_nzlist The location of the symbol table.
144
145 sdt_filler2
146 Currently unused.
147
148 sdt_buckets
149 The number of buckets in sdt_hash
150
151 sdt_strings
152 The location of the symbol string table that goes with
153 sdt_nzlist.
154
155 sdt_str_sz The size of the string table.
156
157 sdt_text_sz
158 The size of the object's text segment.
159
160 sdt_plt_sz The size of the Procedure Linkage Table.
161
162 A sod structure describes a shared object that is needed to complete the
163 link edit process of the object containing it. A list of such objects
164 (chained through sod_next) is pointed at by the sdt_sods in the sec-
165 tion_dispatch_table structure.
166
167 struct sod {
168 long sod_name;
169 u_int sod_library : 1,
170 sod_unused : 31;
171 short sod_major;
172 short sod_minor;
173 long sod_next;
174 };
175
176 sod_name The offset in the text segment of a string describing this
177 link object.
178
179 sod_library If set, sod_name specifies a library that is to be searched
180 for by ld.so. The path name is obtained by searching a set
181 of directories (see also ldconfig(8)) for a shared object
182 matching lib&lt;sod_name&gt;.so.n.m. If not set, sod_name should
183 point at a full path name for the desired shared object.
184
185 sod_major Specifies the major version number of the shared object to
186 load.
187
188 sod_minor Specifies the preferred minor version number of the shared
189 object to load.
190
191 The run-time link-editor maintains a list of structures called link maps
192 to keep track of all shared objects loaded into a process' address space.
193 These structures are only used at run-time and do not occur within the
194 text or data segment of an executable or shared library.
195
196 struct so_map {
197 caddr_t som_addr;
198 char *som_path;
199 struct so_map *som_next;
200 struct sod *som_sod;
201 caddr_t som_sodbase;
202 u_int som_write : 1;
203 struct _dynamic *som_dynamic;
204 caddr_t som_spd;
205 };
206
207 som_addr The address at which the shared object associated with this
208 link map has been loaded.
209
210 som_path The full path name of the loaded object.
211
212 som_next Pointer to the next link map.
213
214 som_sod The sod structure that was responsible for loading this
215 shared object.
216
217 som_sodbase Tossed in later versions the run-time linker.
218
219 som_write Set if (some portion of) this object's text segment is cur-
220 rently writable.
221
222 som_dynamic Pointer to this object's _dynamic structure.
223
224 som_spd Hook for attaching private data maintained by the run-time
225 link-editor.
226
227 Symbol description with size. This is simply an nlist structure with one
228 field (nz_size) added. Used to convey size information on items in the
229 data segment of shared objects. An array of these lives in the shared
230 object's text segment and is addressed by the sdt_nzlist field of
231 section_dispatch_table.
232
233 struct nzlist {
234 struct nlist nlist;
235 u_long nz_size;
236 #define nz_un nlist.n_un
237 #define nz_strx nlist.n_un.n_strx
238 #define nz_name nlist.n_un.n_name
239 #define nz_type nlist.n_type
240 #define nz_value nlist.n_value
241 #define nz_desc nlist.n_desc
242 #define nz_other nlist.n_other
243 };
244
245 nlist (see nlist(3)).
246
247 nz_size The size of the data represented by this symbol.
248
249 A hash table is included within the text segment of shared object to
250 facilitate quick lookup of symbols during run-time link-editing. The
251 sdt_hash field of the section_dispatch_table structure points at an array
252 of rrs_hash structures:
253
254 struct rrs_hash {
255 int rh_symbolnum; /* symbol number */
256 int rh_next; /* next hash entry */
257 };
258
259 rh_symbolnum The index of the symbol in the shared object's symbol table
260 (as given by the ld_symbols field).
261
262 rh_next In case of collisions, this field is the offset of the next
263 entry in this hash table bucket. It is zero for the last
264 bucket element.
265 The rt_symbol structure is used to keep track of run-time allocated com-
266 mons and data items copied from shared objects. These items are kept on
267 linked list and is exported through the dd_cc field in the so_debug
268 structure (see below) for use by debuggers.
269
270 struct rt_symbol {
271 struct nzlist *rt_sp;
272 struct rt_symbol *rt_next;
273 struct rt_symbol *rt_link;
274 caddr_t rt_srcaddr;
275 struct so_map *rt_smp;
276 };
277
278 rt_sp The symbol description.
279
280 rt_next Virtual address of next rt_symbol.
281
282 rt_link Next in hash bucket. Used by internally by ld.so.
283
284 rt_srcaddr Location of the source of initialized data within a shared
285 object.
286
287 rt_smp The shared object which is the original source of the data
288 that this run-time symbol describes.
289
290 The so_debug structure is used by debuggers to gain knowledge of any
291 shared objects that have been loaded in the process's address space as a
292 result of run-time link-editing. Since the run-time link-editor runs as
293 a part of process initialization, a debugger that wishes to access sym-
294 bols from shared objects can only do so after the link-editor has been
295 called from crt0. A dynamically linked binary contains a so_debug struc-
296 ture which can be located by means of the d_debug field in _dynamic.
297
298 struct so_debug {
299 int dd_version;
300 int dd_in_debugger;
301 int dd_sym_loaded;
302 char *dd_bpt_addr;
303 int dd_bpt_shadow;
304 struct rt_symbol *dd_cc;
305 };
306
307 dd_version Version number of this interface.
308
309 dd_in_debugger Set by the debugger to indicate to the run-time linker
310 that the program is run under control of a debugger.
311
312 dd_sym_loaded Set by the run-time linker whenever it adds symbols by
313 loading shared objects.
314
315 dd_bpt_addr The address were a breakpoint will be set by the run-time
316 linker to divert control to the debugger. This address
317 is determined by the start-up module, crt0.o, to be some
318 convenient place before the call to _main.
319
320 dd_bpt_shadow Contains the original instruction that was at
321 dd_bpt_addr. The debugger is expected to put this
322 instruction back before continuing the program.
323
324 dd_cc A pointer to the linked list of run-time allocated sym-
325 bols that the debugger may be interested in.
326
327 The ld_entry structure defines a set of service routines within ld.so.
328 See dlfcn(3) for more information.
329
330 struct ld_entry {
331 void *(*dlopen)(char *, int);
332 int (*dlclose)(void *);
333 void *(*dlsym)(void *, char *);
334 int (*dlctl)(void *, int, void *);
335 void (*dlexit)(void);
336 };
337
338 The crt_ldso structure defines the interface between ld.so and the start-
339 up code in crt0.
340
341 struct crt_ldso {
342 int crt_ba;
343 int crt_dzfd;
344 int crt_ldfd;
345 struct _dynamic *crt_dp;
346 char **crt_ep;
347 caddr_t crt_bp;
348 char *crt_prog;
349 char *crt_ldso;
350 char *crt_ldentry;
351 };
352 #define CRT_VERSION_SUN 1
353 #define CRT_VERSION_BSD2 2
354 #define CRT_VERSION_BSD3 3
355 #define CRT_VERSION_BSD4 4
356
357 crt_ba The virtual address at which ld.so was loaded by crt0.
358
359 crt_dzfd On SunOS systems, this field contains an open file descriptor
360 to ``/dev/zero'' used to get demand paged zeroed pages. On
361 NetBSD systems it contains -1.
362
363 crt_ldfd Contains an open file descriptor that was used by crt0 to load
364 ld.so.
365
366 crt_dp A pointer to main's _dynamic structure.
367
368 crt_ep A pointer to the environment strings.
369
370 crt_bp The address at which a breakpoint will be placed by the run-
371 time linker if the main program is run by a debugger. See
372 so_debug
373
374 crt_prog The name of the main program as determined by crt0 (CRT_VER-
375 SION_BSD3 only).
376
377 crt_ldso The path of the run-time linker as mapped by crt0 (CRT_VER-
378 SION_BSD4 only).
379
380 crt_ldentry
381 The dlfcn(3) entry points provided by the run-time linker
382 (CRT_VERSION_BSD4 only).
383
384 The hints_header and hints_bucket structures define the layout of the
385 library hints, normally found in ``/var/run/ld.so.hints'', which is used
386 by ld.so to quickly locate the shared object images in the file system.
387 The organization of the hints file is not unlike that of an a.out(5)
388 object file, in that it contains a header determining the offset and size
389 of a table of fixed sized hash buckets and a common string pool.
390
391 struct hints_header {
392 long hh_magic;
393 #define HH_MAGIC 011421044151
394 long hh_version;
395 #define LD_HINTS_VERSION_1 1
396 #define LD_HINTS_VERSION_2 2
397 long hh_hashtab;
398 long hh_nbucket;
399 long hh_strtab;
400 long hh_strtab_sz;
401 long hh_ehints;
402 long hh_dirlist;
403 };
404
405 hh_magic Hints file magic number.
406
407 hh_version Interface version number.
408
409 hh_hashtab Offset of hash table.
410
411 hh_strtab Offset of string table.
412
413 hh_strtab_sz Size of strings.
414
415 hh_ehints Maximum usable offset in hints file.
416
417 hh_dirlist Offset in string table of a colon-separated list of direc-
418 tories that was used in constructing the hints file. See
419 also ldconfig(8). This field is only available with inter-
420 face version number LD_HINTS_VERSION_2 and higher.
421
422 /*
423 * Hash table element in hints file.
424 */
425 struct hints_bucket {
426 int hi_namex;
427 int hi_pathx;
428 int hi_dewey[MAXDEWEY];
429 int hi_ndewey;
430 #define hi_major hi_dewey[0]
431 #define hi_minor hi_dewey[1]
432 int hi_next;
433 };
434
435 hi_namex Index of the string identifying the library.
436
437 hi_pathx Index of the string representing the full path name of the
438 library.
439
440 hi_dewey The version numbers of the shared library.
441
442 hi_ndewey The number of valid entries in hi_dewey.
443
444 hi_next Next bucket in case of hashing collisions.
445
446 BSD October 23, 1993 BSD
447 </pre>
448 </body>
449 </html>

  ViewVC Help
Powered by ViewVC 1.1.20