diff options
| author | George Rimar <grimar@accesssoftek.com> | 2018-02-23 10:53:04 +0000 |
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2018-02-23 10:53:04 +0000 |
| commit | db1a06244758537fe831a680ce2b1aedcafafe23 (patch) | |
| tree | 313f0a055a4e4781acd75396c3dc13f13e22b79e /lld/ELF/LinkerScript.cpp | |
| parent | c7711ba2efea9108a5046272ebc2434aaaa8a23e (diff) | |
| download | bcm5719-llvm-db1a06244758537fe831a680ce2b1aedcafafe23.tar.gz bcm5719-llvm-db1a06244758537fe831a680ce2b1aedcafafe23.zip | |
[ELF] - Do not remove empty output sections that are explicitly assigned to phdr in script.
This continues direction started in D43069.
We can keep sections that are explicitly assigned to segment in script.
It helps to simplify code.
Differential revision: https://reviews.llvm.org/D43571
llvm-svn: 325887
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 0426c503df0..63738d88d8d 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -752,21 +752,12 @@ void LinkerScript::assignOffsets(OutputSection *Sec) { } } -void LinkerScript::removeEmptyCommands() { - // It is common practice to use very generic linker scripts. So for any - // given run some of the output sections in the script will be empty. - // We could create corresponding empty output sections, but that would - // clutter the output. - // We instead remove trivially empty sections. The bfd linker seems even - // more aggressive at removing them. - llvm::erase_if(SectionCommands, [&](BaseCommand *Base) { - if (auto *Sec = dyn_cast<OutputSection>(Base)) - return !Sec->Live; +static bool isAllSectionDescription(const OutputSection &Cmd) { + // We do not remove empty sections that are explicitly + // assigned to any segment. + if (!Cmd.Phdrs.empty()) return false; - }); -} -static bool isAllSectionDescription(const OutputSection &Cmd) { // We do not want to remove sections that have custom address or align // expressions set even if them are empty. We keep them because we // want to be sure that any expressions can be evaluated and report @@ -803,7 +794,7 @@ void LinkerScript::adjustSectionsBeforeSorting() { // the previous sections. Only a few flags are needed to keep the impact low. uint64_t Flags = SHF_ALLOC; - for (BaseCommand *Cmd : SectionCommands) { + for (BaseCommand *&Cmd : SectionCommands) { auto *Sec = dyn_cast<OutputSection>(Cmd); if (!Sec) continue; @@ -812,20 +803,25 @@ void LinkerScript::adjustSectionsBeforeSorting() { continue; } - if (isAllSectionDescription(*Sec)) - continue; - - Sec->Live = true; - Sec->Flags = Flags; + if (!isAllSectionDescription(*Sec)) + Sec->Flags = Flags; + else + Cmd = nullptr; } + + // It is common practice to use very generic linker scripts. So for any + // given run some of the output sections in the script will be empty. + // We could create corresponding empty output sections, but that would + // clutter the output. + // We instead remove trivially empty sections. The bfd linker seems even + // more aggressive at removing them. + llvm::erase_if(SectionCommands, [&](BaseCommand *Base) { return !Base; }); } void LinkerScript::adjustSectionsAfterSorting() { // Try and find an appropriate memory region to assign offsets in. for (BaseCommand *Base : SectionCommands) { if (auto *Sec = dyn_cast<OutputSection>(Base)) { - if (!Sec->Live) - continue; if (!Sec->LMARegionName.empty()) { if (MemoryRegion *M = MemoryRegions.lookup(Sec->LMARegionName)) Sec->LMARegion = M; |

