[ELF] - Stop removing sections in removeUnusedSyntheticSections().

That makes code a bit more consistent. Instead of removing sections there
we can just mark them as dead. So that removeEmptyCommands() will
handle the rest.

Differential revision: https://reviews.llvm.org/D38393

llvm-svn: 314654
This commit is contained in:
George Rimar
2017-10-02 09:11:13 +00:00
parent 3bbbf31590
commit ba45584c4b
2 changed files with 5 additions and 6 deletions

View File

@@ -677,6 +677,8 @@ void LinkerScript::adjustSectionsAfterSorting() {
// Try and find an appropriate memory region to assign offsets in.
for (BaseCommand *Base : Opt.Commands) {
if (auto *Sec = dyn_cast<OutputSection>(Base)) {
if (!Sec->Live)
continue;
Sec->MemRegion = findMemoryRegion(Sec);
// Handle align (e.g. ".foo : ALIGN(16) { ... }").
if (Sec->AlignExpr)
@@ -713,8 +715,6 @@ void LinkerScript::adjustSectionsAfterSorting() {
DefPhdrs = Sec->Phdrs;
}
}
removeEmptyCommands();
}
static OutputSection *findFirstSection(PhdrEntry *Load) {

View File

@@ -1054,8 +1054,7 @@ findOrphanPos(std::vector<BaseCommand *>::iterator B,
}
template <class ELFT> void Writer<ELFT>::sortSections() {
if (Script->Opt.HasSections)
Script->adjustSectionsBeforeSorting();
Script->adjustSectionsBeforeSorting();
// Don't sort if using -r. It is not necessary and we want to preserve the
// relative order for SHF_LINK_ORDER sections.
@@ -1197,8 +1196,7 @@ static void removeUnusedSyntheticSections() {
// If there are no other sections in the output section, remove it from the
// output.
if (OS->Commands.empty())
llvm::erase_if(Script->Opt.Commands,
[&](BaseCommand *Cmd) { return Cmd == OS; });
OS->Live = false;
}
}
@@ -1304,6 +1302,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
removeUnusedSyntheticSections();
sortSections();
Script->removeEmptyCommands();
// Now that we have the final list, create a list of all the
// OutputSections for convenience.