rld Manual

Using the rld Loader Library
RLD Manual528857-006
2-7
dlsym()
Considerations
The dlsym() function allows a process to obtain the address of an external symbol
defined within any loadfile currently loaded in the process.
A dlopen_handle returned by a call of the form dlopen(0, mode) causes the
symbol search to occur on the cumulative loadList (that is, on the main program and all
the explicit DLLs currently loaded in the process, in the order they were loaded initially
by rld and subsequently by calls to dlopen). Otherwise, the symbol search is done
on the loadList of the library designated by the object_pathname value in the
dlopen invocation that returned the dlopen_handle (that is, starting with that library
followed by the breadth-first transitive closure of its libList). Import and re-export
controls are ignored.
The dlsym() function does not set the errno variable. Error information is available
through the dlerror() or dlresultcode() function.
Examples
The dlsym() function is typically used to declare pointers of the appropriate function
or data types and to assign the typecast addresses returned by dlsym() to those
pointers. For example:
typedef int (*someFunction_p) (int); // pointer to function of
// int returning int
typedef struct someData { ... } someData; // structure
someFunction_p theFunction; // pointer to function
// "theFunction" in "mydll"
someData *theData; // pointer to structure
// variable "theData" in "mydll"
dlHandle handle; // handle from loading "mydll"
handle = dlopen("mydll",RTLD_NOW);
if (! handle) ... // error handling
theFunction = (someFunction_p)dlsym(handle,"theFunction");
if (! theFunction) ... //error handling
theData = (someData*)dlsym(handle,"theData");
if (! theData) ... // error handling