19 #include "llvm/Config/config.h" 31 typedef std::vector<void *> HandleList;
36 static void *
DLOpen(
const char *Filename, std::string *Err);
37 static void DLClose(
void *Handle);
38 static void *
DLSym(
void *Handle,
const char *
Symbol);
43 HandleList::iterator
Find(
void *Handle) {
44 return std::find(Handles.begin(), Handles.end(), Handle);
48 return Handle == Process ||
Find(Handle) != Handles.end();
51 bool AddLibrary(
void *Handle,
bool IsProcess =
false,
bool CanClose =
true) {
53 assert((Handle ==
this ? IsProcess : !IsProcess) &&
"Bad Handle.");
57 if (
Find(Handle) != Handles.end()) {
62 Handles.push_back(Handle);
68 if (Process == Handle)
79 for (
void *Handle : Handles) {
80 if (
void *Ptr =
DLSym(Handle, Symbol))
85 if (
void *Ptr =
DLSym(Handle, Symbol))
96 if (!Process || (Order & SO_LoadedFirst)) {
102 if (
void *Ptr =
DLSym(Process, Symbol))
106 if (Order & SO_LoadedLast) {
107 if (
void *Ptr =
LibLookup(Symbol, Order))
134 char DynamicLibrary::Invalid;
140 return DoSearch(SymbolName);
156 if (Handle != &Invalid) {
168 if (!OpenedHandles->AddLibrary(Handle,
false,
false))
169 *Err =
"Library already loaded";
185 if (ExplicitSymbols.isConstructed()) {
188 if (i != ExplicitSymbols->end())
193 if (OpenedHandles.isConstructed()) {
194 if (
void *Ptr = OpenedHandles->Lookup(SymbolName,
SearchOrder))
void * SearchForAddressOfSpecialSymbol(const char *SymbolName)
static void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName...
This class represents lattice values for constants.
DynamicLibrary(void *data=&Invalid)
bool Contains(void *Handle)
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static void * DLSym(void *Handle, const char *Symbol)
static void * DLOpen(const char *Filename, std::string *Err)
void * getAddressOfSymbol(const char *symbolName)
Searches through the library for the symbol symbolName.
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
void * Lookup(const char *Symbol, DynamicLibrary::SearchOrdering Order)
void * LLVMSearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName...
static DynamicLibrary addPermanentLibrary(void *handle, std::string *errMsg=nullptr)
Registers an externally loaded library.
bool isValid() const
Returns true if the object refers to a valid library.
HandleList::iterator Find(void *Handle)
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path.
LLVMBool LLVMLoadLibraryPermanently(const char *Filename)
This function permanently loads the dynamic library at the given path.
void LLVMAddSymbol(const char *symbolName, void *symbolValue)
This functions permanently adds the symbol symbolName with the value symbolValue. ...
SO_LoadedFirst - Search all loaded libraries, then as SO_Linker would.
SO_LoadedLast - Search as SO_Linker would, then loaded libraries.
static void DLClose(void *Handle)
A collection of legacy interfaces for querying information about the current executing process...
SO_Linker - Search as a call to dlsym(dlopen(NULL)) would when DynamicLibrary::getPermanentLibrary(NU...
static void AddSymbol(StringRef symbolName, void *symbolValue)
This functions permanently adds the symbol symbolName with the value symbolValue. ...
static SearchOrdering SearchOrder
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SO_LoadOrder - Or this in to search libraries in the ordered loaded.
void * LibLookup(const char *Symbol, DynamicLibrary::SearchOrdering Order)
#define LLVM_LIKELY(EXPR)
bool AddLibrary(void *Handle, bool IsProcess=false, bool CanClose=true)
StringRef - Represent a constant reference to a string, i.e.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...