|
CppInterOp
C++ Language Interoperability Layer
|
A helper class managing dynamic shared objects. More...
#include "lib/CppInterOp/DynamicLibraryManager.h"
Classes | |
| struct | SearchPathInfo |
| Describes the library search paths. More... | |
Public Types | |
| enum | LoadLibResult { kLoadLibSuccess , kLoadLibAlreadyLoaded , kLoadLibNotFound , kLoadLibLoadError , kLoadLibNumResults } |
| Describes the result of loading a library. More... | |
| using | SearchPathInfos = llvm::SmallVector< SearchPathInfo, 32 > |
Public Member Functions | |
| DynamicLibraryManager () | |
| ~DynamicLibraryManager () | |
| DynamicLibraryManager (const DynamicLibraryManager &)=delete | |
| DynamicLibraryManager & | operator= (const DynamicLibraryManager &)=delete |
| InterpreterCallbacks * | getCallbacks () |
| const InterpreterCallbacks * | getCallbacks () const |
| void | setCallbacks (InterpreterCallbacks *C) |
| const SearchPathInfos & | getSearchPaths () const |
| Returns the system include paths. | |
| void | addSearchPath (llvm::StringRef dir, bool isUser=true, bool prepend=false) |
| std::string | lookupLibrary (llvm::StringRef libStem, llvm::SmallVector< llvm::StringRef, 2 > RPath={}, llvm::SmallVector< llvm::StringRef, 2 > RunPath={}, llvm::StringRef libLoader="", bool variateLibStem=true) const |
| Looks up a library taking into account the current include paths and the system include paths. | |
| LoadLibResult | loadLibrary (llvm::StringRef, bool permanent, bool resolved=false) |
| Loads a shared library. | |
| void | unloadLibrary (llvm::StringRef libStem) |
| bool | isLibraryLoaded (llvm::StringRef fullPath) const |
| Returns true if the file was a dynamic library and it was already loaded. | |
| void | initializeDyld (std::function< bool(llvm::StringRef)> shouldPermanentlyIgnore) |
| Initialize the dyld. | |
| std::string | searchLibrariesForSymbol (llvm::StringRef mangledName, bool searchSystem=true) const |
| Find the first not-yet-loaded shared object that contains the symbol. | |
| void | dump (llvm::raw_ostream *S=nullptr) const |
Static Public Member Functions | |
| template<class T > | |
| static std::string | getSymbolLocation (T func) |
| On a success returns to full path to a shared object that holds the symbol pointed by func. | |
| static std::string | normalizePath (llvm::StringRef path) |
| static bool | isSharedLibrary (llvm::StringRef libFullPath, bool *exists=nullptr) |
| Returns true if file is a shared library. | |
A helper class managing dynamic shared objects.
Definition at line 26 of file DynamicLibraryManager.h.
| using CppInternal::DynamicLibraryManager::SearchPathInfos = llvm::SmallVector<SearchPathInfo, 32> |
Definition at line 52 of file DynamicLibraryManager.h.
Describes the result of loading a library.
Definition at line 30 of file DynamicLibraryManager.h.
| CppInternal::DynamicLibraryManager::DynamicLibraryManager | ( | ) |
Definition at line 35 of file DynamicLibraryManager.cpp.
References addSearchPath(), GetEnv(), CppInternal::utils::platform::GetSystemLibraryPaths(), CppInternal::utils::platform::kEnvDelim, and CppInternal::utils::SplitPaths().
| CppInternal::DynamicLibraryManager::~DynamicLibraryManager | ( | ) |
Definition at line 1306 of file DynamicLibraryManagerSymbol.cpp.
|
delete |
|
inline |
Definition at line 129 of file DynamicLibraryManager.h.
Referenced by Cpp::AddSearchPath(), and DynamicLibraryManager().
| void CppInternal::DynamicLibraryManager::dump | ( | llvm::raw_ostream * | S = nullptr | ) | const |
Definition at line 425 of file DynamicLibraryManager.cpp.
References getSearchPaths().
|
inline |
Definition at line 119 of file DynamicLibraryManager.h.
|
inline |
Definition at line 120 of file DynamicLibraryManager.h.
|
inline |
Returns the system include paths.
Definition at line 127 of file DynamicLibraryManager.h.
Referenced by dump().
|
inlinestatic |
On a success returns to full path to a shared object that holds the symbol pointed by func.
Definition at line 205 of file DynamicLibraryManager.h.
| void CppInternal::DynamicLibraryManager::initializeDyld | ( | std::function< bool(llvm::StringRef)> | shouldPermanentlyIgnore | ) |
Initialize the dyld.
| [in] | shouldPermanentlyIgnore | - a callback deciding if a library should be ignored from the result set. Useful for ignoring dangerous libraries such as the ones overriding malloc. |
Definition at line 1311 of file DynamicLibraryManagerSymbol.cpp.
References CppInternal::GetExecutablePath().
| bool CppInternal::DynamicLibraryManager::isLibraryLoaded | ( | llvm::StringRef | fullPath | ) | const |
Returns true if the file was a dynamic library and it was already loaded.
Definition at line 418 of file DynamicLibraryManager.cpp.
References normalizePath().
Referenced by unloadLibrary().
|
static |
Returns true if file is a shared library.
| [in] | libFullPath | - the full path to file. |
| [out] | exists | - sets if the file exists. Useful to distinguish if it is a library but of incompatible file format. |
Definition at line 451 of file DynamicLibraryManager.cpp.
Referenced by lookupLibrary().
| DynamicLibraryManager::LoadLibResult CppInternal::DynamicLibraryManager::loadLibrary | ( | llvm::StringRef | , |
| bool | permanent, | ||
| bool | resolved = false |
||
| ) |
Loads a shared library.
| [in] | libStem | - The file to load. |
| [in] | permanent | - If false, the file can be unloaded later. |
| [in] | resolved | - Whether libStem is an absolute path or resolved from a previous call to DynamicLibraryManager::lookupLibrary |
Definition at line 345 of file DynamicLibraryManager.cpp.
References CppInternal::utils::platform::DLOpen(), kLoadLibAlreadyLoaded, kLoadLibLoadError, kLoadLibNotFound, kLoadLibSuccess, and lookupLibrary().
Referenced by CppInternal::Interpreter::loadLibrary().
| std::string CppInternal::DynamicLibraryManager::lookupLibrary | ( | llvm::StringRef | libStem, |
| llvm::SmallVector< llvm::StringRef, 2 > | RPath = {}, |
||
| llvm::SmallVector< llvm::StringRef, 2 > | RunPath = {}, |
||
| llvm::StringRef | libLoader = "", |
||
| bool | variateLibStem = true |
||
| ) | const |
Looks up a library taking into account the current include paths and the system include paths.
See more information for RPATH and RUNPATH: https://en.wikipedia.org/wiki/Rpath
| [in] | libStem | - The filename being looked up |
| [in] | RPath | - RPATH as provided by loader library, searching for libStem |
| [in] | RunPath | - RUNPATH as provided by loader library, searching for libStem |
| [in] | libLoader | - The library that loads libStem. Use "" for main program. |
| [in] | variateLibStem | - If this param is true, and libStem is "L", then we search for "L", "libL", "L.so", "libL.so"", etc. |
Definition at line 283 of file DynamicLibraryManager.cpp.
References isSharedLibrary(), CppInternal::utils::platform::NormalizePath(), normalizePath(), CppInternal::RPathToStr2(), CppInternal::substAll(), and CppInternal::substFront().
Referenced by CppInternal::Interpreter::loadLibrary(), loadLibrary(), and unloadLibrary().
|
static |
Definition at line 259 of file DynamicLibraryManager.cpp.
References CppInternal::utils::platform::NormalizePath().
Referenced by isLibraryLoaded(), and lookupLibrary().
|
delete |
| std::string CppInternal::DynamicLibraryManager::searchLibrariesForSymbol | ( | llvm::StringRef | mangledName, |
| bool | searchSystem = true |
||
| ) | const |
Find the first not-yet-loaded shared object that contains the symbol.
| [in] | mangledName | - the mangled name to look for. |
| [in] | searchSystem | - whether to descend into system libraries. |
Definition at line 1324 of file DynamicLibraryManagerSymbol.cpp.
|
inline |
Definition at line 121 of file DynamicLibraryManager.h.
| void CppInternal::DynamicLibraryManager::unloadLibrary | ( | llvm::StringRef | libStem | ) |
Definition at line 387 of file DynamicLibraryManager.cpp.
References CppInternal::utils::platform::DLClose(), isLibraryLoaded(), and lookupLibrary().
Referenced by Cpp::UnloadLibrary().