Rename CieRecord instance variables.

CieRecord is a struct containing a CIE and FDEs, but oftentimes the
struct itself is named `Cie` which caused some confusion. This patch
renames them `CieRecords` or `Rec`.

llvm-svn: 313681
This commit is contained in:
Rui Ueyama 2017-09-19 21:31:57 +00:00
parent 85908aa84b
commit 74ea1f0938
2 changed files with 29 additions and 29 deletions

View File

@ -403,38 +403,38 @@ EhFrameSection<ELFT>::EhFrameSection()
// and where their relocations point to.
template <class ELFT>
template <class RelTy>
CieRecord *EhFrameSection<ELFT>::addCie(EhSectionPiece &Piece,
CieRecord *EhFrameSection<ELFT>::addCie(EhSectionPiece &Cie,
ArrayRef<RelTy> Rels) {
auto *Sec = cast<EhInputSection>(Piece.Sec);
auto *Sec = cast<EhInputSection>(Cie.Sec);
const endianness E = ELFT::TargetEndianness;
if (read32<E>(Piece.data().data() + 4) != 0)
if (read32<E>(Cie.data().data() + 4) != 0)
fatal(toString(Sec) + ": CIE expected at beginning of .eh_frame");
SymbolBody *Personality = nullptr;
unsigned FirstRelI = Piece.FirstRelocation;
unsigned FirstRelI = Cie.FirstRelocation;
if (FirstRelI != (unsigned)-1)
Personality =
&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 *Rec = &CieMap[{Cie.data(), Personality}];
// If not found, create a new one.
if (Cie->Piece == nullptr) {
Cie->Piece = &Piece;
Cies.push_back(Cie);
if (Rec->Cie == nullptr) {
Rec->Cie = &Cie;
CieRecords.push_back(Rec);
}
return Cie;
return Rec;
}
// There is one FDE per function. Returns true if a given FDE
// points to a live function.
template <class ELFT>
template <class RelTy>
bool EhFrameSection<ELFT>::isFdeLive(EhSectionPiece &Piece,
bool EhFrameSection<ELFT>::isFdeLive(EhSectionPiece &Fde,
ArrayRef<RelTy> Rels) {
auto *Sec = cast<EhInputSection>(Piece.Sec);
unsigned FirstRelI = Piece.FirstRelocation;
auto *Sec = cast<EhInputSection>(Fde.Sec);
unsigned FirstRelI = Fde.FirstRelocation;
// An FDE should point to some function because FDEs are to describe
// functions. That's however not always the case due to an issue of
@ -476,13 +476,13 @@ void EhFrameSection<ELFT>::addSectionAux(EhInputSection *Sec,
}
uint32_t CieOffset = Offset + 4 - ID;
CieRecord *Cie = OffsetToCie[CieOffset];
if (!Cie)
CieRecord *Rec = OffsetToCie[CieOffset];
if (!Rec)
fatal(toString(Sec) + ": invalid CIE reference");
if (!isFdeLive(Piece, Rels))
continue;
Cie->FdePieces.push_back(&Piece);
Rec->Fdes.push_back(&Piece);
NumFdes++;
}
}
@ -530,11 +530,11 @@ template <class ELFT> void EhFrameSection<ELFT>::finalizeContents() {
return; // Already finalized.
size_t Off = 0;
for (CieRecord *Cie : Cies) {
Cie->Piece->OutputOff = Off;
Off += alignTo(Cie->Piece->Size, Config->Wordsize);
for (CieRecord *Rec : CieRecords) {
Rec->Cie->OutputOff = Off;
Off += alignTo(Rec->Cie->Size, Config->Wordsize);
for (EhSectionPiece *Fde : Cie->FdePieces) {
for (EhSectionPiece *Fde : Rec->Fdes) {
Fde->OutputOff = Off;
Off += alignTo(Fde->Size, Config->Wordsize);
}
@ -584,11 +584,11 @@ uint64_t EhFrameSection<ELFT>::getFdePc(uint8_t *Buf, size_t FdeOff,
template <class ELFT> void EhFrameSection<ELFT>::writeTo(uint8_t *Buf) {
const endianness E = ELFT::TargetEndianness;
for (CieRecord *Cie : Cies) {
size_t CieOffset = Cie->Piece->OutputOff;
writeCieFde<ELFT>(Buf + CieOffset, Cie->Piece->data());
for (CieRecord *Rec : CieRecords) {
size_t CieOffset = Rec->Cie->OutputOff;
writeCieFde<ELFT>(Buf + CieOffset, Rec->Cie->data());
for (EhSectionPiece *Fde : Cie->FdePieces) {
for (EhSectionPiece *Fde : Rec->Fdes) {
size_t Off = Fde->OutputOff;
writeCieFde<ELFT>(Buf + Off, Fde->data());
@ -605,9 +605,9 @@ template <class ELFT> void EhFrameSection<ELFT>::writeTo(uint8_t *Buf) {
// to get a FDE from an address to which FDE is applied. So here
// we obtain two addresses and pass them to EhFrameHdr object.
if (In<ELFT>::EhFrameHdr) {
for (CieRecord *Cie : Cies) {
uint8_t Enc = getFdeEncoding<ELFT>(Cie->Piece);
for (EhSectionPiece *Fde : Cie->FdePieces) {
for (CieRecord *Rec : CieRecords) {
uint8_t Enc = getFdeEncoding<ELFT>(Rec->Cie);
for (EhSectionPiece *Fde : Rec->Fdes) {
uint64_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
uint64_t FdeVA = getParent()->Addr + Fde->OutputOff;
In<ELFT>::EhFrameHdr->addFde(Pc, FdeVA);

View File

@ -59,8 +59,8 @@ public:
};
struct CieRecord {
EhSectionPiece *Piece = nullptr;
std::vector<EhSectionPiece *> FdePieces;
EhSectionPiece *Cie = nullptr;
std::vector<EhSectionPiece *> Fdes;
};
// Section for .eh_frame.
@ -100,7 +100,7 @@ private:
uint64_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc);
std::vector<CieRecord *> Cies;
std::vector<CieRecord *> CieRecords;
// CIE records are uniquified by their contents and personality functions.
llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord> CieMap;