Index: lld/trunk/ELF/LinkerScript.cpp =================================================================== --- lld/trunk/ELF/LinkerScript.cpp +++ lld/trunk/ELF/LinkerScript.cpp @@ -283,14 +283,9 @@ 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. Index: lld/trunk/ELF/MarkLive.cpp =================================================================== --- lld/trunk/ELF/MarkLive.cpp +++ lld/trunk/ELF/MarkLive.cpp @@ -289,6 +289,13 @@ // Follow the graph to mark all live sections. doGcSections(); + + // 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(); Index: lld/trunk/ELF/OutputSections.h =================================================================== --- lld/trunk/ELF/OutputSections.h +++ lld/trunk/ELF/OutputSections.h @@ -167,7 +167,6 @@ }; uint64_t getHeaderSize(); -void reportDiscarded(InputSectionBase *IS); void sortByOrder(llvm::MutableArrayRef In, std::function Order); Index: lld/trunk/ELF/OutputSections.cpp =================================================================== --- lld/trunk/ELF/OutputSections.cpp +++ lld/trunk/ELF/OutputSections.cpp @@ -89,11 +89,6 @@ } 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 @@ 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, ""); Sec->Type = IS->Type; @@ -235,10 +223,6 @@ 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 Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -860,7 +860,7 @@ template void Writer::createSections() { std::vector Vec; for (InputSectionBase *IS : InputSections) - if (IS) + if (IS && IS->Live) if (OutputSection *Sec = Factory.addInputSec(IS, getOutputSectionName(IS->Name))) Vec.push_back(Sec);