[lld] r316759 - [ELF] - Simplify reporting of garbage collected sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 27 04:32:22 PDT 2017


Author: grimar
Date: Fri Oct 27 04:32:22 2017
New Revision: 316759

URL: http://llvm.org/viewvc/llvm-project?rev=316759&view=rev
Log:
[ELF] - Simplify reporting of garbage collected sections.

This moves reporting of garbage collected sections right after
we do GC. That simplifies things.

Differential revision: https://reviews.llvm.org/D39058

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/MarkLive.cpp
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=316759&r1=316758&r2=316759&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Oct 27 04:32:22 2017
@@ -283,14 +283,9 @@ LinkerScript::computeInputSections(const
     size_t SizeBefore = Ret.size();
 
     for (InputSectionBase *Sec : InputSections) {
-      if (Sec->Assigned)
+      if (!Sec->Live || Sec->Assigned)
         continue;
 
-      if (!Sec->Live) {
-        reportDiscarded(Sec);
-        continue;
-      }
-
       // For -emit-relocs we have to ignore entries like
       //   .rela.dyn : { *(.rela.data) }
       // which are common because they are in the default bfd script.

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=316759&r1=316758&r2=316759&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Fri Oct 27 04:32:22 2017
@@ -289,6 +289,13 @@ template <class ELFT> void elf::markLive
 
   // Follow the graph to mark all live sections.
   doGcSections<ELFT>();
+
+  // Report garbage-collected sections.
+  if (Config->PrintGcSections)
+    for (InputSectionBase *Sec : InputSections)
+      if (!Sec->Live)
+        message("removing unused section from '" + Sec->Name + "' in file '" +
+                Sec->File->getName() + "'");
 }
 
 template void elf::markLive<ELF32LE>();

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=316759&r1=316758&r2=316759&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Oct 27 04:32:22 2017
@@ -89,11 +89,6 @@ static bool canMergeToProgbits(unsigned
 }
 
 void OutputSection::addSection(InputSection *IS) {
-  if (!IS->Live) {
-    reportDiscarded(IS);
-    return;
-  }
-
   if (!Live) {
     // If IS is the first section to be added to this section,
     // initialize Type by IS->Type.
@@ -218,13 +213,6 @@ void elf::sortByOrder(MutableArrayRef<In
     In[I] = V[I].second;
 }
 
-void elf::reportDiscarded(InputSectionBase *IS) {
-  if (!Config->PrintGcSections)
-    return;
-  message("removing unused section from '" + IS->Name + "' in file '" +
-          IS->File->getName() + "'");
-}
-
 static OutputSection *createSection(InputSectionBase *IS, StringRef OutsecName) {
   OutputSection *Sec = Script->createOutputSection(OutsecName, "<internal>");
   Sec->Type = IS->Type;
@@ -235,10 +223,6 @@ static OutputSection *createSection(Inpu
 
 OutputSection *OutputSectionFactory::addInputSec(InputSectionBase *IS,
                                                  StringRef OutsecName) {
-  if (!IS->Live) {
-    reportDiscarded(IS);
-    return nullptr;
-  }
 
   // Sections with SHT_GROUP or SHF_GROUP attributes reach here only when the -r
   // option is given. A section with SHT_GROUP defines a "section group", and

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=316759&r1=316758&r2=316759&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Fri Oct 27 04:32:22 2017
@@ -167,7 +167,6 @@ private:
 };
 
 uint64_t getHeaderSize();
-void reportDiscarded(InputSectionBase *IS);
 void sortByOrder(llvm::MutableArrayRef<InputSection *> In,
                  std::function<int(InputSectionBase *S)> Order);
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=316759&r1=316758&r2=316759&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Oct 27 04:32:22 2017
@@ -860,7 +860,7 @@ void Writer<ELFT>::forEachRelSec(std::fu
 template <class ELFT> void Writer<ELFT>::createSections() {
   std::vector<OutputSection *> Vec;
   for (InputSectionBase *IS : InputSections)
-    if (IS)
+    if (IS && IS->Live)
       if (OutputSection *Sec =
               Factory.addInputSec(IS, getOutputSectionName(IS->Name)))
         Vec.push_back(Sec);




More information about the llvm-commits mailing list