From 6a53737c92e6382b6a698cb03d96cf164b529795 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 14 Nov 2016 14:33:49 +0000 Subject: [PATCH] Delay removing empty section commands. NFC. To fix pr30997 we will have to keep them a bit longer, this just splits that part of the diff. llvm-svn: 286827 --- lld/ELF/LinkerScript.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 9dffb0bd3be9..2cf088e91e28 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -526,21 +526,19 @@ template void LinkerScript::removeEmptyCommands() { auto *Cmd = dyn_cast(Base.get()); if (!Cmd) return false; - std::vector Secs = - findSections(Cmd->Name, *OutputSections); - if (!Secs.empty()) - return false; - for (const std::unique_ptr &I : Cmd->Commands) - if (!isa(I.get())) - return false; - return true; + return findSections(Cmd->Name, *OutputSections).empty(); }); Opt.Commands.erase(Pos, Opt.Commands.end()); } -template void LinkerScript::adjustSectionsBeforeSorting() { - removeEmptyCommands(); +static bool isAllSectionDescription(const OutputSectionCommand &Cmd) { + for (const std::unique_ptr &I : Cmd.Commands) + if (!isa(*I)) + return false; + return true; +} +template void LinkerScript::adjustSectionsBeforeSorting() { // If the output section contains only symbol assignments, create a // corresponding output section. The bfd linker seems to only create them if // '.' is assigned to, but creating these section should not have any bad @@ -559,9 +557,14 @@ template void LinkerScript::adjustSectionsBeforeSorting() { continue; } + if (isAllSectionDescription(*Cmd)) + continue; + auto *OutSec = make>(Cmd->Name, Type, Flags); OutputSections->push_back(OutSec); } + + removeEmptyCommands(); } // When placing orphan sections, we want to place them after symbol assignments