[lld] r270386 - Split MergeInputSection's ctor. NFC.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sun May 22 17:40:28 PDT 2016
Author: ruiu
Date: Sun May 22 19:40:24 2016
New Revision: 270386
URL: http://llvm.org/viewvc/llvm-project?rev=270386&view=rev
Log:
Split MergeInputSection's ctor. NFC.
Modified:
lld/trunk/ELF/InputSection.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=270386&r1=270385&r2=270386&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sun May 22 19:40:24 2016
@@ -468,32 +468,45 @@ static size_t findNull(ArrayRef<uint8_t>
return StringRef::npos;
}
-template <class ELFT>
-MergeInputSection<ELFT>::MergeInputSection(elf::ObjectFile<ELFT> *F,
- const Elf_Shdr *Header)
- : SplitInputSection<ELFT>(F, Header, InputSectionBase<ELFT>::Merge) {
- uintX_t EntSize = Header->sh_entsize;
- ArrayRef<uint8_t> Data = this->getSectionData();
-
- if (Header->sh_flags & SHF_STRINGS) {
- uintX_t Offset = 0;
- while (!Data.empty()) {
- size_t End = findNull(Data, EntSize);
- if (End == StringRef::npos)
- fatal("string is not null terminated");
- uintX_t Size = End + EntSize;
- this->Pieces.emplace_back(Offset, Data.slice(0, Size));
- Data = Data.slice(Size);
- Offset += Size;
- }
- return;
+// Split SHF_STRINGS section. Such section is a sequence of
+// null-terminated strings.
+std::vector<SectionPiece> splitStrings(ArrayRef<uint8_t> Data, size_t EntSize) {
+ std::vector<SectionPiece> V;
+ size_t Off = 0;
+ while (!Data.empty()) {
+ size_t End = findNull(Data, EntSize);
+ if (End == StringRef::npos)
+ fatal("string is not null terminated");
+ size_t Size = End + EntSize;
+ V.emplace_back(Off, Data.slice(0, Size));
+ Data = Data.slice(Size);
+ Off += Size;
}
+ return V;
+}
- // If this is not of type string, every entry has the same size.
+// Split non-SHF_STRINGS section. Such section is a sequence of
+// fixed size records.
+std::vector<SectionPiece>
+splitNonStrings(ArrayRef<uint8_t> Data, size_t EntSize) {
+ std::vector<SectionPiece> V;
size_t Size = Data.size();
assert((Size % EntSize) == 0);
for (unsigned I = 0, N = Size; I != N; I += EntSize)
- this->Pieces.emplace_back(I, Data.slice(I, EntSize));
+ V.emplace_back(I, Data.slice(I, EntSize));
+ return V;
+}
+
+template <class ELFT>
+MergeInputSection<ELFT>::MergeInputSection(elf::ObjectFile<ELFT> *F,
+ const Elf_Shdr *Header)
+ : SplitInputSection<ELFT>(F, Header, InputSectionBase<ELFT>::Merge) {
+ ArrayRef<uint8_t> Data = this->getSectionData();
+ uintX_t EntSize = this->Header->sh_entsize;
+ if (this->Header->sh_flags & SHF_STRINGS)
+ this->Pieces = splitStrings(Data, EntSize);
+ else
+ this->Pieces = splitNonStrings(Data, EntSize);
}
template <class ELFT>
More information about the llvm-commits
mailing list