1.\" 2.\" Copyright (c) 1998 John D. Polstra 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 26.\" $Id: dladdr.3,v 1.1 1998/02/09 06:05:24 jdp Exp $ 27.\" 28.Dd February 5, 1998 29.Os FreeBSD 30.Dt DLADDR 3 31.Sh NAME 32.Nm dladdr 33.Nd find the shared object containing a given address 34.Sh SYNOPSIS 35.Fd #include <dlfcn.h> 36.Ft int 37.Fn dladdr "const void *addr" "Dl_info *info" 38.Sh DESCRIPTION 39.Nm 40queries the dynamic linker for information about the shared object 41containing the address 42.Fa addr . 43The information is returned in the structure specified by 44.Fa info . 45The structure contains at least the following members: 46.Bl -tag -width "XXXconst char *dli_fname" 47.It Li "const char *dli_fname" 48The pathname of the shared object containing the address. 49.It Li "void *dli_fbase" 50The base address at which the shared object is mapped into the 51address space of the calling process. 52.It Li "const char *dli_sname" 53The name of the nearest run-time symbol with a value less than or 54equal to 55.Fa addr . 56When possible, the symbol name is returned as it would appear in C 57source code. 58.Pp 59If no symbol with a suitable value is found, both this field and 60.Va dli_saddr 61are set to 62.Dv NULL . 63.It Li "void *dli_saddr" 64The value of the symbol returned in 65.Li dli_sname . 66.El 67.Pp 68.Nm 69is available only in dynamically linked programs. 70.Sh ERRORS 71If a mapped shared object containing 72.Fa addr 73cannot be found, 74.Nm 75returns 0. 76In that case, a message detailing the failure can be retrieved by 77calling 78.Fn dlerror . 79.Pp 80On success, a non-zero value is returned. 81.Sh SEE ALSO 82.Xr rtld 1 , 83.Xr dlopen 3 84.Sh HISTORY 85The 86.Nm 87function first appeared in the Solaris operating system. 88.Sh BUGS 89This implementation is bug-compatible with the Solaris 90implementation. In particular, the following bugs are present: 91.Bl -bullet 92.It 93If 94.Fa addr 95lies in the main executable rather than in a shared library, the 96pathname returned in 97.Va dli_fname 98may not be correct. The pathname is taken directly from 99.Va argv[0] 100of the calling process. When executing a program specified by its 101full pathname, most shells set 102.Va argv[0] 103to the pathname. But this is not required of shells or guaranteed 104by the operating system. 105.It 106If 107.Fa addr 108is of the form 109.Va &func , 110where 111.Va func 112is a global function, its value may be an unpleasant surprise. In 113dynamically linked programs, the address of a global function is 114considered to point to its program linkage table entry, rather than to 115the entry point of the function itself. This causes most global 116functions to appear to be defined within the main executable, rather 117than in the shared libraries where the actual code resides. 118.It 119Returning 0 as an indication of failure goes against long-standing 120Unix tradition. 121.El 122