2 .\" Copyright (C) 2015 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" and Copyright (C) 2008 Petr Baudis <pasky@suse.cz> (dladdr caveat)
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
27 .TH DLADDR 3 2017-09-15 "Linux" "Linux Programmer's Manual"
29 dladdr, dladdr1 \- translate address to symbolic information
32 .B #define _GNU_SOURCE
35 .BI "int dladdr(void *" addr ", Dl_info *" info );
37 .BI "int dladdr1(void *" addr ", Dl_info *" info ", void **" \
38 extra_info ", int " flags );
40 Link with \fI\-ldl\fP.
45 determines whether the address specified in
47 is located in one of the shared objects loaded by the calling application.
50 returns information about the shared object and symbol that overlaps
52 This information is returned in a
59 const char *dli_fname; /* Pathname of shared object that
61 void *dli_fbase; /* Base address at which shared
63 const char *dli_sname; /* Name of symbol whose definition
64 overlaps \fIaddr\fP */
65 void *dli_saddr; /* Exact address of symbol named
83 but returns additional information via the argument
85 The information returned depends on the value specified in
87 which can have one of the following values:
90 Obtain a pointer to the link map for the matched file.
93 argument points to a pointer to a
96 .IR "struct link_map\ **" ),
104 ElfW(Addr) l_addr; /* Difference between the
105 address in the ELF file and
106 the address in memory */
107 char *l_name; /* Absolute pathname where
109 ElfW(Dyn) *l_ld; /* Dynamic section of the
111 struct link_map *l_next, *l_prev;
112 /* Chain of loaded objects */
114 /* Plus additional fields private to the
121 Obtain a pointer to the ELF symbol table entry of the matching symbol.
124 argument is a pointer to a symbol pointer:
125 .IR "const ElfW(Sym) **" .
128 macro definition turns its argument into the name of an ELF data
129 type suitable for the hardware architecture.
130 For example, on a 64-bit platform,
132 yields the data type name
141 Elf64_Word st_name; /* Symbol name */
142 unsigned char st_info; /* Symbol type and binding */
143 unsigned char st_other; /* Symbol visibility */
144 Elf64_Section st_shndx; /* Section index */
145 Elf64_Addr st_value; /* Symbol value */
146 Elf64_Xword st_size; /* Symbol size */
153 field is an index into the string table.
157 field encodes the symbol's type and binding.
158 The type can be extracted using the macro
159 .BR ELF64_ST_TYPE(st_info)
162 on 32-bit platforms), which yields one of the following values:
168 STT_NOTYPE Symbol type is unspecified
169 STT_OBJECT Symbol is a data object
170 STT_FUNC Symbol is a code object
171 STT_SECTION Symbol associated with a section
172 STT_FILE Symbol's name is file name
173 STT_COMMON Symbol is a common data object
174 STT_TLS Symbol is thread-local data object
175 STT_GNU_IFUNC Symbol is indirect code object
179 The symbol binding can be extracted from the
181 field using the macro
182 .BR ELF64_ST_BIND(st_info)
185 on 32-bit platforms), which yields one of the following values:
191 STB_LOCAL Local symbol
192 STB_GLOBAL Global symbol
194 STB_GNU_UNIQUE Unique symbol
200 field contains the symbol's visibility, which can be extracted using the macro
201 .BR ELF64_ST_VISIBILITY(st_info)
203 .BR ELF32_ST_VISIBILITY()
204 on 32-bit platforms), which yields one of the following values:
210 STV_DEFAULT Default symbol visibility rules
211 STV_INTERNAL Processor-specific hidden class
212 STV_HIDDEN Symbol unavailable in other modules
213 STV_PROTECTED Not preemptible, not exported
217 On success, these functions return a nonzero value.
218 If the address specified in
220 could be matched to a shared object,
221 but not to a symbol in the shared object, then the
225 fields are set to NULL.
227 If the address specified in
229 could not be matched to a shared object, then these functions return 0.
230 In this case, an error message is
232 .\" According to the FreeBSD man page, dladdr1() does signal an
233 .\" error via dlerror() for this case.
238 is present in glibc 2.0 and later.
240 first appeared in glibc 2.3.3.
242 For an explanation of the terms used in this section, see
248 Interface Attribute Value
252 T} Thread safety MT-Safe
255 These functions are nonstandard GNU extensions
256 that are also present on Solaris.
258 Sometimes, the function pointers you pass to
261 On some architectures (notably i386 and x86-64),
265 may end up pointing back at the object from which you called
267 even if the function used as an argument should come from
268 a dynamically linked library.
270 The problem is that the function pointer will still be resolved
271 at compile time, but merely point to the
273 (Procedure Linkage Table)
274 section of the original object (which dispatches the call after
275 asking the dynamic linker to resolve the symbol).
277 you can try to compile the code to be position-independent:
278 then, the compiler cannot prepare the pointer
279 at compile time any more and
281 will generate code that just loads the final symbol address from the
283 (Global Offset Table) at run time before passing it to
286 .BR dl_iterate_phdr (3),