From 94444b9a0778d076a73bd430f69ea84aff7185d5 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Wed, 20 Sep 2017 09:27:41 +0000 Subject: [PATCH] [ELF] - Fix segfault when processing .eh_frame. 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. Differential revision: https://reviews.llvm.org/D38034 llvm-svn: 313741 --- lld/ELF/SyntheticSections.cpp | 5 +++-- lld/ELF/SyntheticSections.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index b13aa47fd6341..9f33ab33846c1 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -417,10 +417,11 @@ CieRecord *EhFrameSection::addCie(EhSectionPiece &Cie, &Sec->template getFile()->getRelocTargetSym(Rels[FirstRelI]); // Search for an existing CIE by CIE contents/relocation target pair. - CieRecord *Rec = &CieMap[{Cie.data(), Personality}]; + CieRecord *&Rec = CieMap[{Cie.data(), Personality}]; // If not found, create a new one. - if (Rec->Cie == nullptr) { + if (!Rec) { + Rec = make(); Rec->Cie = &Cie; CieRecords.push_back(Rec); } diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 31766794d417a..3f19afbdba5d0 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -103,7 +103,8 @@ template class EhFrameSection final : public SyntheticSection { std::vector CieRecords; // CIE records are uniquified by their contents and personality functions. - llvm::DenseMap, SymbolBody *>, CieRecord> CieMap; + llvm::DenseMap, SymbolBody *>, CieRecord *> + CieMap; }; class GotSection : public SyntheticSection {