xref: /freebsd/lib/libc/gen/dladdr.3 (revision 95f4226b2755f1600e3bf4e32e8aa0db0886c280)
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
29a307d598SRuslan Ermilov.Os
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
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
96645c4be3SJohn Polstraimplementation.  In particular, the following bugs are present:
97645c4be3SJohn Polstra.Bl -bullet
98645c4be3SJohn Polstra.It
99645c4be3SJohn PolstraIf
100645c4be3SJohn Polstra.Fa addr
101645c4be3SJohn Polstralies in the main executable rather than in a shared library, the
102645c4be3SJohn Polstrapathname returned in
103645c4be3SJohn Polstra.Va dli_fname
104645c4be3SJohn Polstramay not be correct.  The pathname is taken directly from
105645c4be3SJohn Polstra.Va argv[0]
106645c4be3SJohn Polstraof the calling process.  When executing a program specified by its
107645c4be3SJohn Polstrafull pathname, most shells set
108645c4be3SJohn Polstra.Va argv[0]
109645c4be3SJohn Polstrato the pathname.  But this is not required of shells or guaranteed
110645c4be3SJohn Polstraby the operating system.
111645c4be3SJohn Polstra.It
112645c4be3SJohn PolstraIf
113645c4be3SJohn Polstra.Fa addr
114645c4be3SJohn Polstrais of the form
115645c4be3SJohn Polstra.Va &func ,
116645c4be3SJohn Polstrawhere
117645c4be3SJohn Polstra.Va func
118645c4be3SJohn Polstrais a global function, its value may be an unpleasant surprise.  In
119645c4be3SJohn Polstradynamically linked programs, the address of a global function is
120645c4be3SJohn Polstraconsidered to point to its program linkage table entry, rather than to
121645c4be3SJohn Polstrathe entry point of the function itself.  This causes most global
122645c4be3SJohn Polstrafunctions to appear to be defined within the main executable, rather
123645c4be3SJohn Polstrathan in the shared libraries where the actual code resides.
124645c4be3SJohn Polstra.It
125645c4be3SJohn PolstraReturning 0 as an indication of failure goes against long-standing
126645c4be3SJohn PolstraUnix tradition.
127645c4be3SJohn Polstra.El
128