[PATCH] D38034: [ELF] - Fix segfault when processing .eh_frame.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 06:03:21 PDT 2017


grimar created this revision.
Herald added a subscriber: emaste.

Its a PR34648 which was a segfault that happened because
we stored pointers to elements in DenseMap. 
When DenseMap grows such pointers are invalidated.
Solution implemented is to keep elements by pointer
and not by value.


https://reviews.llvm.org/D38034

Files:
  ELF/SyntheticSections.cpp
  ELF/SyntheticSections.h


Index: ELF/SyntheticSections.h
===================================================================
--- ELF/SyntheticSections.h
+++ ELF/SyntheticSections.h
@@ -103,7 +103,8 @@
   std::vector<CieRecord *> Cies;
 
   // CIE records are uniquified by their contents and personality functions.
-  llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord> CieMap;
+  llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord *>
+      CieMap;
 };
 
 class GotSection : public SyntheticSection {
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -417,10 +417,11 @@
         &Sec->template getFile<ELFT>()->getRelocTargetSym(Rels[FirstRelI]);
 
   // Search for an existing CIE by CIE contents/relocation target pair.
-  CieRecord *Cie = &CieMap[{Piece.data(), Personality}];
+  CieRecord *&Cie = CieMap[{Piece.data(), Personality}];
 
   // If not found, create a new one.
-  if (Cie->Piece == nullptr) {
+  if (!Cie) {
+    Cie = make<CieRecord>();
     Cie->Piece = &Piece;
     Cies.push_back(Cie);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38034.115829.patch
Type: text/x-patch
Size: 1137 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170919/67ad5645/attachment.bin>


More information about the llvm-commits mailing list