From 8f9026baff6889079f79910187d3d77ded2d1ca1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 8 Nov 2016 18:23:02 +0000 Subject: [PATCH] Don't add null and discarded sections to the global list. Avoids having to skip them multiple times. llvm-svn: 286261 --- lld/ELF/Driver.cpp | 5 +++-- lld/ELF/ICF.cpp | 2 +- lld/ELF/LinkerScript.cpp | 8 ++------ lld/ELF/MarkLive.cpp | 2 -- lld/ELF/Writer.cpp | 11 +++-------- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 5b2eb69..a32a2d4 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -761,7 +761,8 @@ template void LinkerDriver::link(opt::InputArgList &Args) { // Aggregate all input sections into one place. for (elf::ObjectFile *F : Symtab.getObjectFiles()) for (InputSectionBase *S : F->getSections()) - Symtab.Sections.push_back(S); + if (S && S != &InputSection::Discarded) + Symtab.Sections.push_back(S); for (BinaryFile *F : Symtab.getBinaryFiles()) for (InputSectionData *S : F->getSections()) Symtab.Sections.push_back(cast>(S)); @@ -775,7 +776,7 @@ template void LinkerDriver::link(opt::InputArgList &Args) { // MergeInputSection::splitIntoPieces needs to be called before // any call of MergeInputSection::getOffset. Do that. for (InputSectionBase *S : Symtab.Sections) { - if (!S || S == &InputSection::Discarded || !S->Live) + if (!S->Live) continue; if (S->Compressed) S->uncompress(); diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 418cf53..8b0beb5 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -128,7 +128,7 @@ template uint64_t ICF::getHash(InputSection *S) { // Returns true if Sec is subject of ICF. template bool ICF::isEligible(InputSectionBase *Sec) { - if (!Sec || Sec == &InputSection::Discarded || !Sec->Live) + if (!Sec->Live) return false; auto *S = dyn_cast>(Sec); if (!S) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 53d2cc5..ddd2f9f 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -117,10 +117,6 @@ bool BytesDataCommand::classof(const BaseCommand *C) { return C->Kind == BytesDataKind; } -template static bool isDiscarded(InputSectionBase *S) { - return !S || !S->Live; -} - template LinkerScript::LinkerScript() = default; template LinkerScript::~LinkerScript() = default; @@ -195,7 +191,7 @@ void LinkerScript::computeInputSections(InputSectionDescription *I) { size_t SizeBefore = I->Sections.size(); for (InputSectionBase *S : Symtab::X->Sections) { - if (isDiscarded(S) || S->OutSec) + if (!S->Live || S->OutSec) continue; StringRef Filename; @@ -368,7 +364,7 @@ void LinkerScript::createSections(OutputSectionFactory &Factory) { // Add orphan sections. for (InputSectionBase *S : Symtab::X->Sections) - if (!isDiscarded(S) && !S->OutSec) + if (S->Live && !S->OutSec) addSection(Factory, S, getOutputSectionName(S->Name)); } diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 97300a7..60995a7 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -239,8 +239,6 @@ template void elf::markLive() { // Preserve special sections and those which are specified in linker // script KEEP command. for (InputSectionBase *Sec : Symtab::X->Sections) { - if (!Sec || Sec == &InputSection::Discarded) - continue; // .eh_frame is always marked as live now, but also it can reference to // sections that contain personality. We preserve all non-text sections // referred by .eh_frame here. diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index b77f0ea..7c4535f 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -118,8 +118,7 @@ StringRef elf::getOutputSectionName(StringRef Name) { } template void elf::reportDiscarded(InputSectionBase *IS) { - if (!Config->PrintGcSections || !IS || IS == &InputSection::Discarded || - IS->Live) + if (!Config->PrintGcSections) return; errs() << "removing unused section from '" << IS->Name << "' in file '" << IS->getFile()->getName() << "'\n"; @@ -512,10 +511,6 @@ static bool compareSections(const OutputSectionBase *A, return compareSectionsNonScript(A, B); } -template static bool isDiscarded(InputSectionBase *S) { - return !S || S == &InputSection::Discarded || !S->Live; -} - // Program header entry template PhdrEntry::PhdrEntry(unsigned Type, unsigned Flags) { @@ -653,7 +648,7 @@ void Writer::forEachRelSec( std::function &, const typename ELFT::Shdr &)> Fn) { for (InputSectionBase *IS : Symtab::X->Sections) { - if (isDiscarded(IS)) + if (!IS->Live) continue; // Scan all relocations. Each relocation goes through a series // of tests to determine if it needs special treatment, such as @@ -675,7 +670,7 @@ void Writer::forEachRelSec( template void Writer::addInputSec(InputSectionBase *IS) { - if (isDiscarded(IS)) { + if (!IS->Live) { reportDiscarded(IS); return; } -- 2.7.4