The symbols introduced by dlopen operations and available through dlsym are those which are "exported" as symbols of global scope by the shared library. For shared libraries, such symbols are typically those that were specified in (for example) C source code as having extern linkage.
In
The dlopene routine is an extension to dlopen, which allows the caller to specify explicitly the placement of a shared library's text and data segment when the library is dynamically loaded. The dlopen_opts structure has the following members:
struct dlopen_opts { long flags; char* text_addr; char* data_addr;
};
Flags contain the load option, defined by logical OR of the following values:
RTLD_EXT_TEXT_ADDR indicates that an explicit base address for the shared library text segment is provided.
RTLD_EXT_DATA_ADDR indicates that an explicit base address for the shared library private data segment is provided.
If the RTLD_EXT_DATA_NO_ZERO_FILL flag is set, dlopene does not zero fill the bss part of the data segment. This may improve load time for libraries with large bss sections. This flag is only valid with RTLD_EXT_DATA_ADDR.
The dynamic load accesses only the address fields that are specified by the "Flags" fields.
The text_addr contains the explicit base address for the shared library's text segment.
The data_addr contains the explicit base address for the shared library's data segment.
Both the text_addr and data_addr must be aligned at a
The caller can invoke dlgetfileinfo to obtain the information needed to allocate memory for the load segments. The caller of dlopene is responsible for allocating memory with the following permission:
•read, write and execute (RWX) permission for text_addr
•read and write (RW) permission for data_addr
NOTE: The environment variable LD_LIBRARY_PATH must contain a
In
Using dlopen to load a shared library
The following example shows how to use dlopen to load a shared library. The RTLD_GLOBAL flag enables global visibility to symbols in lib1.so. The RTLD_LAZY flag indicates that only references to data symbols are to be relocated and all function symbol references are to be delayed until their first invocation.
#include <stdio.h> #include <dlfcn.h>
int main(int argc, char **argv)
152 Shared Library Management Routines