Skip to content

Commit

Permalink
[ELF] - Fix segfault when processing .eh_frame.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
George Rimar committed Sep 20, 2017
1 parent 06064d1 commit 94444b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lld/ELF/SyntheticSections.cpp
Expand Up @@ -417,10 +417,11 @@ CieRecord *EhFrameSection<ELFT>::addCie(EhSectionPiece &Cie,
&Sec->template getFile<ELFT>()->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<CieRecord>();
Rec->Cie = &Cie;
CieRecords.push_back(Rec);
}
Expand Down
3 changes: 2 additions & 1 deletion lld/ELF/SyntheticSections.h
Expand Up @@ -103,7 +103,8 @@ template <class ELFT> class EhFrameSection final : public SyntheticSection {
std::vector<CieRecord *> CieRecords;

// 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 {
Expand Down

0 comments on commit 94444b9

Please sign in to comment.