Simplify setting the Live bit in SectionPiece. NFC.

llvm-svn: 283340
This commit is contained in:
Rafael Espindola 2016-10-05 17:02:09 +00:00
parent d836a9d5f1
commit 939e9493bf
2 changed files with 7 additions and 13 deletions

View File

@ -533,12 +533,13 @@ std::vector<SectionPiece>
MergeInputSection<ELFT>::splitStrings(ArrayRef<uint8_t> Data, size_t EntSize) {
std::vector<SectionPiece> V;
size_t Off = 0;
bool IsAlloca = this->getSectionHdr()->sh_flags & SHF_ALLOC;
while (!Data.empty()) {
size_t End = findNull(Data, EntSize);
if (End == StringRef::npos)
fatal(getName(this) + ": string is not null terminated");
size_t Size = End + EntSize;
V.emplace_back(Off, Data.slice(0, Size));
V.emplace_back(Off, Data.slice(0, Size), !IsAlloca);
Data = Data.slice(Size);
Off += Size;
}
@ -573,16 +574,9 @@ template <class ELFT> void MergeInputSection<ELFT>::splitIntoPieces() {
else
this->Pieces = splitNonStrings(Data, EntSize);
if (Config->GcSections) {
if (this->getSectionHdr()->sh_flags & SHF_ALLOC) {
for (uintX_t Off : LiveOffsets)
this->getSectionPiece(Off)->Live = true;
return;
}
for (SectionPiece &Piece : this->Pieces)
Piece.Live = true;
}
if (Config->GcSections && this->getSectionHdr()->sh_flags & SHF_ALLOC)
for (uintX_t Off : LiveOffsets)
this->getSectionPiece(Off)->Live = true;
}
template <class ELFT>

View File

@ -122,9 +122,9 @@ template <class ELFT> InputSectionBase<ELFT> InputSectionBase<ELFT>::Discarded;
// SectionPiece represents a piece of splittable section contents.
struct SectionPiece {
SectionPiece(size_t Off, ArrayRef<uint8_t> Data)
SectionPiece(size_t Off, ArrayRef<uint8_t> Data, bool Live = false)
: InputOff(Off), Data((const uint8_t *)Data.data()), Size(Data.size()),
Live(!Config->GcSections) {}
Live(Live || !Config->GcSections) {}
ArrayRef<uint8_t> data() { return {Data, Size}; }
size_t size() const { return Size; }