Section 5.7. Dynamic Loading


5.7. Dynamic Loading

Dynamically loaded (DL) libraries are libraries that are loaded at times other than during the startup of a program. At runtime, the program allows applications to load new modules into its address space for new functionalities without having to link the required libraries. They are particularly useful for implementing plug-ins or modules. Both AIX and Linux support dynamic loading. Table 5-5 compares the differences in how to dynamically load routines between AIX and Linux.

Table 5-5. Dynamically Loading Routines Between AIX and Linux

AIX

Linux

Description

dlopen Flags: RTLD_LAZY RTLD_NOW RTLD_GLOBAL RTLD_LOCAL RTLD_MEMBER RTLD_NOAUTODEFER

dlopen Flags: RTLD_LAZY RTLD_NOW RTLD_GLOBAL RTLD LOCAL RTLD_NODELETE RTLD_NOLOAD RTLD_BINDING_MASK RTLD_DEEPBIND

Dynamically loads a module into the calling process.

dlsym Handles: RTLD_DEFAULT RTLD_NEXT RTLD_MYSELF

dlsym Handles: RTLD_DEFAULT RTLD_NEXT

Looks up the location of a symbol in a module that is loaded with dlsym.

dlerror

dlerror

Returns a pointer to information about the last dlopen, dlsym, or dlclose error.

dlclose

dlcloseg

Closes and unloads a module loaded by the dlopen subroutine.

dladdr DI_info_structure: const char *dli_fname; void *dli_fbase; const char *dli_sname; void *dli_saddr; size_t dli_size; int dli_bind; int dli_type;

dladdr DI_info_structure: const char *dli_fname; void *dli_fbase; const char *dli_sname; void *dli_saddr; size_t dli_size;

Translates address to symbolic information.

None

dlvsym

(Linux only) Does the same as dlsym() but takes a version string as an additional argument.


The basic dl functions (dlopen, dlclose, dladdr, and so on) for using DL libraries exhibit the same behavior in Linux as in AIX. The transition from AIX to Linux should be seamless. In Linux, to enable DL functionality, the application must link with the libld.so library, -ldl. Chapter 3 shows an example of how to use DL on Linux.




UNIX to Linux Porting. A Comprehensive Reference
UNIX to Linux Porting: A Comprehensive Reference
ISBN: 0131871099
EAN: 2147483647
Year: 2004
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net