LLVM API Documentation
#include <DynamicLibrary.h>
Collaboration diagram for llvm::sys::DynamicLibrary:
Implementation | |
void * | handle |
DynamicLibrary (const DynamicLibrary &) | |
Do not implement. | |
DynamicLibrary & | operator= (const DynamicLibrary &) |
Public Member Functions | |
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 bool | LoadLibraryPermanently (const char *filename, std::string *ErrMsg=0) |
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. |
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.
Definition at line 35 of file DynamicLibrary.h.
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.
std::string | indicating why the program couldn't be opened. |
Definition at line 60 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 filename Path.
std::string | indicating why the library couldn't be opened. |
Definition at line 72 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.
Definition at line 87 of file DynamicLibrary.cpp.
References E, handle, lt_dlclose(), and OpenedHandles.
llvm::sys::DynamicLibrary::DynamicLibrary | ( | const DynamicLibrary & | ) | [protected] |
Do not implement.
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.
std::string | indicating why the program couldn't be opened. |
Definition at line 60 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 filename Path.
std::string | indicating why the library couldn't be opened. |
Definition at line 72 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.
Definition at line 87 of file DynamicLibrary.cpp.
References E, handle, lt_dlclose(), and OpenedHandles.
bool DynamicLibrary::LoadLibraryPermanently | ( | const char * | filename, | |
std::string * | ErrMsg = 0 | |||
) | [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. This returns false on success or returns true and fills in *ErrMsg on failure.
Definition at line 103 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=().
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).
std::string | on error. |
Definition at line 124 of file DynamicLibrary.cpp.
References check_ltdl_initialization(), E, g_symbols, lt_dlsym(), lt_ptr, and OpenedHandles.
Referenced by llvm::ExecutionEngine::emitGlobals(), llvm::JIT::getOrEmitGlobalVariable(), llvm::JIT::getPointerToNamedFunction(), and SearchForAddressOfSymbol().
static void* llvm::sys::DynamicLibrary::SearchForAddressOfSymbol | ( | const std::string & | symbolName | ) | [inline, static] |
Convenience function for C++ophiles.
Definition at line 85 of file DynamicLibrary.h.
References SearchForAddressOfSymbol().
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().
static void llvm::sys::DynamicLibrary::AddSymbol | ( | const std::string & | symbolName, | |
void * | symbolValue | |||
) | [inline, static] |
Convenience function for C++ophiles.
Definition at line 96 of file DynamicLibrary.h.
References AddSymbol().
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.
Definition at line 170 of file DynamicLibrary.cpp.
References handle, and lt_dlsym().
Referenced by GetAddressOfSymbol().
void* llvm::sys::DynamicLibrary::GetAddressOfSymbol | ( | const std::string & | symbolName | ) | [inline] |
Convenience function for C++ophiles.
Definition at line 111 of file DynamicLibrary.h.
References GetAddressOfSymbol().
DynamicLibrary& llvm::sys::DynamicLibrary::operator= | ( | const DynamicLibrary & | ) | [protected] |
Do not implement
void* llvm::sys::DynamicLibrary::handle [protected] |
Definition at line 119 of file DynamicLibrary.h.
Referenced by DynamicLibrary(), GetAddressOfSymbol(), and ~DynamicLibrary().