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.\" 267f3dea24SPeter Wemm.\" $FreeBSD$ 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 3425bb73e0SAlexey Zelkin.Sh LIBRARY 3525bb73e0SAlexey Zelkin.Lb libc 36645c4be3SJohn Polstra.Sh SYNOPSIS 37645c4be3SJohn Polstra.Fd #include <dlfcn.h> 38645c4be3SJohn Polstra.Ft int 39645c4be3SJohn Polstra.Fn dladdr "const void *addr" "Dl_info *info" 40645c4be3SJohn Polstra.Sh DESCRIPTION 41645c4be3SJohn Polstra.Nm 42645c4be3SJohn Polstraqueries the dynamic linker for information about the shared object 43645c4be3SJohn Polstracontaining the address 44645c4be3SJohn Polstra.Fa addr . 45645c4be3SJohn PolstraThe information is returned in the structure specified by 46645c4be3SJohn Polstra.Fa info . 47645c4be3SJohn PolstraThe structure contains at least the following members: 48645c4be3SJohn Polstra.Bl -tag -width "XXXconst char *dli_fname" 49645c4be3SJohn Polstra.It Li "const char *dli_fname" 50645c4be3SJohn PolstraThe pathname of the shared object containing the address. 51645c4be3SJohn Polstra.It Li "void *dli_fbase" 52645c4be3SJohn PolstraThe base address at which the shared object is mapped into the 53645c4be3SJohn Polstraaddress space of the calling process. 54645c4be3SJohn Polstra.It Li "const char *dli_sname" 55645c4be3SJohn PolstraThe name of the nearest run-time symbol with a value less than or 56645c4be3SJohn Polstraequal to 57645c4be3SJohn Polstra.Fa addr . 58645c4be3SJohn PolstraWhen possible, the symbol name is returned as it would appear in C 59645c4be3SJohn Polstrasource code. 60645c4be3SJohn Polstra.Pp 61645c4be3SJohn PolstraIf no symbol with a suitable value is found, both this field and 62645c4be3SJohn Polstra.Va dli_saddr 63645c4be3SJohn Polstraare set to 64645c4be3SJohn Polstra.Dv NULL . 65645c4be3SJohn Polstra.It Li "void *dli_saddr" 66645c4be3SJohn PolstraThe value of the symbol returned in 67645c4be3SJohn Polstra.Li dli_sname . 68645c4be3SJohn Polstra.El 69645c4be3SJohn Polstra.Pp 70645c4be3SJohn Polstra.Nm 71645c4be3SJohn Polstrais available only in dynamically linked programs. 72645c4be3SJohn Polstra.Sh ERRORS 73645c4be3SJohn PolstraIf a mapped shared object containing 74645c4be3SJohn Polstra.Fa addr 75645c4be3SJohn Polstracannot be found, 76645c4be3SJohn Polstra.Nm 77645c4be3SJohn Polstrareturns 0. 78645c4be3SJohn PolstraIn that case, a message detailing the failure can be retrieved by 79645c4be3SJohn Polstracalling 80645c4be3SJohn Polstra.Fn dlerror . 81645c4be3SJohn Polstra.Pp 82645c4be3SJohn PolstraOn success, a non-zero value is returned. 83645c4be3SJohn Polstra.Sh SEE ALSO 84acd80190SWolfram Schneider.Xr rtld 1 , 85acd80190SWolfram Schneider.Xr dlopen 3 86645c4be3SJohn Polstra.Sh HISTORY 87645c4be3SJohn PolstraThe 88645c4be3SJohn Polstra.Nm 89645c4be3SJohn Polstrafunction first appeared in the Solaris operating system. 90645c4be3SJohn Polstra.Sh BUGS 91645c4be3SJohn PolstraThis implementation is bug-compatible with the Solaris 92645c4be3SJohn Polstraimplementation. In particular, the following bugs are present: 93645c4be3SJohn Polstra.Bl -bullet 94645c4be3SJohn Polstra.It 95645c4be3SJohn PolstraIf 96645c4be3SJohn Polstra.Fa addr 97645c4be3SJohn Polstralies in the main executable rather than in a shared library, the 98645c4be3SJohn Polstrapathname returned in 99645c4be3SJohn Polstra.Va dli_fname 100645c4be3SJohn Polstramay not be correct. The pathname is taken directly from 101645c4be3SJohn Polstra.Va argv[0] 102645c4be3SJohn Polstraof the calling process. When executing a program specified by its 103645c4be3SJohn Polstrafull pathname, most shells set 104645c4be3SJohn Polstra.Va argv[0] 105645c4be3SJohn Polstrato the pathname. But this is not required of shells or guaranteed 106645c4be3SJohn Polstraby the operating system. 107645c4be3SJohn Polstra.It 108645c4be3SJohn PolstraIf 109645c4be3SJohn Polstra.Fa addr 110645c4be3SJohn Polstrais of the form 111645c4be3SJohn Polstra.Va &func , 112645c4be3SJohn Polstrawhere 113645c4be3SJohn Polstra.Va func 114645c4be3SJohn Polstrais a global function, its value may be an unpleasant surprise. In 115645c4be3SJohn Polstradynamically linked programs, the address of a global function is 116645c4be3SJohn Polstraconsidered to point to its program linkage table entry, rather than to 117645c4be3SJohn Polstrathe entry point of the function itself. This causes most global 118645c4be3SJohn Polstrafunctions to appear to be defined within the main executable, rather 119645c4be3SJohn Polstrathan in the shared libraries where the actual code resides. 120645c4be3SJohn Polstra.It 121645c4be3SJohn PolstraReturning 0 as an indication of failure goes against long-standing 122645c4be3SJohn PolstraUnix tradition. 123645c4be3SJohn Polstra.El 124