Don't add null and discarded sections to the global list.
Avoids having to skip them multiple times.
llvm-svn: 286261
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 @@
// Aggregate all input sections into one place.
for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles())
for (InputSectionBase<ELFT> *S : F->getSections())
- Symtab.Sections.push_back(S);
+ if (S && S != &InputSection<ELFT>::Discarded)
+ Symtab.Sections.push_back(S);
for (BinaryFile *F : Symtab.getBinaryFiles())
for (InputSectionData *S : F->getSections())
Symtab.Sections.push_back(cast<InputSection<ELFT>>(S));
@@ -775,7 +776,7 @@
// MergeInputSection::splitIntoPieces needs to be called before
// any call of MergeInputSection::getOffset. Do that.
for (InputSectionBase<ELFT> *S : Symtab.Sections) {
- if (!S || S == &InputSection<ELFT>::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 @@
// Returns true if Sec is subject of ICF.
template <class ELFT> bool ICF<ELFT>::isEligible(InputSectionBase<ELFT> *Sec) {
- if (!Sec || Sec == &InputSection<ELFT>::Discarded || !Sec->Live)
+ if (!Sec->Live)
return false;
auto *S = dyn_cast<InputSection<ELFT>>(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 @@
return C->Kind == BytesDataKind;
}
-template <class ELFT> static bool isDiscarded(InputSectionBase<ELFT> *S) {
- return !S || !S->Live;
-}
-
template <class ELFT> LinkerScript<ELFT>::LinkerScript() = default;
template <class ELFT> LinkerScript<ELFT>::~LinkerScript() = default;
@@ -195,7 +191,7 @@
size_t SizeBefore = I->Sections.size();
for (InputSectionBase<ELFT> *S : Symtab<ELFT>::X->Sections) {
- if (isDiscarded(S) || S->OutSec)
+ if (!S->Live || S->OutSec)
continue;
StringRef Filename;
@@ -368,7 +364,7 @@
// Add orphan sections.
for (InputSectionBase<ELFT> *S : Symtab<ELFT>::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 @@
// Preserve special sections and those which are specified in linker
// script KEEP command.
for (InputSectionBase<ELFT> *Sec : Symtab<ELFT>::X->Sections) {
- if (!Sec || Sec == &InputSection<ELFT>::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 @@
}
template <class ELFT> void elf::reportDiscarded(InputSectionBase<ELFT> *IS) {
- if (!Config->PrintGcSections || !IS || IS == &InputSection<ELFT>::Discarded ||
- IS->Live)
+ if (!Config->PrintGcSections)
return;
errs() << "removing unused section from '" << IS->Name << "' in file '"
<< IS->getFile()->getName() << "'\n";
@@ -512,10 +511,6 @@
return compareSectionsNonScript(A, B);
}
-template <class ELFT> static bool isDiscarded(InputSectionBase<ELFT> *S) {
- return !S || S == &InputSection<ELFT>::Discarded || !S->Live;
-}
-
// Program header entry
template <class ELFT>
PhdrEntry<ELFT>::PhdrEntry(unsigned Type, unsigned Flags) {
@@ -653,7 +648,7 @@
std::function<void(InputSectionBase<ELFT> &, const typename ELFT::Shdr &)>
Fn) {
for (InputSectionBase<ELFT> *IS : Symtab<ELFT>::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 @@
template <class ELFT>
void Writer<ELFT>::addInputSec(InputSectionBase<ELFT> *IS) {
- if (isDiscarded(IS)) {
+ if (!IS->Live) {
reportDiscarded(IS);
return;
}