2015-07-06 14:02:00 +00:00
|
|
|
'\" t
|
|
|
|
.\" Copyright (C) 2015 Michael Kerrisk <mtk.manpages@gmail.com>
|
|
|
|
.\" and Copyright (C) 2008 Petr Baudis <pasky@suse.cz> (dladdr caveat)
|
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(VERBATIM)
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\" %%%LICENSE_END
|
|
|
|
.\"
|
ldd.1, sprof.1, accept.2, alarm.2, bind.2, chdir.2, clock_nanosleep.2, close.2, connect.2, dup.2, execve.2, fsync.2, getgid.2, getpeername.2, getsid.2, getsockname.2, getsockopt.2, getuid.2, io_getevents.2, kill.2, listen.2, lseek.2, mmap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nice.2, pause.2, pipe.2, rmdir.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select_tut.2, semctl.2, semop.2, setsid.2, shmctl.2, shmget.2, shmop.2, shutdown.2, sigaction.2, signal.2, socketpair.2, sync.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, times.2, truncate.2, umask.2, MB_CUR_MAX.3, a64l.3, abs.3, assert.3, atexit.3, atof.3, atoi.3, basename.3, bsearch.3, btowc.3, byteorder.3, catgets.3, catopen.3, clock.3, clock_getcpuclockid.3, closedir.3, confstr.3, crypt.3, ctermid.3, difftime.3, div.3, dladdr.3, dlerror.3, dlinfo.3, dlopen.3, dlsym.3, drand48.3, encrypt.3, exit.3, fclose.3, ffs.3, fgetc.3, fgetwc.3, fgetws.3, flockfile.3, fmtmsg.3, fnmatch.3, fopen.3, fpathconf.3, fpclassify.3, fputwc.3, fputws.3, fseek.3, fseeko.3, ftok.3, fwide.3, getdate.3, getenv.3, getgrent.3, getgrnam.3, gethostid.3, getlogin.3, getnetent.3, getopt.3, getpwent.3, getpwnam.3, getsubopt.3, getutent.3, getwchar.3, grantpt.3, hsearch.3, iconv.3, iconv_close.3, iconv_open.3, if_nameindex.3, inet.3, inet_ntop.3, inet_pton.3, insque.3, isatty.3, isgreater.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, lockf.3, longjmp.3, lsearch.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, memccpy.3, memchr.3, memcmp.3, memmove.3, memset.3, mktemp.3, mq_close.3, mq_getattr.3, mq_receive.3, mq_send.3, mq_unlink.3, offsetof.3, popen.3, posix_memalign.3, posix_openpt.3, printf.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstacksize.3, pthread_equal.3, pthread_exit.3, pthread_getcpuclockid.3, pthread_kill.3, pthread_self.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, pthread_sigmask.3, pthread_testcancel.3, ptsname.3, putenv.3, puts.3, putwchar.3, qsort.3, raise.3, random.3, readdir.3, regex.3, remove.3, rewinddir.3, seekdir.3, sem_destroy.3, sem_getvalue.3, sem_unlink.3, sem_wait.3, setenv.3, setjmp.3, setlocale.3, setlogmask.3, signbit.3, sigpause.3, sigset.3, sigsetops.3, sigwait.3, sleep.3, sockatmark.3, statvfs.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strlen.3, strpbrk.3, strptime.3, strspn.3, strstr.3, strtod.3, strtoimax.3, strtok.3, strtol.3, strtoul.3, strxfrm.3, swab.3, sysconf.3, system.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tmpfile.3, towctrans.3, tsearch.3, ttyname.3, tzset.3, ungetwc.3, unlocked_stdio.3, unlockpt.3, wcrtomb.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstoimax.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wordexp.3, wprintf.3, fanotify.7, mq_overview.7, nptl.7, sem_overview.7, shm_overview.7, sigevent.7, symlink.7, ld.so.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2015-08-08 16:21:22 +00:00
|
|
|
.TH DLADDR 3 2015-08-08 "Linux" "Linux Programmer's Manual"
|
2015-07-06 14:02:00 +00:00
|
|
|
.SH NAME
|
|
|
|
dladdr, dladdr1 \- translate address to symbolic information
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #define _GNU_SOURCE
|
|
|
|
.B #include <dlfcn.h>
|
|
|
|
|
|
|
|
.BI "int dladdr(void *" addr ", Dl_info *" info );
|
|
|
|
|
|
|
|
.BI "int dladdr1(void *" addr ", Dl_info *" info ", void **" \
|
|
|
|
extra_info ", int " flags );
|
|
|
|
|
|
|
|
Link with \fI\-ldl\fP.
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
The function
|
|
|
|
.BR dladdr ()
|
|
|
|
determines whether the address specified in
|
|
|
|
.IR addr
|
|
|
|
is located in one of the shared objects loaded by the calling application.
|
|
|
|
If it is, then
|
|
|
|
.BR dladdr ()
|
|
|
|
returns information about the shared object and symbol that overlaps
|
|
|
|
.IR addr .
|
|
|
|
This information is returned in a
|
|
|
|
.I Dl_info
|
|
|
|
structure:
|
|
|
|
.sp
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
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
|
|
|
|
overlaps \fIaddr\fP */
|
|
|
|
void *dli_saddr; /* Exact address of symbol named
|
|
|
|
in \fIdli_sname\fP */
|
|
|
|
} Dl_info;
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
If no symbol matching
|
|
|
|
.I addr
|
|
|
|
could be found, then
|
|
|
|
.I dli_sname
|
|
|
|
and
|
|
|
|
.I dli_saddr
|
|
|
|
are set to NULL.
|
|
|
|
|
|
|
|
The function
|
|
|
|
.BR dladdr1 ()
|
|
|
|
is like
|
|
|
|
.BR dladdr (),
|
|
|
|
but returns additional information via the argument
|
|
|
|
.IR extra_info .
|
|
|
|
The information returned depends on the value specified in
|
|
|
|
.IR flags ,
|
|
|
|
which can have one of the following values:
|
|
|
|
.TP
|
|
|
|
.B RTLD_DL_LINKMAP
|
2015-07-06 14:07:21 +00:00
|
|
|
Obtain a pointer to the link map for the matched file.
|
2015-07-06 14:02:00 +00:00
|
|
|
The
|
|
|
|
.IR extra_info
|
|
|
|
argument points to a pointer to a
|
|
|
|
.I link_map
|
|
|
|
structure (i.e.,
|
|
|
|
.IR "struct link_map\ **" ),
|
|
|
|
defined in
|
|
|
|
.I <link.h>
|
|
|
|
as:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
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 */
|
|
|
|
};
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.TP
|
|
|
|
.B RTLD_DL_SYMENT
|
2015-07-06 14:07:21 +00:00
|
|
|
Obtain a pointer to the ELF symbol table entry of the matching symbol.
|
2015-07-06 14:02:00 +00:00
|
|
|
The
|
|
|
|
.IR extra_info
|
|
|
|
argument is a pointer to a symbol pointer:
|
|
|
|
.IR "const ElfW(Sym) **" .
|
|
|
|
The
|
|
|
|
.IR ElfW ()
|
|
|
|
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,
|
|
|
|
.I ElfW(Sym)
|
|
|
|
yields the data type name
|
|
|
|
.IR Elf64_Sym ,
|
|
|
|
which is defined in
|
|
|
|
.IR <elf.h>
|
|
|
|
as:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
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;
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
|
|
|
|
The
|
|
|
|
.I st_name
|
|
|
|
field is an index into the string table.
|
|
|
|
|
|
|
|
The
|
|
|
|
.I st_info
|
|
|
|
field encodes the symbol's type and binding.
|
|
|
|
The type can be extracted using the macro
|
|
|
|
.BR ELF64_ST_TYPE(st_info)
|
|
|
|
(or
|
|
|
|
.BR ELF32_ST_TYPE()
|
|
|
|
on 32-bit platforms), which yields one of the following values:
|
|
|
|
.in +4n
|
|
|
|
.TS
|
|
|
|
lb lb
|
|
|
|
lb l.
|
|
|
|
Value Description
|
|
|
|
STT_NOTYPE Symbol type is unspecified
|
|
|
|
STT_OBJECT Symbol is a data object
|
|
|
|
STT_FUNC Symbol is a code object
|
|
|
|
STT_SECTION Symbol associated with a section
|
|
|
|
STT_FILE Symbol's name is file name
|
|
|
|
STT_COMMON Symbol is a common data object
|
|
|
|
STT_TLS Symbol is thread-local data object
|
|
|
|
STT_GNU_IFUNC Symbol is indirect code object
|
|
|
|
.TE
|
|
|
|
.in
|
|
|
|
.IP
|
|
|
|
The symbol binding can be extracted from the
|
|
|
|
.I st_info
|
|
|
|
field using the macro
|
|
|
|
.BR ELF64_ST_BIND(st_info)
|
|
|
|
(or
|
|
|
|
.BR ELF32_ST_BIND()
|
|
|
|
on 32-bit platforms), which yields one of the following values:
|
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.TS
|
|
|
|
lb lb
|
|
|
|
lb l.
|
|
|
|
Value Description
|
|
|
|
STB_LOCAL Local symbol
|
|
|
|
STB_GLOBAL Global symbol
|
|
|
|
STB_WEAK Weak symbol
|
|
|
|
STB_GNU_UNIQUE Unique symbol
|
|
|
|
.TE
|
|
|
|
.in
|
|
|
|
.IP
|
|
|
|
The
|
|
|
|
.I st_other
|
|
|
|
field contains the symbol's visibility, which can be extracted using the macro
|
|
|
|
.BR ELF64_ST_VISIBILITY(st_info)
|
|
|
|
(or
|
|
|
|
.BR ELF32_ST_VISIBILITY()
|
|
|
|
on 32-bit platforms), which yields one of the following values:
|
|
|
|
.in +4n
|
|
|
|
.TS
|
|
|
|
lb lb
|
|
|
|
lb l.
|
|
|
|
Value Description
|
|
|
|
STV_DEFAULT Default symbol visibility rules
|
|
|
|
STV_INTERNAL Processor-specific hidden class
|
|
|
|
STV_HIDDEN Symbol unavailable in other modules
|
|
|
|
STV_PROTECTED Not preemptible, not exported
|
|
|
|
.TE
|
|
|
|
.in
|
|
|
|
.SH RETURN VALUE
|
|
|
|
On success, these functions return a nonzero value.
|
|
|
|
If the address specified in
|
|
|
|
.I addr
|
|
|
|
could be matched to a shared object,
|
|
|
|
but not to a symbol in the shared object, then the
|
|
|
|
.I info->dli_sname
|
|
|
|
and
|
|
|
|
.I info->dli_saddr
|
|
|
|
fields are set to NULL.
|
|
|
|
|
|
|
|
|
|
|
|
If the address specified in
|
|
|
|
.I addr
|
|
|
|
could not be matched to a shared object, then these functions return 0.
|
|
|
|
In this case, an error message is
|
|
|
|
.I not
|
|
|
|
.\" According to the FreeBSD man page, dladdr1() does signal an
|
|
|
|
.\" error via dlerror() for this case.
|
|
|
|
available via
|
|
|
|
.BR dlerror (3).
|
|
|
|
.SH VERSIONS
|
|
|
|
.BR dladdr ()
|
|
|
|
is present in glibc 2.0 and later.
|
|
|
|
.BR dladdr1 ()
|
|
|
|
first appeared in glibc 2.3.3.
|
2015-07-19 12:43:45 +00:00
|
|
|
.SH ATTRIBUTES
|
|
|
|
For an explanation of the terms used in this section, see
|
|
|
|
.BR attributes (7).
|
|
|
|
.TS
|
|
|
|
allbox;
|
|
|
|
lbw19 lb lb
|
|
|
|
l l l.
|
|
|
|
Interface Attribute Value
|
|
|
|
T{
|
|
|
|
.BR dladdr (),
|
|
|
|
.BR dladdr1 ()
|
|
|
|
T} Thread safety MT-Safe
|
|
|
|
.TE
|
2015-07-06 14:02:00 +00:00
|
|
|
.SH CONFORMING TO
|
|
|
|
These functions are nonstandard GNU extensions
|
|
|
|
that are also present on Solaris.
|
|
|
|
.SH BUGS
|
|
|
|
Sometimes, the function pointers you pass to
|
|
|
|
.BR dladdr ()
|
|
|
|
may surprise you.
|
|
|
|
On some architectures (notably i386 and x86_64),
|
|
|
|
.I dli_fname
|
|
|
|
and
|
|
|
|
.I dli_fbase
|
|
|
|
may end up pointing back at the object from which you called
|
|
|
|
.BR dladdr (),
|
|
|
|
even if the function used as an argument should come from
|
|
|
|
a dynamically linked library.
|
|
|
|
.PP
|
|
|
|
The problem is that the function pointer will still be resolved
|
|
|
|
at compile time, but merely point to the
|
|
|
|
.I plt
|
|
|
|
(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
|
2015-07-24 15:08:05 +00:00
|
|
|
at compile time any more and
|
2015-07-06 14:02:00 +00:00
|
|
|
.BR gcc (1)
|
|
|
|
will generate code that just loads the final symbol address from the
|
|
|
|
.I got
|
|
|
|
(Global Offset Table) at run time before passing it to
|
|
|
|
.BR dladdr ().
|
|
|
|
.SH SEE ALSO
|
|
|
|
.BR dl_iterate_phdr (3),
|
2015-07-07 12:39:23 +00:00
|
|
|
.BR dlinfo (3),
|
2015-07-06 14:02:00 +00:00
|
|
|
.BR dlopen (3),
|
2015-07-16 08:01:06 +00:00
|
|
|
.BR dlsym (3),
|
2015-07-06 14:02:00 +00:00
|
|
|
.BR ld.so (8)
|