diff options
Diffstat (limited to 'contrib/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp')
-rw-r--r-- | contrib/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/contrib/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/contrib/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 7fb328b..ff8749f 100644 --- a/contrib/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/contrib/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -29,8 +29,6 @@ using namespace llvm; -void ObjectCache::anchor() {} - namespace { static struct RegisterJIT { @@ -46,7 +44,7 @@ ExecutionEngine* MCJIT::createJIT(std::unique_ptr<Module> M, std::string *ErrorStr, std::shared_ptr<MCJITMemoryManager> MemMgr, - std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver, + std::shared_ptr<JITSymbolResolver> Resolver, std::unique_ptr<TargetMachine> TM) { // Try to register the program as a source of symbols to resolve against. // @@ -67,7 +65,7 @@ MCJIT::createJIT(std::unique_ptr<Module> M, MCJIT::MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> TM, std::shared_ptr<MCJITMemoryManager> MemMgr, - std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver) + std::shared_ptr<JITSymbolResolver> Resolver) : ExecutionEngine(TM->createDataLayout(), std::move(M)), TM(std::move(TM)), Ctx(nullptr), MemMgr(std::move(MemMgr)), Resolver(*this, std::move(Resolver)), Dyld(*this->MemMgr, this->Resolver), @@ -276,20 +274,21 @@ void MCJIT::finalizeModule(Module *M) { finalizeLoadedModules(); } -RuntimeDyld::SymbolInfo MCJIT::findExistingSymbol(const std::string &Name) { - SmallString<128> FullName; - Mangler::getNameWithPrefix(FullName, Name, getDataLayout()); - - if (void *Addr = getPointerToGlobalIfAvailable(FullName)) - return RuntimeDyld::SymbolInfo(static_cast<uint64_t>( - reinterpret_cast<uintptr_t>(Addr)), - JITSymbolFlags::Exported); +JITSymbol MCJIT::findExistingSymbol(const std::string &Name) { + if (void *Addr = getPointerToGlobalIfAvailable(Name)) + return JITSymbol(static_cast<uint64_t>( + reinterpret_cast<uintptr_t>(Addr)), + JITSymbolFlags::Exported); - return Dyld.getSymbol(FullName); + return Dyld.getSymbol(Name); } Module *MCJIT::findModuleForSymbol(const std::string &Name, bool CheckFunctionsOnly) { + StringRef DemangledName = Name; + if (DemangledName[0] == getDataLayout().getGlobalPrefix()) + DemangledName = DemangledName.substr(1); + MutexGuard locked(lock); // If it hasn't already been generated, see if it's in one of our modules. @@ -297,11 +296,11 @@ Module *MCJIT::findModuleForSymbol(const std::string &Name, E = OwnedModules.end_added(); I != E; ++I) { Module *M = *I; - Function *F = M->getFunction(Name); + Function *F = M->getFunction(DemangledName); if (F && !F->isDeclaration()) return M; if (!CheckFunctionsOnly) { - GlobalVariable *G = M->getGlobalVariable(Name); + GlobalVariable *G = M->getGlobalVariable(DemangledName); if (G && !G->isDeclaration()) return M; // FIXME: Do we need to worry about global aliases? @@ -313,11 +312,16 @@ Module *MCJIT::findModuleForSymbol(const std::string &Name, uint64_t MCJIT::getSymbolAddress(const std::string &Name, bool CheckFunctionsOnly) { - return findSymbol(Name, CheckFunctionsOnly).getAddress(); + std::string MangledName; + { + raw_string_ostream MangledNameStream(MangledName); + Mangler::getNameWithPrefix(MangledNameStream, Name, getDataLayout()); + } + return findSymbol(MangledName, CheckFunctionsOnly).getAddress(); } -RuntimeDyld::SymbolInfo MCJIT::findSymbol(const std::string &Name, - bool CheckFunctionsOnly) { +JITSymbol MCJIT::findSymbol(const std::string &Name, + bool CheckFunctionsOnly) { MutexGuard locked(lock); // First, check to see if we already have this symbol. @@ -367,7 +371,7 @@ RuntimeDyld::SymbolInfo MCJIT::findSymbol(const std::string &Name, if (LazyFunctionCreator) { auto Addr = static_cast<uint64_t>( reinterpret_cast<uintptr_t>(LazyFunctionCreator(Name))); - return RuntimeDyld::SymbolInfo(Addr, JITSymbolFlags::Exported); + return JITSymbol(Addr, JITSymbolFlags::Exported); } return nullptr; @@ -442,7 +446,7 @@ void MCJIT::runStaticConstructorsDestructors(bool isDtors) { isDtors, OwnedModules.begin_finalized(), OwnedModules.end_finalized()); } -Function *MCJIT::FindFunctionNamedInModulePtrSet(const char *FnName, +Function *MCJIT::FindFunctionNamedInModulePtrSet(StringRef FnName, ModulePtrSet::iterator I, ModulePtrSet::iterator E) { for (; I != E; ++I) { @@ -453,7 +457,7 @@ Function *MCJIT::FindFunctionNamedInModulePtrSet(const char *FnName, return nullptr; } -GlobalVariable *MCJIT::FindGlobalVariableNamedInModulePtrSet(const char *Name, +GlobalVariable *MCJIT::FindGlobalVariableNamedInModulePtrSet(StringRef Name, bool AllowInternal, ModulePtrSet::iterator I, ModulePtrSet::iterator E) { @@ -466,7 +470,7 @@ GlobalVariable *MCJIT::FindGlobalVariableNamedInModulePtrSet(const char *Name, } -Function *MCJIT::FindFunctionNamed(const char *FnName) { +Function *MCJIT::FindFunctionNamed(StringRef FnName) { Function *F = FindFunctionNamedInModulePtrSet( FnName, OwnedModules.begin_added(), OwnedModules.end_added()); if (!F) @@ -478,7 +482,7 @@ Function *MCJIT::FindFunctionNamed(const char *FnName) { return F; } -GlobalVariable *MCJIT::FindGlobalVariableNamed(const char *Name, bool AllowInternal) { +GlobalVariable *MCJIT::FindGlobalVariableNamed(StringRef Name, bool AllowInternal) { GlobalVariable *GV = FindGlobalVariableNamedInModulePtrSet( Name, AllowInternal, OwnedModules.begin_added(), OwnedModules.end_added()); if (!GV) @@ -587,7 +591,10 @@ GenericValue MCJIT::runFunction(Function *F, ArrayRef<GenericValue> ArgValues) { } } - llvm_unreachable("Full-featured argument passing not supported yet!"); + report_fatal_error("MCJIT::runFunction does not support full-featured " + "argument passing. Please use " + "ExecutionEngine::getFunctionAddress and cast the result " + "to the desired function pointer type."); } void *MCJIT::getPointerToNamedFunction(StringRef Name, bool AbortOnFailure) { @@ -622,7 +629,7 @@ void MCJIT::UnregisterJITEventListener(JITEventListener *L) { if (!L) return; MutexGuard locked(lock); - auto I = std::find(EventListeners.rbegin(), EventListeners.rend(), L); + auto I = find(reverse(EventListeners), L); if (I != EventListeners.rend()) { std::swap(*I, EventListeners.back()); EventListeners.pop_back(); @@ -644,13 +651,9 @@ void MCJIT::NotifyFreeingObject(const object::ObjectFile& Obj) { L->NotifyFreeingObject(Obj); } -RuntimeDyld::SymbolInfo +JITSymbol LinkingSymbolResolver::findSymbol(const std::string &Name) { auto Result = ParentEngine.findSymbol(Name, false); - // If the symbols wasn't found and it begins with an underscore, try again - // without the underscore. - if (!Result && Name[0] == '_') - Result = ParentEngine.findSymbol(Name.substr(1), false); if (Result) return Result; if (ParentEngine.isSymbolSearchingDisabled()) |