forked from OSchip/llvm-project
Simplify SplitInputSection::getRangeAndSize.
This patch adds Size member to SectionPiece so that getRangeAndSize can just return a SectionPiece instead of a std::pair<SectionPiece *, uint_t>. Also renamed the function. llvm-svn: 270346
This commit is contained in:
parent
dca03f8596
commit
90fa3722d2
|
@ -414,7 +414,7 @@ typename ELFT::uint EHInputSection<ELFT>::getOffset(uintX_t Offset) {
|
||||||
// identify the start of the output .eh_frame. Handle this special case.
|
// identify the start of the output .eh_frame. Handle this special case.
|
||||||
if (this->getSectionHdr()->sh_size == 0)
|
if (this->getSectionHdr()->sh_size == 0)
|
||||||
return Offset;
|
return Offset;
|
||||||
SectionPiece *Piece = this->getRangeAndSize(Offset).first;
|
SectionPiece *Piece = this->getSectionPiece(Offset);
|
||||||
if (Piece->OutputOff == size_t(-1))
|
if (Piece->OutputOff == size_t(-1))
|
||||||
return -1; // Not in the output
|
return -1; // Not in the output
|
||||||
|
|
||||||
|
@ -449,8 +449,8 @@ MergeInputSection<ELFT>::MergeInputSection(elf::ObjectFile<ELFT> *F,
|
||||||
size_t End = findNull(Data, EntSize);
|
size_t End = findNull(Data, EntSize);
|
||||||
if (End == StringRef::npos)
|
if (End == StringRef::npos)
|
||||||
fatal("string is not null terminated");
|
fatal("string is not null terminated");
|
||||||
this->Pieces.emplace_back(Offset);
|
|
||||||
uintX_t Size = End + EntSize;
|
uintX_t Size = End + EntSize;
|
||||||
|
this->Pieces.emplace_back(Offset, Size);
|
||||||
Data = Data.substr(Size);
|
Data = Data.substr(Size);
|
||||||
Offset += Size;
|
Offset += Size;
|
||||||
}
|
}
|
||||||
|
@ -461,7 +461,7 @@ MergeInputSection<ELFT>::MergeInputSection(elf::ObjectFile<ELFT> *F,
|
||||||
size_t Size = Data.size();
|
size_t Size = Data.size();
|
||||||
assert((Size % EntSize) == 0);
|
assert((Size % EntSize) == 0);
|
||||||
for (unsigned I = 0, N = Size; I != N; I += EntSize)
|
for (unsigned I = 0, N = Size; I != N; I += EntSize)
|
||||||
this->Pieces.emplace_back(I);
|
this->Pieces.emplace_back(I, EntSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
@ -470,8 +470,7 @@ bool MergeInputSection<ELFT>::classof(const InputSectionBase<ELFT> *S) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
std::pair<SectionPiece *, typename ELFT::uint>
|
SectionPiece *SplitInputSection<ELFT>::getSectionPiece(uintX_t Offset) {
|
||||||
SplitInputSection<ELFT>::getRangeAndSize(uintX_t Offset) {
|
|
||||||
ArrayRef<uint8_t> D = this->getSectionData();
|
ArrayRef<uint8_t> D = this->getSectionData();
|
||||||
StringRef Data((const char *)D.data(), D.size());
|
StringRef Data((const char *)D.data(), D.size());
|
||||||
uintX_t Size = Data.size();
|
uintX_t Size = Data.size();
|
||||||
|
@ -482,16 +481,13 @@ SplitInputSection<ELFT>::getRangeAndSize(uintX_t Offset) {
|
||||||
auto I = std::upper_bound(
|
auto I = std::upper_bound(
|
||||||
Pieces.begin(), Pieces.end(), Offset,
|
Pieces.begin(), Pieces.end(), Offset,
|
||||||
[](const uintX_t &A, const SectionPiece &B) { return A < B.InputOff; });
|
[](const uintX_t &A, const SectionPiece &B) { return A < B.InputOff; });
|
||||||
uintX_t End = (I == Pieces.end()) ? Data.size() : I->InputOff;
|
|
||||||
--I;
|
--I;
|
||||||
return {&*I, End};
|
return &*I;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
typename ELFT::uint MergeInputSection<ELFT>::getOffset(uintX_t Offset) {
|
typename ELFT::uint MergeInputSection<ELFT>::getOffset(uintX_t Offset) {
|
||||||
std::pair<SectionPiece *, uintX_t> T = this->getRangeAndSize(Offset);
|
SectionPiece &Piece = *this->getSectionPiece(Offset);
|
||||||
SectionPiece &Piece = *T.first;
|
|
||||||
uintX_t End = T.second;
|
|
||||||
assert(Piece.Live);
|
assert(Piece.Live);
|
||||||
|
|
||||||
// Compute the Addend and if the Base is cached, return.
|
// Compute the Addend and if the Base is cached, return.
|
||||||
|
@ -502,7 +498,7 @@ typename ELFT::uint MergeInputSection<ELFT>::getOffset(uintX_t Offset) {
|
||||||
// Map the base to the offset in the output section and cache it.
|
// Map the base to the offset in the output section and cache it.
|
||||||
ArrayRef<uint8_t> D = this->getSectionData();
|
ArrayRef<uint8_t> D = this->getSectionData();
|
||||||
StringRef Data((const char *)D.data(), D.size());
|
StringRef Data((const char *)D.data(), D.size());
|
||||||
StringRef Entry = Data.substr(Piece.InputOff, End - Piece.InputOff);
|
StringRef Entry = Data.substr(Piece.InputOff, Piece.Size);
|
||||||
auto *MOS = static_cast<MergeOutputSection<ELFT> *>(this->OutSec);
|
auto *MOS = static_cast<MergeOutputSection<ELFT> *>(this->OutSec);
|
||||||
Piece.OutputOff = MOS->getOffset(Entry);
|
Piece.OutputOff = MOS->getOffset(Entry);
|
||||||
return Piece.OutputOff + Addend;
|
return Piece.OutputOff + Addend;
|
||||||
|
|
|
@ -132,8 +132,10 @@ template <class ELFT> InputSectionBase<ELFT> InputSectionBase<ELFT>::Discarded;
|
||||||
|
|
||||||
// SectionPiece represents a piece of splittable section contents.
|
// SectionPiece represents a piece of splittable section contents.
|
||||||
struct SectionPiece {
|
struct SectionPiece {
|
||||||
SectionPiece(size_t I) : InputOff(I), Live(!Config->GcSections) {}
|
SectionPiece(size_t Off, size_t Size)
|
||||||
|
: InputOff(Off), Size(Size), Live(!Config->GcSections) {}
|
||||||
size_t InputOff;
|
size_t InputOff;
|
||||||
|
size_t Size;
|
||||||
size_t OutputOff = -1;
|
size_t OutputOff = -1;
|
||||||
bool Live;
|
bool Live;
|
||||||
};
|
};
|
||||||
|
@ -154,7 +156,7 @@ public:
|
||||||
// rather than a single large blob of data.
|
// rather than a single large blob of data.
|
||||||
std::vector<SectionPiece> Pieces;
|
std::vector<SectionPiece> Pieces;
|
||||||
|
|
||||||
std::pair<SectionPiece *, uintX_t> getRangeAndSize(uintX_t Offset);
|
SectionPiece *getSectionPiece(uintX_t Offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
// This corresponds to a SHF_MERGE section of an input file.
|
// This corresponds to a SHF_MERGE section of an input file.
|
||||||
|
|
|
@ -136,15 +136,14 @@ template <class ELFT> static bool isReserved(InputSectionBase<ELFT> *Sec) {
|
||||||
// Starting from GC-root sections, this function visits all reachable
|
// Starting from GC-root sections, this function visits all reachable
|
||||||
// sections to set their "Live" bits.
|
// sections to set their "Live" bits.
|
||||||
template <class ELFT> void elf::markLive() {
|
template <class ELFT> void elf::markLive() {
|
||||||
typedef typename ELFT::uint uintX_t;
|
|
||||||
SmallVector<InputSection<ELFT> *, 256> Q;
|
SmallVector<InputSection<ELFT> *, 256> Q;
|
||||||
|
|
||||||
auto Enqueue = [&](ResolvedReloc<ELFT> R) {
|
auto Enqueue = [&](ResolvedReloc<ELFT> R) {
|
||||||
if (!R.Sec)
|
if (!R.Sec)
|
||||||
return;
|
return;
|
||||||
if (auto *MS = dyn_cast<MergeInputSection<ELFT>>(R.Sec)) {
|
if (auto *MS = dyn_cast<MergeInputSection<ELFT>>(R.Sec)) {
|
||||||
std::pair<SectionPiece *, uintX_t> T = MS->getRangeAndSize(R.Offset);
|
SectionPiece *Piece = MS->getSectionPiece(R.Offset);
|
||||||
T.first->Live = true;
|
Piece->Live = true;
|
||||||
}
|
}
|
||||||
if (R.Sec->Live)
|
if (R.Sec->Live)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1142,9 +1142,6 @@ void EHOutputSection<ELFT>::addSectionAux(EHInputSection<ELFT> *Sec,
|
||||||
|
|
||||||
DenseMap<uintX_t, uintX_t> OffsetToIndex;
|
DenseMap<uintX_t, uintX_t> OffsetToIndex;
|
||||||
while (!D.empty()) {
|
while (!D.empty()) {
|
||||||
unsigned Index = Sec->Pieces.size();
|
|
||||||
Sec->Pieces.emplace_back(Offset);
|
|
||||||
|
|
||||||
uintX_t Length = readEntryLength<ELFT>(D);
|
uintX_t Length = readEntryLength<ELFT>(D);
|
||||||
// If CIE/FDE data length is zero then Length is 4, this
|
// If CIE/FDE data length is zero then Length is 4, this
|
||||||
// shall be considered a terminator and processing shall end.
|
// shall be considered a terminator and processing shall end.
|
||||||
|
@ -1152,6 +1149,9 @@ void EHOutputSection<ELFT>::addSectionAux(EHInputSection<ELFT> *Sec,
|
||||||
break;
|
break;
|
||||||
StringRef Entry((const char *)D.data(), Length);
|
StringRef Entry((const char *)D.data(), Length);
|
||||||
|
|
||||||
|
unsigned Index = Sec->Pieces.size();
|
||||||
|
Sec->Pieces.emplace_back(Offset, Length);
|
||||||
|
|
||||||
uint32_t ID = read32<E>(D.data() + 4);
|
uint32_t ID = read32<E>(D.data() + 4);
|
||||||
if (ID == 0) {
|
if (ID == 0) {
|
||||||
// CIE
|
// CIE
|
||||||
|
|
|
@ -855,7 +855,7 @@ template <class ELFT> static bool includeInSymtab(const SymbolBody &B) {
|
||||||
if (!D->Section->Live)
|
if (!D->Section->Live)
|
||||||
return false;
|
return false;
|
||||||
if (auto *S = dyn_cast<MergeInputSection<ELFT>>(D->Section))
|
if (auto *S = dyn_cast<MergeInputSection<ELFT>>(D->Section))
|
||||||
if (!S->getRangeAndSize(D->Value).first->Live)
|
if (!S->getSectionPiece(D->Value)->Live)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue