1 .\" Copyright (C) 2015 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (C) 2008 Petr Baudis <pasky@suse.cz> (dladdr caveat)
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH DLADDR 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
8 dladdr, dladdr1 \- translate address to symbolic information
10 Dynamic linking library
11 .RI ( libdl ", " \-ldl )
14 .B #define _GNU_SOURCE
17 .BI "int dladdr(const void *" addr ", Dl_info *" info );
18 .BI "int dladdr1(const void *" addr ", Dl_info *" info ", void **" extra_info ,
24 determines whether the address specified in
26 is located in one of the shared objects loaded by the calling application.
29 returns information about the shared object and symbol that overlaps
31 This information is returned in a
38 const char *dli_fname; /* Pathname of shared object that
40 void *dli_fbase; /* Base address at which shared
42 const char *dli_sname; /* Name of symbol whose definition
43 overlaps \fIaddr\fP */
44 void *dli_saddr; /* Exact address of symbol named
62 but returns additional information via the argument
64 The information returned depends on the value specified in
66 which can have one of the following values:
69 Obtain a pointer to the link map for the matched file.
72 argument points to a pointer to a
75 .IR "struct link_map\~**" ),
83 ElfW(Addr) l_addr; /* Difference between the
84 address in the ELF file and
85 the address in memory */
86 char *l_name; /* Absolute pathname where
88 ElfW(Dyn) *l_ld; /* Dynamic section of the
90 struct link_map *l_next, *l_prev;
91 /* Chain of loaded objects */
93 /* Plus additional fields private to the
100 Obtain a pointer to the ELF symbol table entry of the matching symbol.
103 argument is a pointer to a symbol pointer:
104 .IR "const ElfW(Sym) **" .
107 macro definition turns its argument into the name of an ELF data
108 type suitable for the hardware architecture.
109 For example, on a 64-bit platform,
111 yields the data type name
120 Elf64_Word st_name; /* Symbol name */
121 unsigned char st_info; /* Symbol type and binding */
122 unsigned char st_other; /* Symbol visibility */
123 Elf64_Section st_shndx; /* Section index */
124 Elf64_Addr st_value; /* Symbol value */
125 Elf64_Xword st_size; /* Symbol size */
132 field is an index into the string table.
136 field encodes the symbol's type and binding.
137 The type can be extracted using the macro
138 .B ELF64_ST_TYPE(st_info)
141 on 32-bit platforms), which yields one of the following values:
147 STT_NOTYPE Symbol type is unspecified
148 STT_OBJECT Symbol is a data object
149 STT_FUNC Symbol is a code object
150 STT_SECTION Symbol associated with a section
151 STT_FILE Symbol's name is filename
152 STT_COMMON Symbol is a common data object
153 STT_TLS Symbol is thread-local data object
154 STT_GNU_IFUNC Symbol is indirect code object
158 The symbol binding can be extracted from the
160 field using the macro
161 .B ELF64_ST_BIND(st_info)
164 on 32-bit platforms), which yields one of the following values:
170 STB_LOCAL Local symbol
171 STB_GLOBAL Global symbol
173 STB_GNU_UNIQUE Unique symbol
179 field contains the symbol's visibility, which can be extracted using the macro
180 .B ELF64_ST_VISIBILITY(st_info)
182 .B ELF32_ST_VISIBILITY()
183 on 32-bit platforms), which yields one of the following values:
189 STV_DEFAULT Default symbol visibility rules
190 STV_INTERNAL Processor-specific hidden class
191 STV_HIDDEN Symbol unavailable in other modules
192 STV_PROTECTED Not preemptible, not exported
196 On success, these functions return a nonzero value.
197 If the address specified in
199 could be matched to a shared object,
200 but not to a symbol in the shared object, then the
204 fields are set to NULL.
206 If the address specified in
208 could not be matched to a shared object, then these functions return 0.
209 In this case, an error message is
211 .\" According to the FreeBSD man page, dladdr1() does signal an
212 .\" error via dlerror() for this case.
217 is present in glibc 2.0 and later.
219 first appeared in glibc 2.3.3.
221 For an explanation of the terms used in this section, see
229 Interface Attribute Value
233 T} Thread safety MT-Safe
239 These functions are nonstandard GNU extensions
240 that are also present on Solaris.
242 Sometimes, the function pointers you pass to
245 On some architectures (notably i386 and x86-64),
249 may end up pointing back at the object from which you called
251 even if the function used as an argument should come from
252 a dynamically linked library.
254 The problem is that the function pointer will still be resolved
255 at compile time, but merely point to the
257 (Procedure Linkage Table)
258 section of the original object (which dispatches the call after
259 asking the dynamic linker to resolve the symbol).
261 you can try to compile the code to be position-independent:
262 then, the compiler cannot prepare the pointer
263 at compile time any more and
265 will generate code that just loads the final symbol address from the
267 (Global Offset Table) at run time before passing it to
270 .BR dl_iterate_phdr (3),