diff options
| author | George Rimar <grimar@accesssoftek.com> | 2015-12-10 09:12:18 +0000 |
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2015-12-10 09:12:18 +0000 |
| commit | a5fbebc2065d12a403f82380cbe0c3a571cfccbe (patch) | |
| tree | c63f3cf75900c832b63c8e8ce07fd112b09bf121 /lld/ELF/Writer.cpp | |
| parent | e451eeff5c7e070764584aba20ffdd8919b4b4cd (diff) | |
| download | bcm5719-llvm-a5fbebc2065d12a403f82380cbe0c3a571cfccbe.tar.gz bcm5719-llvm-a5fbebc2065d12a403f82380cbe0c3a571cfccbe.zip | |
[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
llvm-svn: 255235
Diffstat (limited to 'lld/ELF/Writer.cpp')
| -rw-r--r-- | lld/ELF/Writer.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 465dc68a3c0..1a86881c5b4 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -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>::getOutputSectionName(StringRef S) const { } 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>::createSections() { 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. |

