xref: /freebsd/lib/libc/gen/dladdr.3 (revision aa12cea2ccc6e686d6d31cf67d6bc69cbc1ba744)
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.Dt DLADDR 3
30*aa12cea2SUlrich Spörlein.Os
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
3732eef9aeSRuslan Ermilov.In dlfcn.h
38645c4be3SJohn Polstra.Ft int
39645c4be3SJohn Polstra.Fn dladdr "const void *addr" "Dl_info *info"
40645c4be3SJohn Polstra.Sh DESCRIPTION
4195f4226bSRuslan ErmilovThe
4295f4226bSRuslan Ermilov.Fn dladdr
4395f4226bSRuslan Ermilovfunction
44645c4be3SJohn Polstraqueries the dynamic linker for information about the shared object
45645c4be3SJohn Polstracontaining the address
46645c4be3SJohn Polstra.Fa addr .
47645c4be3SJohn PolstraThe information is returned in the structure specified by
48645c4be3SJohn Polstra.Fa info .
49645c4be3SJohn PolstraThe structure contains at least the following members:
50645c4be3SJohn Polstra.Bl -tag -width "XXXconst char *dli_fname"
51645c4be3SJohn Polstra.It Li "const char *dli_fname"
52645c4be3SJohn PolstraThe pathname of the shared object containing the address.
53645c4be3SJohn Polstra.It Li "void *dli_fbase"
54645c4be3SJohn PolstraThe base address at which the shared object is mapped into the
55645c4be3SJohn Polstraaddress space of the calling process.
56645c4be3SJohn Polstra.It Li "const char *dli_sname"
57645c4be3SJohn PolstraThe name of the nearest run-time symbol with a value less than or
58645c4be3SJohn Polstraequal to
59645c4be3SJohn Polstra.Fa addr .
60645c4be3SJohn PolstraWhen possible, the symbol name is returned as it would appear in C
61645c4be3SJohn Polstrasource code.
62645c4be3SJohn Polstra.Pp
63645c4be3SJohn PolstraIf no symbol with a suitable value is found, both this field and
64645c4be3SJohn Polstra.Va dli_saddr
65645c4be3SJohn Polstraare set to
66645c4be3SJohn Polstra.Dv NULL .
67645c4be3SJohn Polstra.It Li "void *dli_saddr"
68645c4be3SJohn PolstraThe value of the symbol returned in
69645c4be3SJohn Polstra.Li dli_sname .
70645c4be3SJohn Polstra.El
71645c4be3SJohn Polstra.Pp
7295f4226bSRuslan ErmilovThe
7395f4226bSRuslan Ermilov.Fn dladdr
7495f4226bSRuslan Ermilovfunction
75645c4be3SJohn Polstrais available only in dynamically linked programs.
76645c4be3SJohn Polstra.Sh ERRORS
77645c4be3SJohn PolstraIf a mapped shared object containing
78645c4be3SJohn Polstra.Fa addr
79645c4be3SJohn Polstracannot be found,
8095f4226bSRuslan Ermilov.Fn dladdr
81645c4be3SJohn Polstrareturns 0.
82645c4be3SJohn PolstraIn that case, a message detailing the failure can be retrieved by
83645c4be3SJohn Polstracalling
84645c4be3SJohn Polstra.Fn dlerror .
85645c4be3SJohn Polstra.Pp
86645c4be3SJohn PolstraOn success, a non-zero value is returned.
87645c4be3SJohn Polstra.Sh SEE ALSO
88acd80190SWolfram Schneider.Xr rtld 1 ,
89acd80190SWolfram Schneider.Xr dlopen 3
90645c4be3SJohn Polstra.Sh HISTORY
91645c4be3SJohn PolstraThe
9295f4226bSRuslan Ermilov.Fn dladdr
93645c4be3SJohn Polstrafunction first appeared in the Solaris operating system.
94645c4be3SJohn Polstra.Sh BUGS
95645c4be3SJohn PolstraThis implementation is bug-compatible with the Solaris
961a0a9345SRuslan Ermilovimplementation.
971a0a9345SRuslan ErmilovIn particular, the following bugs are present:
98645c4be3SJohn Polstra.Bl -bullet
99645c4be3SJohn Polstra.It
100645c4be3SJohn PolstraIf
101645c4be3SJohn Polstra.Fa addr
102645c4be3SJohn Polstralies in the main executable rather than in a shared library, the
103645c4be3SJohn Polstrapathname returned in
104645c4be3SJohn Polstra.Va dli_fname
1051a0a9345SRuslan Ermilovmay not be correct.
1061a0a9345SRuslan ErmilovThe pathname is taken directly from
107645c4be3SJohn Polstra.Va argv[0]
1081a0a9345SRuslan Ermilovof the calling process.
1091a0a9345SRuslan ErmilovWhen executing a program specified by its
110645c4be3SJohn Polstrafull pathname, most shells set
111645c4be3SJohn Polstra.Va argv[0]
1121a0a9345SRuslan Ermilovto the pathname.
1131a0a9345SRuslan ErmilovBut this is not required of shells or guaranteed
114645c4be3SJohn Polstraby the operating system.
115645c4be3SJohn Polstra.It
116645c4be3SJohn PolstraIf
117645c4be3SJohn Polstra.Fa addr
118645c4be3SJohn Polstrais of the form
119645c4be3SJohn Polstra.Va &func ,
120645c4be3SJohn Polstrawhere
121645c4be3SJohn Polstra.Va func
1221a0a9345SRuslan Ermilovis a global function, its value may be an unpleasant surprise.
1231a0a9345SRuslan ErmilovIn
124645c4be3SJohn Polstradynamically linked programs, the address of a global function is
125645c4be3SJohn Polstraconsidered to point to its program linkage table entry, rather than to
1261a0a9345SRuslan Ermilovthe entry point of the function itself.
1271a0a9345SRuslan ErmilovThis causes most global
128645c4be3SJohn Polstrafunctions to appear to be defined within the main executable, rather
129645c4be3SJohn Polstrathan in the shared libraries where the actual code resides.
130645c4be3SJohn Polstra.It
131645c4be3SJohn PolstraReturning 0 as an indication of failure goes against long-standing
132645c4be3SJohn PolstraUnix tradition.
133645c4be3SJohn Polstra.El
134