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
This commit is contained in:
Rafael Espindola 2016-11-14 14:33:49 +00:00
parent 07fe612973
commit 6a53737c92
1 changed files with 13 additions and 10 deletions

View File

@ -526,21 +526,19 @@ template <class ELFT> void LinkerScript<ELFT>::removeEmptyCommands() {
auto *Cmd = dyn_cast<OutputSectionCommand>(Base.get());
if (!Cmd)
return false;
std::vector<OutputSectionBase *> Secs =
findSections<ELFT>(Cmd->Name, *OutputSections);
if (!Secs.empty())
return false;
for (const std::unique_ptr<BaseCommand> &I : Cmd->Commands)
if (!isa<InputSectionDescription>(I.get()))
return false;
return true;
return findSections<ELFT>(Cmd->Name, *OutputSections).empty();
});
Opt.Commands.erase(Pos, Opt.Commands.end());
}
template <class ELFT> void LinkerScript<ELFT>::adjustSectionsBeforeSorting() {
removeEmptyCommands();
static bool isAllSectionDescription(const OutputSectionCommand &Cmd) {
for (const std::unique_ptr<BaseCommand> &I : Cmd.Commands)
if (!isa<InputSectionDescription>(*I))
return false;
return true;
}
template <class ELFT> void LinkerScript<ELFT>::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 <class ELFT> void LinkerScript<ELFT>::adjustSectionsBeforeSorting() {
continue;
}
if (isAllSectionDescription(*Cmd))
continue;
auto *OutSec = make<OutputSection<ELFT>>(Cmd->Name, Type, Flags);
OutputSections->push_back(OutSec);
}
removeEmptyCommands();
}
// When placing orphan sections, we want to place them after symbol assignments