[llvm] [ORC] Add LLLazyJIT destructor with call to endSession. (PR #209399)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 14 01:15:26 PDT 2026
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/209399
Add an LLLazyJIT destructor with a call to ExecutionSession::endSession. This ensures that the ExecutionSession's TaskDispatcher is shut down (and in-flight tasks completed) before LLLazyJIT class members are destroyed. Failure to do this could lead to use-after-free errors when using thread-based task dispatch. This was likely the cause of flakiness in test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll.
rdar://181982834
>From 10d261851a7efa65d8a508fd071413c3f39498af Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Tue, 14 Jul 2026 17:47:43 +1000
Subject: [PATCH] [ORC] Add LLLazyJIT destructor with call to endSession.
Add an LLLazyJIT destructor with a call to ExecutionSession::endSession.
This ensures that the ExecutionSession's TaskDispatcher is shut down
(and in-flight tasks completed) before LLLazyJIT class members are
destroyed. Failure to do this could lead to use-after-free errors when
using thread-based task dispatch. This was likely the cause of flakiness
in test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll.
rdar://181982834
---
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h | 2 ++
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 8 ++++++++
2 files changed, 10 insertions(+)
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index 3ba472305066d..62fe44d6bcba7 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -296,6 +296,8 @@ class LLLazyJIT : public LLJIT {
IPLayer->setPartitionFunction(std::move(Partition));
}
+ LLVM_ABI ~LLLazyJIT();
+
/// Returns a reference to the on-demand layer.
CompileOnDemandLayer &getCompileOnDemandLayer() { return *CODLayer; }
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 18db7d24a8262..21e2c5ed41a83 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -1312,6 +1312,14 @@ Error LLLazyJIT::addLazyIRModule(JITDylib &JD, ThreadSafeModule TSM) {
return CODLayer->add(JD, std::move(TSM));
}
+// End the session before this class's members (CODLayer, IPLayer, LCTMgr) are
+// destroyed: endSession joins the compile threads, and those threads may still
+// be operating on the CompileOnDemandLayer's per-dylib IndirectStubsManagers.
+LLLazyJIT::~LLLazyJIT() {
+ if (auto Err = ES->endSession())
+ ES->reportError(std::move(Err));
+}
+
LLLazyJIT::LLLazyJIT(LLLazyJITBuilderState &S, Error &Err) : LLJIT(S, Err) {
// If LLJIT construction failed then bail out.
More information about the llvm-commits
mailing list