From 4db7c7dbb415c67ddd5248c149fc6fa8ac30161d Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 29 Jul 2022 00:03:50 -0700 Subject: [PATCH] [ELF] Remove one inputSections loop. NFC --- lld/ELF/Driver.cpp | 3 --- lld/ELF/LinkerScript.cpp | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 6c0fd3139e87..7dc4ab2f57de 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2779,9 +2779,6 @@ void LinkerDriver::link(opt::InputArgList &args) { for (SectionCommand *cmd : script->sectionCommands) if (auto *osd = dyn_cast(cmd)) osd->osec.finalizeInputSections(); - llvm::erase_if(inputSections, [](InputSectionBase *s) { - return isa(s); - }); } // Two input sections with different output sections should not be folded. diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 9f30117c0279..6028652b2b20 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -846,7 +846,11 @@ void LinkerScript::addOrphanSections() { // to be created before we create relocation output section, so we want // to create target sections first. We do not want priority handling // for synthetic sections because them are special. + size_t n = 0; for (InputSectionBase *isec : inputSections) { + if (!isa(isec)) + inputSections[n++] = isec; + // In -r links, SHF_LINK_ORDER sections are added while adding their parent // sections because we need to know the parent's output section before we // can select an output section for the SHF_LINK_ORDER section. @@ -863,6 +867,7 @@ void LinkerScript::addOrphanSections() { if (depSec->flags & SHF_LINK_ORDER) add(depSec); } + inputSections.resize(n); // If no SECTIONS command was given, we should insert sections commands // before others, so that we can handle scripts which refers them,