summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-02-17 17:35:07 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-02-17 17:35:07 +0000
commitecbfd871f9aad6c13aa5af56465b2cf00fa18ba7 (patch)
tree723c792de662eace2fb9ccab9ac61e5701e1e926
parente91e9dd7bb95bd34fa871300be807b5870170dc6 (diff)
downloadbcm5719-llvm-ecbfd871f9aad6c13aa5af56465b2cf00fa18ba7.tar.gz
bcm5719-llvm-ecbfd871f9aad6c13aa5af56465b2cf00fa18ba7.zip
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. llvm-svn: 295467
-rw-r--r--lld/ELF/LinkerScript.cpp3
-rw-r--r--lld/ELF/OutputSections.cpp7
-rw-r--r--lld/ELF/Writer.cpp14
-rw-r--r--lld/ELF/Writer.h1
-rw-r--r--lld/test/ELF/linkerscript/discard-print-gc.s13
5 files changed, 22 insertions, 16 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 9f2ac61b463..ac5ac99b97b 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -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())
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 8d2b1668eab..7998d89367e 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -565,6 +565,13 @@ static bool canMergeToProgbits(unsigned Type) {
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) {
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 79799f03e0b..5e790fe45fd 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -131,15 +131,6 @@ StringRef elf::getOutputSectionName(StringRef Name) {
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<ELF32LE>(const OutputSectionBase *);
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> *);
diff --git a/lld/ELF/Writer.h b/lld/ELF/Writer.h
index afecdd04901..b5be425b043 100644
--- a/lld/ELF/Writer.h
+++ b/lld/ELF/Writer.h
@@ -52,7 +52,6 @@ llvm::StringRef getOutputSectionName(llvm::StringRef Name);
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();
diff --git a/lld/test/ELF/linkerscript/discard-print-gc.s b/lld/test/ELF/linkerscript/discard-print-gc.s
new file mode 100644
index 00000000000..2d6cb0460f3
--- /dev/null
+++ b/lld/test/ELF/linkerscript/discard-print-gc.s
@@ -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'
OpenPOWER on IntegriCloud