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.
34 .Nd dynamic loader and link editor interface
42 declares several structures that are present in dynamically linked
43 programs and libraries.
44 The structures define the interface between several components of the
45 link-editor and loader mechanism.
46 The layout of a number of these
47 structures within the binaries resembles the a.out format in many places
48 as it serves such similar functions as symbol definitions (including the
49 accompanying string table) and relocation records needed to resolve
50 references to external entities.
51 It also records a number of data structures
52 unique to the dynamic loading and linking process.
53 These include references
54 to other objects that are required to complete the link-editing process and
55 indirection tables to facilitate
56 .Em Position Independent Code
57 (PIC for short) to improve sharing of code pages among different processes.
58 The collection of data structures described here will be referred to as the
59 .Em Run-time Relocation Section (RRS)
60 and is embedded in the standard text and data segments of the dynamically
61 linked program or shared object image as the existing
63 format offers no room for it elsewhere.
65 Several utilities cooperate to ensure that the task of getting a program
66 ready to run can complete successfully in a way that optimizes the use
68 The compiler emits PIC code from which shared libraries
71 The compiler also includes size information of any initialized data items
72 through the .size assembler directive.
73 PIC code differs from conventional code
74 in that it accesses data variables through an indirection table, the
75 Global Offset Table, by convention accessible by the reserved name
76 .Dv _GLOBAL_OFFSET_TABLE_ .
77 The exact mechanism used for this is machine dependent, usually a machine
78 register is reserved for the purpose.
79 The rational behind this construct
80 is to generate code that is independent of the actual load address.
82 the values contained in the Global Offset Table may need updating at run-time
83 depending on the load addresses of the various shared objects in the address
86 Likewise, procedure calls to globally defined functions are redirected through
87 the Procedure Linkage Table (PLT) residing in the data segment of the core
89 Again, this is done to avoid run-time modifications to the text segment.
91 The linker-editor allocates the Global Offset Table and Procedure Linkage Table
92 when combining PIC object files into an image suitable for mapping into the
93 process address space.
94 It also collects all symbols that may be needed by the
95 run-time link-editor and stores these along with the image's text and data bits.
96 Another reserved symbol,
98 is used to indicate the presence of the run-time linker structures.
100 _DYNAMIC is relocated to 0, there is no need to invoke the run-time
102 If this symbol is non-zero, it points at a data structure from
103 which the location of the necessary relocation- and symbol information can
105 This is most notably used by the start-up module,
107 The _DYNAMIC structure is conventionally located at the start of the data
108 segment of the image to which it pertains.
110 The data structures supporting dynamic linking and run-time relocation
111 reside both in the text and data segments of the image they apply to.
112 The text segments contain read-only data such as symbols descriptions and
113 names, while the data segments contain the tables that need to be modified by
114 during the relocation process.
116 The _DYNAMIC symbol references a
119 .Bd -literal -offset indent
122 struct so_debug *d_debug;
124 struct section_dispatch_table *d_sdt;
126 struct ld_entry *d_entry;
129 .Bl -tag -width d_version
131 This field provides for different versions of the dynamic linking
133 The current version numbers understood by
138 .Em LD_VERSION_SUN (3) ,
142 .Em LD_VERSION_BSD (8) ,
143 which has been in use since
148 dependent data structure.
150 this field provides debuggers with a hook to access symbol tables of shared
151 objects loaded as a result of the actions of the run-time link-editor.
155 .Fa section_dispatch_table
156 structure is the main
158 table, containing offsets into the image's segments where various symbol
159 and relocation information is located.
160 .Bd -literal -offset indent
161 struct section_dispatch_table {
162 struct so_map *sdt_loaded;
178 .Bl -tag -width sdt_filler1
180 A pointer to the first link map loaded (see below).
184 The start of a (linked) list of shared object descriptors needed by
188 Deprecated (used by SunOS to specify library search rules).
190 The location of the Global Offset Table within this image.
192 The location of the Procedure Linkage Table within this image.
194 The location of an array of
199 specifying run-time relocations.
201 The location of the hash table for fast symbol lookup in this object's
204 The location of the symbol table.
208 The number of buckets in
211 The location of the symbol string table that goes with
214 The size of the string table.
216 The size of the object's text segment.
218 The size of the Procedure Linkage Table.
223 structure describes a shared object that is needed
224 to complete the link edit process of the object containing it.
225 A list of such objects
231 in the section_dispatch_table structure.
232 .Bd -literal -offset indent
235 u_int sod_library : 1,
242 .Bl -tag -width sod_library
244 The offset in the text segment of a string describing this link object.
248 specifies a library that is to be searched for by
251 is obtained by searching a set of directories
254 for a shared object matching
255 .Em lib\&<sod_name>\&.so.n.m .
258 should point at a full path name for the desired shared object.
260 Specifies the major version number of the shared object to load.
262 Specifies the preferred minor version number of the shared object to load.
265 The run-time link-editor maintains a list of structures called
267 to keep track of all shared objects loaded into a process' address space.
268 These structures are only used at run-time and do not occur within
269 the text or data segment of an executable or shared library.
270 .Bd -literal -offset indent
274 struct so_map *som_next;
278 struct _dynamic *som_dynamic;
282 .Bl -tag -width som_dynamic
284 The address at which the shared object associated with this link map has
287 The full path name of the loaded object.
289 Pointer to the next link map.
293 structure that was responsible for loading this shared object.
295 Tossed out in later versions of the run-time linker.
297 Set if (some portion of) this object's text segment is currently writable.
299 Pointer to this object's
303 Hook for attaching private data maintained by the run-time link-editor.
306 Symbol description with size.
309 structure with one field
312 Used to convey size information on items in the data segment
314 An array of these lives in the shared object's
315 text segment and is addressed by the
318 .Fa section_dispatch_table .
319 .Bd -literal -offset indent
323 #define nz_un nlist.n_un
324 #define nz_strx nlist.n_un.n_strx
325 #define nz_name nlist.n_un.n_name
326 #define nz_type nlist.n_type
327 #define nz_value nlist.n_value
328 #define nz_desc nlist.n_desc
329 #define nz_other nlist.n_other
332 .Bl -tag -width nz_size
337 The size of the data represented by this symbol.
340 A hash table is included within the text segment of shared object
341 to facilitate quick lookup of symbols during run-time link-editing.
345 .Fa section_dispatch_table
346 structure points at an array of
349 .Bd -literal -offset indent
351 int rh_symbolnum; /* symbol number */
352 int rh_next; /* next hash entry */
355 .Bl -tag -width rh_symbolnum
357 The index of the symbol in the shared object's symbol table (as given by the
361 In case of collisions, this field is the offset of the next entry in this
363 It is zero for the last bucket element.
367 structure is used to keep track of run-time allocated commons
368 and data items copied from shared objects.
369 These items are kept on linked list
370 and is exported through the
374 structure (see below) for use by debuggers.
375 .Bd -literal -offset indent
377 struct nzlist *rt_sp;
378 struct rt_symbol *rt_next;
379 struct rt_symbol *rt_link;
381 struct so_map *rt_smp;
384 .Bl -tag -width rt_scraddr
386 The symbol description.
388 Virtual address of next rt_symbol.
394 Location of the source of initialized data within a shared object.
396 The shared object which is the original source of the data that this
397 run-time symbol describes.
402 structure is used by debuggers to gain knowledge of any shared objects
403 that have been loaded in the process's address space as a result of run-time
405 Since the run-time link-editor runs as a part of process
406 initialization, a debugger that wishes to access symbols from shared objects
407 can only do so after the link-editor has been called from crt0.
408 A dynamically linked binary contains a
410 structure which can be located by means of the
414 .Bd -literal -offset indent
421 struct rt_symbol *dd_cc;
424 .Bl -tag -width dd_in_debugger
426 Version number of this interface.
427 .It Fa dd_in_debugger
428 Set by the debugger to indicate to the run-time linker that the program is
429 run under control of a debugger.
431 Set by the run-time linker whenever it adds symbols by loading shared objects.
433 The address where a breakpoint will be set by the run-time linker to
434 divert control to the debugger.
435 This address is determined by the start-up
438 to be some convenient place before the call to _main.
440 Contains the original instruction that was at
442 The debugger is expected to put this instruction back before continuing the
445 A pointer to the linked list of run-time allocated symbols that the debugger
446 may be interested in.
451 structure defines a set of service routines within
455 .\" for more information.
456 .Bd -literal -offset indent
458 void *(*dlopen)(char *, int);
459 int (*dlclose)(void *);
460 void *(*dlsym)(void *, char *);
461 char *(*dlerror)(void);
467 structure defines the interface between the start-up code in crt0 and
469 .Bd -literal -offset indent
474 struct _dynamic *crt_dp;
479 struct ld_entry *crt_ldentry;
481 #define CRT_VERSION_SUN 1
482 #define CRT_VERSION_BSD_2 2
483 #define CRT_VERSION_BSD_3 3
484 #define CRT_VERSION_BSD_4 4
486 .Bl -tag -width crt_dzfd
488 The virtual address at which
492 On SunOS systems, this field contains an open file descriptor to
494 used to get demand paged zeroed pages.
497 systems it contains -1.
499 Contains an open file descriptor that was used by crt0 to load
506 A pointer to the environment strings.
508 The address at which a breakpoint will be placed by the run-time linker
509 if the main program is run by a debugger.
513 The name of the main program as determined by crt0 (CRT_VERSION_BSD3 only).
515 The path of the run-time linker as mapped by crt0 (CRT_VERSION_BSD4 only).
522 structures define the layout of the library hints, normally found in
523 .Dq Pa /var/run/ld.so.hints ,
526 to quickly locate the shared object images in the
528 The organization of the hints file is not unlike that of an
530 object file, in that it contains a header determining the offset and size
531 of a table of fixed sized hash buckets and a common string pool.
532 .Bd -literal -offset indent
533 struct hints_header {
535 #define HH_MAGIC 011421044151
537 #define LD_HINTS_VERSION_1 1
545 .Bl -tag -width hh_strtab_sz
547 Hints file magic number.
549 Interface version number.
551 Offset of hash table.
553 Offset of string table.
557 Maximum usable offset in hints file.
559 .Bd -literal -offset indent
561 * Hash table element in hints file.
563 struct hints_bucket {
566 int hi_dewey[MAXDEWEY];
568 #define hi_major hi_dewey[0]
569 #define hi_minor hi_dewey[1]
573 .Bl -tag -width hi_ndewey
575 Index of the string identifying the library.
577 Index of the string representing the full path name of the library.
579 The version numbers of the shared library.
581 The number of valid entries in
584 Next bucket in case of hashing collisions.
587 Only the (GNU) C compiler currently supports the creation of shared libraries.
588 Other programming languages cannot be used.