[lld] r255235 - [ELF] - Implemented --print-gc-sections command line argument.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 10 01:12:19 PST 2015
Author: grimar
Date: Thu Dec 10 03:12:18 2015
New Revision: 255235
URL: http://llvm.org/viewvc/llvm-project?rev=255235&view=rev
Log:
[ELF] - Implemented --print-gc-sections command line argument.
List all sections removed by garbage collection. This option is only effective if garbage collection has been enabled via the `--gc-sections' option.
Differential revision: http://reviews.llvm.org/D15327
Added:
lld/trunk/test/ELF/gc-sections-print.s
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Options.td
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=255235&r1=255234&r2=255235&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Thu Dec 10 03:12:18 2015
@@ -58,6 +58,7 @@ struct Configuration {
bool Mips64EL = false;
bool NoInhibitExec;
bool NoUndefined;
+ bool PrintGcSections;
bool Shared;
bool Static = false;
bool StripAll;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=255235&r1=255234&r2=255235&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Dec 10 03:12:18 2015
@@ -163,6 +163,7 @@ void LinkerDriver::createFiles(opt::Inpu
Config->GcSections = Args.hasArg(OPT_gc_sections);
Config->NoInhibitExec = Args.hasArg(OPT_noinhibit_exec);
Config->NoUndefined = Args.hasArg(OPT_no_undefined);
+ Config->PrintGcSections = Args.hasArg(OPT_print_gc_sections);
Config->Shared = Args.hasArg(OPT_shared);
Config->StripAll = Args.hasArg(OPT_strip_all);
Config->Verbose = Args.hasArg(OPT_verbose);
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=255235&r1=255234&r2=255235&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Thu Dec 10 03:12:18 2015
@@ -79,6 +79,9 @@ def no_undefined : Flag<["--"], "no-unde
def o : Separate<["-"], "o">, MetaVarName<"<path>">,
HelpText<"Path to file to write output">;
+def print_gc_sections: Flag<["--"], "print-gc-sections">,
+ HelpText<"List removed unused sections">;
+
def rpath : Separate<["-"], "rpath">,
HelpText<"Add a DT_RUNPATH to the output">;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=255235&r1=255234&r2=255235&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Dec 10 03:12:18 2015
@@ -16,6 +16,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/FileOutputBuffer.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/StringSaver.h"
using namespace llvm;
@@ -532,6 +533,15 @@ StringRef Writer<ELFT>::getOutputSection
}
template <class ELFT>
+void reportDiscarded(InputSectionBase<ELFT> *IS,
+ const std::unique_ptr<ObjectFile<ELFT>> &File) {
+ if (!Config->PrintGcSections || !IS || IS->isLive())
+ return;
+ llvm::errs() << "removing unused section from '" << IS->getSectionName()
+ << "' in file '" << File->getName() << "'\n";
+}
+
+template <class ELFT>
bool Writer<ELFT>::isDiscarded(InputSectionBase<ELFT> *IS) const {
if (!IS || !IS->isLive() || IS == &InputSection<ELFT>::Discarded)
return true;
@@ -564,8 +574,10 @@ template <class ELFT> void Writer<ELFT>:
for (const std::unique_ptr<ObjectFile<ELFT>> &F : Symtab.getObjectFiles()) {
for (InputSectionBase<ELFT> *C : F->getSections()) {
- if (isDiscarded(C))
+ if (isDiscarded(C)) {
+ reportDiscarded(C, F);
continue;
+ }
const Elf_Shdr *H = C->getSectionHdr();
uintX_t OutFlags = H->sh_flags & ~SHF_GROUP;
// For SHF_MERGE we create different output sections for each sh_entsize.
Added: lld/trunk/test/ELF/gc-sections-print.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gc-sections-print.s?rev=255235&view=auto
==============================================================================
--- lld/trunk/test/ELF/gc-sections-print.s (added)
+++ lld/trunk/test/ELF/gc-sections-print.s Thu Dec 10 03:12:18 2015
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t --gc-sections --print-gc-sections -o %t2 2>&1 | FileCheck -check-prefix=PRINT %s
+
+# PRINT: removing unused section from '.text.x' in file
+# PRINT-NEXT: removing unused section from '.text.y' in file
+
+.globl _start
+.protected a, x, y
+_start:
+ call a
+
+.section .text.a,"ax", at progbits
+a:
+ nop
+
+.section .text.x,"ax", at progbits
+x:
+ nop
+
+.section .text.y,"ax", at progbits
+y:
+ nop
More information about the llvm-commits
mailing list