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