[llvm] [ORC] Move DylibManager impl out of SimpleRemoteEPC. (PR #188439)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 25 02:06:19 PDT 2026


https://github.com/lhames created https://github.com/llvm/llvm-project/pull/188439

This updates EPCGenericDylibManager to implement the DylibManager interface, and drops the DylibManager implementation from SimpleRemoteEPC. Since SimpleRemoteEPC already owned an EPCGenericDylibManager it can simply provide that as its DylibManager implementation. This change should not affect the behavior of SimpleRemoteEPC from the perspective of API clients.

>From 2cd50a1b39ff1b25a48639570a7b2679e503fa7f Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Wed, 25 Mar 2026 19:44:30 +1100
Subject: [PATCH] [ORC] Move DylibManager impl out of SimpleRemoteEPC.

This updates EPCGenericDylibManager to implement the DylibManager interface,
and drops the DylibManager implementation from SimpleRemoteEPC. Since
SimpleRemoteEPC already owned an EPCGenericDylibManager it can simply provide
that as its DylibManager implementation. This change should not affect the
behavior of SimpleRemoteEPC from the perspective of API clients.
---
 .../Orc/EPCGenericDylibManager.h              | 13 ++++++-
 .../ExecutionEngine/Orc/SimpleRemoteEPC.h     | 12 +-----
 .../Orc/EPCGenericDylibManager.cpp            | 38 ++++++++++++++++++
 .../ExecutionEngine/Orc/SimpleRemoteEPC.cpp   | 39 +------------------
 4 files changed, 54 insertions(+), 48 deletions(-)

diff --git a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericDylibManager.h b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericDylibManager.h
index 7c995a727e348..12394e85ff2c9 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericDylibManager.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericDylibManager.h
@@ -28,7 +28,7 @@ namespace orc {
 
 class SymbolLookupSet;
 
-class EPCGenericDylibManager {
+class EPCGenericDylibManager : public DylibManager {
 public:
   /// Function addresses for memory access.
   struct SymbolAddrs {
@@ -81,6 +81,17 @@ class EPCGenericDylibManager {
                             const RemoteSymbolLookupSet &Lookup,
                             SymbolLookupCompleteFn Complete);
 
+  /// Load the dynamic library at the given path and return a handle to it.
+  /// If DylibPath is null this function will return the global handle for
+  /// the target process.
+  LLVM_ABI Expected<tpctypes::DylibHandle>
+  loadDylib(const char *DylibPath) override;
+
+  /// Search for symbols in the target process.
+  LLVM_ABI void
+  lookupSymbolsAsync(ArrayRef<DylibManager::LookupRequest> Request,
+                     DylibManager::SymbolLookupCompleteFn Complete) override;
+
 private:
   ExecutorProcessControl &EPC;
   SymbolAddrs SAs;
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h b/llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
index 83f4908ce6a98..ab97fb5f19ee2 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h
@@ -30,8 +30,7 @@ namespace llvm {
 namespace orc {
 
 class LLVM_ABI SimpleRemoteEPC : public ExecutorProcessControl,
-                                 public SimpleRemoteEPCTransportClient,
-                                 private DylibManager {
+                                 public SimpleRemoteEPCTransportClient {
 public:
   /// A setup object containing callbacks to construct a memory manager and
   /// memory access object. Both are optional. If not specified,
@@ -93,9 +92,7 @@ class LLVM_ABI SimpleRemoteEPC : public ExecutorProcessControl,
 private:
   SimpleRemoteEPC(std::shared_ptr<SymbolStringPool> SSP,
                   std::unique_ptr<TaskDispatcher> D)
-      : ExecutorProcessControl(std::move(SSP), std::move(D)) {
-    this->DylibMgr = this;
-  }
+      : ExecutorProcessControl(std::move(SSP), std::move(D)) {}
 
   static Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>
   createDefaultMemoryManager(SimpleRemoteEPC &SREPC);
@@ -118,11 +115,6 @@ class LLVM_ABI SimpleRemoteEPC : public ExecutorProcessControl,
   uint64_t getNextSeqNo() { return NextSeqNo++; }
   void releaseSeqNo(uint64_t SeqNo) {}
 
-  Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;
-
-  void lookupSymbolsAsync(ArrayRef<LookupRequest> Request,
-                          SymbolLookupCompleteFn F) override;
-
   using PendingCallWrapperResultsMap =
     DenseMap<uint64_t, IncomingWFRHandler>;
 
diff --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp
index 1f19d178039e5..4b751c224ef05 100644
--- a/llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp
@@ -119,5 +119,43 @@ void EPCGenericDylibManager::lookupAsync(tpctypes::DylibHandle H,
       H, Lookup);
 }
 
+Expected<tpctypes::DylibHandle>
+EPCGenericDylibManager::loadDylib(const char *DylibPath) {
+  return open(DylibPath, 0);
+}
+
+/// Async helper to chain together calls to lookupAsync to fulfill all
+/// the requests.
+/// FIXME: The dylib manager should support multiple LookupRequests natively.
+static void
+lookupSymbolsAsyncHelper(EPCGenericDylibManager &DylibMgr,
+                         ArrayRef<DylibManager::LookupRequest> Request,
+                         std::vector<tpctypes::LookupResult> Result,
+                         DylibManager::SymbolLookupCompleteFn Complete) {
+  if (Request.empty())
+    return Complete(std::move(Result));
+
+  auto &Element = Request.front();
+  DylibMgr.lookupAsync(Element.Handle, Element.Symbols,
+                       [&DylibMgr, Request, Complete = std::move(Complete),
+                        Result = std::move(Result)](auto R) mutable {
+                         if (!R)
+                           return Complete(R.takeError());
+                         Result.push_back({});
+                         Result.back().reserve(R->size());
+                         llvm::append_range(Result.back(), *R);
+
+                         lookupSymbolsAsyncHelper(
+                             DylibMgr, Request.drop_front(), std::move(Result),
+                             std::move(Complete));
+                       });
+}
+
+void EPCGenericDylibManager::lookupSymbolsAsync(
+    ArrayRef<DylibManager::LookupRequest> Request,
+    DylibManager::SymbolLookupCompleteFn Complete) {
+  lookupSymbolsAsyncHelper(*this, Request, {}, std::move(Complete));
+}
+
 } // end namespace orc
 } // end namespace llvm
diff --git a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
index c7f8e5fb74134..18132523a33f0 100644
--- a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
@@ -23,43 +23,6 @@ SimpleRemoteEPC::~SimpleRemoteEPC() {
 #endif // NDEBUG
 }
 
-Expected<tpctypes::DylibHandle>
-SimpleRemoteEPC::loadDylib(const char *DylibPath) {
-  return EPCDylibMgr->open(DylibPath, 0);
-}
-
-/// Async helper to chain together calls to DylibMgr::lookupAsync to fulfill all
-/// all the requests.
-/// FIXME: The dylib manager should support multiple LookupRequests natively.
-static void
-lookupSymbolsAsyncHelper(EPCGenericDylibManager &DylibMgr,
-                         ArrayRef<DylibManager::LookupRequest> Request,
-                         std::vector<tpctypes::LookupResult> Result,
-                         DylibManager::SymbolLookupCompleteFn Complete) {
-  if (Request.empty())
-    return Complete(std::move(Result));
-
-  auto &Element = Request.front();
-  DylibMgr.lookupAsync(Element.Handle, Element.Symbols,
-                       [&DylibMgr, Request, Complete = std::move(Complete),
-                        Result = std::move(Result)](auto R) mutable {
-                         if (!R)
-                           return Complete(R.takeError());
-                         Result.push_back({});
-                         Result.back().reserve(R->size());
-                         llvm::append_range(Result.back(), *R);
-
-                         lookupSymbolsAsyncHelper(
-                             DylibMgr, Request.drop_front(), std::move(Result),
-                             std::move(Complete));
-                       });
-}
-
-void SimpleRemoteEPC::lookupSymbolsAsync(ArrayRef<LookupRequest> Request,
-                                         SymbolLookupCompleteFn Complete) {
-  lookupSymbolsAsyncHelper(*EPCDylibMgr, Request, {}, std::move(Complete));
-}
-
 Expected<int32_t> SimpleRemoteEPC::runAsMain(ExecutorAddr MainFnAddr,
                                              ArrayRef<std::string> Args) {
   int64_t Result = 0;
@@ -375,6 +338,8 @@ Error SimpleRemoteEPC::setup(Setup S) {
   else
     return DM.takeError();
 
+  this->DylibMgr = EPCDylibMgr.get();
+
   // Set a default CreateMemoryManager if none is specified.
   if (!S.CreateMemoryManager)
     S.CreateMemoryManager = createDefaultMemoryManager;



More information about the llvm-commits mailing list