NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ATTRIBUTES |STANDARDS |HISTORY |BUGS |SEE ALSO |COLOPHON | |
dladdr(3) Library Functions Manualdladdr(3)dladdr, dladdr1 - translate address to symbolic information
Dynamic linking library (libdl,-ldl)
#define _GNU_SOURCE#include <dlfcn.h>int dladdr(const void *addr, Dl_info *info);int dladdr1(const void *addr, Dl_info *info, void **extra_info,intflags);
The functiondladdr() determines whether the address specified inaddr is located in one of the shared objects loaded by the calling application. If it is, thendladdr() returns information about the shared object and symbol that overlapsaddr. This information is returned in aDl_info structure: typedef struct { const char *dli_fname; /* Pathname of shared object that contains address */ void *dli_fbase; /* Base address at which shared object is loaded */ const char *dli_sname; /* Name of symbol whose definition overlapsaddr */ void *dli_saddr; /* Exact address of symbol named indli_sname */ } Dl_info; If no symbol matchingaddr could be found, thendli_sname anddli_saddr are set to NULL. The functiondladdr1() is likedladdr(), but returns additional information via the argumentextra_info. The information returned depends on the value specified inflags, which can have one of the following values:RTLD_DL_LINKMAP Obtain a pointer to the link map for the matched file. Theextra_info argument points to a pointer to alink_map structure (i.e.,struct link_map **), defined in<link.h> as: struct link_map { ElfW(Addr) l_addr; /* Difference between the address in the ELF file and the address in memory */ char *l_name; /* Absolute pathname where object was found */ ElfW(Dyn) *l_ld; /* Dynamic section of the shared object */ struct link_map *l_next, *l_prev; /* Chain of loaded objects */ /* Plus additional fields private to the implementation */ };RTLD_DL_SYMENT Obtain a pointer to the ELF symbol table entry of the matching symbol. Theextra_info argument is a pointer to a symbol pointer:const ElfW(Sym) **. TheElfW() macro definition turns its argument into the name of an ELF data type suitable for the hardware architecture. For example, on a 64-bit platform,ElfW(Sym) yields the data type nameElf64_Sym, which is defined in<elf.h> as: typedef struct { Elf64_Word st_name; /* Symbol name */ unsigned char st_info; /* Symbol type and binding */ unsigned char st_other; /* Symbol visibility */ Elf64_Section st_shndx; /* Section index */ Elf64_Addr st_value; /* Symbol value */ Elf64_Xword st_size; /* Symbol size */ } Elf64_Sym; Thest_name field is an index into the string table. Thest_info field encodes the symbol's type and binding. The type can be extracted using the macroELF64_ST_TYPE(st_info)(orELF32_ST_TYPE()on 32-bit platforms), which yields one of the following values:Value DescriptionSTT_NOTYPESymbol type is unspecifiedSTT_OBJECTSymbol is a data objectSTT_FUNCSymbol is a code objectSTT_SECTIONSymbol associated with a sectionSTT_FILESymbol's name is filenameSTT_COMMONSymbol is a common data objectSTT_TLSSymbol is thread-local data objectSTT_GNU_IFUNCSymbol is indirect code object The symbol binding can be extracted from thest_info field using the macroELF64_ST_BIND(st_info)(orELF32_ST_BIND() on 32-bit platforms), which yields one of the following values:Value DescriptionSTB_LOCALLocal symbolSTB_GLOBALGlobal symbolSTB_WEAKWeak symbolSTB_GNU_UNIQUEUnique symbol Thest_other field contains the symbol's visibility, which can be extracted using the macroELF64_ST_VISIBILITY(st_info)(orELF32_ST_VISIBILITY()on 32-bit platforms), which yields one of the following values:Value DescriptionSTV_DEFAULTDefault symbol visibility rulesSTV_INTERNALProcessor-specific hidden classSTV_HIDDENSymbol unavailable in other modulesSTV_PROTECTEDNot preemptible, not exportedOn success, these functions return a nonzero value. If the address specified inaddr could be matched to a shared object, but not to a symbol in the shared object, then theinfo->dli_sname andinfo->dli_saddr fields are set to NULL. If the address specified inaddr could not be matched to a shared object, then these functions return 0. In this case, an error message isnot available viadlerror(3).
For an explanation of the terms used in this section, seeattributes(7). ┌──────────────────────────────────────┬───────────────┬─────────┐ │Interface│Attribute│Value│ ├──────────────────────────────────────┼───────────────┼─────────┤ │dladdr(),dladdr1() │ Thread safety │ MT-Safe │ └──────────────────────────────────────┴───────────────┴─────────┘
GNU.
dladdr() glibc 2.0.dladdr1() glibc 2.3.3. Solaris.
Sometimes, the function pointers you pass todladdr() may surprise you. On some architectures (notably i386 and x86-64),dli_fname anddli_fbase may end up pointing back at the object from which you calleddladdr(), even if the function used as an argument should come from a dynamically linked library. The problem is that the function pointer will still be resolved at compile time, but merely point to theplt (Procedure Linkage Table) section of the original object (which dispatches the call after asking the dynamic linker to resolve the symbol). To work around this, you can try to compile the code to be position- independent: then, the compiler cannot prepare the pointer at compile time any more andgcc(1) will generate code that just loads the final symbol address from thegot (Global Offset Table) at run time before passing it todladdr().
dl_iterate_phdr(3),dlinfo(3),dlopen(3),dlsym(3),ld.so(8)
This page is part of theman-pages (Linux kernel and C library user-space interface documentation) project. Information about the project can be found at ⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report for this manual page, see ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩. This page was obtained from the tarball man-pages-6.15.tar.gz fetched from ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on 2025-08-11. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up- to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgLinux man-pages 6.15 2025-05-17dladdr(3)Pages that refer to this page:dlerror(3), dlinfo(3), dl_iterate_phdr(3), dlopen(3), dlsym(3)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |