diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-07-03 16:54:39 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-07-03 16:54:39 +0000 |
commit | c080ff64dc05a0940082f3a9f4be0258ed70210f (patch) | |
tree | b6457048a058d1ace0648fd71c8d644105716e53 | |
parent | bdfb3b1d5fc35c8c593c1ff33547264a83a8e98b (diff) | |
download | bcm5719-llvm-c080ff64dc05a0940082f3a9f4be0258ed70210f.tar.gz bcm5719-llvm-c080ff64dc05a0940082f3a9f4be0258ed70210f.zip |
Move clearOutputSections earlier.
Now removeUnusedSyntheticSections operates entirely on the linker
script.
llvm-svn: 307043
-rw-r--r-- | lld/ELF/Writer.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 551ca260de1..3a8af2d4021 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1132,7 +1132,7 @@ static void applySynthetic(const std::vector<SyntheticSection *> &Sections, // 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 the output. -static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V) { +static void removeUnusedSyntheticSections() { // All input synthetic sections that can be empty are placed after // all regular ones. We iterate over them all and exit at first // non-synthetic. @@ -1145,12 +1145,24 @@ static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V) { continue; if ((SS == InX::Got || SS == InX::MipsGot) && ElfSym::GlobalOffsetTable) continue; - OS->Sections.erase(std::find(OS->Sections.begin(), OS->Sections.end(), SS)); - SS->Live = false; + + OutputSectionCommand *Cmd = Script->getCmd(OS); + BaseCommand **Empty = nullptr; + for (BaseCommand *&B : Cmd->Commands) { + if (auto *ISD = dyn_cast<InputSectionDescription>(B)) { + auto I = std::find(ISD->Sections.begin(), ISD->Sections.end(), SS); + if (I != ISD->Sections.end()) + ISD->Sections.erase(I); + if (ISD->Sections.empty()) + Empty = &B; + } + } + if (Empty) + Cmd->Commands.erase(std::vector<BaseCommand *>::iterator(Empty)); + // If there are no other sections in the output section, remove it from the // output. - if (OS->Sections.empty()) { - V.erase(std::find(V.begin(), V.end(), OS)); + if (Cmd->Commands.empty()) { // Also remove script commands matching the output section. auto &Cmds = Script->Opt.Commands; auto I = std::remove_if(Cmds.begin(), Cmds.end(), [&](BaseCommand *Cmd) { @@ -1227,9 +1239,9 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { return; addPredefinedSections(); - removeUnusedSyntheticSections(OutputSections); - clearOutputSections(); + removeUnusedSyntheticSections(); + sortSections(); // Now that we have the final list, create a list of all the |