[llvm] 6613f4a - [ORC] Use raw OS handle values, ExecutorAddr for EPC dylib handles.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 24 14:16:28 PDT 2022


Author: Lang Hames
Date: 2022-10-24T13:57:04-07:00
New Revision: 6613f4aff85b24a13d4f5f7e9cd24bf3f44037a3

URL: https://github.com/llvm/llvm-project/commit/6613f4aff85b24a13d4f5f7e9cd24bf3f44037a3
DIFF: https://github.com/llvm/llvm-project/commit/6613f4aff85b24a13d4f5f7e9cd24bf3f44037a3.diff

LOG: [ORC] Use raw OS handle values, ExecutorAddr for EPC dylib handles.

Updates tpctypes::DylibHandle to be an ExecutorAddr (rather than a uint64_t),
and SimpleExecutorDylibManager to hold and return raw OS handle values (as
ExecutorAddrs) rather than index values into a map of DynamicLibrary instances.

This will allow clients to use EPCGenericDylibManager in contexts where the
existing DynamicLibrary interface is too limited to be used. (e.g. to look up
JIT symbols in a dylib that was loaded with RTLD_LOCAL).

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
    llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
    llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.h
    llvm/include/llvm/Support/DynamicLibrary.h
    llvm/lib/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.cpp
    llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp
    llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
    llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp
    llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
    llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
index 82d6901c08153..b2633579c4fd3 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
@@ -51,12 +51,13 @@ extern const char *RunAsVoidFunctionWrapperName;
 extern const char *RunAsIntFunctionWrapperName;
 
 using SPSSimpleExecutorDylibManagerOpenSignature =
-    shared::SPSExpected<uint64_t>(shared::SPSExecutorAddr, shared::SPSString,
-                                  uint64_t);
+    shared::SPSExpected<shared::SPSExecutorAddr>(shared::SPSExecutorAddr,
+                                                 shared::SPSString, uint64_t);
 
 using SPSSimpleExecutorDylibManagerLookupSignature =
     shared::SPSExpected<shared::SPSSequence<shared::SPSExecutorAddr>>(
-        shared::SPSExecutorAddr, uint64_t, shared::SPSRemoteSymbolLookupSet);
+        shared::SPSExecutorAddr, shared::SPSExecutorAddr,
+        shared::SPSRemoteSymbolLookupSet);
 
 using SPSSimpleExecutorMemoryManagerReserveSignature =
     shared::SPSExpected<shared::SPSExecutorAddr>(shared::SPSExecutorAddr,

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
index 4096366d2e36e..565fb5477c4af 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h
@@ -85,9 +85,9 @@ struct BufferWrite {
 };
 
 /// A handle used to represent a loaded dylib in the target process.
-using DylibHandle = JITTargetAddress;
+using DylibHandle = ExecutorAddr;
 
-using LookupResult = std::vector<JITTargetAddress>;
+using LookupResult = std::vector<ExecutorAddr>;
 
 } // end namespace tpctypes
 

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.h b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.h
index cbab234f8a2d3..fd4504cfb7fb0 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.h
@@ -16,7 +16,7 @@
 #ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEEXECUTORDYLIBMANAGER_H
 #define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEEXECUTORDYLIBMANAGER_H
 
-#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
 #include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
@@ -44,7 +44,7 @@ class SimpleExecutorDylibManager : public ExecutorBootstrapService {
   void addBootstrapSymbols(StringMap<ExecutorAddr> &M) override;
 
 private:
-  using DylibsMap = DenseMap<uint64_t, sys::DynamicLibrary>;
+  using DylibSet = DenseSet<void *>;
 
   static llvm::orc::shared::CWrapperFunctionResult
   openWrapper(const char *ArgData, size_t ArgSize);
@@ -53,8 +53,7 @@ class SimpleExecutorDylibManager : public ExecutorBootstrapService {
   lookupWrapper(const char *ArgData, size_t ArgSize);
 
   std::mutex M;
-  uint64_t NextId = 0;
-  DylibsMap Dylibs;
+  DylibSet Dylibs;
 };
 
 } // end namespace rt_bootstrap

diff  --git a/llvm/include/llvm/Support/DynamicLibrary.h b/llvm/include/llvm/Support/DynamicLibrary.h
index 0771606a75f56..f7db8fba39084 100644
--- a/llvm/include/llvm/Support/DynamicLibrary.h
+++ b/llvm/include/llvm/Support/DynamicLibrary.h
@@ -42,6 +42,9 @@ class DynamicLibrary {
 public:
   explicit DynamicLibrary(void *data = &Invalid) : Data(data) {}
 
+  /// Return the OS specific handle value.
+  void *getOSSpecificHandle() const { return Data; }
+
   /// Returns true if the object refers to a valid library.
   bool isValid() const { return Data != &Invalid; }
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.cpp b/llvm/lib/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.cpp
index ba154aaecd1aa..1adcc91569572 100644
--- a/llvm/lib/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.cpp
@@ -54,7 +54,7 @@ Error EPCDynamicLibrarySearchGenerator::tryToGenerate(
   for (auto &KV : LookupSymbols) {
     if (*ResultI)
       NewSymbols[KV.first] =
-          JITEvaluatedSymbol(*ResultI, JITSymbolFlags::Exported);
+          JITEvaluatedSymbol(ResultI->getValue(), JITSymbolFlags::Exported);
     ++ResultI;
   }
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp b/llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp
index 6c47c5c5f7bbf..e70749cdfab24 100644
--- a/llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/EPCGenericDylibManager.cpp
@@ -73,7 +73,7 @@ EPCGenericDylibManager::CreateWithDefaultBootstrapSymbols(
 
 Expected<tpctypes::DylibHandle> EPCGenericDylibManager::open(StringRef Path,
                                                              uint64_t Mode) {
-  Expected<tpctypes::DylibHandle> H(0);
+  Expected<tpctypes::DylibHandle> H((ExecutorAddr()));
   if (auto Err =
           EPC.callSPSWrapper<rt::SPSSimpleExecutorDylibManagerOpenSignature>(
               SAs.Open, H, SAs.Instance, Path, Mode))

diff  --git a/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
index 8f3bd92cb3b4f..b48d60b77809d 100644
--- a/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
@@ -80,7 +80,7 @@ SelfExecutorProcessControl::loadDylib(const char *DylibPath) {
   if (!Dylib->isValid())
     return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
   DynamicLibraries.push_back(std::move(Dylib));
-  return pointerToJITTargetAddress(DynamicLibraries.back().get());
+  return ExecutorAddr::fromPtr(DynamicLibraries.back().get());
 }
 
 Expected<std::vector<tpctypes::LookupResult>>
@@ -88,14 +88,14 @@ SelfExecutorProcessControl::lookupSymbols(ArrayRef<LookupRequest> Request) {
   std::vector<tpctypes::LookupResult> R;
 
   for (auto &Elem : Request) {
-    auto *Dylib = jitTargetAddressToPointer<sys::DynamicLibrary *>(Elem.Handle);
+    auto *Dylib = Elem.Handle.toPtr<sys::DynamicLibrary *>();
     assert(llvm::any_of(DynamicLibraries,
                         [=](const std::unique_ptr<sys::DynamicLibrary> &DL) {
                           return DL.get() == Dylib;
                         }) &&
            "Invalid handle");
 
-    R.push_back(std::vector<JITTargetAddress>());
+    R.push_back(std::vector<ExecutorAddr>());
     for (auto &KV : Elem.Symbols) {
       auto &Sym = KV.first;
       std::string Tmp((*Sym).data() + !!GlobalManglingPrefix,
@@ -107,7 +107,7 @@ SelfExecutorProcessControl::lookupSymbols(ArrayRef<LookupRequest> Request) {
         MissingSymbols.push_back(Sym);
         return make_error<SymbolsNotFound>(SSP, std::move(MissingSymbols));
       }
-      R.back().push_back(pointerToJITTargetAddress(Addr));
+      R.back().push_back(ExecutorAddr::fromPtr(Addr));
     }
   }
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp b/llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp
index 3452267e4df4c..59c63d38458ba 100644
--- a/llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LookupAndRecordAddrs.cpp
@@ -73,7 +73,7 @@ Error lookupAndRecordAddrs(
                                    inconvertibleErrorCode());
 
   for (unsigned I = 0; I != Pairs.size(); ++I)
-    Pairs[I].second->setValue(Result->front()[I]);
+    *Pairs[I].second = Result->front()[I];
 
   return Error::success();
 }

diff  --git a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
index c69df4f45588f..1bd10c9c6c0ea 100644
--- a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
@@ -38,7 +38,7 @@ SimpleRemoteEPC::lookupSymbols(ArrayRef<LookupRequest> Request) {
       Result.push_back({});
       Result.back().reserve(R->size());
       for (auto Addr : *R)
-        Result.back().push_back(Addr.getValue());
+        Result.back().push_back(Addr);
     } else
       return R.takeError();
   }

diff  --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.cpp
index 3c9dd21b08320..cb11b68e27195 100644
--- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorDylibManager.cpp
@@ -35,24 +35,18 @@ SimpleExecutorDylibManager::open(const std::string &Path, uint64_t Mode) {
     return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
 
   std::lock_guard<std::mutex> Lock(M);
-  Dylibs[NextId] = std::move(DL);
-  return NextId++;
+  auto H = ExecutorAddr::fromPtr(DL.getOSSpecificHandle());
+  Dylibs.insert(DL.getOSSpecificHandle());
+  return H;
 }
 
 Expected<std::vector<ExecutorAddr>>
 SimpleExecutorDylibManager::lookup(tpctypes::DylibHandle H,
                                    const RemoteSymbolLookupSet &L) {
   std::vector<ExecutorAddr> Result;
-
-  std::lock_guard<std::mutex> Lock(M);
-  auto I = Dylibs.find(H);
-  if (I == Dylibs.end())
-    return make_error<StringError>("No dylib for handle " + formatv("{0:x}", H),
-                                   inconvertibleErrorCode());
-  auto &DL = I->second;
+  auto DL = sys::DynamicLibrary(H.toPtr<void *>());
 
   for (const auto &E : L) {
-
     if (E.Name.empty()) {
       if (E.Required)
         return make_error<StringError>("Required address for empty symbol \"\"",
@@ -85,10 +79,10 @@ SimpleExecutorDylibManager::lookup(tpctypes::DylibHandle H,
 
 Error SimpleExecutorDylibManager::shutdown() {
 
-  DylibsMap DM;
+  DylibSet DS;
   {
     std::lock_guard<std::mutex> Lock(M);
-    std::swap(DM, Dylibs);
+    std::swap(DS, Dylibs);
   }
 
   // There is no removal of dylibs at the moment, so nothing to do here.


        


More information about the llvm-commits mailing list