HP-UX Linker and Libraries User's Guide

Return Values
If the specified address does not fall within one of the load modules, 0 is returned; the contents of
the D1_info structure are not modified. Otherwise, a non-zero value is returned and the fields of
the D1_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 .
For a.out's, only a subset of externally visible symbols are typically exported: specifically those
referenced by the load modules with which the a.out is linked. The exact set of exported symbols
for any shared library or the a.out can be controlled using the linker (seeld(1)).
Description
The dladdr routine 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 line). The dladdr routine allows
a process to obtain information about the symbol that most closely defines a given address. The
dladdr routine 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 not less than, the
specified address.
The dlip parameter is a pointer to a D1_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 D1_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 Official Plabel Descriptor (OPD) for the nearest code symbol.
The dli_sizefield 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).
164 Shared Library Management Routines