1*6577dba0Sgutteridge.\" $NetBSD: link.5,v 1.25 2022/12/29 22:41:36 gutteridge Exp $ 2730768feSpk.\" 3e8b50101Spk.\" Copyright (c) 1996 The NetBSD Foundation, Inc. 4730768feSpk.\" All rights reserved. 5730768feSpk.\" 6e8b50101Spk.\" This code is derived from software contributed to The NetBSD Foundation 7e8b50101Spk.\" by Paul Kranenburg. 8e8b50101Spk.\" 9730768feSpk.\" Redistribution and use in source and binary forms, with or without 10730768feSpk.\" modification, are permitted provided that the following conditions 11730768feSpk.\" are met: 12730768feSpk.\" 1. Redistributions of source code must retain the above copyright 13730768feSpk.\" notice, this list of conditions and the following disclaimer. 14730768feSpk.\" 2. Redistributions in binary form must reproduce the above copyright 15730768feSpk.\" notice, this list of conditions and the following disclaimer in the 16730768feSpk.\" documentation and/or other materials provided with the distribution. 17730768feSpk.\" 18e8b50101Spk.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19e8b50101Spk.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20e8b50101Spk.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21e8b50101Spk.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22e8b50101Spk.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23e8b50101Spk.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24e8b50101Spk.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25e8b50101Spk.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26e8b50101Spk.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27e8b50101Spk.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28e8b50101Spk.\" POSSIBILITY OF SUCH DAMAGE. 29730768feSpk.\" 30b84d5b62Spk.Dd October 23, 1993 31b84d5b62Spk.Dt LINK 5 32b84d5b62Spk.Os 33b84d5b62Spk.Sh NAME 34b84d5b62Spk.Nm link 35b84d5b62Spk.Nd dynamic loader and link editor interface 36b84d5b62Spk.Sh SYNOPSIS 37472351e1Swiz.In link.h 38b84d5b62Spk.Sh DESCRIPTION 39b84d5b62SpkThe include file 405e015e5eSjoerg.In link.h 41b84d5b62Spkdeclares several structures that are present in dynamically linked 42b84d5b62Spkprograms and libraries. 43b84d5b62SpkThe structures define the interface between several components of the 44fa72f5deSfairlink-editor and loader mechanism. 45fa72f5deSfairThe layout of a number of these structures within the binaries resembles the 46fa72f5deSfair.Xr a.out 5 47fa72f5deSfairformat in many places as it serves such similar functions as symbol 48fa72f5deSfairdefinitions (including the accompanying string table) and relocation records 49fa72f5deSfairneeded to resolve references to external entities. 50fa72f5deSfair.Pp 51fa72f5deSfairIt also records a number of data structures 52fa72f5deSfairunique to the dynamic loading and linking process. 53fa72f5deSfairThese include references to other objects that are required to 54fa72f5deSfaircomplete the link-editing process and indirection tables to facilitate 55730768feSpk.Em Position Independent Code 56fa72f5deSfair(PIC) to improve sharing of code pages among different processes. 57fa72f5deSfair.Pp 586abe6d18SwizThe collection of data structures described here will be referred to as the 59fa72f5deSfair.Em Run-time Relocation Section 60fa72f5deSfair(RRS) and is embedded in the standard text and data segments of 61fa72f5deSfairthe dynamically linked program or shared object image as the existing 62fa72f5deSfair.Xr a.out 5 63b84d5b62Spkformat offers no room for it elsewhere. 64b84d5b62Spk.Pp 6598ae7790SgrantSeveral utilities cooperate to ensure that the task of getting a program 66b84d5b62Spkready to run can complete successfully in a way that optimizes the use 67fa72f5deSfairof system resources. 68fa72f5deSfairThe compiler emits PIC code from which shared libraries can be built by 69730768feSpk.Xr ld 1 . 70b84d5b62SpkThe compiler also includes size information of any initialized data items 71fa72f5deSfairthrough the .size assembler directive. 72fa72f5deSfair.Pp 73fa72f5deSfairPIC code differs from conventional code in that it accesses data 74fa72f5deSfairvariables through an indirection table, the Global Offset Table, 756abe6d18Swizby convention accessible by the reserved name 76730768feSpk.Em _GLOBAL_OFFSET_TABLE_ . 77b84d5b62SpkThe exact mechanism used for this is machine dependent, usually a machine 78fa72f5deSfairregister is reserved for the purpose. 79*6577dba0SgutteridgeThe rationale behind this construct is to generate code that is 80fa72f5deSfairindependent of the actual load address. 81fa72f5deSfairOnly the values contained in the Global Offset Table may need 82fa72f5deSfairupdating at run-time depending on the load addresses of the various 83fa72f5deSfairshared objects in the address space. 84b84d5b62Spk.Pp 85fa72f5deSfairLikewise, procedure calls to globally defined functions are redirected 86fa72f5deSfairthrough the Procedure Linkage Table (PLT) residing in the data 87fa72f5deSfairsegment of the core image. 88fa72f5deSfairAgain, this is done to avoid run-time modifications to the text segment. 89b84d5b62Spk.Pp 90fa72f5deSfairThe linker-editor allocates the Global Offset Table and Procedure 91fa72f5deSfairLinkage Table when combining PIC object files into an image suitable 92fa72f5deSfairfor mapping into the process address space. 93fa72f5deSfairIt also collects all symbols that may be needed by the run-time 94fa72f5deSfairlink-editor and stores these along with the image's text and data bits. 95b84d5b62SpkAnother reserved symbol, 96730768feSpk.Em _DYNAMIC 97fa72f5deSfairis used to indicate the presence of the run-time linker structures. 98fa72f5deSfairWhenever 99fa72f5deSfair.Em _DYNAMIC 100fa72f5deSfairis relocated to 0, there is no need to invoke the run-time link-editor. 101fa72f5deSfairIf this symbol is non-zero, it points at a data structure from 102*6577dba0Sgutteridgewhich the location of the necessary relocation and symbol information 103fa72f5deSfaircan be derived. 104fa72f5deSfairThis is most notably used by the start-up module, 105730768feSpk.Em crt0 . 106b84d5b62SpkThe _DYNAMIC structure is conventionally located at the start of the data 107b84d5b62Spksegment of the image to which it pertains. 108b84d5b62Spk.Sh DATA STRUCTURES 109b84d5b62SpkThe data structures supporting dynamic linking and run-time relocation 110b84d5b62Spkreside both in the text and data segments of the image they apply to. 111b84d5b62SpkThe text segments contain read-only data such as symbols descriptions and 112b84d5b62Spknames, while the data segments contain the tables that need to be modified by 113b84d5b62Spkduring the relocation process. 114b84d5b62Spk.Pp 115b84d5b62SpkThe _DYNAMIC symbol references a 116730768feSpk.Fa _dynamic 117b84d5b62Spkstructure: 118b84d5b62Spk.Bd -literal -offset indent 119730768feSpkstruct _dynamic { 120730768feSpk int d_version; 121730768feSpk struct so_debug *d_debug; 122b84d5b62Spk union { 123730768feSpk struct section_dispatch_table *d_sdt; 124730768feSpk } d_un; 125730768feSpk struct ld_entry *d_entry; 126b84d5b62Spk}; 127b84d5b62Spk.Ed 128730768feSpk.Bl -tag -width d_version 129730768feSpk.It Fa d_version 130b84d5b62SpkThis field provides for different versions of the dynamic linking 131fa72f5deSfairimplementation. 132fa72f5deSfairThe current version numbers understood by ld and ld.so are 133730768feSpk.Em LD_VERSION_SUN (3) , 13434a98169Sperrywhich is used by the 135fa72f5deSfair.Tn "SunOS 4.x" 13634a98169Sperryreleases, and 137730768feSpk.Em LD_VERSION_BSD (8) , 13834a98169Sperrywhich is currently in use by 13934a98169Sperry.Nx . 140730768feSpk.It Fa d_un 141b84d5b62SpkRefers to a 142730768feSpk.Em d_version 143b84d5b62Spkdependent data structure. 144996bd19dSpk.It Fa d_debug 145b84d5b62Spkthis field provides debuggers with a hook to access symbol tables of shared 146b84d5b62Spkobjects loaded as a result of the actions of the run-time link-editor. 147996bd19dSpk.It Fa d_entry 148996bd19dSpkthis field is obsoleted by CRT interface version CRT_VERSION_BSD4, and is 149996bd19dSpkreplaced by the crt_ldentry in 150996bd19dSpk.Fa crt_ldso . 151b84d5b62Spk.El 152b84d5b62Spk.Pp 153b84d5b62SpkThe 154730768feSpk.Fa section_dispatch_table 155b84d5b62Spkstructure is the main 156b84d5b62Spk.Dq dispatcher 157b84d5b62Spktable, containing offsets into the image's segments where various symbol 158b84d5b62Spkand relocation information is located. 159b84d5b62Spk.Bd -literal -offset indent 160730768feSpkstruct section_dispatch_table { 161730768feSpk struct so_map *sdt_loaded; 162730768feSpk long sdt_sods; 163996bd19dSpk long sdt_paths; 164730768feSpk long sdt_got; 165730768feSpk long sdt_plt; 166730768feSpk long sdt_rel; 167730768feSpk long sdt_hash; 168730768feSpk long sdt_nzlist; 169730768feSpk long sdt_filler2; 170730768feSpk long sdt_buckets; 171730768feSpk long sdt_strings; 172730768feSpk long sdt_str_sz; 173730768feSpk long sdt_text_sz; 174730768feSpk long sdt_plt_sz; 175b84d5b62Spk}; 176b84d5b62Spk.Ed 177b84d5b62Spk.Pp 178996bd19dSpk.Bl -tag -width sdt_loaded 179730768feSpk.It Fa sdt_loaded 180fa72f5deSfairA pointer to the first link map loaded (see below). 181fa72f5deSfairThis field is set by 182fa72f5deSfair.Xr ld.so 1 183996bd19dSpkfor the benefit of debuggers that may use it to load a shared object's 184996bd19dSpksymbol table. 185730768feSpk.It Fa sdt_sods 186730768feSpkThe start of a (linked) list of shared object descriptors needed by 187730768feSpk.Em this 188b84d5b62Spkobject. 189996bd19dSpk.It Fa sdt_paths 190fa72f5deSfairLibrary search rules. 191fa72f5deSfairA colon separated list of directories corresponding to the 192996bd19dSpk.Fl R 193996bd19dSpkoption of 194996bd19dSpk.Xr ld 1 . 195730768feSpk.It Fa sdt_got 196b84d5b62SpkThe location of the Global Offset Table within this image. 197730768feSpk.It Fa sdt_plt 198b84d5b62SpkThe location of the Procedure Linkage Table within this image. 199730768feSpk.It Fa sdt_rel 200b84d5b62SpkThe location of an array of 201b84d5b62Spk.Fa relocation_info 202730768feSpkstructures 203730768feSpk.Po 204730768feSpksee 205730768feSpk.Xr a.out 5 206730768feSpk.Pc 207b84d5b62Spkspecifying run-time relocations. 208730768feSpk.It Fa sdt_hash 209b84d5b62SpkThe location of the hash table for fast symbol lookup in this object's 210b84d5b62Spksymbol table. 211730768feSpk.It Fa sdt_nzlist 212b84d5b62SpkThe location of the symbol table. 213730768feSpk.It Fa sdt_filler2 214b84d5b62SpkCurrently unused. 215730768feSpk.It Fa sdt_buckets 216b84d5b62SpkThe number of buckets in 217730768feSpk.Fa sdt_hash 218730768feSpk.It Fa sdt_strings 219b84d5b62SpkThe location of the symbol string table that goes with 220730768feSpk.Fa sdt_nzlist . 221730768feSpk.It Fa sdt_str_sz 222b84d5b62SpkThe size of the string table. 223730768feSpk.It Fa sdt_text_sz 224b84d5b62SpkThe size of the object's text segment. 225730768feSpk.It Fa sdt_plt_sz 226b84d5b62SpkThe size of the Procedure Linkage Table. 227b84d5b62Spk.El 228b84d5b62Spk.Pp 229b84d5b62SpkA 230730768feSpk.Fa sod 2316abe6d18Swizstructure describes a shared object that is needed 232b84d5b62Spkto complete the link edit process of the object containing it. 233730768feSpkA list of such objects 234730768feSpk.Po 235730768feSpkchained through 236730768feSpk.Fa sod_next 237730768feSpk.Pc 238b84d5b62Spkis pointed at 239b84d5b62Spkby the 240730768feSpk.Fa sdt_sods 241730768feSpkin the section_dispatch_table structure. 242b84d5b62Spk.Bd -literal -offset indent 243730768feSpkstruct sod { 244730768feSpk long sod_name; 245730768feSpk u_int sod_library : 1, 246730768feSpk sod_unused : 31; 247730768feSpk short sod_major; 248730768feSpk short sod_minor; 249730768feSpk long sod_next; 250b84d5b62Spk}; 251b84d5b62Spk.Ed 252b84d5b62Spk.Pp 253730768feSpk.Bl -tag -width sod_library 254730768feSpk.It Fa sod_name 255b84d5b62SpkThe offset in the text segment of a string describing this link object. 256730768feSpk.It Fa sod_library 257b84d5b62SpkIf set, 258730768feSpk.Fa sod_name 259fa72f5deSfairspecifies a library that is to be searched for by ld.so. 260fa72f5deSfairThe path name is obtained by searching a set of directories 261730768feSpk.Po 262730768feSpksee also 263730768feSpk.Xr ldconfig 8 264730768feSpk.Pc 265b84d5b62Spkfor a shared object matching 26601869ca4Swiz.Em lib\&<sod_name>\&.so.n.m . 267b84d5b62SpkIf not set, 268730768feSpk.Fa sod_name 269b84d5b62Spkshould point at a full path name for the desired shared object. 270730768feSpk.It Fa sod_major 271b84d5b62SpkSpecifies the major version number of the shared object to load. 272730768feSpk.It Fa sod_minor 2736abe6d18SwizSpecifies the preferred minor version number of the shared object to load. 274b84d5b62Spk.El 275b84d5b62Spk.Pp 276730768feSpkThe run-time link-editor maintains a list of structures called 277730768feSpk.Em link maps 278730768feSpkto keep track of all shared objects loaded into a process' address space. 279b84d5b62SpkThese structures are only used at run-time and do not occur within 280b84d5b62Spkthe text or data segment of an executable or shared library. 281b84d5b62Spk.Bd -literal -offset indent 282730768feSpkstruct so_map { 283c1a14b53Sdogcow void *som_addr; 284730768feSpk char *som_path; 285730768feSpk struct so_map *som_next; 286730768feSpk struct sod *som_sod; 287c1a14b53Sdogcow void *som_sodbase; 288730768feSpk u_int som_write : 1; 289730768feSpk struct _dynamic *som_dynamic; 290c1a14b53Sdogcow void *som_spd; 291b84d5b62Spk}; 292730768feSpk.Ed 293730768feSpk.Bl -tag -width som_dynamic 294730768feSpk.It Fa som_addr 295b84d5b62SpkThe address at which the shared object associated with this link map has 296b84d5b62Spkbeen loaded. 297730768feSpk.It Fa som_path 298b84d5b62SpkThe full path name of the loaded object. 299730768feSpk.It Fa som_next 300b84d5b62SpkPointer to the next link map. 301730768feSpk.It Fa som_sod 302b84d5b62SpkThe 303730768feSpk.Fa sod 304730768feSpkstructure that was responsible for loading this shared object. 305730768feSpk.It Fa som_sodbase 306730768feSpkTossed in later versions the run-time linker. 307730768feSpk.It Fa som_write 308730768feSpkSet if (some portion of) this object's text segment is currently writable. 309730768feSpk.It Fa som_dynamic 310730768feSpkPointer to this object's 311730768feSpk.Fa _dynamic 312b84d5b62Spkstructure. 313730768feSpk.It Fa som_spd 314b84d5b62SpkHook for attaching private data maintained by the run-time link-editor. 315b84d5b62Spk.El 316b84d5b62Spk.Pp 317fa72f5deSfairSymbol description with size. 318fa72f5deSfairThis is simply an 319b84d5b62Spk.Fa nlist 320730768feSpkstructure with one field 321730768feSpk.Pq Fa nz_size 322fa72f5deSfairadded. 323fa72f5deSfairUsed to convey size information on items in the data segment of 324fa72f5deSfairshared objects. 325fa72f5deSfairAn array of these lives in the shared object's text segment and is 326fa72f5deSfairaddressed by the 327730768feSpk.Fa sdt_nzlist 328b84d5b62Spkfield of 329730768feSpk.Fa section_dispatch_table . 330b84d5b62Spk.Bd -literal -offset indent 331b84d5b62Spkstruct nzlist { 332b84d5b62Spk struct nlist nlist; 333b84d5b62Spk u_long nz_size; 334b84d5b62Spk#define nz_un nlist.n_un 335b84d5b62Spk#define nz_strx nlist.n_un.n_strx 336b84d5b62Spk#define nz_name nlist.n_un.n_name 337b84d5b62Spk#define nz_type nlist.n_type 338b84d5b62Spk#define nz_value nlist.n_value 339b84d5b62Spk#define nz_desc nlist.n_desc 340b84d5b62Spk#define nz_other nlist.n_other 341b84d5b62Spk}; 342b84d5b62Spk.Ed 343b84d5b62Spk.Bl -tag -width nz_size 344b84d5b62Spk.It Fa nlist 345730768feSpk.Po 346730768feSpksee 347fa72f5deSfair.Xr nlist 3 348730768feSpk.Pc . 349b84d5b62Spk.It Fa nz_size 350b84d5b62SpkThe size of the data represented by this symbol. 351b84d5b62Spk.El 352b84d5b62Spk.Pp 353aae59958SrumbleA hash table is included within the text segment of shared object 354b84d5b62Spkto facilitate quick lookup of symbols during run-time link-editing. 355b84d5b62SpkThe 356730768feSpk.Fa sdt_hash 357b84d5b62Spkfield of the 358730768feSpk.Fa section_dispatch_table 359b84d5b62Spkstructure points at an array of 360b84d5b62Spk.Fa rrs_hash 361b84d5b62Spkstructures: 362b84d5b62Spk.Bd -literal -offset indent 363b84d5b62Spkstruct rrs_hash { 364b84d5b62Spk int rh_symbolnum; /* symbol number */ 365b84d5b62Spk int rh_next; /* next hash entry */ 366b84d5b62Spk}; 367b84d5b62Spk.Ed 368b84d5b62Spk.Pp 369b84d5b62Spk.Bl -tag -width rh_symbolnum 370b84d5b62Spk.It Fa rh_symbolnum 371b84d5b62SpkThe index of the symbol in the shared object's symbol table (as given by the 372b84d5b62Spk.Fa ld_symbols 373b84d5b62Spkfield). 374b84d5b62Spk.It Fa rh_next 375b84d5b62SpkIn case of collisions, this field is the offset of the next entry in this 376fa72f5deSfairhash table bucket. 377fa72f5deSfairIt is zero for the last bucket element. 378b84d5b62Spk.El 379b84d5b62SpkThe 380b84d5b62Spk.Fa rt_symbol 381b84d5b62Spkstructure is used to keep track of run-time allocated commons 382fa72f5deSfairand data items copied from shared objects. 383*6577dba0SgutteridgeThese items are kept in a linked list which is exported through the 384730768feSpk.Fa dd_cc 385b84d5b62Spkfield in the 386730768feSpk.Fa so_debug 387b84d5b62Spkstructure (see below) for use by debuggers. 388b84d5b62Spk.Bd -literal -offset indent 389b84d5b62Spkstruct rt_symbol { 390b84d5b62Spk struct nzlist *rt_sp; 391b84d5b62Spk struct rt_symbol *rt_next; 392b84d5b62Spk struct rt_symbol *rt_link; 393c1a14b53Sdogcow void *rt_srcaddr; 394730768feSpk struct so_map *rt_smp; 395b84d5b62Spk}; 396b84d5b62Spk.Ed 397b84d5b62Spk.Pp 398b84d5b62Spk.Bl -tag -width rt_scraddr 399b84d5b62Spk.It Fa rt_sp 400b84d5b62SpkThe symbol description. 401b84d5b62Spk.It Fa rt_next 402b84d5b62SpkVirtual address of next rt_symbol. 403b84d5b62Spk.It Fa rt_link 404fa72f5deSfairNext in hash bucket. 405fa72f5deSfairUsed by internally by ld.so. 406b84d5b62Spk.It Fa rt_srcaddr 407b84d5b62SpkLocation of the source of initialized data within a shared object. 408730768feSpk.It Fa rt_smp 409730768feSpkThe shared object which is the original source of the data that this 410730768feSpkrun-time symbol describes. 411b84d5b62Spk.El 412b84d5b62Spk.Pp 413b84d5b62SpkThe 414730768feSpk.Fa so_debug 415b84d5b62Spkstructure is used by debuggers to gain knowledge of any shared objects 416b84d5b62Spkthat have been loaded in the process's address space as a result of run-time 417fa72f5deSfairlink-editing. 418fa72f5deSfairSince the run-time link-editor runs as a part of process initialization, 419fa72f5deSfaira debugger that wishes to access symbols from shared objects can 420fa72f5deSfaironly do so after the link-editor has been called from crt0. 421b84d5b62SpkA dynamically linked binary contains a 422730768feSpk.Fa so_debug 423b84d5b62Spkstructure which can be located by means of the 424730768feSpk.Fa d_debug 425b84d5b62Spkfield in 426730768feSpk.Fa _dynamic . 427b84d5b62Spk.Bd -literal -offset indent 428730768feSpkstruct so_debug { 429730768feSpk int dd_version; 430730768feSpk int dd_in_debugger; 431730768feSpk int dd_sym_loaded; 432730768feSpk char *dd_bpt_addr; 433730768feSpk int dd_bpt_shadow; 434730768feSpk struct rt_symbol *dd_cc; 435b84d5b62Spk}; 436b84d5b62Spk.Ed 437b84d5b62Spk.Pp 438730768feSpk.Bl -tag -width dd_in_debugger 439730768feSpk.It Fa dd_version 440b84d5b62SpkVersion number of this interface. 441730768feSpk.It Fa dd_in_debugger 442730768feSpkSet by the debugger to indicate to the run-time linker that the program is 443730768feSpkrun under control of a debugger. 444730768feSpk.It Fa dd_sym_loaded 445730768feSpkSet by the run-time linker whenever it adds symbols by loading shared objects. 446730768feSpk.It Fa dd_bpt_addr 4475d37ffa7SlukemThe address were a breakpoint will be set by the run-time linker to 448fa72f5deSfairdivert control to the debugger. 449fa72f5deSfairThis address is determined by the start-up module, 450730768feSpk.Em crt0.o , 451b84d5b62Spkto be some convenient place before the call to _main. 452730768feSpk.It Fa dd_bpt_shadow 453b84d5b62SpkContains the original instruction that was at 454730768feSpk.Fa dd_bpt_addr . 455b84d5b62SpkThe debugger is expected to put this instruction back before continuing the 456b84d5b62Spkprogram. 457730768feSpk.It Fa dd_cc 458b84d5b62SpkA pointer to the linked list of run-time allocated symbols that the debugger 459730768feSpkmay be interested in. 460b84d5b62Spk.El 461b84d5b62Spk.Pp 462b84d5b62SpkThe 463730768feSpk.Em ld_entry 464fa72f5deSfairstructure defines a set of service routines within ld.so. 465fa72f5deSfairSee 466996bd19dSpk.Xr dlfcn 3 467b84d5b62Spkfor more information. 468730768feSpk.Bd -literal -offset indent 469b84d5b62Spkstruct ld_entry { 470730768feSpk void *(*dlopen)(char *, int); 471730768feSpk int (*dlclose)(void *); 472730768feSpk void *(*dlsym)(void *, char *); 473730768feSpk int (*dlctl)(void *, int, void *); 474267e4b3dSwiz void (*dlexit)(void); 475b84d5b62Spk}; 476b84d5b62Spk.Ed 47742704c41Swiz.Pp 478b84d5b62SpkThe 479b84d5b62Spk.Fa crt_ldso 480996bd19dSpkstructure defines the interface between ld.so and the start-up code in crt0. 481730768feSpk.Bd -literal -offset indent 482b84d5b62Spkstruct crt_ldso { 483b84d5b62Spk int crt_ba; 484b84d5b62Spk int crt_dzfd; 485b84d5b62Spk int crt_ldfd; 486730768feSpk struct _dynamic *crt_dp; 487b84d5b62Spk char **crt_ep; 488c1a14b53Sdogcow void *crt_bp; 489730768feSpk char *crt_prog; 490730768feSpk char *crt_ldso; 491996bd19dSpk char *crt_ldentry; 492b84d5b62Spk}; 493b84d5b62Spk#define CRT_VERSION_SUN 1 494730768feSpk#define CRT_VERSION_BSD2 2 495730768feSpk#define CRT_VERSION_BSD3 3 496996bd19dSpk#define CRT_VERSION_BSD4 4 497b84d5b62Spk.Ed 498b84d5b62Spk.Bl -tag -width crt_dzfd 499b84d5b62Spk.It Fa crt_ba 500b84d5b62SpkThe virtual address at which ld.so was loaded by crt0. 501b84d5b62Spk.It Fa crt_dzfd 50234a98169SperryOn 50334a98169Sperry.Tn SunOS 50434a98169Sperrysystems, this field contains an open file descriptor to 505b84d5b62Spk.Dq /dev/zero 506fa72f5deSfairused to get demand paged zeroed pages. 507fa72f5deSfairOn 50834a98169Sperry.Nx 50934a98169Sperrysystems it contains -1. 510b84d5b62Spk.It Fa crt_ldfd 511b84d5b62SpkContains an open file descriptor that was used by crt0 to load ld.so. 512b84d5b62Spk.It Fa crt_dp 513b84d5b62SpkA pointer to main's 514730768feSpk.Fa _dynamic 515b84d5b62Spkstructure. 516b84d5b62Spk.It Fa crt_ep 517b84d5b62SpkA pointer to the environment strings. 518b84d5b62Spk.It Fa crt_bp 519730768feSpkThe address at which a breakpoint will be placed by the run-time linker 520730768feSpkif the main program is run by a debugger. 521b84d5b62SpkSee 522730768feSpk.Fa so_debug 523730768feSpk.It Fa crt_prog 524730768feSpkThe name of the main program as determined by crt0 (CRT_VERSION_BSD3 only). 525730768feSpk.It Fa crt_ldso 526730768feSpkThe path of the run-time linker as mapped by crt0 (CRT_VERSION_BSD4 only). 527996bd19dSpk.It Fa crt_ldentry 528996bd19dSpkThe 529996bd19dSpk.Xr dlfcn 3 530996bd19dSpkentry points provided by the run-time linker (CRT_VERSION_BSD4 only). 531b84d5b62Spk.El 532b84d5b62Spk.Pp 533b84d5b62SpkThe 534b84d5b62Spk.Fa hints_header 535b84d5b62Spkand 536b84d5b62Spk.Fa hints_bucket 537b84d5b62Spkstructures define the layout of the library hints, normally found in 538b84d5b62Spk.Dq /var/run/ld.so.hints , 539b84d5b62Spkwhich is used by ld.so to quickly locate the shared object images in the 540b84d5b62Spkfile system. 541b84d5b62SpkThe organization of the hints file is not unlike that of an 542fa72f5deSfair.Xr a.out 5 543b84d5b62Spkobject file, in that it contains a header determining the offset and size 544b84d5b62Spkof a table of fixed sized hash buckets and a common string pool. 545b84d5b62Spk.Bd -literal -offset indent 546b84d5b62Spkstruct hints_header { 547b84d5b62Spk long hh_magic; 548b84d5b62Spk#define HH_MAGIC 011421044151 549b84d5b62Spk long hh_version; 550b84d5b62Spk#define LD_HINTS_VERSION_1 1 551c7ad3faeSpk#define LD_HINTS_VERSION_2 2 552b84d5b62Spk long hh_hashtab; 553b84d5b62Spk long hh_nbucket; 554b84d5b62Spk long hh_strtab; 555b84d5b62Spk long hh_strtab_sz; 556b84d5b62Spk long hh_ehints; 557c7ad3faeSpk long hh_dirlist; 558b84d5b62Spk}; 559b84d5b62Spk.Ed 560b84d5b62Spk.Bl -tag -width hh_strtab_sz 561b84d5b62Spk.It Fa hh_magic 562b84d5b62SpkHints file magic number. 563b84d5b62Spk.It Fa hh_version 564b84d5b62SpkInterface version number. 565b84d5b62Spk.It Fa hh_hashtab 566b84d5b62SpkOffset of hash table. 567b84d5b62Spk.It Fa hh_strtab 568b84d5b62SpkOffset of string table. 569b84d5b62Spk.It Fa hh_strtab_sz 570b84d5b62SpkSize of strings. 571b84d5b62Spk.It Fa hh_ehints 572b84d5b62SpkMaximum usable offset in hints file. 573c7ad3faeSpk.It Fa hh_dirlist 574c7ad3faeSpkOffset in string table of a colon-separated list of directories that was 575fa72f5deSfairused in constructing the hints file. 576fa72f5deSfairSee also 577c7ad3faeSpk.Xr ldconfig 8 . 578c7ad3faeSpkThis field is only available with interface version number 579c7ad3faeSpk.Dv LD_HINTS_VERSION_2 580c7ad3faeSpkand higher. 581b84d5b62Spk.El 582b84d5b62Spk.Pp 583b84d5b62Spk.Bd -literal -offset indent 584b84d5b62Spk/* 585b84d5b62Spk * Hash table element in hints file. 586b84d5b62Spk */ 587b84d5b62Spkstruct hints_bucket { 588b84d5b62Spk int hi_namex; 589b84d5b62Spk int hi_pathx; 590b84d5b62Spk int hi_dewey[MAXDEWEY]; 591b84d5b62Spk int hi_ndewey; 592b84d5b62Spk#define hi_major hi_dewey[0] 593b84d5b62Spk#define hi_minor hi_dewey[1] 594b84d5b62Spk int hi_next; 595b84d5b62Spk}; 596b84d5b62Spk.Ed 597b84d5b62Spk.Bl -tag -width hi_ndewey 598b84d5b62Spk.It Fa hi_namex 599b84d5b62SpkIndex of the string identifying the library. 600b84d5b62Spk.It Fa hi_pathx 601b84d5b62SpkIndex of the string representing the full path name of the library. 602b84d5b62Spk.It Fa hi_dewey 603b84d5b62SpkThe version numbers of the shared library. 604b84d5b62Spk.It Fa hi_ndewey 605b84d5b62SpkThe number of valid entries in 606b84d5b62Spk.Fa hi_dewey . 607b84d5b62Spk.It Fa hi_next 608b84d5b62SpkNext bucket in case of hashing collisions. 609b84d5b62Spk.El 610