xref: /freebsd/lib/libc/gen/dladdr.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.Dd February 5, 1998
27645c4be3SJohn Polstra.Dt DLADDR 3
28*aa12cea2SUlrich Spörlein.Os
29645c4be3SJohn Polstra.Sh NAME
30645c4be3SJohn Polstra.Nm dladdr
31645c4be3SJohn Polstra.Nd find the shared object containing a given address
3225bb73e0SAlexey Zelkin.Sh LIBRARY
3325bb73e0SAlexey Zelkin.Lb libc
34645c4be3SJohn Polstra.Sh SYNOPSIS
3532eef9aeSRuslan Ermilov.In dlfcn.h
36645c4be3SJohn Polstra.Ft int
37645c4be3SJohn Polstra.Fn dladdr "const void *addr" "Dl_info *info"
38645c4be3SJohn Polstra.Sh DESCRIPTION
3995f4226bSRuslan ErmilovThe
4095f4226bSRuslan Ermilov.Fn dladdr
4195f4226bSRuslan Ermilovfunction
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
7095f4226bSRuslan ErmilovThe
7195f4226bSRuslan Ermilov.Fn dladdr
7295f4226bSRuslan Ermilovfunction
73645c4be3SJohn Polstrais available only in dynamically linked programs.
74645c4be3SJohn Polstra.Sh ERRORS
75645c4be3SJohn PolstraIf a mapped shared object containing
76645c4be3SJohn Polstra.Fa addr
77645c4be3SJohn Polstracannot be found,
7895f4226bSRuslan Ermilov.Fn dladdr
79645c4be3SJohn Polstrareturns 0.
80645c4be3SJohn PolstraIn that case, a message detailing the failure can be retrieved by
81645c4be3SJohn Polstracalling
82645c4be3SJohn Polstra.Fn dlerror .
83645c4be3SJohn Polstra.Pp
84645c4be3SJohn PolstraOn success, a non-zero value is returned.
85645c4be3SJohn Polstra.Sh SEE ALSO
86acd80190SWolfram Schneider.Xr rtld 1 ,
87acd80190SWolfram Schneider.Xr dlopen 3
88645c4be3SJohn Polstra.Sh HISTORY
89645c4be3SJohn PolstraThe
9095f4226bSRuslan Ermilov.Fn dladdr
91645c4be3SJohn Polstrafunction first appeared in the Solaris operating system.
92645c4be3SJohn Polstra.Sh BUGS
93645c4be3SJohn PolstraThis implementation is bug-compatible with the Solaris
941a0a9345SRuslan Ermilovimplementation.
951a0a9345SRuslan ErmilovIn particular, the following bugs are present:
96645c4be3SJohn Polstra.Bl -bullet
97645c4be3SJohn Polstra.It
98645c4be3SJohn PolstraIf
99645c4be3SJohn Polstra.Fa addr
100645c4be3SJohn Polstralies in the main executable rather than in a shared library, the
101645c4be3SJohn Polstrapathname returned in
102645c4be3SJohn Polstra.Va dli_fname
1031a0a9345SRuslan Ermilovmay not be correct.
1041a0a9345SRuslan ErmilovThe pathname is taken directly from
105645c4be3SJohn Polstra.Va argv[0]
1061a0a9345SRuslan Ermilovof the calling process.
1071a0a9345SRuslan ErmilovWhen executing a program specified by its
108645c4be3SJohn Polstrafull pathname, most shells set
109645c4be3SJohn Polstra.Va argv[0]
1101a0a9345SRuslan Ermilovto the pathname.
1111a0a9345SRuslan ErmilovBut this is not required of shells or guaranteed
112645c4be3SJohn Polstraby the operating system.
113645c4be3SJohn Polstra.It
114645c4be3SJohn PolstraIf
115645c4be3SJohn Polstra.Fa addr
116645c4be3SJohn Polstrais of the form
117645c4be3SJohn Polstra.Va &func ,
118645c4be3SJohn Polstrawhere
119645c4be3SJohn Polstra.Va func
1201a0a9345SRuslan Ermilovis a global function, its value may be an unpleasant surprise.
1211a0a9345SRuslan ErmilovIn
122645c4be3SJohn Polstradynamically linked programs, the address of a global function is
123645c4be3SJohn Polstraconsidered to point to its program linkage table entry, rather than to
1241a0a9345SRuslan Ermilovthe entry point of the function itself.
1251a0a9345SRuslan ErmilovThis causes most global
126645c4be3SJohn Polstrafunctions to appear to be defined within the main executable, rather
127645c4be3SJohn Polstrathan in the shared libraries where the actual code resides.
128645c4be3SJohn Polstra.It
129645c4be3SJohn PolstraReturning 0 as an indication of failure goes against long-standing
130645c4be3SJohn PolstraUnix tradition.
131645c4be3SJohn Polstra.El
132