LLVM API Documentation

llvm::sys::DynamicLibrary Class Reference

Portable dynamic library abstraction. More...

#include <DynamicLibrary.h>

Collaboration diagram for llvm::sys::DynamicLibrary:

Collaboration graph
[legend]
List of all members.

Implementation

 DynamicLibrary (const DynamicLibrary &)
 Do not implement.
DynamicLibraryoperator= (const DynamicLibrary &)
void * handle

Public Member Functions

Constructors
 DynamicLibrary ()
 Open program as dynamic library.
 DynamicLibrary (const char *filename)
 Open a dynamic library.
 ~DynamicLibrary ()
 Closes the DynamicLibrary.
Accessors
void * GetAddressOfSymbol (const char *symbolName)
 Get the address of a symbol in the DynamicLibrary.
void * GetAddressOfSymbol (const std::string &symbolName)
 Convenience function for C++ophiles.

Static Public Member Functions

Functions
static void LoadLibraryPermanently (const char *filename)
 Open a dynamic library permanently.
static void * SearchForAddressOfSymbol (const char *symbolName)
 Search through libraries for address of a symbol.
static void * SearchForAddressOfSymbol (const std::string &symbolName)
 Convenience function for C++ophiles.
static void AddSymbol (const char *symbolName, void *symbolValue)
 Add searchable symbol/value pair.
static void AddSymbol (const std::string &symbolName, void *symbolValue)
 Convenience function for C++ophiles.

Detailed Description

Portable dynamic library abstraction.

This class provides a portable interface to dynamic libraries which also might be known as shared libraries, shared objects, dynamic shared objects, or dynamic link libraries. Regardless of the terminology or the operating system interface, this class provides a portable interface that allows dynamic libraries to be loaded and and searched for externally defined symbols. This is typically used to provide "plug-in" support. It also allows for symbols to be defined which don't live in any library, but rather the main program itself, useful on Windows where the main executable cannot be searched.

Since:
1.4

Definition at line 34 of file DynamicLibrary.h.


Constructor & Destructor Documentation

DynamicLibrary::DynamicLibrary (  ) 

Open program as dynamic library.

Construct a DynamicLibrary that represents the currently executing program. The program must have been linked with -export-dynamic or -dlopen self for this to work. Any symbols retrieved with the GetAddressOfSymbol function will refer to the program not to any library.

Exceptions:
std::string indicating why the program couldn't be opened.

Definition at line 59 of file DynamicLibrary.cpp.

References check_ltdl_initialization(), handle, lt_dlopen(), and OpenedHandles.

DynamicLibrary::DynamicLibrary ( const char *  filename  ) 

Open a dynamic library.

This is the constructor for DynamicLibrary instances. It will open the dynamic library specified by the Path.

Exceptions:
std::string indicating why the library couldn't be opened.

Definition at line 71 of file DynamicLibrary.cpp.

References check_ltdl_initialization(), handle, lt_dlerror(), lt_dlopen(), lt_dlopenext(), and OpenedHandles.

DynamicLibrary::~DynamicLibrary (  ) 

Closes the DynamicLibrary.

After destruction, the symbols of the library will no longer be available to the program. It is important to make sure the lifespan of a DynamicLibrary exceeds the lifetime of the pointers returned by the GetAddressOfSymbol otherwise the program may walk off into uncharted territory.

See also:
GetAddressOfSymbol.

Definition at line 86 of file DynamicLibrary.cpp.

References E, handle, I, lt_dlclose(), and OpenedHandles.

llvm::sys::DynamicLibrary::DynamicLibrary ( const DynamicLibrary  )  [protected]

Do not implement.


Member Function Documentation

static void llvm::sys::DynamicLibrary::AddSymbol ( const std::string &  symbolName,
void *  symbolValue 
) [inline, static]

Convenience function for C++ophiles.

Definition at line 94 of file DynamicLibrary.h.

References AddSymbol().

void llvm::sys::DynamicLibrary::AddSymbol ( const char *  symbolName,
void *  symbolValue 
) [static]

Add searchable symbol/value pair.

This functions permanently adds the symbol symbolName with the value symbolValue. These symbols are searched before any libraries.

Definition at line 21 of file DynamicLibrary.cpp.

References g_symbols.

Referenced by AddSymbol().

void* llvm::sys::DynamicLibrary::GetAddressOfSymbol ( const std::string &  symbolName  )  [inline]

Convenience function for C++ophiles.

Definition at line 109 of file DynamicLibrary.h.

References GetAddressOfSymbol().

void * DynamicLibrary::GetAddressOfSymbol ( const char *  symbolName  ) 

Get the address of a symbol in the DynamicLibrary.

Looks up a symbolName in the DynamicLibrary and returns its address if it exists. If the symbol does not exist, returns (void*)0.

Returns:
the address of the symbol or 0.

Definition at line 162 of file DynamicLibrary.cpp.

References handle, and lt_dlsym().

Referenced by GetAddressOfSymbol().

void DynamicLibrary::LoadLibraryPermanently ( const char *  filename  )  [static]

Open a dynamic library permanently.

This function allows a library to be loaded without instantiating a DynamicLibrary object. Consequently, it is marked as being permanent and will only be unloaded when the program terminates.

Exceptions:
std::string on error.

Definition at line 101 of file DynamicLibrary.cpp.

References check_ltdl_initialization(), lt_dlerror(), lt_dlmakeresident(), lt_dlopen(), lt_dlopenext(), and OpenedHandles.

Referenced by llvm::ExecutionEngine::create(), and llvm::PluginLoader::operator=().

DynamicLibrary& llvm::sys::DynamicLibrary::operator= ( const DynamicLibrary  )  [protected]

Do not implement

static void* llvm::sys::DynamicLibrary::SearchForAddressOfSymbol ( const std::string &  symbolName  )  [inline, static]

Convenience function for C++ophiles.

Definition at line 83 of file DynamicLibrary.h.

References SearchForAddressOfSymbol().

void * DynamicLibrary::SearchForAddressOfSymbol ( const char *  symbolName  )  [static]

Search through libraries for address of a symbol.

This function will search through all previously loaded dynamic libraries for the symbol symbolName. If it is found, the addressof that symbol is returned. If not, null is returned. Note that this will search permanently loaded libraries (LoadLibraryPermanently) as well as ephemerally loaded libraries (constructors).

Exceptions:
std::string on error.

Definition at line 116 of file DynamicLibrary.cpp.

References check_ltdl_initialization(), E, g_symbols, I, lt_dlsym(), lt_ptr, and OpenedHandles.

Referenced by llvm::ExecutionEngine::emitGlobals(), llvm::JIT::getOrEmitGlobalVariable(), llvm::JIT::getPointerToNamedFunction(), and SearchForAddressOfSymbol().


Member Data Documentation

void* llvm::sys::DynamicLibrary::handle [protected]

Definition at line 117 of file DynamicLibrary.h.

Referenced by DynamicLibrary(), GetAddressOfSymbol(), and ~DynamicLibrary().


The documentation for this class was generated from the following files: