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.
|
||||
if (this->getSectionHdr()->sh_size == 0)
|
||||
return Offset;
|
||||
SectionPiece *Piece = this->getRangeAndSize(Offset).first;
|
||||
SectionPiece *Piece = this->getSectionPiece(Offset);
|
||||
if (Piece->OutputOff == size_t(-1))
|
||||
return -1; // Not in the output
|
||||
|
||||
|
@ -449,8 +449,8 @@ MergeInputSection<ELFT>::MergeInputSection(elf::ObjectFile<ELFT> *F,
|
|||
size_t End = findNull(Data, EntSize);
|
||||
if (End == StringRef::npos)
|
||||
fatal("string is not null terminated");
|
||||
this->Pieces.emplace_back(Offset);
|
||||
uintX_t Size = End + EntSize;
|
||||
this->Pieces.emplace_back(Offset, Size);
|
||||
Data = Data.substr(Size);
|
||||
Offset += Size;
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ MergeInputSection<ELFT>::MergeInputSection(elf::ObjectFile<ELFT> *F,
|
|||
size_t Size = Data.size();
|
||||
assert((Size % EntSize) == 0);
|
||||
for (unsigned I = 0, N = Size; I != N; I += EntSize)
|
||||
this->Pieces.emplace_back(I);
|
||||
this->Pieces.emplace_back(I, EntSize);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
|
@ -470,8 +470,7 @@ bool MergeInputSection<ELFT>::classof(const InputSectionBase<ELFT> *S) {
|
|||
}
|
||||
|
||||
template <class ELFT>
|
||||
std::pair<SectionPiece *, typename ELFT::uint>
|
||||
SplitInputSection<ELFT>::getRangeAndSize(uintX_t Offset) {
|
||||
SectionPiece *SplitInputSection<ELFT>::getSectionPiece(uintX_t Offset) {
|
||||
ArrayRef<uint8_t> D = this->getSectionData();
|
||||
StringRef Data((const char *)D.data(), D.size());
|
||||
uintX_t Size = Data.size();
|
||||
|
@ -482,16 +481,13 @@ SplitInputSection<ELFT>::getRangeAndSize(uintX_t Offset) {
|
|||
auto I = std::upper_bound(
|
||||
Pieces.begin(), Pieces.end(), Offset,
|
||||
[](const uintX_t &A, const SectionPiece &B) { return A < B.InputOff; });
|
||||
uintX_t End = (I == Pieces.end()) ? Data.size() : I->InputOff;
|
||||
--I;
|
||||
return {&*I, End};
|
||||
return &*I;
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
typename ELFT::uint MergeInputSection<ELFT>::getOffset(uintX_t Offset) {
|
||||
std::pair<SectionPiece *, uintX_t> T = this->getRangeAndSize(Offset);
|
||||
SectionPiece &Piece = *T.first;
|
||||
uintX_t End = T.second;
|
||||
SectionPiece &Piece = *this->getSectionPiece(Offset);
|
||||
assert(Piece.Live);
|
||||
|
||||
// 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.
|
||||
ArrayRef<uint8_t> D = this->getSectionData();
|
||||
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);
|
||||
Piece.OutputOff = MOS->getOffset(Entry);
|
||||
return Piece.OutputOff + Addend;
|
||||
|
|
|
@ -132,8 +132,10 @@ template <class ELFT> InputSectionBase<ELFT> InputSectionBase<ELFT>::Discarded;
|
|||
|
||||
// SectionPiece represents a piece of splittable section contents.
|
||||
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 Size;
|
||||
size_t OutputOff = -1;
|
||||
bool Live;
|
||||
};
|
||||
|
@ -154,7 +156,7 @@ public:
|
|||
// rather than a single large blob of data.
|
||||
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.
|
||||
|
|
|
@ -136,15 +136,14 @@ template <class ELFT> static bool isReserved(InputSectionBase<ELFT> *Sec) {
|
|||
// Starting from GC-root sections, this function visits all reachable
|
||||
// sections to set their "Live" bits.
|
||||
template <class ELFT> void elf::markLive() {
|
||||
typedef typename ELFT::uint uintX_t;
|
||||
SmallVector<InputSection<ELFT> *, 256> Q;
|
||||
|
||||
auto Enqueue = [&](ResolvedReloc<ELFT> R) {
|
||||
if (!R.Sec)
|
||||
return;
|
||||
if (auto *MS = dyn_cast<MergeInputSection<ELFT>>(R.Sec)) {
|
||||
std::pair<SectionPiece *, uintX_t> T = MS->getRangeAndSize(R.Offset);
|
||||
T.first->Live = true;
|
||||
SectionPiece *Piece = MS->getSectionPiece(R.Offset);
|
||||
Piece->Live = true;
|
||||
}
|
||||
if (R.Sec->Live)
|
||||
return;
|
||||
|
|
|
@ -1142,9 +1142,6 @@ void EHOutputSection<ELFT>::addSectionAux(EHInputSection<ELFT> *Sec,
|
|||
|
||||
DenseMap<uintX_t, uintX_t> OffsetToIndex;
|
||||
while (!D.empty()) {
|
||||
unsigned Index = Sec->Pieces.size();
|
||||
Sec->Pieces.emplace_back(Offset);
|
||||
|
||||
uintX_t Length = readEntryLength<ELFT>(D);
|
||||
// If CIE/FDE data length is zero then Length is 4, this
|
||||
// shall be considered a terminator and processing shall end.
|
||||
|
@ -1152,6 +1149,9 @@ void EHOutputSection<ELFT>::addSectionAux(EHInputSection<ELFT> *Sec,
|
|||
break;
|
||||
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);
|
||||
if (ID == 0) {
|
||||
// CIE
|
||||
|
|
|
@ -855,7 +855,7 @@ template <class ELFT> static bool includeInSymtab(const SymbolBody &B) {
|
|||
if (!D->Section->Live)
|
||||
return false;
|
||||
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 true;
|
||||
|
|
Loading…
Reference in New Issue