diff options
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/Core.cpp | 36 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp | 26 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp | 15 |
5 files changed, 54 insertions, 37 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp index 6a9ebb4..d47eb44 100644 --- a/llvm/lib/ExecutionEngine/Orc/Core.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -1576,12 +1576,22 @@ void Platform::lookupInitSymbolsAsync( } } +MaterializationTask::~MaterializationTask() { + // If this task wasn't run then fail materialization. + if (MR) + MR->failMaterialization(); +} + void MaterializationTask::printDescription(raw_ostream &OS) { OS << "Materialization task: " << MU->getName() << " in " << MR->getTargetJITDylib().getName(); } -void MaterializationTask::run() { MU->materialize(std::move(MR)); } +void MaterializationTask::run() { + assert(MU && "MU should not be null"); + assert(MR && "MR should not be null"); + MU->materialize(std::move(MR)); +} void LookupTask::printDescription(raw_ostream &OS) { OS << "Lookup task"; } @@ -1821,17 +1831,10 @@ ExecutionSession::lookup(const JITDylibSearchOrder &SearchOrder, RegisterDependenciesFunction RegisterDependencies) { #if LLVM_ENABLE_THREADS // In the threaded case we use promises to return the results. - std::promise<SymbolMap> PromisedResult; - Error ResolutionError = Error::success(); + std::promise<MSVCPExpected<SymbolMap>> PromisedResult; auto NotifyComplete = [&](Expected<SymbolMap> R) { - if (R) - PromisedResult.set_value(std::move(*R)); - else { - ErrorAsOutParameter _(ResolutionError); - ResolutionError = R.takeError(); - PromisedResult.set_value(SymbolMap()); - } + PromisedResult.set_value(std::move(R)); }; #else @@ -1848,18 +1851,11 @@ ExecutionSession::lookup(const JITDylibSearchOrder &SearchOrder, #endif // Perform the asynchronous lookup. - lookup(K, SearchOrder, std::move(Symbols), RequiredState, NotifyComplete, - RegisterDependencies); + lookup(K, SearchOrder, std::move(Symbols), RequiredState, + std::move(NotifyComplete), RegisterDependencies); #if LLVM_ENABLE_THREADS - auto ResultFuture = PromisedResult.get_future(); - auto Result = ResultFuture.get(); - - if (ResolutionError) - return std::move(ResolutionError); - - return std::move(Result); - + return PromisedResult.get_future().get(); #else if (ResolutionError) return std::move(ResolutionError); diff --git a/llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp index c08e52e..0d9a912 100644 --- a/llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp @@ -148,7 +148,7 @@ public: DSec.BuilderSec->align = Log2_64(SR.getFirstBlock()->getAlignment()); StringRef SectionData(SR.getFirstBlock()->getContent().data(), SR.getFirstBlock()->getSize()); - DebugSectionMap[SecName] = + DebugSectionMap[SecName.drop_front(2)] = // drop "__" prefix. MemoryBuffer::getMemBuffer(SectionData, G.getName(), false); if (SecName == "__debug_line") DebugLineSectionData = SectionData; @@ -167,11 +167,10 @@ public: DebugLineSectionData, G.getEndianness() == llvm::endianness::little, G.getPointerSize()); uint64_t Offset = 0; - DWARFDebugLine::LineTable LineTable; + DWARFDebugLine::Prologue P; // Try to parse line data. Consume error on failure. - if (auto Err = LineTable.parse(DebugLineData, &Offset, *DWARFCtx, nullptr, - consumeError)) { + if (auto Err = P.parse(DebugLineData, &Offset, consumeError, *DWARFCtx)) { handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) { LLVM_DEBUG({ dbgs() << "Cannot parse line table for \"" << G.getName() << "\": "; @@ -180,15 +179,26 @@ public: }); }); } else { - if (!LineTable.Prologue.FileNames.empty()) - FileName = *dwarf::toString(LineTable.Prologue.FileNames[0].Name); + for (auto &FN : P.FileNames) + if ((FileName = dwarf::toString(FN.Name))) { + LLVM_DEBUG({ + dbgs() << "Using FileName = \"" << *FileName + << "\" from DWARF line table\n"; + }); + break; + } } } // If no line table (or unable to use) then use graph name. // FIXME: There are probably other debug sections we should look in first. - if (!FileName) - FileName = StringRef(G.getName()); + if (!FileName) { + LLVM_DEBUG({ + dbgs() << "Could not find source name from DWARF line table. " + "Using FileName = \"\"\n"; + }); + FileName = ""; + } Builder.addSymbol("", MachO::N_SO, 0, 0, 0); Builder.addSymbol(*FileName, MachO::N_SO, 0, 0, 0); diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp index 0e83497..9f324c7 100644 --- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp @@ -937,6 +937,12 @@ Error MachOPlatform::MachOPlatformPlugin::bootstrapPipelineEnd( jitlink::LinkGraph &G) { std::lock_guard<std::mutex> Lock(MP.Bootstrap.load()->Mutex); assert(MP.Bootstrap && "DeferredAAs reset before bootstrap completed"); + + // Transfer any allocation actions to DeferredAAs. + std::move(G.allocActions().begin(), G.allocActions().end(), + std::back_inserter(MP.Bootstrap.load()->DeferredAAs)); + G.allocActions().clear(); + --MP.Bootstrap.load()->ActiveGraphs; // Notify Bootstrap->CV while holding the mutex because the mutex is // also keeping Bootstrap->CV alive. @@ -1397,10 +1403,6 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections( SPSExecutorAddrRange, SPSExecutorAddrRange>>, SPSSequence<SPSTuple<SPSString, SPSExecutorAddrRange>>>; - shared::AllocActions &allocActions = LLVM_LIKELY(!InBootstrapPhase) - ? G.allocActions() - : MP.Bootstrap.load()->DeferredAAs; - ExecutorAddr HeaderAddr; { std::lock_guard<std::mutex> Lock(MP.PlatformMutex); @@ -1410,7 +1412,7 @@ Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections( assert(I->second && "Null header registered for JD"); HeaderAddr = I->second; } - allocActions.push_back( + G.allocActions().push_back( {cantFail( WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>( MP.RegisterObjectPlatformSections.Addr, HeaderAddr, UnwindInfo, diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp index 6688b09..9bc0aa8 100644 --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -16,8 +16,6 @@ namespace llvm::orc { char ObjectLinkingLayer::ID; -using BaseObjectLayer = RTTIExtends<ObjectLinkingLayer, ObjectLayer>; - void ObjectLinkingLayer::emit(std::unique_ptr<MaterializationResponsibility> R, std::unique_ptr<MemoryBuffer> O) { assert(O && "Object must not be null"); diff --git a/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp b/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp index fbe4b09..1af17e8 100644 --- a/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp +++ b/llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp @@ -31,6 +31,10 @@ void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) { { std::lock_guard<std::mutex> Lock(DispatchMutex); + // Reject new tasks if they're dispatched after a call to shutdown. + if (Shutdown) + return; + if (IsMaterializationTask) { // If this is a materialization task and there are too many running @@ -54,6 +58,14 @@ void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) { // Run the task. T->run(); + // Reset the task to free any resources. We need this to happen *before* + // we notify anyone (via Outstanding) that this thread is done to ensure + // that we don't proceed with JIT shutdown while still holding resources. + // (E.g. this was causing "Dangling SymbolStringPtr" assertions). + T.reset(); + + // Check the work queue state and either proceed with the next task or + // end this thread. std::lock_guard<std::mutex> Lock(DispatchMutex); if (!MaterializationTaskQueue.empty()) { // If there are any materialization tasks running then steal that work. @@ -64,7 +76,6 @@ void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) { IsMaterializationTask = true; } } else { - // Otherwise decrement work counters. if (IsMaterializationTask) --NumMaterializationThreads; --Outstanding; @@ -78,7 +89,7 @@ void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) { void DynamicThreadPoolTaskDispatcher::shutdown() { std::unique_lock<std::mutex> Lock(DispatchMutex); - Running = false; + Shutdown = true; OutstandingCV.wait(Lock, [this]() { return Outstanding == 0; }); } #endif |