]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/gen/dladdr.3
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / gen / dladdr.3
1 .\"
2 .\" Copyright (c) 1998 John D. Polstra
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd February 5, 1998
29 .Dt DLADDR 3
30 .Os
31 .Sh NAME
32 .Nm dladdr
33 .Nd find the shared object containing a given address
34 .Sh LIBRARY
35 .Lb libc
36 .Sh SYNOPSIS
37 .In dlfcn.h
38 .Ft int
39 .Fn dladdr "const void *addr" "Dl_info *info"
40 .Sh DESCRIPTION
41 The
42 .Fn dladdr
43 function
44 queries the dynamic linker for information about the shared object
45 containing the address
46 .Fa addr .
47 The information is returned in the structure specified by
48 .Fa info .
49 The structure contains at least the following members:
50 .Bl -tag -width "XXXconst char *dli_fname"
51 .It Li "const char *dli_fname"
52 The pathname of the shared object containing the address.
53 .It Li "void *dli_fbase"
54 The base address at which the shared object is mapped into the
55 address space of the calling process.
56 .It Li "const char *dli_sname"
57 The name of the nearest run-time symbol with a value less than or
58 equal to
59 .Fa addr .
60 When possible, the symbol name is returned as it would appear in C
61 source code.
62 .Pp
63 If no symbol with a suitable value is found, both this field and
64 .Va dli_saddr
65 are set to
66 .Dv NULL .
67 .It Li "void *dli_saddr"
68 The value of the symbol returned in
69 .Li dli_sname .
70 .El
71 .Pp
72 The
73 .Fn dladdr
74 function
75 is available only in dynamically linked programs.
76 .Sh ERRORS
77 If a mapped shared object containing
78 .Fa addr
79 cannot be found,
80 .Fn dladdr
81 returns 0.
82 In that case, a message detailing the failure can be retrieved by
83 calling
84 .Fn dlerror .
85 .Pp
86 On success, a non-zero value is returned.
87 .Sh SEE ALSO
88 .Xr rtld 1 ,
89 .Xr dlopen 3
90 .Sh HISTORY
91 The
92 .Fn dladdr
93 function first appeared in the Solaris operating system.
94 .Sh BUGS
95 This implementation is bug-compatible with the Solaris
96 implementation.
97 In particular, the following bugs are present:
98 .Bl -bullet
99 .It
100 If
101 .Fa addr
102 lies in the main executable rather than in a shared library, the
103 pathname returned in
104 .Va dli_fname
105 may not be correct.
106 The pathname is taken directly from
107 .Va argv[0]
108 of the calling process.
109 When executing a program specified by its
110 full pathname, most shells set
111 .Va argv[0]
112 to the pathname.
113 But this is not required of shells or guaranteed
114 by the operating system.
115 .It
116 If
117 .Fa addr
118 is of the form
119 .Va &func ,
120 where
121 .Va func
122 is a global function, its value may be an unpleasant surprise.
123 In
124 dynamically linked programs, the address of a global function is
125 considered to point to its program linkage table entry, rather than to
126 the entry point of the function itself.
127 This causes most global
128 functions to appear to be defined within the main executable, rather
129 than in the shared libraries where the actual code resides.
130 .It
131 Returning 0 as an indication of failure goes against long-standing
132 Unix tradition.
133 .El