Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
Copyright 1989 AT&T
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
#include <dlfcn.h> int dladdr(void *address, Dl_info_t *dlip);
int dladdr1(void *address, Dl_info_t *dlip, void **info, int flags);
The Dl_info_t structure must be preallocated by the user. The structure members are filled in by dladdr(), based on the specified address. The Dl_info_t structure includes the following members:
const char *dli_fname; void *dli_fbase; const char *dli_sname; void *dli_saddr;
The Dl_info_t members provide the following information. dli_fname
Contains a pointer to the filename of the containing object.
Contains the base address of the containing object.
Contains a pointer to the symbol name that is nearest to the specified address. This symbol either represents the exact address that was specified, or is the nearest symbol with a lower address.
Contains the actual address of the symbol pointed to by dli_sname.
The dladdr1() function provides for addition information to be returned as specified by the flags argument: RTLD_DL_SYMENT
Obtain the ELF symbol table entry for the matched symbol. The info argument points to a symbol pointer as defined in <sys/elf.h> (Elf32_Sym **info or Elf64_Sym **info). Most of the information found in an ELF symbol can only be properly interpreted by the runtime linker. However, there are two fields that contain information useful to the caller of dladdr1(): The st_size field contains the size of the referenced item. The st_info field provides symbol type and binding attributes. See the Linker and Libraries Guide for more information.
Obtain the Link_map for the matched file. The info argument points to a Link_map pointer as defined in <sys/link.h> (Link_map **info).
ATTRIBUTE TYPE ATTRIBUTE VALUE |
MT-Level MT-Safe |
Linker and Libraries Guide
If no symbol is found to describe the specified address, both the dli_sname and dli_saddr members are set to 0.
If the address specified exists within a mapped object in the range between the base address and the address of the first global symbol in the object, the reserved local symbol _START_ is returned. This symbol acts as a label representing the start of the mapped object. As a label, this symbol has no size. The dli_saddr member is set to the base address of the associated object. The dli_sname member is set to the symbol name _START_. If the flag argument is set to RTLD_DL_SYMENT, symbol information for _START_ is returned.
If an object is acting as a filter, care should be taken when interpreting the address of any symbol obtained using a handle to this object. For example, using dlsym(3C) to obtain the symbol _end for this object, results in returning the address of the symbol _end within the filtee, not the filter. For more information on filters see the Linker and Libraries Guide.