[lld] r270348 - Store section contents to SectionPiece. NFC.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat May 21 18:15:33 PDT 2016
Author: ruiu
Date: Sat May 21 20:15:32 2016
New Revision: 270348
URL: http://llvm.org/viewvc/llvm-project?rev=270348&view=rev
Log:
Store section contents to SectionPiece. NFC.
So that we don't need to cut a slice when we use a SectionPiece.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/OutputSections.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=270348&r1=270347&r2=270348&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sat May 21 20:15:32 2016
@@ -422,8 +422,9 @@ typename ELFT::uint EHInputSection<ELFT>
return Piece->OutputOff + Addend;
}
-static size_t findNull(StringRef S, size_t EntSize) {
+static size_t findNull(ArrayRef<uint8_t> A, size_t EntSize) {
// Optimize the common case.
+ StringRef S((const char *)A.data(), A.size());
if (EntSize == 1)
return S.find(0);
@@ -440,8 +441,7 @@ MergeInputSection<ELFT>::MergeInputSecti
const Elf_Shdr *Header)
: SplitInputSection<ELFT>(F, Header, InputSectionBase<ELFT>::Merge) {
uintX_t EntSize = Header->sh_entsize;
- ArrayRef<uint8_t> D = this->getSectionData();
- StringRef Data((const char *)D.data(), D.size());
+ ArrayRef<uint8_t> Data = this->getSectionData();
if (Header->sh_flags & SHF_STRINGS) {
uintX_t Offset = 0;
@@ -450,8 +450,8 @@ MergeInputSection<ELFT>::MergeInputSecti
if (End == StringRef::npos)
fatal("string is not null terminated");
uintX_t Size = End + EntSize;
- this->Pieces.emplace_back(Offset, Size);
- Data = Data.substr(Size);
+ this->Pieces.emplace_back(Offset, Data.slice(0, Size));
+ Data = Data.slice(Size);
Offset += Size;
}
return;
@@ -461,7 +461,7 @@ MergeInputSection<ELFT>::MergeInputSecti
size_t Size = Data.size();
assert((Size % EntSize) == 0);
for (unsigned I = 0, N = Size; I != N; I += EntSize)
- this->Pieces.emplace_back(I, EntSize);
+ this->Pieces.emplace_back(I, Data.slice(I, EntSize));
}
template <class ELFT>
@@ -498,7 +498,7 @@ typename ELFT::uint MergeInputSection<EL
// 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, Piece.Size);
+ 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;
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=270348&r1=270347&r2=270348&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Sat May 21 20:15:32 2016
@@ -132,11 +132,13 @@ template <class ELFT> InputSectionBase<E
// SectionPiece represents a piece of splittable section contents.
struct SectionPiece {
- SectionPiece(size_t Off, size_t Size)
- : InputOff(Off), Size(Size), Live(!Config->GcSections) {}
+ SectionPiece(size_t Off, ArrayRef<uint8_t> Data)
+ : InputOff(Off), Data(Data), Live(!Config->GcSections) {}
+ size_t size() const { return Data.size(); }
+
size_t InputOff;
- size_t Size;
size_t OutputOff = -1;
+ ArrayRef<uint8_t> Data; // slice of the input section
bool Live;
};
@@ -156,6 +158,7 @@ public:
// rather than a single large blob of data.
std::vector<SectionPiece> Pieces;
+ // Returns the SectionPiece at a given input section offset.
SectionPiece *getSectionPiece(uintX_t Offset);
};
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=270348&r1=270347&r2=270348&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Sat May 21 20:15:32 2016
@@ -977,9 +977,7 @@ EHRegion<ELFT>::EHRegion(EHInputSection<
: Sec(Sec), Index(Index) {}
template <class ELFT> ArrayRef<uint8_t> EHRegion<ELFT>::data() const {
- ArrayRef<uint8_t> SecData = Sec->getSectionData();
- SectionPiece &Piece = Sec->Pieces[Index];
- return SecData.slice(Piece.InputOff, Piece.Size);
+ return Sec->Pieces[Index].Data;
}
template <class ELFT>
@@ -1147,7 +1145,7 @@ void EHOutputSection<ELFT>::addSectionAu
StringRef Entry((const char *)D.data(), Length);
unsigned Index = Sec->Pieces.size();
- Sec->Pieces.emplace_back(Offset, Length);
+ Sec->Pieces.emplace_back(Offset, D.slice(0, Length));
uint32_t ID = read32<E>(D.data() + 4);
if (ID == 0) {
@@ -1271,6 +1269,10 @@ template <class ELFT> void MergeOutputSe
}
}
+static StringRef toStringRef(ArrayRef<uint8_t> A) {
+ return {(const char *)A.data(), A.size()};
+}
+
template <class ELFT>
void MergeOutputSection<ELFT>::addSection(InputSectionBase<ELFT> *C) {
auto *Sec = cast<MergeInputSection<ELFT>>(C);
@@ -1286,8 +1288,7 @@ void MergeOutputSection<ELFT>::addSectio
SectionPiece &Piece = Sec->Pieces[I];
if (!Piece.Live)
continue;
- StringRef Entry = Data.substr(Piece.InputOff, Piece.Size);
- uintX_t OutputOffset = Builder.add(Entry);
+ uintX_t OutputOffset = Builder.add(toStringRef(Piece.Data));
if (!IsString || !shouldTailMerge())
Piece.OutputOff = OutputOffset;
}
More information about the llvm-commits
mailing list