[lld] r295467 - Don't print DISCARD sections as gced.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 17 09:35:07 PST 2017


Author: rafael
Date: Fri Feb 17 11:35:07 2017
New Revision: 295467

URL: http://llvm.org/viewvc/llvm-project?rev=295467&view=rev
Log:
Don't print DISCARD sections as gced.

This is a small difference I noticed to gold and bfd. When given
--print-gc-sections, we print sections a linkerscript marks
DISCARD. The other linkers don't.

Added:
    lld/trunk/test/ELF/linkerscript/discard-print-gc.s
Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/Writer.cpp
    lld/trunk/ELF/Writer.h

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=295467&r1=295466&r2=295467&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Feb 17 11:35:07 2017
@@ -296,7 +296,8 @@ template <class ELFT>
 void LinkerScript<ELFT>::discard(ArrayRef<InputSectionBase<ELFT> *> V) {
   for (InputSectionBase<ELFT> *S : V) {
     S->Live = false;
-    reportDiscarded(S);
+    if (S == In<ELFT>::ShStrTab)
+      error("discarding .shstrtab section is not allowed");
 
     InputSection<ELFT> *IS = dyn_cast<InputSection<ELFT>>(S);
     if (!IS || IS->DependentSections.empty())

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=295467&r1=295466&r2=295467&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Feb 17 11:35:07 2017
@@ -565,6 +565,13 @@ static bool canMergeToProgbits(unsigned
          Type == SHT_NOTE;
 }
 
+template <class ELFT> static void reportDiscarded(InputSectionBase<ELFT> *IS) {
+  if (!Config->PrintGcSections)
+    return;
+  errs() << "removing unused section from '" << IS->Name << "' in file '"
+         << IS->getFile()->getName() << "'\n";
+}
+
 template <class ELFT>
 void OutputSectionFactory<ELFT>::addInputSec(InputSectionBase<ELFT> *IS,
                                              StringRef OutsecName) {

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=295467&r1=295466&r2=295467&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Feb 17 11:35:07 2017
@@ -131,15 +131,6 @@ StringRef elf::getOutputSectionName(Stri
   return Name;
 }
 
-template <class ELFT> void elf::reportDiscarded(InputSectionBase<ELFT> *IS) {
-  if (IS == In<ELFT>::ShStrTab)
-    error("discarding .shstrtab section is not allowed");
-  if (!Config->PrintGcSections)
-    return;
-  errs() << "removing unused section from '" << IS->Name << "' in file '"
-         << IS->getFile()->getName() << "'\n";
-}
-
 template <class ELFT> static bool needsInterpSection() {
   return !Symtab<ELFT>::X->getSharedFiles().empty() &&
          !Config->DynamicLinker.empty() &&
@@ -1867,8 +1858,3 @@ template bool elf::isRelroSection<ELF32L
 template bool elf::isRelroSection<ELF32BE>(const OutputSectionBase *);
 template bool elf::isRelroSection<ELF64LE>(const OutputSectionBase *);
 template bool elf::isRelroSection<ELF64BE>(const OutputSectionBase *);
-
-template void elf::reportDiscarded<ELF32LE>(InputSectionBase<ELF32LE> *);
-template void elf::reportDiscarded<ELF32BE>(InputSectionBase<ELF32BE> *);
-template void elf::reportDiscarded<ELF64LE>(InputSectionBase<ELF64LE> *);
-template void elf::reportDiscarded<ELF64BE>(InputSectionBase<ELF64BE> *);

Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=295467&r1=295466&r2=295467&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Fri Feb 17 11:35:07 2017
@@ -52,7 +52,6 @@ llvm::StringRef getOutputSectionName(llv
 template <class ELFT>
 bool allocateHeaders(std::vector<PhdrEntry> &,
                      llvm::ArrayRef<OutputSectionBase *>, uint64_t Min);
-template <class ELFT> void reportDiscarded(InputSectionBase<ELFT> *IS);
 
 template <class ELFT> uint32_t getMipsEFlags();
 

Added: lld/trunk/test/ELF/linkerscript/discard-print-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/discard-print-gc.s?rev=295467&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/discard-print-gc.s (added)
+++ lld/trunk/test/ELF/linkerscript/discard-print-gc.s Fri Feb 17 11:35:07 2017
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+# RUN: echo "SECTIONS { /DISCARD/ : { *(.foo) } }" > %t.script
+# RUN: llvm-mc -triple x86_64-pc-linux %s -o %t.o -filetype=obj
+# RUN: ld.lld -o %t.so --gc-sections %t.o --print-gc-sections -shared 2>&1 | \
+# RUN:   FileCheck -check-prefix=CHECK %s
+# RUN: ld.lld -o %t.so -T %t.script %t.o --print-gc-sections -shared 2>&1 | \
+# RUN:   FileCheck -check-prefix=QUIET --allow-empty %s
+
+.section .foo,"a"
+.quad 0
+
+# CHECK: removing unused section from '.foo'
+# QUIET-NOT: removing unused section from '.foo'




More information about the llvm-commits mailing list