diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
commit | d8e91e46262bc44006913e6796843909f1ac7bcd (patch) | |
tree | 7d0c143d9b38190e0fa0180805389da22cd834c5 /lib/ExecutionEngine/Orc/ExecutionUtils.cpp | |
parent | b7eb8e35e481a74962664b63dfb09483b200209a (diff) |
Notes
Diffstat (limited to 'lib/ExecutionEngine/Orc/ExecutionUtils.cpp')
-rw-r--r-- | lib/ExecutionEngine/Orc/ExecutionUtils.cpp | 104 |
1 files changed, 44 insertions, 60 deletions
diff --git a/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/lib/ExecutionEngine/Orc/ExecutionUtils.cpp index 6157677ce355..7c3c50b4d6e5 100644 --- a/lib/ExecutionEngine/Orc/ExecutionUtils.cpp +++ b/lib/ExecutionEngine/Orc/ExecutionUtils.cpp @@ -19,45 +19,6 @@ namespace llvm { namespace orc { -JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT) - : TT(std::move(TT)) {} - -Expected<JITTargetMachineBuilder> JITTargetMachineBuilder::detectHost() { - return JITTargetMachineBuilder(Triple(sys::getProcessTriple())); -} - -Expected<std::unique_ptr<TargetMachine>> -JITTargetMachineBuilder::createTargetMachine() { - if (!Arch.empty()) { - Triple::ArchType Type = Triple::getArchTypeForLLVMName(Arch); - - if (Type == Triple::UnknownArch) - return make_error<StringError>(std::string("Unknown arch: ") + Arch, - inconvertibleErrorCode()); - } - - std::string ErrMsg; - auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg); - if (!TheTarget) - return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode()); - - auto *TM = - TheTarget->createTargetMachine(TT.getTriple(), CPU, Features.getString(), - Options, RM, CM, OptLevel, /*JIT*/ true); - if (!TM) - return make_error<StringError>("Could not allocate target machine", - inconvertibleErrorCode()); - - return std::unique_ptr<TargetMachine>(TM); -} - -JITTargetMachineBuilder &JITTargetMachineBuilder::addFeatures( - const std::vector<std::string> &FeatureVec) { - for (const auto &F : FeatureVec) - Features.AddFeature(F); - return *this; -} - CtorDtorIterator::CtorDtorIterator(const GlobalVariable *GV, bool End) : InitList( GV ? dyn_cast_or_null<ConstantArray>(GV->getInitializer()) : nullptr), @@ -126,18 +87,24 @@ iterator_range<CtorDtorIterator> getDestructors(const Module &M) { CtorDtorIterator(DtorsList, true)); } -void CtorDtorRunner2::add(iterator_range<CtorDtorIterator> CtorDtors) { - if (CtorDtors.begin() == CtorDtors.end()) +void CtorDtorRunner::add(iterator_range<CtorDtorIterator> CtorDtors) { + if (empty(CtorDtors)) return; MangleAndInterner Mangle( - V.getExecutionSession(), + JD.getExecutionSession(), (*CtorDtors.begin()).Func->getParent()->getDataLayout()); for (const auto &CtorDtor : CtorDtors) { assert(CtorDtor.Func && CtorDtor.Func->hasName() && "Ctor/Dtor function must be named to be runnable under the JIT"); + // FIXME: Maybe use a symbol promoter here instead. + if (CtorDtor.Func->hasLocalLinkage()) { + CtorDtor.Func->setLinkage(GlobalValue::ExternalLinkage); + CtorDtor.Func->setVisibility(GlobalValue::HiddenVisibility); + } + if (CtorDtor.Data && cast<GlobalValue>(CtorDtor.Data)->isDeclaration()) { dbgs() << " Skipping because why now?\n"; continue; @@ -148,7 +115,7 @@ void CtorDtorRunner2::add(iterator_range<CtorDtorIterator> CtorDtors) { } } -Error CtorDtorRunner2::run() { +Error CtorDtorRunner::run() { using CtorDtorTy = void (*)(); SymbolNameSet Names; @@ -161,7 +128,10 @@ Error CtorDtorRunner2::run() { } } - if (auto CtorDtorMap = lookup({&V}, std::move(Names))) { + auto &ES = JD.getExecutionSession(); + if (auto CtorDtorMap = + ES.lookup(JITDylibSearchList({{&JD, true}}), std::move(Names), + NoDependenciesToRegister, true)) { for (auto &KV : CtorDtorsByPriority) { for (auto &Name : KV.second) { assert(CtorDtorMap->count(Name) && "No entry for Name"); @@ -195,32 +165,46 @@ int LocalCXXRuntimeOverridesBase::CXAAtExitOverride(DestructorPtr Destructor, return 0; } -Error LocalCXXRuntimeOverrides2::enable(VSO &V, MangleAndInterner &Mangle) { - SymbolMap RuntimeInterposes( - {{Mangle("__dso_handle"), - JITEvaluatedSymbol(toTargetAddress(&DSOHandleOverride), - JITSymbolFlags::Exported)}, - {Mangle("__cxa_atexit"), - JITEvaluatedSymbol(toTargetAddress(&CXAAtExitOverride), - JITSymbolFlags::Exported)}}); +Error LocalCXXRuntimeOverrides::enable(JITDylib &JD, + MangleAndInterner &Mangle) { + SymbolMap RuntimeInterposes; + RuntimeInterposes[Mangle("__dso_handle")] = + JITEvaluatedSymbol(toTargetAddress(&DSOHandleOverride), + JITSymbolFlags::Exported); + RuntimeInterposes[Mangle("__cxa_atexit")] = + JITEvaluatedSymbol(toTargetAddress(&CXAAtExitOverride), + JITSymbolFlags::Exported); - return V.define(absoluteSymbols(std::move(RuntimeInterposes))); + return JD.define(absoluteSymbols(std::move(RuntimeInterposes))); } -DynamicLibraryFallbackGenerator::DynamicLibraryFallbackGenerator( +DynamicLibrarySearchGenerator::DynamicLibrarySearchGenerator( sys::DynamicLibrary Dylib, const DataLayout &DL, SymbolPredicate Allow) : Dylib(std::move(Dylib)), Allow(std::move(Allow)), GlobalPrefix(DL.getGlobalPrefix()) {} -SymbolNameSet DynamicLibraryFallbackGenerator:: -operator()(VSO &V, const SymbolNameSet &Names) { +Expected<DynamicLibrarySearchGenerator> +DynamicLibrarySearchGenerator::Load(const char *FileName, const DataLayout &DL, + SymbolPredicate Allow) { + std::string ErrMsg; + auto Lib = sys::DynamicLibrary::getPermanentLibrary(FileName, &ErrMsg); + if (!Lib.isValid()) + return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode()); + return DynamicLibrarySearchGenerator(std::move(Lib), DL, std::move(Allow)); +} + +SymbolNameSet DynamicLibrarySearchGenerator:: +operator()(JITDylib &JD, const SymbolNameSet &Names) { orc::SymbolNameSet Added; orc::SymbolMap NewSymbols; bool HasGlobalPrefix = (GlobalPrefix != '\0'); for (auto &Name : Names) { - if (!Allow(Name) || (*Name).empty()) + if ((*Name).empty()) + continue; + + if (Allow && !Allow(Name)) continue; if (HasGlobalPrefix && (*Name).front() != GlobalPrefix) @@ -235,11 +219,11 @@ operator()(VSO &V, const SymbolNameSet &Names) { } } - // Add any new symbols to V. Since the fallback generator is only called for - // symbols that are not already defined, this will never trigger a duplicate + // Add any new symbols to JD. Since the generator is only called for symbols + // that are not already defined, this will never trigger a duplicate // definition error, so we can wrap this call in a 'cantFail'. if (!NewSymbols.empty()) - cantFail(V.define(absoluteSymbols(std::move(NewSymbols)))); + cantFail(JD.define(absoluteSymbols(std::move(NewSymbols)))); return Added; } |