p The linker will search for libraries in three lists of paths: l -enum t A user defined list of paths as specified in LD_LIBRARY_PATH and .Xr ld.so.conf 5 .
p The use of ld.so.conf should be avoided as the setting of a global search path can present a security risk. t A list of paths specified within a shared object using the .Dv DT_RPATH and .Dv DT_RUNPATH entries in the dynamic section. This is defined at shared object link time. t The list of default paths which is set to
p Dynamic loading via .Xr dlopen 3 uses the .Dv DT_RPATH and .Dv DT_RUNPATH entries of the main binary, independently of which object the call came from.
p .Nm will expand the following variables if present in the paths: l -tag -width $PLATFORM t $HWCAP Processor hardware capabilities, for example FPU, MMX, SSE. Currently unimplemented. t $ISALIST List of instructions sets this processor can execute. Currently unimplemented. t $ORIGIN The directory of the main object. t $OSNAME The value of the .Dv kern.ostype .Xr sysctl 3 . t $OSREL The value of the .Dv kern.osrelease .Xr sysctl 3 . t $PLATFORM The value of the .Dv hw.machine_arch .Xr sysctl 3 . .El
p Both .Dv ${VARIABLE} and .Dv $VARIABLE are recognized.
p The filename string can be considered free form, however, it will almost always take the form lib<name>.so.<number>, where name specifies the .Sq library name and number is conceptually the library's major version number.
p This name and another of the form lib<name>.so are normally symbolic links to the real shared object which has a filename of the form lib<name>.so.<major>.<minor>[.<teeny>]. This naming convention allows a versioning scheme similar to .Xr a.out 5 . .Ss Relocation .Nm will perform all necessary relocations immediately except for relocations relating to the Procedure Linkage Table (PLT). The PLT is used as an indirection method for procedure calls to globally defined functions. It allows, through the use of intermediate code, the delayed binding of a call to a globally defined function to be performed at procedure call time. This .Sq lazy method is the default (see LD_BIND_NOW). .Ss Initialization A mechanism is provided for initialization and termination routines to be called, on a per-object basis before execution of the program proper begins or after the program has completed. This gives a shared object an opportunity to perform any extra set-up or completion work.
p The .Dv DT_INIT and .Dv DT_FINI entries in the dynamic section specify the addresses of the initialization and termination functions, respectively, for the shared object. .Nm arranges for each initialization function to be called before control is passed to the program and for the termination functions to be called by using .Xr atexit 3 .
p This mechanism is exploited by the system-supplied constructor initialization and destructor code located in
a /usr/lib/crtbeginS.o and
a /usr/lib/crtendS.o . These files are automatically included by .Xr cc 1 and .Xr c++ 1 in the list of object-code files passed to .Xr ld 1 when building a shared C or C++ object. .Sh ENVIRONMENT If the following environment variables exist they will be used by .Nm . l -tag -width "LD_LIBRARY_PATH" t Ev LD_LIBRARY_PATH A colon separated list of directories, overriding the default search path for shared libraries. t Ev LD_PRELOAD A colon or space separated list of shared object filenames to be loaded .Em after the main program but .Em before its shared object dependencies. Space is allowed as a separator for backwards compatibility only. Support may be removed in a future release and should not be relied upon. t Ev LD_BIND_NOW If defined immediate binding of Procedure Link Table (PLT) entries is performed instead of the default lazy method. t Ev LD_DEBUG If defined a variety of debug information will be written to the standard error of a dynamically linked executed when it is run. This variable is only recognized if .Nm was compiled with debugging support .Sy ( -DDEBUG ) . .El .Sh FILES l -tag -width /etc/ld.so.conf -compact t Pa /etc/ld.so.conf library location hints supplied by the system administrator. .El .Sh SEE ALSO .Xr ld 1 , .Xr ld.aout_so 1 , .Xr dlfcn 3 , .Xr elf 5 .Sh HISTORY The ELF shared library model employed first appeared in Sys V R4.
p The path expansion variables first appeared in Solaris 10, and in .Nx 5.0 . .Sh SECURITY CONSIDERATIONS The environment variables .Ev LD_LIBRARY_PATH and .Ev LD_PRELOAD are not honored when executing in a set-user-ID or set-group-ID environment. This action is taken to prevent malicious substitution of shared object dependencies or interposition of symbols.