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 PA-32 mode, for a.out files, only a subset of externally visible symbols are typically exported: specifically those referenced by the shared libraries 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 [see ld(1)].

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 16-byte boundary.

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 colon-separated list of directories, in the same format as the PATH variable [see sh(1)]. In PA-64 and IPF mode LD_LIBRARY_PATH is ignored if the process' real user id is different from its effective user id or its real group id is different from its effective group id [see exec(2)] or if the process has acquired any privileges [see tfadmin(1M)].

In IPF/PA-64 mode, with the +compat option specified, LD_LIBRARY_PATH and the +b embedded path are ignored when searching for dependent libraries.

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

Page 152
Image 152
HP UX Software Transition Kit (STK) manual Using dlopen to load a shared library