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 2015-08-08 "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:
192 STB_LOCAL Local symbol
193 STB_GLOBAL Global symbol
195 STB_GNU_UNIQUE Unique symbol
201 field contains the symbol's visibility, which can be extracted using the macro
202 .BR ELF64_ST_VISIBILITY(st_info)
204 .BR ELF32_ST_VISIBILITY()
205 on 32-bit platforms), which yields one of the following values:
211 STV_DEFAULT Default symbol visibility rules
212 STV_INTERNAL Processor-specific hidden class
213 STV_HIDDEN Symbol unavailable in other modules
214 STV_PROTECTED Not preemptible, not exported
218 On success, these functions return a nonzero value.
219 If the address specified in
221 could be matched to a shared object,
222 but not to a symbol in the shared object, then the
226 fields are set to NULL.
229 If the address specified in
231 could not be matched to a shared object, then these functions return 0.
232 In this case, an error message is
234 .\" According to the FreeBSD man page, dladdr1() does signal an
235 .\" error via dlerror() for this case.
240 is present in glibc 2.0 and later.
242 first appeared in glibc 2.3.3.
244 For an explanation of the terms used in this section, see
250 Interface Attribute Value
254 T} Thread safety MT-Safe
257 These functions are nonstandard GNU extensions
258 that are also present on Solaris.
260 Sometimes, the function pointers you pass to
263 On some architectures (notably i386 and x86_64),
267 may end up pointing back at the object from which you called
269 even if the function used as an argument should come from
270 a dynamically linked library.
272 The problem is that the function pointer will still be resolved
273 at compile time, but merely point to the
275 (Procedure Linkage Table)
276 section of the original object (which dispatches the call after
277 asking the dynamic linker to resolve the symbol).
279 you can try to compile the code to be position-independent:
280 then, the compiler cannot prepare the pointer
281 at compile time any more and
283 will generate code that just loads the final symbol address from the
285 (Global Offset Table) at run time before passing it to
288 .BR dl_iterate_phdr (3),