1 .\" Copyright (c) 1993 Paul Kranenburg
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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
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.
29 .\" $FreeBSD: src/share/man/man5/link.5,v 1.14.2.10 2004/05/17 11:38:55 brueffer Exp $
36 .Nd dynamic loader and link editor interface
44 declares several structures that are present in dynamically linked
45 programs and libraries.
46 The structures define the interface between several components of the
47 link-editor and loader mechanism.
48 The layout of a number of these
49 structures within the binaries resembles the a.out format in many places
50 as it serves such similar functions as symbol definitions (including the
51 accompanying string table) and relocation records needed to resolve
52 references to external entities.
53 It also records a number of data structures
54 unique to the dynamic loading and linking process.
55 These include references
56 to other objects that are required to complete the link-editing process and
57 indirection tables to facilitate
58 .Em Position Independent Code
59 (PIC for short) to improve sharing of code pages among different processes.
60 The collection of data structures described here will be referred to as the
61 .Em Run-time Relocation Section (RRS)
62 and is embedded in the standard text and data segments of the dynamically
63 linked program or shared object image as the existing
65 format offers no room for it elsewhere.
67 Several utilities cooperate to ensure that the task of getting a program
68 ready to run can complete successfully in a way that optimizes the use
70 The compiler emits PIC code from which shared libraries
73 The compiler also includes size information of any initialized data items
74 through the .size assembler directive.
75 PIC code differs from conventional code
76 in that it accesses data variables through an indirection table, the
77 Global Offset Table, by convention accessible by the reserved name
78 .Dv _GLOBAL_OFFSET_TABLE_ .
79 The exact mechanism used for this is machine dependent, usually a machine
80 register is reserved for the purpose.
81 The rationale behind this construct
82 is to generate code that is independent of the actual load address.
84 the values contained in the Global Offset Table may need updating at run-time
85 depending on the load addresses of the various shared objects in the address
88 Likewise, procedure calls to globally defined functions are redirected through
89 the Procedure Linkage Table (PLT) residing in the data segment of the core
91 Again, this is done to avoid run-time modifications to the text segment.
93 The linker-editor allocates the Global Offset Table and Procedure Linkage Table
94 when combining PIC object files into an image suitable for mapping into the
95 process address space.
96 It also collects all symbols that may be needed by the
97 run-time link-editor and stores these along with the image's text and data bits.
98 Another reserved symbol,
100 is used to indicate the presence of the run-time linker structures.
102 _DYNAMIC is relocated to 0, there is no need to invoke the run-time
104 If this symbol is non-zero, it points at a data structure from
105 which the location of the necessary relocation- and symbol information can
107 This is most notably used by the start-up module,
109 The _DYNAMIC structure is conventionally located at the start of the data
110 segment of the image to which it pertains.
112 The data structures supporting dynamic linking and run-time relocation
113 reside both in the text and data segments of the image they apply to.
114 The text segments contain read-only data such as symbols descriptions and
115 names, while the data segments contain the tables that need to be modified by
116 during the relocation process.
118 The _DYNAMIC symbol references a
121 .Bd -literal -offset indent
124 struct so_debug *d_debug;
126 struct section_dispatch_table *d_sdt;
128 struct ld_entry *d_entry;
131 .Bl -tag -width d_version
133 This field provides for different versions of the dynamic linking
135 The current version numbers understood by
140 .Em LD_VERSION_SUN (3) ,
144 .Em LD_VERSION_BSD (8) ,
145 which has been in use since
150 dependent data structure.
152 this field provides debuggers with a hook to access symbol tables of shared
153 objects loaded as a result of the actions of the run-time link-editor.
157 .Fa section_dispatch_table
158 structure is the main
160 table, containing offsets into the image's segments where various symbol
161 and relocation information is located.
162 .Bd -literal -offset indent
163 struct section_dispatch_table {
164 struct so_map *sdt_loaded;
180 .Bl -tag -width sdt_filler1
182 A pointer to the first link map loaded (see below). This field is set by
185 The start of a (linked) list of shared object descriptors needed by
189 Deprecated (used by SunOS to specify library search rules).
191 The location of the Global Offset Table within this image.
193 The location of the Procedure Linkage Table within this image.
195 The location of an array of
200 specifying run-time relocations.
202 The location of the hash table for fast symbol lookup in this object's
205 The location of the symbol table.
209 The number of buckets in
212 The location of the symbol string table that goes with
215 The size of the string table.
217 The size of the object's text segment.
219 The size of the Procedure Linkage Table.
224 structure describes a shared object that is needed
225 to complete the link edit process of the object containing it.
226 A list of such objects
232 in the section_dispatch_table structure.
233 .Bd -literal -offset indent
236 u_int sod_library : 1,
243 .Bl -tag -width sod_library
245 The offset in the text segment of a string describing this link object.
249 specifies a library that is to be searched for by
252 is obtained by searching a set of directories
255 for a shared object matching
256 .Em lib\&<sod_name>\&.so.n.m .
259 should point at a full path name for the desired shared object.
261 Specifies the major version number of the shared object to load.
263 Specifies the preferred minor version number of the shared object to load.
266 The run-time link-editor maintains a list of structures called
268 to keep track of all shared objects loaded into a process' address space.
269 These structures are only used at run-time and do not occur within
270 the text or data segment of an executable or shared library.
271 .Bd -literal -offset indent
275 struct so_map *som_next;
279 struct _dynamic *som_dynamic;
283 .Bl -tag -width som_dynamic
285 The address at which the shared object associated with this link map has
288 The full path name of the loaded object.
290 Pointer to the next link map.
294 structure that was responsible for loading this shared object.
296 Tossed out in later versions of the run-time linker.
298 Set if (some portion of) this object's text segment is currently writable.
300 Pointer to this object's
304 Hook for attaching private data maintained by the run-time link-editor.
307 Symbol description with size.
310 structure with one field
313 Used to convey size information on items in the data segment
315 An array of these lives in the shared object's
316 text segment and is addressed by the
319 .Fa section_dispatch_table .
320 .Bd -literal -offset indent
324 #define nz_un nlist.n_un
325 #define nz_strx nlist.n_un.n_strx
326 #define nz_name nlist.n_un.n_name
327 #define nz_type nlist.n_type
328 #define nz_value nlist.n_value
329 #define nz_desc nlist.n_desc
330 #define nz_other nlist.n_other
333 .Bl -tag -width nz_size
338 The size of the data represented by this symbol.
341 A hash table is included within the text segment of shared object
342 to facilitate quick lookup of symbols during run-time link-editing.
346 .Fa section_dispatch_table
347 structure points at an array of
350 .Bd -literal -offset indent
352 int rh_symbolnum; /* symbol number */
353 int rh_next; /* next hash entry */
356 .Bl -tag -width rh_symbolnum
358 The index of the symbol in the shared object's symbol table (as given by the
362 In case of collisions, this field is the offset of the next entry in this
364 It is zero for the last bucket element.
368 structure is used to keep track of run-time allocated commons
369 and data items copied from shared objects.
370 These items are kept on linked list
371 and is exported through the
375 structure (see below) for use by debuggers.
376 .Bd -literal -offset indent
378 struct nzlist *rt_sp;
379 struct rt_symbol *rt_next;
380 struct rt_symbol *rt_link;
382 struct so_map *rt_smp;
385 .Bl -tag -width rt_scraddr
387 The symbol description.
389 Virtual address of next rt_symbol.
395 Location of the source of initialized data within a shared object.
397 The shared object which is the original source of the data that this
398 run-time symbol describes.
403 structure is used by debuggers to gain knowledge of any shared objects
404 that have been loaded in the process's address space as a result of run-time
406 Since the run-time link-editor runs as a part of process
407 initialization, a debugger that wishes to access symbols from shared objects
408 can only do so after the link-editor has been called from crt0.
409 A dynamically linked binary contains a
411 structure which can be located by means of the
415 .Bd -literal -offset indent
422 struct rt_symbol *dd_cc;
425 .Bl -tag -width dd_in_debugger
427 Version number of this interface.
428 .It Fa dd_in_debugger
429 Set by the debugger to indicate to the run-time linker that the program is
430 run under control of a debugger.
432 Set by the run-time linker whenever it adds symbols by loading shared objects.
434 The address where a breakpoint will be set by the run-time linker to
435 divert control to the debugger.
436 This address is determined by the start-up
439 to be some convenient place before the call to _main.
441 Contains the original instruction that was at
443 The debugger is expected to put this instruction back before continuing the
446 A pointer to the linked list of run-time allocated symbols that the debugger
447 may be interested in.
452 structure defines a set of service routines within
456 .\" for more information.
457 .Bd -literal -offset indent
459 void *(*dlopen)(char *, int);
460 int (*dlclose)(void *);
461 void *(*dlsym)(void *, char *);
462 char *(*dlerror)(void);
468 structure defines the interface between the start-up code in crt0 and
470 .Bd -literal -offset indent
475 struct _dynamic *crt_dp;
480 struct ld_entry *crt_ldentry;
482 #define CRT_VERSION_SUN 1
483 #define CRT_VERSION_BSD_2 2
484 #define CRT_VERSION_BSD_3 3
485 #define CRT_VERSION_BSD_4 4
487 .Bl -tag -width crt_dzfd
489 The virtual address at which
493 On SunOS systems, this field contains an open file descriptor to
495 used to get demand paged zeroed pages.
498 systems it contains -1.
500 Contains an open file descriptor that was used by crt0 to load
507 A pointer to the environment strings.
509 The address at which a breakpoint will be placed by the run-time linker
510 if the main program is run by a debugger.
514 The name of the main program as determined by crt0 (CRT_VERSION_BSD3 only).
516 The path of the run-time linker as mapped by crt0 (CRT_VERSION_BSD4 only).
523 structures define the layout of the library hints, normally found in
524 .Dq Pa /var/run/ld-elf.so.hints ,
527 to quickly locate the shared object images in the
529 The organization of the hints file is not unlike that of an
531 object file, in that it contains a header determining the offset and size
532 of a table of fixed sized hash buckets and a common string pool.
533 .Bd -literal -offset indent
534 struct hints_header {
536 #define HH_MAGIC 011421044151
538 #define LD_HINTS_VERSION_1 1
546 .Bl -tag -width hh_strtab_sz
548 Hints file magic number.
550 Interface version number.
552 Offset of hash table.
554 Offset of string table.
558 Maximum usable offset in hints file.
560 .Bd -literal -offset indent
562 * Hash table element in hints file.
564 struct hints_bucket {
567 int hi_dewey[MAXDEWEY];
569 #define hi_major hi_dewey[0]
570 #define hi_minor hi_dewey[1]
574 .Bl -tag -width hi_ndewey
576 Index of the string identifying the library.
578 Index of the string representing the full path name of the library.
580 The version numbers of the shared library.
582 The number of valid entries in
585 Next bucket in case of hashing collisions.
588 Only the (GNU) C compiler currently supports the creation of shared libraries.
589 Other programming languages cannot be used.