From c38860b0d22c205e95f5c80970c6daeec362256f Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 5 Dec 2016 21:39:35 +0000 Subject: [PATCH] Revert r288707: Split removeUnusedSyntheticSections into two functions. That patch broke build. llvm-svn: 288708 --- lld/ELF/Writer.cpp | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 5f9ad3e..28a9563 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -60,7 +60,6 @@ private: void sortSections(); void finalizeSections(); void addPredefinedSections(); - void removeEmptyOutputSections(); std::vector createPhdrs(); void addPtArmExid(std::vector &Phdrs); @@ -911,38 +910,29 @@ finalizeSynthetic(const std::vector *> &Sections) { } // We need to add input synthetic sections early in createSyntheticSections() -// to make them visible from linker scripts before we can see whether they -// will be needed or not. As a result, some syntehtic input sections could be -// left empty. We remove such sections in this function. -template static void removeEmptySyntheticSections() { +// to make them visible from linkescript side. But not all sections are always +// required to be in output. For example we don't need dynamic section content +// sometimes. This function filters out such unused sections from output. +template +static void removeUnusedSyntheticSections(std::vector &V) { // Input synthetic sections are placed after all regular ones. We iterate over // them all and exit at first non-synthetic. - for (InputSectionBase *Sec : llvm::reverse(Symtab::X->Sections)) { - SyntheticSection *In = dyn_cast>(S); - if (!In) + for (InputSectionBase *S : llvm::reverse(Symtab::X->Sections)) { + SyntheticSection *SS = dyn_cast>(S); + if (!SS) return; - if (!In->empty() || !In->OutSec) + if (!SS->empty() || !SS->OutSec) continue; - OutputSection *Out = cast>(In->OutSec); - Out->Sections.erase( - std::find(Out->Sections.begin(), Out->Sections.end(), In)); + OutputSection *OutSec = cast>(SS->OutSec); + OutSec->Sections.erase( + std::find(OutSec->Sections.begin(), OutSec->Sections.end(), SS)); + // If there is no other sections in output section, remove it from output. + if (OutSec->Sections.empty()) + V.erase(std::find(V.begin(), V.end(), OutSec)); } } -// This function removes empty output sections so that LLD doesn't create -// empty sections. Such output sections are usually results of linker scripts. -template void Writer::removeEmptyOutputSections() { - OutputSections.erase( - std::remove_if(OutputSections.begin(), OutputSections.end(), - [](OutputSectionBase *Sec) { - if (auto *S = dyn_cast>(Sec)) - return S->Sections.empty(); - return false; - }), - OutputSections.end()); -} - // Create output section objects and add them to OutputSections. template void Writer::finalizeSections() { Out::DebugInfo = findSection(".debug_info"); @@ -1003,8 +993,7 @@ template void Writer::finalizeSections() { // So far we have added sections from input object files. // This function adds linker-created Out::* sections. addPredefinedSections(); - removeEmptySyntheticSections(); - removeEmptyOutputSections(); + removeUnusedSyntheticSections(OutputSections); sortSections(); -- 2.7.4