[llvm] c1baf94 - [ORC] Avoid invalidating iterators in EHFrameRegistrationPlugin.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 25 18:04:20 PDT 2021


Author: Lang Hames
Date: 2021-04-25T16:55:19-07:00
New Revision: c1baf946e6cf611ae871e34db5cfea0f94f4b5a0

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

LOG: [ORC] Avoid invalidating iterators in EHFrameRegistrationPlugin.

In EHFrameRegistrationPlugin::notifyTransferringResources if SrcKey had
eh-frames associated but DstKey did not we would create a new entry for DskKey,
invalidating the iterator for SrcKey in the process. This commit fixes that by
removing SrcKey first in this case.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
index dc3cf87798cf..ccac4b8c545b 100644
--- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
@@ -654,13 +654,23 @@ Error EHFrameRegistrationPlugin::notifyRemovingResources(ResourceKey K) {
 void EHFrameRegistrationPlugin::notifyTransferringResources(
     ResourceKey DstKey, ResourceKey SrcKey) {
   auto SI = EHFrameRanges.find(SrcKey);
-  if (SI != EHFrameRanges.end()) {
+  if (SI == EHFrameRanges.end())
+    return;
+
+  auto DI = EHFrameRanges.find(DstKey);
+  if (DI != EHFrameRanges.end()) {
     auto &SrcRanges = SI->second;
-    auto &DstRanges = EHFrameRanges[DstKey];
+    auto &DstRanges = DI->second;
     DstRanges.reserve(DstRanges.size() + SrcRanges.size());
     for (auto &SrcRange : SrcRanges)
       DstRanges.push_back(std::move(SrcRange));
     EHFrameRanges.erase(SI);
+  } else {
+    // We need to move SrcKey's ranges over without invalidating the SI
+    // iterator.
+    auto Tmp = std::move(SI->second);
+    EHFrameRanges.erase(SI);
+    EHFrameRanges[DstKey] = std::move(Tmp);
   }
 }
 


        


More information about the llvm-commits mailing list