LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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.

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.

Since:
1.4

Definition at line 31 of file DynamicLibrary.h.


Constructor & Destructor Documentation

llvm::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 37 of file DynamicLibrary.cpp.

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

llvm::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 49 of file DynamicLibrary.cpp.

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

llvm::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 64 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

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

Convenience function for C++ophiles.

Definition at line 95 of file DynamicLibrary.h.

References GetAddressOfSymbol().

void * llvm::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 133 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 79 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 80 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 94 of file DynamicLibrary.cpp.

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

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


Member Data Documentation

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

Definition at line 103 of file DynamicLibrary.h.

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


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