HP-UX Reference (11i v2 03/08) - 3 Library Functions A-M (vol 6)
d
dladdr(3C) dladdr(3C)
NAME
dladdr - get the symbolic information for an address.
SYNOPSIS
cc [flag ... ] cfile ...
-ldl [library ] ...
#include <dlfcn.h>
int dladdr(void *address, Dl_info *dlip);
DESCRIPTION
dladdr is one of a family of routines that give the user direct access to the dynamic linking facilities
(using the -ldl option on the compiler or
ld command line). dladdr allows a process to obtain infor-
mation about the symbol that most closely defines a given address.
dladdr determines whether the
specified address is located within one of the load modules (executable or shared libraries) that make up
the process’ address space. An address is deemed to fall within a load module when it is between the base
address at which the load module was mapped and the highest virtual address mapped for that load
module, inclusive. If a load module fits this criteria, its dynamic symbol table is searched to locate the
nearest symbol to the specified address . The nearest symbol is the one whose value is equal to, or closest
to but less than the specified address .
dlip is a pointer to a
Dl_info structure. The structure must be allocated by the user. The structure
members are set by
dladdr if the specified address falls within one of the load modules. The
Dl_info
structure contains the following members:
struct {
const char *dli_fname;
void *dli_fbase;
const char *dli_sname;
void *dli_saddr;
size_t dli_size;
int dli_bind;
int dli_type;
};
The dli_fname field contains a pointer to the filename of the load module containing the address. The
contents of this memory location can change between calls to
dladdr.
The dli_fbase field contains a handle to the load module. This can be used as the first argument to
dlsym.
The dli_sname field contains a pointer to the name of the nearest symbol to the specified address. This
symbol either has the same address, or is the nearest symbol with a lower address. The contents of this
memory location can change between calls to
dladdr.
The dli_saddr field contains the actual address of the nearest symbol. For code symbols, it contains the
address of the OPD (Official Plabel Descriptor) for the nearest code symbol.
The dli_size field contains the size of the nearest symbol as defined in the dynamic symbol table.
The dli_bind field contains the binding attribute of the nearest symbol as defined in the dynamic symbol
table. The values for this are those used for a symbol’s binding in the ELF symbol table (see <elf.h>)
The dli_type field contains the type of the nearest symbol as defined in the dynamic symbol table. The
values for this are those used for a symbol’s type in the ELF symbol table (see
<elf.h>).
MULTITHREAD USAGE
This routine is thread-safe.
RETURN VALUE
If the specified address does not fall within one of the load modules,
0 is returned; the contents of the
Dl_info structure are not modified. Otherwise, a non-zero value is returned and the fields of the
Dl_info structure are set.
DIAGNOSTICS
If no symbol is found within the load module containing address whose value is less than or equal to
address, the dli_sname , dli_saddr and dli_size fields are set to
0; the dli_bind field is set to STB_LOCAL,
and the dli_type field is set to STT_NOTYPE.
Section 3−−190 Hewlett-Packard Company − 1 − HP-UX 11i Version 2: August 2003