1.\" $NetBSD: ld.aout_so.1,v 1.3 2002/02/07 03:15:07 ross Exp $ 2.\" 3.\" Copyright (c) 1998 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Paul Kranenburg. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd March 24, 2000 38.Dt LD.AOUT_SO 1 39.Os 40.Sh NAME 41.Nm ld.so 42.Nd run-time link-editor 43.Sh DESCRIPTION 44.Nm 45is a self-contained, position independent program image providing run-time 46support for loading and link-editing shared objects into a process' 47address space. It uses the data structures 48.Po 49see 50.Xr link 5 51.Pc 52contained within dynamically linked programs to determine which shared 53libraries are needed and loads them at a convenient virtual address 54using the 55.Xr mmap 2 56system call. 57.Pp 58After all shared libraries have been successfully loaded, 59.Nm 60proceeds to resolve external references from both the main program and 61all objects loaded. A mechanism is provided for initialisation routines 62to be called, on a per-object basis, giving a shared object an opportunity 63to perform any extra set-up, before execution of the program proper begins. 64.Nm 65looks for a symbol named 66.Em .init 67in each object's symbol table. If present, this symbol is assumed to 68represent a C-function declared as 69.Ft void 70.Fn .init "void" , 71which is then called. Similarly, a 72.Ft void 73.Fn .fini "void" 74function is called just before an object is unloaded from the process 75address space as a result of calling 76.Xr dlclose 3 . 77Note that while an object's 78.Em .init 79is always called, whether the object is loaded automatically at program 80startup or programatically by using 81.Xr dlopen 3 , 82the 83.Em .fini 84function is called only on 85.Sq last Xr dlclose 3 . 86.Pp 87This mechanism is exploited by the system-supplied C++ constructor 88initialization code located in 89.Pa /usr/lib/c++rt.o . 90This file should be included in the list of object-code files passed to 91.Xr ld 1 92when building a shared C++ library. 93.Pp 94.Nm 95is itself a shared object that is initially loaded by the startup module 96.Em crt0 . 97Since 98.Xr a.out 5 99formats do not provide easy access to the file header from within a running 100process, 101.Em crt0 102uses the special symbol 103.Va _DYNAMIC 104to determine whether a program is in fact dynamically linked or not. Whenever 105the linker 106.Xr ld 1 107has relocated this symbol to a location other than 0, 108.Em crt0 109assumes the services of 110.Nm 111are needed 112.Po 113see 114.Xr link 5 115for details 116.Pc Ns \&. 117.Em crt0 118passes control to 119.Nm rtld Ns 's 120entry point before the program's 121.Fn main 122routine is called. Thus, 123.Nm 124can complete the link-editing process before the dynamic program calls upon 125services of any dynamic library. 126.Pp 127To quickly locate the required shared objects in the filesystem, 128.Nm 129may use a 130.Dq hints 131file, prepared by the 132.Xr ldconfig 8 133utility, in which the full path specification of the shared objects can be 134looked up by hashing on the 3-tuple 135.Ao 136library-name, major-version-number, minor-version-number 137.Ac Ns \&. 138.Pp 139.Nm 140recognises a number of environment variables that can be used to modify 141its behaviour as follows: 142.Pp 143.Bl -tag -width LD_TRACE_LOADED_OBJECTS \" intentionally not the longest 144.It Ev LD_LIBRARY_PATH 145A colon separated list of directories, overriding the default search path 146for shared libraries. 147.It Ev LD_PRELOAD 148A colon separated list of shared object filenames to be loaded 149.Em after 150the main program but 151.Em before 152its shared object dependencies. 153.It Ev LD_WARN_NON_PURE_CODE 154When set, issue a warning whenever a link-editing operation requires 155modification of the text segment of some loaded object. This is usually 156indicative of an incorrectly built library. 157.It Ev LD_SUPPRESS_WARNINGS 158When set, no warning messages of any kind are issued. Normally, a warning 159is given if satisfactorily versioned library could not be found. 160.It Ev LD_TRACE_LOADED_OBJECTS 161When set, causes 162.Nm 163to exit after loading the shared objects and printing a summary which includes 164the absolute pathnames of all objects, to standard output. 165.It Ev LD_TRACE_LOADED_OBJECTS_FMT1 166.It Ev LD_TRACE_LOADED_OBJECTS_FMT2 167When set, these variables are interpreted as format strings a la 168.Xr printf 3 169to customize the trace output and are used by 170.Xr ldd 1 's 171.Fl f 172option and allows 173.Xr ldd 1 174to be operated as a filter more conveniently. 175The following conversions can be used: 176.Bl -tag -width xxxx 177.It \&%a 178The main program's name 179.Po also known as 180.Dq __progname 181.Pc . 182.It \&%A 183The value of the environment variable 184.Ev LD_TRACE_LOADED_OBJECTS_PROGNAME 185.It \&%o 186The library name. 187.It \&%m 188The library's major version number. 189.It \&%n 190The library's minor version number. 191.It \&%p 192The full pathname as determined by 193.Nm rtld Ns 's 194library search rules. 195.It \&%x 196The library's load address. 197.El 198.Pp 199Additionally, 200.Sy \en 201and 202.Sy \et 203are recognised and have their usual meaning. 204.It Ev LD_NO_INTERN_SEARCH 205When set, 206.Nm 207does not process any internal search paths that were recorded in the 208executable. 209.It Ev LD_NOSTD_PATH 210When set, do not include a set of built-in standard directory paths for 211searching. This might be useful when running on a system with a completely 212non-standard filesystem layout. 213.El 214.Sh FILES 215.Bl -tag -width /var/run/ld.so.hintsXXX -compact 216.It Pa /var/run/ld.so.hints 217library location hints built by 218.Xr ldconfig 8 219.El 220.Sh SEE ALSO 221.Xr ld 1 , 222.Xr ld.elf_so 1 , 223.Xr ld.so 1 , 224.Xr link 5 , 225.Xr ldconfig 8 226.Sh HISTORY 227The shared library model employed first appeared in SunOS 4.0. 228.Sh SECURITY CONSIDERATIONS 229The environment variables 230.Ev LD_LIBRARY_PATH 231and 232.Ev LD_PRELOAD 233are not honored when executing in a set-user-ID or set-group-ID environment. 234This action is taken to prevent malicious substitution of shared object 235dependencies or interposition of symbols. 236