[lld] r286261 - Don't add null and discarded sections to the global list.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 8 10:23:03 PST 2016


Author: rafael
Date: Tue Nov  8 12:23:02 2016
New Revision: 286261

URL: http://llvm.org/viewvc/llvm-project?rev=286261&view=rev
Log:
Don't add null and discarded sections to the global list.

Avoids having to skip them multiple times.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/ICF.cpp
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/MarkLive.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=286261&r1=286260&r2=286261&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Nov  8 12:23:02 2016
@@ -761,7 +761,8 @@ template <class ELFT> void LinkerDriver:
   // 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 @@ template <class ELFT> void LinkerDriver:
   // 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();

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=286261&r1=286260&r2=286261&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Tue Nov  8 12:23:02 2016
@@ -128,7 +128,7 @@ template <class ELFT> uint64_t ICF<ELFT>
 
 // 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)

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=286261&r1=286260&r2=286261&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Nov  8 12:23:02 2016
@@ -117,10 +117,6 @@ bool BytesDataCommand::classof(const Bas
   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 @@ void LinkerScript<ELFT>::computeInputSec
     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 @@ void LinkerScript<ELFT>::createSections(
 
   // 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));
 }
 

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=286261&r1=286260&r2=286261&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Tue Nov  8 12:23:02 2016
@@ -239,8 +239,6 @@ template <class ELFT> void elf::markLive
   // 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.

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=286261&r1=286260&r2=286261&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Nov  8 12:23:02 2016
@@ -118,8 +118,7 @@ StringRef elf::getOutputSectionName(Stri
 }
 
 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 @@ static bool compareSections(const Output
   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 @@ void Writer<ELFT>::forEachRelSec(
     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 @@ void Writer<ELFT>::forEachRelSec(
 
 template <class ELFT>
 void Writer<ELFT>::addInputSec(InputSectionBase<ELFT> *IS) {
-  if (isDiscarded(IS)) {
+  if (!IS->Live) {
     reportDiscarded(IS);
     return;
   }




More information about the llvm-commits mailing list