[lld] r247032 - Every output section should be added to the OutputSecitons vector.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 10:39:40 PDT 2015
Author: rafael
Date: Tue Sep 8 12:39:39 2015
New Revision: 247032
URL: http://llvm.org/viewvc/llvm-project?rev=247032&view=rev
Log:
Every output section should be added to the OutputSecitons vector.
Simplify.
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247032&r1=247031&r2=247032&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Sep 8 12:39:39 2015
@@ -174,6 +174,7 @@ private:
std::unique_ptr<llvm::FileOutputBuffer> Buffer;
llvm::SpecificBumpPtrAllocator<OutputSection<ELFT>> CAlloc;
std::vector<OutputSectionBase<ELFT::Is64Bits> *> OutputSections;
+ unsigned getNumSections() const { return OutputSections.size() + 1; }
uintX_t FileSize;
uintX_t SizeOfHeaders;
@@ -184,8 +185,6 @@ private:
SymbolTableSection<ELFT> SymTable;
- unsigned NumSections;
-
void addOutputSection(OutputSectionBase<ELFT::Is64Bits> *Sec) {
OutputSections.push_back(Sec);
Sec->setSectionIndex(OutputSections.size());
@@ -525,17 +524,11 @@ template <class ELFT> void Writer<ELFT>:
FileOff += RoundUpToAlignment(Size, Align);
}
- // Regular sections.
- NumSections = OutputSections.size();
-
- // First dummy section.
- NumSections++;
-
FileOff += OffsetToAlignment(FileOff, ELFT::Is64Bits ? 8 : 4);
// Add space for section headers.
SectionHeaderOff = FileOff;
- FileOff += NumSections * sizeof(Elf_Shdr_Impl<ELFT>);
+ FileOff += getNumSections() * sizeof(Elf_Shdr_Impl<ELFT>);
FileSize = SizeOfHeaders + RoundUpToAlignment(FileOff - SizeOfHeaders, 8);
}
@@ -565,7 +558,7 @@ template <class ELFT> void Writer<ELFT>:
EHdr->e_phentsize = sizeof(Elf_Phdr_Impl<ELFT>);
EHdr->e_phnum = 1;
EHdr->e_shentsize = sizeof(Elf_Shdr_Impl<ELFT>);
- EHdr->e_shnum = NumSections;
+ EHdr->e_shnum = getNumSections();
EHdr->e_shstrndx = StringTableIndex;
auto PHdrs = reinterpret_cast<Elf_Phdr_Impl<ELFT> *>(Buf + EHdr->e_phoff);
More information about the llvm-commits
mailing list