aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/llvm/tools/lld/ELF/Writer.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/contrib/llvm/tools/lld/ELF/Writer.cpp b/contrib/llvm/tools/lld/ELF/Writer.cpp
index 080d8e787301..551ca260de10 100644
--- a/contrib/llvm/tools/lld/ELF/Writer.cpp
+++ b/contrib/llvm/tools/lld/ELF/Writer.cpp
@@ -1149,8 +1149,17 @@ static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V) {
SS->Live = false;
// If there are no other sections in the output section, remove it from the
// output.
- if (OS->Sections.empty())
+ if (OS->Sections.empty()) {
V.erase(std::find(V.begin(), V.end(), OS));
+ // Also remove script commands matching the output section.
+ auto &Cmds = Script->Opt.Commands;
+ auto I = std::remove_if(Cmds.begin(), Cmds.end(), [&](BaseCommand *Cmd) {
+ if (auto *OSCmd = dyn_cast<OutputSectionCommand>(Cmd))
+ return OSCmd->Sec == OS;
+ return false;
+ });
+ Cmds.erase(I, Cmds.end());
+ }
}
}