- Import driver[acx(4)] for TI acx100/acx111 based WiFi NIC.
[dragonfly.git] / share / man / man5 / link.5
1 .\" Copyright (c) 1993 Paul Kranenburg
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"      This product includes software developed by Paul Kranenburg.
15 .\" 3. The name of the author may not be used to endorse or promote products
16 .\"    derived from this software without specific prior written permission
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .\"
29 .\" $FreeBSD: src/share/man/man5/link.5,v 1.14.2.10 2004/05/17 11:38:55 brueffer Exp $
30 .\" $DragonFly: src/share/man/man5/link.5,v 1.4 2004/07/23 06:43:05 hmp Exp $
31 .\"
32 .Dd October 23, 1993
33 .Dt LINK 5
34 .Os
35 .Sh NAME
36 .Nm link
37 .Nd dynamic loader and link editor interface
38 .Sh SYNOPSIS
39 .In sys/types.h
40 .In nlist.h
41 .In link.h
42 .Sh DESCRIPTION
43 The include file
44 .Aq Pa link.h
45 declares several structures that are present in dynamically linked
46 programs and libraries.
47 The structures define the interface between several components of the
48 link-editor and loader mechanism.
49 The layout of a number of these
50 structures within the binaries resembles the a.out format in many places
51 as it serves such similar functions as symbol definitions (including the
52 accompanying string table) and relocation records needed to resolve
53 references to external entities.
54 It also records a number of data structures
55 unique to the dynamic loading and linking process.
56 These include references
57 to other objects that are required to complete the link-editing process and
58 indirection tables to facilitate
59 .Em Position Independent Code
60 (PIC for short) to improve sharing of code pages among different processes.
61 The collection of data structures described here will be referred to as the
62 .Em Run-time Relocation Section (RRS)
63 and is embedded in the standard text and data segments of the dynamically
64 linked program or shared object image as the existing
65 .Xr a.out 5
66 format offers no room for it elsewhere.
67 .Pp
68 Several utilities cooperate to ensure that the task of getting a program
69 ready to run can complete successfully in a way that optimizes the use
70 of system resources.
71 The compiler emits PIC code from which shared libraries
72 can be built by
73 .Xr ld 1 .
74 The compiler also includes size information of any initialized data items
75 through the .size assembler directive.
76 PIC code differs from conventional code
77 in that it accesses data variables through an indirection table, the
78 Global Offset Table, by convention accessible by the reserved name
79 .Dv _GLOBAL_OFFSET_TABLE_ .
80 The exact mechanism used for this is machine dependent, usually a machine
81 register is reserved for the purpose.
82 The rational behind this construct
83 is to generate code that is independent of the actual load address.
84 Only
85 the values contained in the Global Offset Table may need updating at run-time
86 depending on the load addresses of the various shared objects in the address
87 space.
88 .Pp
89 Likewise, procedure calls to globally defined functions are redirected through
90 the Procedure Linkage Table (PLT) residing in the data segment of the core
91 image.
92 Again, this is done to avoid run-time modifications to the text segment.
93 .Pp
94 The linker-editor allocates the Global Offset Table and Procedure Linkage Table
95 when combining PIC object files into an image suitable for mapping into the
96 process address space.
97 It also collects all symbols that may be needed by the
98 run-time link-editor and stores these along with the image's text and data bits.
99 Another reserved symbol,
100 .Em _DYNAMIC
101 is used to indicate the presence of the run-time linker structures.
102 Whenever
103 _DYNAMIC is relocated to 0, there is no need to invoke the run-time
104 link-editor.
105 If this symbol is non-zero, it points at a data structure from
106 which the location of the necessary relocation- and symbol information can
107 be derived.
108 This is most notably used by the start-up module,
109 .Em crt0 .
110 The _DYNAMIC structure is conventionally located at the start of the data
111 segment of the image to which it pertains.
112 .Sh DATA STRUCTURES
113 The data structures supporting dynamic linking and run-time relocation
114 reside both in the text and data segments of the image they apply to.
115 The text segments contain read-only data such as symbols descriptions and
116 names, while the data segments contain the tables that need to be modified by
117 during the relocation process.
118 .Pp
119 The _DYNAMIC symbol references a
120 .Fa _dynamic
121 structure:
122 .Bd -literal -offset indent
123 struct  _dynamic {
124         int     d_version;
125         struct  so_debug *d_debug;
126         union {
127                 struct section_dispatch_table *d_sdt;
128         } d_un;
129         struct  ld_entry *d_entry;
130 };
131 .Ed
132 .Bl -tag -width d_version
133 .It Fa d_version
134 This field provides for different versions of the dynamic linking
135 implementation.
136 The current version numbers understood by
137 .Xr ld 1
138 and
139 .Xr ld.so 1
140 are
141 .Em LD_VERSION_SUN (3) ,
142 which is used by the
143 .Tn SunOS
144 4.x releases, and
145 .Em LD_VERSION_BSD (8) ,
146 which has been in use since
147 .Fx 1.1 .
148 .It Fa d_un
149 Refers to a
150 .Em d_version
151 dependent data structure.
152 .It Fa so_debug
153 this field provides debuggers with a hook to access symbol tables of shared
154 objects loaded as a result of the actions of the run-time link-editor.
155 .El
156 .Pp
157 The
158 .Fa section_dispatch_table
159 structure is the main
160 .Dq dispatcher
161 table, containing offsets into the image's segments where various symbol
162 and relocation information is located.
163 .Bd -literal -offset indent
164 struct section_dispatch_table {
165         struct  so_map *sdt_loaded;
166         long    sdt_sods;
167         long    sdt_filler1;
168         long    sdt_got;
169         long    sdt_plt;
170         long    sdt_rel;
171         long    sdt_hash;
172         long    sdt_nzlist;
173         long    sdt_filler2;
174         long    sdt_buckets;
175         long    sdt_strings;
176         long    sdt_str_sz;
177         long    sdt_text_sz;
178         long    sdt_plt_sz;
179 };
180 .Ed
181 .Pp
182 .Bl -tag -width sdt_filler1
183 .It Fa sdt_loaded
184 A pointer to the first link map loaded (see below). This field is set by
185 .Nm ld.so
186 .It Fa sdt_sods
187 The start of a (linked) list of shared object descriptors needed by
188 .Em this
189 object.
190 .It Fa sdt_filler1
191 Deprecated (used by SunOS to specify library search rules).
192 .It Fa sdt_got
193 The location of the Global Offset Table within this image.
194 .It Fa sdt_plt
195 The location of the Procedure Linkage Table within this image.
196 .It Fa sdt_rel
197 The location of an array of
198 .Fa relocation_info
199 structures
200 (see
201 .Xr a.out 5 )
202 specifying run-time relocations.
203 .It Fa sdt_hash
204 The location of the hash table for fast symbol lookup in this object's
205 symbol table.
206 .It Fa sdt_nzlist
207 The location of the symbol table.
208 .It Fa sdt_filler2
209 Currently unused.
210 .It Fa sdt_buckets
211 The number of buckets in
212 .Fa sdt_hash
213 .It Fa sdt_strings
214 The location of the symbol string table that goes with
215 .Fa sdt_nzlist .
216 .It Fa sdt_str_sz
217 The size of the string table.
218 .It Fa sdt_text_sz
219 The size of the object's text segment.
220 .It Fa sdt_plt_sz
221 The size of the Procedure Linkage Table.
222 .El
223 .Pp
224 A
225 .Fa sod
226 structure describes a shared object that is needed
227 to complete the link edit process of the object containing it.
228 A list of such objects
229 (chained through
230 .Fa sod_next )
231 is pointed at
232 by the
233 .Fa sdt_sods
234 in the section_dispatch_table structure.
235 .Bd -literal -offset indent
236 struct sod {
237         long    sod_name;
238         u_int   sod_library : 1,
239                 sod_reserved : 31;
240         short   sod_major;
241         short   sod_minor;
242         long    sod_next;
243 };
244 .Ed
245 .Pp
246 .Bl -tag -width sod_library
247 .It Fa sod_name
248 The offset in the text segment of a string describing this link object.
249 .It Fa sod_library
250 If set,
251 .Fa sod_name
252 specifies a library that is to be searched for by
253 .Nm ld.so .
254 The path name
255 is obtained by searching a set of directories
256 (see also
257 .Xr ldconfig 8 )
258 for a shared object matching
259 .Em lib\&<sod_name>\&.so.n.m .
260 If not set,
261 .Fa sod_name
262 should point at a full path name for the desired shared object.
263 .It Fa sod_major
264 Specifies the major version number of the shared object to load.
265 .It Fa sod_minor
266 Specifies the preferred minor version number of the shared object to load.
267 .El
268 .Pp
269 The run-time link-editor maintains a list of structures called
270 .Em link maps
271 to keep track of all shared objects loaded into a process' address space.
272 These structures are only used at run-time and do not occur within
273 the text or data segment of an executable or shared library.
274 .Bd -literal -offset indent
275 struct so_map {
276         caddr_t som_addr;
277         char    *som_path;
278         struct  so_map *som_next;
279         struct  sod *som_sod;
280         caddr_t som_sodbase;
281         u_int   som_write : 1;
282         struct  _dynamic *som_dynamic;
283         caddr_t som_spd;
284 };
285 .Ed
286 .Bl -tag -width som_dynamic
287 .It Fa som_addr
288 The address at which the shared object associated with this link map has
289 been loaded.
290 .It Fa som_path
291 The full path name of the loaded object.
292 .It Fa som_next
293 Pointer to the next link map.
294 .It Fa som_sod
295 The
296 .Fa sod
297 structure that was responsible for loading this shared object.
298 .It Fa som_sodbase
299 Tossed out in later versions of the run-time linker.
300 .It Fa som_write
301 Set if (some portion of) this object's text segment is currently writable.
302 .It Fa som_dynamic
303 Pointer to this object's
304 .Fa _dynamic
305 structure.
306 .It Fa som_spd
307 Hook for attaching private data maintained by the run-time link-editor.
308 .El
309 .Pp
310 Symbol description with size.
311 This is simply an
312 .Fa nlist
313 structure with one field
314 .Pq Fa nz_size
315 added.
316 Used to convey size information on items in the data segment
317 of shared objects.
318 An array of these lives in the shared object's
319 text segment and is addressed by the
320 .Fa sdt_nzlist
321 field of
322 .Fa section_dispatch_table .
323 .Bd -literal -offset indent
324 struct nzlist {
325         struct nlist    nlist;
326         u_long          nz_size;
327 #define nz_un           nlist.n_un
328 #define nz_strx         nlist.n_un.n_strx
329 #define nz_name         nlist.n_un.n_name
330 #define nz_type         nlist.n_type
331 #define nz_value        nlist.n_value
332 #define nz_desc         nlist.n_desc
333 #define nz_other        nlist.n_other
334 };
335 .Ed
336 .Bl -tag -width nz_size
337 .It Fa nlist
338 (see
339 .Xr nlist 3 ) .
340 .It Fa nz_size
341 The size of the data represented by this symbol.
342 .El
343 .Pp
344 A hash table is included within the text segment of shared object
345 to facilitate quick lookup of symbols during run-time link-editing.
346 The
347 .Fa sdt_hash
348 field of the
349 .Fa section_dispatch_table
350 structure points at an array of
351 .Fa rrs_hash
352 structures:
353 .Bd -literal -offset indent
354 struct rrs_hash {
355         int     rh_symbolnum;           /* symbol number */
356         int     rh_next;                /* next hash entry */
357 };
358 .Ed
359 .Pp
360 .Bl -tag -width rh_symbolnum
361 .It Fa rh_symbolnum
362 The index of the symbol in the shared object's symbol table (as given by the
363 .Fa ld_symbols
364 field).
365 .It Fa rh_next
366 In case of collisions, this field is the offset of the next entry in this
367 hash table bucket.
368 It is zero for the last bucket element.
369 .El
370 The
371 .Fa rt_symbol
372 structure is used to keep track of run-time allocated commons
373 and data items copied from shared objects.
374 These items are kept on linked list
375 and is exported through the
376 .Fa dd_cc
377 field in the
378 .Fa so_debug
379 structure (see below) for use by debuggers.
380 .Bd -literal -offset indent
381 struct rt_symbol {
382         struct nzlist           *rt_sp;
383         struct rt_symbol        *rt_next;
384         struct rt_symbol        *rt_link;
385         caddr_t                 rt_srcaddr;
386         struct so_map           *rt_smp;
387 };
388 .Ed
389 .Pp
390 .Bl -tag -width rt_scraddr
391 .It Fa rt_sp
392 The symbol description.
393 .It Fa rt_next
394 Virtual address of next rt_symbol.
395 .It Fa rt_link
396 Next in hash bucket.
397 Used internally by
398 .Nm ld.so .
399 .It Fa rt_srcaddr
400 Location of the source of initialized data within a shared object.
401 .It Fa rt_smp
402 The shared object which is the original source of the data that this
403 run-time symbol describes.
404 .El
405 .Pp
406 The
407 .Fa so_debug
408 structure is used by debuggers to gain knowledge of any shared objects
409 that have been loaded in the process's address space as a result of run-time
410 link-editing.
411 Since the run-time link-editor runs as a part of process
412 initialization, a debugger that wishes to access symbols from shared objects
413 can only do so after the link-editor has been called from crt0.
414 A dynamically linked binary contains a
415 .Fa so_debug
416 structure which can be located by means of the
417 .Fa d_debug
418 field in
419 .Fa _dynamic .
420 .Bd -literal -offset indent
421 struct  so_debug {
422         int     dd_version;
423         int     dd_in_debugger;
424         int     dd_sym_loaded;
425         char    *dd_bpt_addr;
426         int     dd_bpt_shadow;
427         struct rt_symbol *dd_cc;
428 };
429 .Ed
430 .Pp
431 .Bl -tag -width dd_in_debugger
432 .It Fa dd_version
433 Version number of this interface.
434 .It Fa dd_in_debugger
435 Set by the debugger to indicate to the run-time linker that the program is
436 run under control of a debugger.
437 .It Fa dd_sym_loaded
438 Set by the run-time linker whenever it adds symbols by loading shared objects.
439 .It Fa dd_bpt_addr
440 The address where a breakpoint will be set by the run-time linker to
441 divert control to the debugger.
442 This address is determined by the start-up
443 module,
444 .Pa crt0.o ,
445 to be some convenient place before the call to _main.
446 .It Fa dd_bpt_shadow
447 Contains the original instruction that was at
448 .Fa dd_bpt_addr .
449 The debugger is expected to put this instruction back before continuing the
450 program.
451 .It Fa dd_cc
452 A pointer to the linked list of run-time allocated symbols that the debugger
453 may be interested in.
454 .El
455 .Pp
456 The
457 .Em ld_entry
458 structure defines a set of service routines within
459 .Nm ld.so .
460 .\" See
461 .\" .Xr libdl.a
462 .\" for more information.
463 .Bd -literal -offset indent
464 struct ld_entry {
465         void    *(*dlopen)(char *, int);
466         int     (*dlclose)(void *);
467         void    *(*dlsym)(void *, char *);
468         char    *(*dlerror)(void);
469 };
470 .Ed
471 .Pp
472 The
473 .Fa crt_ldso
474 structure defines the interface between the start-up code in crt0 and
475 .Nm ld.so .
476 .Bd -literal -offset indent
477 struct crt_ldso {
478         int             crt_ba;
479         int             crt_dzfd;
480         int             crt_ldfd;
481         struct _dynamic *crt_dp;
482         char            **crt_ep;
483         caddr_t         crt_bp;
484         char            *crt_prog;
485         char            *crt_ldso;
486         struct ld_entry *crt_ldentry;
487 };
488 #define CRT_VERSION_SUN         1
489 #define CRT_VERSION_BSD_2       2
490 #define CRT_VERSION_BSD_3       3
491 #define CRT_VERSION_BSD_4       4
492 .Ed
493 .Bl -tag -width crt_dzfd
494 .It Fa crt_ba
495 The virtual address at which
496 .Nm ld.so
497 was loaded by crt0.
498 .It Fa crt_dzfd
499 On SunOS systems, this field contains an open file descriptor to
500 .Dq Pa /dev/zero
501 used to get demand paged zeroed pages.
502 On
503 .Dx
504 systems it contains -1.
505 .It Fa crt_ldfd
506 Contains an open file descriptor that was used by crt0 to load
507 .Nm ld.so .
508 .It Fa crt_dp
509 A pointer to main's
510 .Fa _dynamic
511 structure.
512 .It Fa crt_ep
513 A pointer to the environment strings.
514 .It Fa crt_bp
515 The address at which a breakpoint will be placed by the run-time linker
516 if the main program is run by a debugger.
517 See
518 .Fa so_debug
519 .It Fa crt_prog
520 The name of the main program as determined by crt0 (CRT_VERSION_BSD3 only).
521 .It Fa crt_ldso
522 The path of the run-time linker as mapped by crt0 (CRT_VERSION_BSD4 only).
523 .El
524 .Pp
525 The
526 .Fa hints_header
527 and
528 .Fa hints_bucket
529 structures define the layout of the library hints, normally found in
530 .Dq Pa /var/run/ld.so.hints ,
531 which is used by
532 .Nm ld.so
533 to quickly locate the shared object images in the
534 filesystem.
535 The organization of the hints file is not unlike that of an
536 .Dq a.out
537 object file, in that it contains a header determining the offset and size
538 of a table of fixed sized hash buckets and a common string pool.
539 .Bd -literal -offset indent
540 struct hints_header {
541         long            hh_magic;
542 #define HH_MAGIC        011421044151
543         long            hh_version;
544 #define LD_HINTS_VERSION_1      1
545         long            hh_hashtab;
546         long            hh_nbucket;
547         long            hh_strtab;
548         long            hh_strtab_sz;
549         long            hh_ehints;
550 };
551 .Ed
552 .Bl -tag -width hh_strtab_sz
553 .It Fa hh_magic
554 Hints file magic number.
555 .It Fa hh_version
556 Interface version number.
557 .It Fa hh_hashtab
558 Offset of hash table.
559 .It Fa hh_strtab
560 Offset of string table.
561 .It Fa hh_strtab_sz
562 Size of strings.
563 .It Fa hh_ehints
564 Maximum usable offset in hints file.
565 .El
566 .Pp
567 .Bd -literal -offset indent
568 /*
569  * Hash table element in hints file.
570  */
571 struct hints_bucket {
572         int             hi_namex;
573         int             hi_pathx;
574         int             hi_dewey[MAXDEWEY];
575         int             hi_ndewey;
576 #define hi_major hi_dewey[0]
577 #define hi_minor hi_dewey[1]
578         int             hi_next;
579 };
580 .Ed
581 .Bl -tag -width hi_ndewey
582 .It Fa hi_namex
583 Index of the string identifying the library.
584 .It Fa hi_pathx
585 Index of the string representing the full path name of the library.
586 .It Fa hi_dewey
587 The version numbers of the shared library.
588 .It Fa hi_ndewey
589 The number of valid entries in
590 .Fa hi_dewey .
591 .It Fa hi_next
592 Next bucket in case of hashing collisions.
593 .El
594 .Sh CAVEATS
595 Only the (GNU) C compiler currently supports the creation of shared libraries.
596 Other programming languages cannot be used.