[llvm] ee5e7a3 - [Orc] Deallocate debug objects explicitly when destroying the DebugObjectManagerPlugin

Stefan Gränitz via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 11 06:27:40 PST 2021


Author: Stefan Gränitz
Date: 2021-03-11T15:26:16+01:00
New Revision: ee5e7a3a85611b3eaf2fd5a0870f4257d43680b5

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

LOG: [Orc] Deallocate debug objects explicitly when destroying the DebugObjectManagerPlugin

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
index 8ed0a5a7240e..6909928f3cfa 100644
--- a/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
@@ -123,6 +123,7 @@ enum class Requirement {
 class DebugObject {
 public:
   DebugObject(JITLinkContext &Ctx) : Ctx(Ctx) {}
+  virtual ~DebugObject() = default;
 
   void set(Requirement Req) { Reqs.insert(Req); }
   bool has(Requirement Req) const { return Reqs.count(Req) > 0; }
@@ -130,9 +131,14 @@ class DebugObject {
   using FinalizeContinuation = std::function<void(Expected<sys::MemoryBlock>)>;
   void finalizeAsync(FinalizeContinuation OnFinalize);
 
+  Error deallocate() {
+    if (Alloc)
+      return Alloc->deallocate();
+    return Error::success();
+  }
+
   virtual void reportSectionTargetMemoryRange(StringRef Name,
                                               SectionRange TargetMem) {}
-  virtual ~DebugObject() {}
 
 protected:
   using Allocation = JITLinkMemoryManager::Allocation;
@@ -392,7 +398,18 @@ DebugObjectManagerPlugin::DebugObjectManagerPlugin(
     ExecutionSession &ES, std::unique_ptr<DebugObjectRegistrar> Target)
     : ES(ES), Target(std::move(Target)) {}
 
-DebugObjectManagerPlugin::~DebugObjectManagerPlugin() {}
+DebugObjectManagerPlugin::~DebugObjectManagerPlugin() {
+  for (auto &KV : PendingObjs) {
+    std::unique_ptr<DebugObject> &DebugObj = KV.second;
+    if (Error Err = DebugObj->deallocate())
+      ES.reportError(std::move(Err));
+  }
+  for (auto &KV : RegisteredObjs) {
+    for (std::unique_ptr<DebugObject> &DebugObj : KV.second)
+      if (Error Err = DebugObj->deallocate())
+        ES.reportError(std::move(Err));
+  }
+}
 
 void DebugObjectManagerPlugin::notifyMaterializing(
     MaterializationResponsibility &MR, LinkGraph &G, JITLinkContext &Ctx,


        


More information about the llvm-commits mailing list