xref: /freebsd/share/man/man5/link.5 (revision dd76c703875c7e1ce786d4d123ee0457d18e7024)
1b35481d4SNate Williams.\" Copyright (c) 1993 Paul Kranenburg
2b35481d4SNate Williams.\" All rights reserved.
3b35481d4SNate Williams.\"
4b35481d4SNate Williams.\" Redistribution and use in source and binary forms, with or without
5b35481d4SNate Williams.\" modification, are permitted provided that the following conditions
6b35481d4SNate Williams.\" are met:
7b35481d4SNate Williams.\" 1. Redistributions of source code must retain the above copyright
8b35481d4SNate Williams.\"    notice, this list of conditions and the following disclaimer.
9b35481d4SNate Williams.\" 2. Redistributions in binary form must reproduce the above copyright
10b35481d4SNate Williams.\"    notice, this list of conditions and the following disclaimer in the
11b35481d4SNate Williams.\"    documentation and/or other materials provided with the distribution.
12b35481d4SNate Williams.\" 3. All advertising materials mentioning features or use of this software
13b35481d4SNate Williams.\"    must display the following acknowledgement:
14b35481d4SNate Williams.\"      This product includes software developed by Paul Kranenburg.
15b35481d4SNate Williams.\" 3. The name of the author may not be used to endorse or promote products
16b35481d4SNate Williams.\"    derived from this software without specific prior written permission
17b35481d4SNate Williams.\"
18b35481d4SNate Williams.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19b35481d4SNate Williams.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20b35481d4SNate Williams.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21b35481d4SNate Williams.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22b35481d4SNate Williams.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23b35481d4SNate Williams.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24b35481d4SNate Williams.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25b35481d4SNate Williams.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26b35481d4SNate Williams.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27b35481d4SNate Williams.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28b35481d4SNate Williams.\"
297f3dea24SPeter Wemm.\" $FreeBSD$
30b35481d4SNate Williams.\"
31b35481d4SNate Williams.Dd October 23, 1993
32b35481d4SNate Williams.Dt LINK 5
33b35481d4SNate Williams.Os
34b35481d4SNate Williams.Sh NAME
35b35481d4SNate Williams.Nm link
36b35481d4SNate Williams.Nd dynamic loader and link editor interface
37b35481d4SNate Williams.Sh SYNOPSIS
3850e9e209SBruce Evans.Fd #include <sys/types.h>
3950e9e209SBruce Evans.Fd #include <nlist.h>
40b35481d4SNate Williams.Fd #include <link.h>
41b35481d4SNate Williams.Sh DESCRIPTION
42b35481d4SNate WilliamsThe include file
43b35481d4SNate Williams.Aq Pa link.h
44b35481d4SNate Williamsdeclares several structures that are present in dynamically linked
45b35481d4SNate Williamsprograms and libraries.
46b35481d4SNate WilliamsThe structures define the interface between several components of the
474e86fcacSSheldon Hearnlink-editor and loader mechanism.
484e86fcacSSheldon HearnThe layout of a number of these
49b35481d4SNate Williamsstructures within the binaries resembles the a.out format in many places
50b35481d4SNate Williamsas it serves such similar functions as symbol definitions (including the
51b35481d4SNate Williamsaccompanying string table) and relocation records needed to resolve
524e86fcacSSheldon Hearnreferences to external entities.
534e86fcacSSheldon HearnIt also records a number of data structures
544e86fcacSSheldon Hearnunique to the dynamic loading and linking process.
554e86fcacSSheldon HearnThese include references
56b35481d4SNate Williamsto other objects that are required to complete the link-editing process and
57b35481d4SNate Williamsindirection tables to facilitate
58b35481d4SNate Williams.Em Position Independent Code
59b35481d4SNate Williams(PIC for short) to improve sharing of code pages among different processes.
604a8d0283SMike PritchardThe collection of data structures described here will be referred to as the
61b35481d4SNate Williams.Em Run-time Relocation Section (RRS)
62b35481d4SNate Williamsand is embedded in the standard text and data segments of the dynamically
63b35481d4SNate Williamslinked program or shared object image as the existing
64edf0e5b3SMike Pritchard.Xr a.out 5
65b35481d4SNate Williamsformat offers no room for it elsewhere.
66b35481d4SNate Williams.Pp
67b35481d4SNate WilliamsSeveral utilities cooperate to ensure that the task of getting a program
68b35481d4SNate Williamsready to run can complete successfully in a way that optimizes the use
694e86fcacSSheldon Hearnof system resources.
704e86fcacSSheldon HearnThe compiler emits PIC code from which shared libraries
71270d3d75SMike Pritchardcan be built by
72b35481d4SNate Williams.Xr ld 1 .
73b35481d4SNate WilliamsThe compiler also includes size information of any initialized data items
744e86fcacSSheldon Hearnthrough the .size assembler directive.
754e86fcacSSheldon HearnPIC code differs from conventional code
76b35481d4SNate Williamsin that it accesses data variables through an indirection table, the
774a8d0283SMike PritchardGlobal Offset Table, by convention accessible by the reserved name
78d0353b83SRuslan Ermilov.Dv _GLOBAL_OFFSET_TABLE_ .
79b35481d4SNate WilliamsThe exact mechanism used for this is machine dependent, usually a machine
804e86fcacSSheldon Hearnregister is reserved for the purpose.
814e86fcacSSheldon HearnThe rational behind this construct
824e86fcacSSheldon Hearnis to generate code that is independent of the actual load address.
834e86fcacSSheldon HearnOnly
84b35481d4SNate Williamsthe values contained in the Global Offset Table may need updating at run-time
85b35481d4SNate Williamsdepending on the load addresses of the various shared objects in the address
86b35481d4SNate Williamsspace.
87b35481d4SNate Williams.Pp
88b35481d4SNate WilliamsLikewise, procedure calls to globally defined functions are redirected through
89b35481d4SNate Williamsthe Procedure Linkage Table (PLT) residing in the data segment of the core
904e86fcacSSheldon Hearnimage.
914e86fcacSSheldon HearnAgain, this is done to avoid run-time modifications to the text segment.
92b35481d4SNate Williams.Pp
93b35481d4SNate WilliamsThe linker-editor allocates the Global Offset Table and Procedure Linkage Table
94b35481d4SNate Williamswhen combining PIC object files into an image suitable for mapping into the
954e86fcacSSheldon Hearnprocess address space.
964e86fcacSSheldon HearnIt also collects all symbols that may be needed by the
97b35481d4SNate Williamsrun-time link-editor and stores these along with the image's text and data bits.
98b35481d4SNate WilliamsAnother reserved symbol,
99b35481d4SNate Williams.Em _DYNAMIC
1004e86fcacSSheldon Hearnis used to indicate the presence of the run-time linker structures.
1014e86fcacSSheldon HearnWhenever
102b35481d4SNate Williams_DYNAMIC is relocated to 0, there is no need to invoke the run-time
1034e86fcacSSheldon Hearnlink-editor.
1044e86fcacSSheldon HearnIf this symbol is non-zero, it points at a data structure from
105b35481d4SNate Williamswhich the location of the necessary relocation- and symbol information can
1064e86fcacSSheldon Hearnbe derived.
1074e86fcacSSheldon HearnThis is most notably used by the start-up module,
108b35481d4SNate Williams.Em crt0 .
109b35481d4SNate WilliamsThe _DYNAMIC structure is conventionally located at the start of the data
110b35481d4SNate Williamssegment of the image to which it pertains.
111b35481d4SNate Williams.Pp
112b35481d4SNate Williams.Sh DATA STRUCTURES
113b35481d4SNate WilliamsThe data structures supporting dynamic linking and run-time relocation
114b35481d4SNate Williamsreside both in the text and data segments of the image they apply to.
115b35481d4SNate WilliamsThe text segments contain read-only data such as symbols descriptions and
116b35481d4SNate Williamsnames, while the data segments contain the tables that need to be modified by
117b35481d4SNate Williamsduring the relocation process.
118b35481d4SNate Williams.Pp
119b35481d4SNate WilliamsThe _DYNAMIC symbol references a
120b35481d4SNate Williams.Fa _dynamic
121b35481d4SNate Williamsstructure:
122b35481d4SNate Williams.Bd -literal -offset indent
123b35481d4SNate Williamsstruct	_dynamic {
124b35481d4SNate Williams	int	d_version;
125b35481d4SNate Williams	struct 	so_debug *d_debug;
126b35481d4SNate Williams	union {
127b35481d4SNate Williams		struct section_dispatch_table *d_sdt;
128b35481d4SNate Williams	} d_un;
129b35481d4SNate Williams	struct  ld_entry *d_entry;
130b35481d4SNate Williams};
131b35481d4SNate Williams.Ed
132b35481d4SNate Williams.Bl -tag -width d_version
133b35481d4SNate Williams.It Fa d_version
134b35481d4SNate WilliamsThis field provides for different versions of the dynamic linking
1354e86fcacSSheldon Hearnimplementation.
1364e86fcacSSheldon HearnThe current version numbers understood by
137edf0e5b3SMike Pritchard.Xr ld 1
138edf0e5b3SMike Pritchardand
139edf0e5b3SMike Pritchard.Xr ld.so 1
140edf0e5b3SMike Pritchardare
141b35481d4SNate Williams.Em LD_VERSION_SUN (3) ,
142dd5527c6SMike Pritchardwhich is used by the
143dd5527c6SMike Pritchard.Tn SunOS
144dd5527c6SMike Pritchard4.x releases, and
145b35481d4SNate Williams.Em LD_VERSION_BSD (8) ,
146dd5527c6SMike Pritchardwhich has been in use since
147dd5527c6SMike Pritchard.Fx 1.1 .
148b35481d4SNate Williams.It Fa d_un
149b35481d4SNate WilliamsRefers to a
150b35481d4SNate Williams.Em d_version
151b35481d4SNate Williamsdependent data structure.
152b35481d4SNate Williams.It Fa so_debug
153b35481d4SNate Williamsthis field provides debuggers with a hook to access symbol tables of shared
154b35481d4SNate Williamsobjects loaded as a result of the actions of the run-time link-editor.
155b35481d4SNate Williams.El
156b35481d4SNate Williams.Pp
157b35481d4SNate WilliamsThe
158b35481d4SNate Williams.Fa section_dispatch_table
159b35481d4SNate Williamsstructure is the main
160b35481d4SNate Williams.Dq dispatcher
161b35481d4SNate Williamstable, containing offsets into the image's segments where various symbol
162b35481d4SNate Williamsand relocation information is located.
163b35481d4SNate Williams.Bd -literal -offset indent
164b35481d4SNate Williamsstruct section_dispatch_table {
165b35481d4SNate Williams	struct	so_map *sdt_loaded;
166b35481d4SNate Williams	long	sdt_sods;
167b35481d4SNate Williams	long	sdt_filler1;
168b35481d4SNate Williams	long	sdt_got;
169b35481d4SNate Williams	long	sdt_plt;
170b35481d4SNate Williams	long	sdt_rel;
171b35481d4SNate Williams	long	sdt_hash;
172b35481d4SNate Williams	long	sdt_nzlist;
173b35481d4SNate Williams	long	sdt_filler2;
174b35481d4SNate Williams	long	sdt_buckets;
175b35481d4SNate Williams	long	sdt_strings;
176b35481d4SNate Williams	long	sdt_str_sz;
177b35481d4SNate Williams	long	sdt_text_sz;
178b35481d4SNate Williams	long	sdt_plt_sz;
179b35481d4SNate Williams};
180b35481d4SNate Williams.Ed
181b35481d4SNate Williams.Pp
182b35481d4SNate Williams.Bl -tag -width sdt_filler1
183b35481d4SNate Williams.It Fa sdt_loaded
184b35481d4SNate WilliamsA pointer to the first link map loaded (see below). This field is set by
185edf0e5b3SMike Pritchard.Nm ld.so
186b35481d4SNate Williams.It Fa sdt_sods
187b35481d4SNate WilliamsThe start of a (linked) list of shared object descriptors needed by
188b35481d4SNate Williams.Em this
189b35481d4SNate Williamsobject.
190b35481d4SNate Williams.It Fa sdt_filler1
1914a8d0283SMike PritchardDeprecated (used by SunOS to specify library search rules).
192b35481d4SNate Williams.It Fa sdt_got
193b35481d4SNate WilliamsThe location of the Global Offset Table within this image.
194b35481d4SNate Williams.It Fa sdt_plt
195b35481d4SNate WilliamsThe location of the Procedure Linkage Table within this image.
196b35481d4SNate Williams.It Fa sdt_rel
197b35481d4SNate WilliamsThe location of an array of
198b35481d4SNate Williams.Fa relocation_info
199b35481d4SNate Williamsstructures
200b35481d4SNate Williams.Po
201b35481d4SNate Williamssee
202b35481d4SNate Williams.Xr a.out 5
203b35481d4SNate Williams.Pc
204b35481d4SNate Williamsspecifying run-time relocations.
205b35481d4SNate Williams.It Fa sdt_hash
206b35481d4SNate WilliamsThe location of the hash table for fast symbol lookup in this object's
207b35481d4SNate Williamssymbol table.
208b35481d4SNate Williams.It Fa sdt_nzlist
209b35481d4SNate WilliamsThe location of the symbol table.
210b35481d4SNate Williams.It Fa sdt_filler2
211b35481d4SNate WilliamsCurrently unused.
212b35481d4SNate Williams.It Fa sdt_buckets
213b35481d4SNate WilliamsThe number of buckets in
214b35481d4SNate Williams.Fa sdt_hash
215b35481d4SNate Williams.It Fa sdt_strings
216b35481d4SNate WilliamsThe location of the symbol string table that goes with
217b35481d4SNate Williams.Fa sdt_nzlist .
218b35481d4SNate Williams.It Fa sdt_str_sz
219b35481d4SNate WilliamsThe size of the string table.
220b35481d4SNate Williams.It Fa sdt_text_sz
221b35481d4SNate WilliamsThe size of the object's text segment.
222b35481d4SNate Williams.It Fa sdt_plt_sz
223b35481d4SNate WilliamsThe size of the Procedure Linkage Table.
224b35481d4SNate Williams.El
225b35481d4SNate Williams.Pp
226b35481d4SNate WilliamsA
227b35481d4SNate Williams.Fa sod
2284a8d0283SMike Pritchardstructure describes a shared object that is needed
229b35481d4SNate Williamsto complete the link edit process of the object containing it.
230b35481d4SNate WilliamsA list of such objects
231b35481d4SNate Williams.Po
232b35481d4SNate Williamschained through
233b35481d4SNate Williams.Fa sod_next
234b35481d4SNate Williams.Pc
235b35481d4SNate Williamsis pointed at
236b35481d4SNate Williamsby the
237b35481d4SNate Williams.Fa sdt_sods
238b35481d4SNate Williamsin the section_dispatch_table structure.
239b35481d4SNate Williams.Bd -literal -offset indent
240b35481d4SNate Williamsstruct sod {
241b35481d4SNate Williams	long	sod_name;
242b35481d4SNate Williams	u_int	sod_library : 1,
24397021799SAndreas Schulz		sod_reserved : 31;
244b35481d4SNate Williams	short	sod_major;
245b35481d4SNate Williams	short	sod_minor;
246b35481d4SNate Williams	long	sod_next;
247b35481d4SNate Williams};
248b35481d4SNate Williams.Ed
249b35481d4SNate Williams.Pp
250b35481d4SNate Williams.Bl -tag -width sod_library
251b35481d4SNate Williams.It Fa sod_name
252b35481d4SNate WilliamsThe offset in the text segment of a string describing this link object.
253b35481d4SNate Williams.It Fa sod_library
254b35481d4SNate WilliamsIf set,
255b35481d4SNate Williams.Fa sod_name
256edf0e5b3SMike Pritchardspecifies a library that is to be searched for by
257edf0e5b3SMike Pritchard.Nm ld.so .
258edf0e5b3SMike PritchardThe path name
259b35481d4SNate Williamsis obtained by searching a set of directories
260b35481d4SNate Williams.Po
261b35481d4SNate Williamssee also
262b35481d4SNate Williams.Xr ldconfig 8
263b35481d4SNate Williams.Pc
264b35481d4SNate Williamsfor a shared object matching
265b35481d4SNate Williams.Em lib\&<sod_name>\&.so.n.m .
266b35481d4SNate WilliamsIf not set,
267b35481d4SNate Williams.Fa sod_name
268b35481d4SNate Williamsshould point at a full path name for the desired shared object.
269b35481d4SNate Williams.It Fa sod_major
270b35481d4SNate WilliamsSpecifies the major version number of the shared object to load.
271b35481d4SNate Williams.It Fa sod_minor
272dd76c703SKris KennawaySpecifies the preferred minor version number of the shared object to load.
273b35481d4SNate Williams.El
274b35481d4SNate Williams.Pp
275b35481d4SNate WilliamsThe run-time link-editor maintains a list of structures called
276b35481d4SNate Williams.Em link maps
277b35481d4SNate Williamsto keep track of all shared objects loaded into a process' address space.
278b35481d4SNate WilliamsThese structures are only used at run-time and do not occur within
279b35481d4SNate Williamsthe text or data segment of an executable or shared library.
280b35481d4SNate Williams.Bd -literal -offset indent
281b35481d4SNate Williamsstruct so_map {
282b35481d4SNate Williams	caddr_t	som_addr;
283b35481d4SNate Williams	char 	*som_path;
284b35481d4SNate Williams	struct	so_map *som_next;
285b35481d4SNate Williams	struct	sod *som_sod;
286b35481d4SNate Williams	caddr_t som_sodbase;
287b35481d4SNate Williams	u_int	som_write : 1;
288b35481d4SNate Williams	struct	_dynamic *som_dynamic;
289b35481d4SNate Williams	caddr_t	som_spd;
290b35481d4SNate Williams};
291b35481d4SNate Williams.Ed
292b35481d4SNate Williams.Bl -tag -width som_dynamic
293b35481d4SNate Williams.It Fa som_addr
294b35481d4SNate WilliamsThe address at which the shared object associated with this link map has
295b35481d4SNate Williamsbeen loaded.
296b35481d4SNate Williams.It Fa som_path
297b35481d4SNate WilliamsThe full path name of the loaded object.
298b35481d4SNate Williams.It Fa som_next
299b35481d4SNate WilliamsPointer to the next link map.
300b35481d4SNate Williams.It Fa som_sod
301b35481d4SNate WilliamsThe
302b35481d4SNate Williams.Fa sod
303b35481d4SNate Williamsstructure that was responsible for loading this shared object.
304b35481d4SNate Williams.It Fa som_sodbase
305b35481d4SNate WilliamsTossed in later versions the run-time linker.
306b35481d4SNate Williams.It Fa som_write
307b35481d4SNate WilliamsSet if (some portion of) this object's text segment is currently writable.
308b35481d4SNate Williams.It Fa som_dynamic
309b35481d4SNate WilliamsPointer to this object's
310b35481d4SNate Williams.Fa _dynamic
311b35481d4SNate Williamsstructure.
312b35481d4SNate Williams.It Fa som_spd
313b35481d4SNate WilliamsHook for attaching private data maintained by the run-time link-editor.
314b35481d4SNate Williams.El
315b35481d4SNate Williams.Pp
3164e86fcacSSheldon HearnSymbol description with size.
3174e86fcacSSheldon HearnThis is simply an
318b35481d4SNate Williams.Fa nlist
319b35481d4SNate Williamsstructure with one field
320b35481d4SNate Williams.Pq Fa nz_size
3214e86fcacSSheldon Hearnadded.
3224e86fcacSSheldon HearnUsed to convey size information on items in the data segment
3234e86fcacSSheldon Hearnof shared objects.
3244e86fcacSSheldon HearnAn array of these lives in the shared object's
325b35481d4SNate Williamstext segment and is addressed by the
326b35481d4SNate Williams.Fa sdt_nzlist
327b35481d4SNate Williamsfield of
328b35481d4SNate Williams.Fa section_dispatch_table .
329b35481d4SNate Williams.Bd -literal -offset indent
330b35481d4SNate Williamsstruct nzlist {
331b35481d4SNate Williams	struct nlist	nlist;
332b35481d4SNate Williams	u_long		nz_size;
333b35481d4SNate Williams#define nz_un		nlist.n_un
334b35481d4SNate Williams#define nz_strx		nlist.n_un.n_strx
335b35481d4SNate Williams#define nz_name		nlist.n_un.n_name
336b35481d4SNate Williams#define nz_type		nlist.n_type
337b35481d4SNate Williams#define nz_value	nlist.n_value
338b35481d4SNate Williams#define nz_desc		nlist.n_desc
339b35481d4SNate Williams#define nz_other	nlist.n_other
340b35481d4SNate Williams};
341b35481d4SNate Williams.Ed
342b35481d4SNate Williams.Bl -tag -width nz_size
343b35481d4SNate Williams.It Fa nlist
344b35481d4SNate Williams.Po
345b35481d4SNate Williamssee
346edf0e5b3SMike Pritchard.Xr nlist 3
347b35481d4SNate Williams.Pc .
348b35481d4SNate Williams.It Fa nz_size
349b35481d4SNate WilliamsThe size of the data represented by this symbol.
350b35481d4SNate Williams.El
351b35481d4SNate Williams.Pp
352b35481d4SNate WilliamsA hash table is included within the text segment of shared object to
353b35481d4SNate Williamsto facilitate quick lookup of symbols during run-time link-editing.
354b35481d4SNate WilliamsThe
355b35481d4SNate Williams.Fa sdt_hash
356b35481d4SNate Williamsfield of the
357b35481d4SNate Williams.Fa section_dispatch_table
358b35481d4SNate Williamsstructure points at an array of
359b35481d4SNate Williams.Fa rrs_hash
360b35481d4SNate Williamsstructures:
361b35481d4SNate Williams.Bd -literal -offset indent
362b35481d4SNate Williamsstruct rrs_hash {
363b35481d4SNate Williams	int	rh_symbolnum;		/* symbol number */
364b35481d4SNate Williams	int	rh_next;		/* next hash entry */
365b35481d4SNate Williams};
366b35481d4SNate Williams.Ed
367b35481d4SNate Williams.Pp
368b35481d4SNate Williams.Bl -tag -width rh_symbolnum
369b35481d4SNate Williams.It Fa rh_symbolnum
370b35481d4SNate WilliamsThe index of the symbol in the shared object's symbol table (as given by the
371b35481d4SNate Williams.Fa ld_symbols
372b35481d4SNate Williamsfield).
373b35481d4SNate Williams.It Fa rh_next
374b35481d4SNate WilliamsIn case of collisions, this field is the offset of the next entry in this
3754e86fcacSSheldon Hearnhash table bucket.
3764e86fcacSSheldon HearnIt is zero for the last bucket element.
377b35481d4SNate Williams.El
378b35481d4SNate WilliamsThe
379b35481d4SNate Williams.Fa rt_symbol
380b35481d4SNate Williamsstructure is used to keep track of run-time allocated commons
3814e86fcacSSheldon Hearnand data items copied from shared objects.
3824e86fcacSSheldon HearnThese items are kept on linked list
383b35481d4SNate Williamsand is exported through the
384b35481d4SNate Williams.Fa dd_cc
385b35481d4SNate Williamsfield in the
386b35481d4SNate Williams.Fa so_debug
387b35481d4SNate Williamsstructure (see below) for use by debuggers.
388b35481d4SNate Williams.Bd -literal -offset indent
389b35481d4SNate Williamsstruct rt_symbol {
390b35481d4SNate Williams	struct nzlist		*rt_sp;
391b35481d4SNate Williams	struct rt_symbol	*rt_next;
392b35481d4SNate Williams	struct rt_symbol	*rt_link;
393b35481d4SNate Williams	caddr_t			rt_srcaddr;
394b35481d4SNate Williams	struct so_map		*rt_smp;
395b35481d4SNate Williams};
396b35481d4SNate Williams.Ed
397b35481d4SNate Williams.Pp
398b35481d4SNate Williams.Bl -tag -width rt_scraddr
399b35481d4SNate Williams.It Fa rt_sp
400b35481d4SNate WilliamsThe symbol description.
401b35481d4SNate Williams.It Fa rt_next
402b35481d4SNate WilliamsVirtual address of next rt_symbol.
403b35481d4SNate Williams.It Fa rt_link
4044e86fcacSSheldon HearnNext in hash bucket.
4054e86fcacSSheldon HearnUsed by internally by
406edf0e5b3SMike Pritchard.Nm ld.so .
407b35481d4SNate Williams.It Fa rt_srcaddr
408b35481d4SNate WilliamsLocation of the source of initialized data within a shared object.
409b35481d4SNate Williams.It Fa rt_smp
410b35481d4SNate WilliamsThe shared object which is the original source of the data that this
411b35481d4SNate Williamsrun-time symbol describes.
412b35481d4SNate Williams.El
413b35481d4SNate Williams.Pp
414b35481d4SNate WilliamsThe
415b35481d4SNate Williams.Fa so_debug
416b35481d4SNate Williamsstructure is used by debuggers to gain knowledge of any shared objects
417b35481d4SNate Williamsthat have been loaded in the process's address space as a result of run-time
4184e86fcacSSheldon Hearnlink-editing.
4194e86fcacSSheldon HearnSince the run-time link-editor runs as a part of process
420b35481d4SNate Williamsinitialization, a debugger that wishes to access symbols from shared objects
421b35481d4SNate Williamscan only do so after the link-editor has been called from crt0.
422b35481d4SNate WilliamsA dynamically linked binary contains a
423b35481d4SNate Williams.Fa so_debug
424b35481d4SNate Williamsstructure which can be located by means of the
425b35481d4SNate Williams.Fa d_debug
426b35481d4SNate Williamsfield in
427b35481d4SNate Williams.Fa _dynamic .
428b35481d4SNate Williams.Bd -literal -offset indent
429b35481d4SNate Williamsstruct 	so_debug {
430b35481d4SNate Williams	int	dd_version;
431b35481d4SNate Williams	int	dd_in_debugger;
432b35481d4SNate Williams	int	dd_sym_loaded;
433b35481d4SNate Williams	char    *dd_bpt_addr;
434b35481d4SNate Williams	int	dd_bpt_shadow;
435b35481d4SNate Williams	struct rt_symbol *dd_cc;
436b35481d4SNate Williams};
437b35481d4SNate Williams.Ed
438b35481d4SNate Williams.Pp
439b35481d4SNate Williams.Bl -tag -width dd_in_debugger
440b35481d4SNate Williams.It Fa dd_version
441b35481d4SNate WilliamsVersion number of this interface.
442b35481d4SNate Williams.It Fa dd_in_debugger
443b35481d4SNate WilliamsSet by the debugger to indicate to the run-time linker that the program is
444b35481d4SNate Williamsrun under control of a debugger.
445b35481d4SNate Williams.It Fa dd_sym_loaded
446b35481d4SNate WilliamsSet by the run-time linker whenever it adds symbols by loading shared objects.
447b35481d4SNate Williams.It Fa dd_bpt_addr
448e627b39bSWolfram SchneiderThe address were a breakpoint will be set by the run-time linker to
4494e86fcacSSheldon Hearndivert control to the debugger.
4504e86fcacSSheldon HearnThis address is determined by the start-up
451b35481d4SNate Williamsmodule,
452d0353b83SRuslan Ermilov.Pa crt0.o ,
453019f1378SMike Pritchardto be some convenient place before the call to _main.
454019f1378SMike Pritchard.It Fa dd_bpt_shadow
455b35481d4SNate WilliamsContains the original instruction that was at
456b35481d4SNate Williams.Fa dd_bpt_addr .
457b35481d4SNate WilliamsThe debugger is expected to put this instruction back before continuing the
458b35481d4SNate Williamsprogram.
459b35481d4SNate Williams.It Fa dd_cc
460b35481d4SNate WilliamsA pointer to the linked list of run-time allocated symbols that the debugger
461b35481d4SNate Williamsmay be interested in.
462b35481d4SNate Williams.El
463b35481d4SNate Williams.Pp
464b35481d4SNate WilliamsThe
465b35481d4SNate Williams.Em ld_entry
466edf0e5b3SMike Pritchardstructure defines a set of service routines within
467edf0e5b3SMike Pritchard.Nm ld.so .
468edf0e5b3SMike Pritchard.\" See
469edf0e5b3SMike Pritchard.\" .Xr libdl.a
470edf0e5b3SMike Pritchard.\" for more information.
471b35481d4SNate Williams.Bd -literal -offset indent
472b35481d4SNate Williamsstruct ld_entry {
473b35481d4SNate Williams	void	*(*dlopen)(char *, int);
474b35481d4SNate Williams	int	(*dlclose)(void *);
475b35481d4SNate Williams	void	*(*dlsym)(void *, char *);
47697021799SAndreas Schulz	char	*(*dlerror)(void);
477b35481d4SNate Williams};
478b35481d4SNate Williams.Ed
4793136363fSRuslan Ermilov.Pp
480b35481d4SNate WilliamsThe
481b35481d4SNate Williams.Fa crt_ldso
482edf0e5b3SMike Pritchardstructure defines the interface between the start-up code in crt0 and
483edf0e5b3SMike Pritchard.Nm ld.so .
484b35481d4SNate Williams.Bd -literal -offset indent
485b35481d4SNate Williamsstruct crt_ldso {
486b35481d4SNate Williams	int		crt_ba;
487b35481d4SNate Williams	int		crt_dzfd;
488b35481d4SNate Williams	int		crt_ldfd;
489b35481d4SNate Williams	struct _dynamic	*crt_dp;
490b35481d4SNate Williams	char		**crt_ep;
491b35481d4SNate Williams	caddr_t		crt_bp;
492b35481d4SNate Williams	char		*crt_prog;
493b35481d4SNate Williams	char		*crt_ldso;
49497021799SAndreas Schulz	struct ld_entry	*crt_ldentry;
495b35481d4SNate Williams};
496b35481d4SNate Williams#define CRT_VERSION_SUN		1
49797021799SAndreas Schulz#define CRT_VERSION_BSD_2	2
49897021799SAndreas Schulz#define CRT_VERSION_BSD_3	3
49997021799SAndreas Schulz#define	CRT_VERSION_BSD_4	4
500b35481d4SNate Williams.Ed
501b35481d4SNate Williams.Bl -tag -width crt_dzfd
502b35481d4SNate Williams.It Fa crt_ba
503edf0e5b3SMike PritchardThe virtual address at which
504edf0e5b3SMike Pritchard.Nm ld.so
505edf0e5b3SMike Pritchardwas loaded by crt0.
506b35481d4SNate Williams.It Fa crt_dzfd
507b35481d4SNate WilliamsOn SunOS systems, this field contains an open file descriptor to
508edf0e5b3SMike Pritchard.Dq Pa /dev/zero
5094e86fcacSSheldon Hearnused to get demand paged zeroed pages.
5104e86fcacSSheldon HearnOn
511b5c508fbSRuslan Ermilov.Fx
512dd5527c6SMike Pritchardsystems it contains -1.
513b35481d4SNate Williams.It Fa crt_ldfd
514edf0e5b3SMike PritchardContains an open file descriptor that was used by crt0 to load
515edf0e5b3SMike Pritchard.Nm ld.so .
516b35481d4SNate Williams.It Fa crt_dp
517b35481d4SNate WilliamsA pointer to main's
518b35481d4SNate Williams.Fa _dynamic
519b35481d4SNate Williamsstructure.
520b35481d4SNate Williams.It Fa crt_ep
521b35481d4SNate WilliamsA pointer to the environment strings.
522b35481d4SNate Williams.It Fa crt_bp
523b35481d4SNate WilliamsThe address at which a breakpoint will be placed by the run-time linker
524b35481d4SNate Williamsif the main program is run by a debugger.
525b35481d4SNate WilliamsSee
526b35481d4SNate Williams.Fa so_debug
527b35481d4SNate Williams.It Fa crt_prog
528b35481d4SNate WilliamsThe name of the main program as determined by crt0 (CRT_VERSION_BSD3 only).
529b35481d4SNate Williams.It Fa crt_ldso
530b35481d4SNate WilliamsThe path of the run-time linker as mapped by crt0 (CRT_VERSION_BSD4 only).
531b35481d4SNate Williams.El
532b35481d4SNate Williams.Pp
533b35481d4SNate WilliamsThe
534b35481d4SNate Williams.Fa hints_header
535b35481d4SNate Williamsand
536b35481d4SNate Williams.Fa hints_bucket
537b35481d4SNate Williamsstructures define the layout of the library hints, normally found in
538edf0e5b3SMike Pritchard.Dq Pa /var/run/ld.so.hints ,
539edf0e5b3SMike Pritchardwhich is used by
540edf0e5b3SMike Pritchard.Nm ld.so
541edf0e5b3SMike Pritchardto quickly locate the shared object images in the
542b35481d4SNate Williamsfilesystem.
543b35481d4SNate WilliamsThe organization of the hints file is not unlike that of an
544b35481d4SNate Williams.Dq a.out
545b35481d4SNate Williamsobject file, in that it contains a header determining the offset and size
546b35481d4SNate Williamsof a table of fixed sized hash buckets and a common string pool.
547b35481d4SNate Williams.Bd -literal -offset indent
548b35481d4SNate Williamsstruct hints_header {
549b35481d4SNate Williams	long		hh_magic;
550b35481d4SNate Williams#define HH_MAGIC	011421044151
551b35481d4SNate Williams	long		hh_version;
552b35481d4SNate Williams#define LD_HINTS_VERSION_1	1
553b35481d4SNate Williams	long		hh_hashtab;
554b35481d4SNate Williams	long		hh_nbucket;
555b35481d4SNate Williams	long		hh_strtab;
556b35481d4SNate Williams	long		hh_strtab_sz;
557b35481d4SNate Williams	long		hh_ehints;
558b35481d4SNate Williams};
559b35481d4SNate Williams.Ed
560b35481d4SNate Williams.Bl -tag -width hh_strtab_sz
561b35481d4SNate Williams.It Fa hh_magic
562b35481d4SNate WilliamsHints file magic number.
563b35481d4SNate Williams.It Fa hh_version
564b35481d4SNate WilliamsInterface version number.
565b35481d4SNate Williams.It Fa hh_hashtab
566b35481d4SNate WilliamsOffset of hash table.
567b35481d4SNate Williams.It Fa hh_strtab
568b35481d4SNate WilliamsOffset of string table.
569b35481d4SNate Williams.It Fa hh_strtab_sz
570b35481d4SNate WilliamsSize of strings.
571b35481d4SNate Williams.It Fa hh_ehints
572b35481d4SNate WilliamsMaximum usable offset in hints file.
573b35481d4SNate Williams.El
574b35481d4SNate Williams.Pp
575b35481d4SNate Williams.Bd -literal -offset indent
576b35481d4SNate Williams/*
577b35481d4SNate Williams * Hash table element in hints file.
578b35481d4SNate Williams */
579b35481d4SNate Williamsstruct hints_bucket {
580b35481d4SNate Williams	int		hi_namex;
581b35481d4SNate Williams	int		hi_pathx;
582b35481d4SNate Williams	int		hi_dewey[MAXDEWEY];
583b35481d4SNate Williams	int		hi_ndewey;
584b35481d4SNate Williams#define hi_major hi_dewey[0]
585b35481d4SNate Williams#define hi_minor hi_dewey[1]
586b35481d4SNate Williams	int		hi_next;
587b35481d4SNate Williams};
588b35481d4SNate Williams.Ed
589b35481d4SNate Williams.Bl -tag -width hi_ndewey
590b35481d4SNate Williams.It Fa hi_namex
591b35481d4SNate WilliamsIndex of the string identifying the library.
592b35481d4SNate Williams.It Fa hi_pathx
593b35481d4SNate WilliamsIndex of the string representing the full path name of the library.
594b35481d4SNate Williams.It Fa hi_dewey
595b35481d4SNate WilliamsThe version numbers of the shared library.
596b35481d4SNate Williams.It Fa hi_ndewey
597b35481d4SNate WilliamsThe number of valid entries in
598b35481d4SNate Williams.Fa hi_dewey .
599b35481d4SNate Williams.It Fa hi_next
600b35481d4SNate WilliamsNext bucket in case of hashing collisions.
601b35481d4SNate Williams.El
602b35481d4SNate Williams.Sh CAVEATS
603b35481d4SNate WilliamsOnly the (GNU) C compiler currently supports the creation of shared libraries.
604b35481d4SNate WilliamsOther programming languages can not be used.
605