1.\" $OpenBSD: ld.so.1,v 1.25 2022/06/14 09:56:07 kn Exp $ 2.\" $NetBSD: rtld.1,v 1.2 1995/10/08 23:43:28 pk Exp $ 3.\" 4.\" Copyright (c) 1995 Paul Kranenburg 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed by Paul Kranenburg. 18.\" 3. The name of the author may not be used to endorse or promote products 19.\" derived from this software without specific prior written permission 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31.\" 32.Dd $Mdocdate: June 14 2022 $ 33.Dt LD.SO 1 34.Os 35.Sh NAME 36.Nm ld.so 37.Nd run-time link-editor 38.Sh DESCRIPTION 39.Nm 40is a self-contained, position independent program image providing run-time 41support for loading and link-editing shared objects into a process's 42address space. 43It uses the data structures 44.Po 45see 46.Xr elf 5 47.Pc 48contained within dynamically linked programs to determine which shared 49libraries are needed and loads them at a convenient virtual address 50using the 51.Xr mmap 2 52system call. 53.Pp 54After all shared libraries have been successfully loaded, 55.Nm 56proceeds to resolve external references from both the main program and 57all objects loaded. 58A mechanism is provided for initialization routines to be called, 59on a per-object basis, giving a shared object an opportunity 60to perform any extra set-up, before execution of the program proper begins. 61.\" 62.\" <talk about CTORS/DTORS> 63.\" 64.Pp 65.Nm 66is itself a shared object that is initially loaded by the kernel. 67.\" 68.\" <How it is run> 69.\" 70.Pp 71To quickly locate the required shared objects in the filesystem, 72.Nm 73may use a 74.Dq hints 75file, prepared by the 76.Xr ldconfig 8 77utility, in which the full path specification of the shared objects can be 78looked up by hashing on the 3-tuple 79.Aq library-name , major-version-number , minor-version-number . 80.Pp 81.Nm 82searches for shared objects in the following lists of paths: 83.Pp 84.Bl -enum -offset ident -compact 85.It 86.Ev LD_LIBRARY_PATH 87environment variable if set 88.It 89.Dv DT_RUNPATH 90of the calling object if set, otherwise: 91.Bl -enum -compact 92.It 93.Dv DT_RPATH 94of the calling object if set 95.It 96.Dv DT_RPATH 97of the program if set 98.El 99(The use of 100.Dv DT_RPATH 101is deprecated as its behaviour varies across operating systems.) 102.It 103default search path set by 104.Xr ldconfig 8 105.It 106.Pa /usr/lib 107.El 108.Pp 109.Nm 110recognises a number of environment variables that can be used to modify 111its behaviour as follows: 112.Pp 113.Bl -tag -width Ds -compact 114.It Ev LD_LIBRARY_PATH 115A colon separated list of directories, prepending the default search path 116for shared libraries. 117This variable is ignored for set-user-ID and set-group-ID executables. 118.Pp 119.It Ev LD_PRELOAD 120A colon separated list of library names to load before any of the regular 121libraries are loaded. 122This variable is ignored for set-user-ID and set-group-ID executables. 123.Pp 124.It Ev LD_BIND_NOW 125Specifies that the dynamic linker should process all relocations before 126transferring control to the program. 127Normally, the procedure linkage table entries are handled lazily, 128avoiding symbol lookup and relocation for unused functions. 129This variable is ignored for set-user-ID and set-group-ID executables. 130.Pp 131.It Ev LD_TRACE_LOADED_OBJECTS 132When set, causes 133.Nm 134to exit after loading the shared objects and printing a summary which includes 135the absolute pathnames of all objects, to standard output. 136.Pp 137.It Ev LD_TRACE_LOADED_OBJECTS_FMT1 138.It Ev LD_TRACE_LOADED_OBJECTS_FMT2 139When set, these variables are interpreted as format strings a la 140.Xr printf 3 141to customize the trace output and are used by 142.Xr ldd 1 Ns 's 143.Fl f 144option and allows 145.Xr ldd 1 146to be operated as a filter more conveniently. 147.Ev LD_TRACE_LOADED_OBJECTS_FMT1 148is used for tracing shared libraries; 149.Ev LD_TRACE_LOADED_OBJECTS_FMT2 150for dynamically loaded objects, the dynamic linker, 151and the main executable. 152The following conversions can be used: 153.Bl -tag -width "xxxx" 154.It %a 155The main program's name 156.Pq also known as Dq __progname . 157.It \&%A 158The value of the environment variable 159.Ev LD_TRACE_LOADED_OBJECTS_PROGNAME . 160.It %e 161The end address of the object. 162.It %g 163The object's group reference count. 164.It %m 165The object's major version number. 166.It %n 167The object's minor version number. 168.It \&%O 169The object's open count. 170.It %o 171The object name. 172.It %p 173The full pathname as determined by 174.Nm ld.so Ns 's 175library search rules. 176.It %r 177The object's reference count. 178.It %x 179The object's load address. 180.El 181.Pp 182Additionally, 183.Sy \en 184and 185.Sy \et 186are recognised and have their usual meaning. 187.Pp 188.It Ev LD_DEBUG 189When set, be verbose about what 190.Nm 191does. 192This variable is ignored for set-user-ID and set-group-ID executables. 193.El 194.Sh FILES 195.Bl -tag -width /var/run/ld.so.hintsXXX -compact 196.It Pa /var/run/ld.so.hints 197library location hints built by 198.Xr ldconfig 8 199.El 200.Sh SEE ALSO 201.Xr ld 1 , 202.Xr elf 5 , 203.Xr ldconfig 8 204.Sh HISTORY 205The shared library model employed first appeared in SunOS 4.0. 206