1645c4be3SJohn Polstra.\" 2645c4be3SJohn Polstra.\" Copyright (c) 1998 John D. Polstra 3645c4be3SJohn Polstra.\" All rights reserved. 4645c4be3SJohn Polstra.\" 5645c4be3SJohn Polstra.\" Redistribution and use in source and binary forms, with or without 6645c4be3SJohn Polstra.\" modification, are permitted provided that the following conditions 7645c4be3SJohn Polstra.\" are met: 8645c4be3SJohn Polstra.\" 1. Redistributions of source code must retain the above copyright 9645c4be3SJohn Polstra.\" notice, this list of conditions and the following disclaimer. 10645c4be3SJohn Polstra.\" 2. Redistributions in binary form must reproduce the above copyright 11645c4be3SJohn Polstra.\" notice, this list of conditions and the following disclaimer in the 12645c4be3SJohn Polstra.\" documentation and/or other materials provided with the distribution. 13645c4be3SJohn Polstra.\" 14645c4be3SJohn Polstra.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15645c4be3SJohn Polstra.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16645c4be3SJohn Polstra.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17645c4be3SJohn Polstra.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18645c4be3SJohn Polstra.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19645c4be3SJohn Polstra.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20645c4be3SJohn Polstra.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21645c4be3SJohn Polstra.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22645c4be3SJohn Polstra.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23645c4be3SJohn Polstra.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24645c4be3SJohn Polstra.\" SUCH DAMAGE. 25645c4be3SJohn Polstra.\" 26645c4be3SJohn Polstra.\" $Id: dladdr.3,v 1.1 1998/02/06 16:46:34 jdp Exp $ 27645c4be3SJohn Polstra.\" 28645c4be3SJohn Polstra.Dd February 5, 1998 29645c4be3SJohn Polstra.Os FreeBSD 30645c4be3SJohn Polstra.Dt DLADDR 3 31645c4be3SJohn Polstra.Sh NAME 32645c4be3SJohn Polstra.Nm dladdr 33645c4be3SJohn Polstra.Nd find the shared object containing a given address 34645c4be3SJohn Polstra.Sh SYNOPSIS 35645c4be3SJohn Polstra.Fd #include <dlfcn.h> 36645c4be3SJohn Polstra.Ft int 37645c4be3SJohn Polstra.Fn dladdr "const void *addr" "Dl_info *info" 38645c4be3SJohn Polstra.Sh DESCRIPTION 39645c4be3SJohn Polstra.Nm 40645c4be3SJohn Polstraqueries the dynamic linker for information about the shared object 41645c4be3SJohn Polstracontaining the address 42645c4be3SJohn Polstra.Fa addr . 43645c4be3SJohn PolstraThe information is returned in the structure specified by 44645c4be3SJohn Polstra.Fa info . 45645c4be3SJohn PolstraThe structure contains at least the following members: 46645c4be3SJohn Polstra.Bl -tag -width "XXXconst char *dli_fname" 47645c4be3SJohn Polstra.It Li "const char *dli_fname" 48645c4be3SJohn PolstraThe pathname of the shared object containing the address. 49645c4be3SJohn Polstra.It Li "void *dli_fbase" 50645c4be3SJohn PolstraThe base address at which the shared object is mapped into the 51645c4be3SJohn Polstraaddress space of the calling process. 52645c4be3SJohn Polstra.It Li "const char *dli_sname" 53645c4be3SJohn PolstraThe name of the nearest run-time symbol with a value less than or 54645c4be3SJohn Polstraequal to 55645c4be3SJohn Polstra.Fa addr . 56645c4be3SJohn PolstraWhen possible, the symbol name is returned as it would appear in C 57645c4be3SJohn Polstrasource code. 58645c4be3SJohn Polstra.Pp 59645c4be3SJohn PolstraIf no symbol with a suitable value is found, both this field and 60645c4be3SJohn Polstra.Va dli_saddr 61645c4be3SJohn Polstraare set to 62645c4be3SJohn Polstra.Dv NULL . 63645c4be3SJohn Polstra.It Li "void *dli_saddr" 64645c4be3SJohn PolstraThe value of the symbol returned in 65645c4be3SJohn Polstra.Li dli_sname . 66645c4be3SJohn Polstra.El 67645c4be3SJohn Polstra.Pp 68645c4be3SJohn Polstra.Nm 69645c4be3SJohn Polstrais available only in dynamically linked programs. 70645c4be3SJohn Polstra.Sh ERRORS 71645c4be3SJohn PolstraIf a mapped shared object containing 72645c4be3SJohn Polstra.Fa addr 73645c4be3SJohn Polstracannot be found, 74645c4be3SJohn Polstra.Nm 75645c4be3SJohn Polstrareturns 0. 76645c4be3SJohn PolstraIn that case, a message detailing the failure can be retrieved by 77645c4be3SJohn Polstracalling 78645c4be3SJohn Polstra.Fn dlerror . 79645c4be3SJohn Polstra.Pp 80645c4be3SJohn PolstraOn success, a non-zero value is returned. 81645c4be3SJohn Polstra.Sh SEE ALSO 82645c4be3SJohn Polstra.Xr dlopen 3 , 83645c4be3SJohn Polstra.Xr rtld 1 84645c4be3SJohn Polstra.Sh HISTORY 85645c4be3SJohn PolstraThe 86645c4be3SJohn Polstra.Nm 87645c4be3SJohn Polstrafunction first appeared in the Solaris operating system. 88645c4be3SJohn Polstra.Sh BUGS 89645c4be3SJohn PolstraThis implementation is bug-compatible with the Solaris 90645c4be3SJohn Polstraimplementation. In particular, the following bugs are present: 91645c4be3SJohn Polstra.Bl -bullet 92645c4be3SJohn Polstra.It 93645c4be3SJohn PolstraIf 94645c4be3SJohn Polstra.Fa addr 95645c4be3SJohn Polstralies in the main executable rather than in a shared library, the 96645c4be3SJohn Polstrapathname returned in 97645c4be3SJohn Polstra.Va dli_fname 98645c4be3SJohn Polstramay not be correct. The pathname is taken directly from 99645c4be3SJohn Polstra.Va argv[0] 100645c4be3SJohn Polstraof the calling process. When executing a program specified by its 101645c4be3SJohn Polstrafull pathname, most shells set 102645c4be3SJohn Polstra.Va argv[0] 103645c4be3SJohn Polstrato the pathname. But this is not required of shells or guaranteed 104645c4be3SJohn Polstraby the operating system. 105645c4be3SJohn Polstra.It 106645c4be3SJohn PolstraIf 107645c4be3SJohn Polstra.Fa addr 108645c4be3SJohn Polstrais of the form 109645c4be3SJohn Polstra.Va &func , 110645c4be3SJohn Polstrawhere 111645c4be3SJohn Polstra.Va func 112645c4be3SJohn Polstrais a global function, its value may be an unpleasant surprise. In 113645c4be3SJohn Polstradynamically linked programs, the address of a global function is 114645c4be3SJohn Polstraconsidered to point to its program linkage table entry, rather than to 115645c4be3SJohn Polstrathe entry point of the function itself. This causes most global 116645c4be3SJohn Polstrafunctions to appear to be defined within the main executable, rather 117645c4be3SJohn Polstrathan in the shared libraries where the actual code resides. 118645c4be3SJohn Polstra.It 119645c4be3SJohn PolstraReturning 0 as an indication of failure goes against long-standing 120645c4be3SJohn PolstraUnix tradition. 121645c4be3SJohn Polstra.El 122