From: Fangrui Song Date: Mon, 29 Nov 2021 05:47:55 +0000 (-0800) Subject: [ELF] Avoid std::stable_partition which may allocate memory. NFC X-Git-Tag: upstream/15.0.7~24623 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4709bacf18b41bf80b3a0fc1c9f16be60fedae8b;p=platform%2Fupstream%2Fllvm.git [ELF] Avoid std::stable_partition which may allocate memory. NFC --- diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 77a6626..423f989 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1836,18 +1836,22 @@ static void removeUnusedSyntheticSections() { }) .base(); - // Mark unused synthetic sections for deletion - auto end = std::stable_partition(start, inputSections.end(), - [&](InputSectionBase *s) { - auto *sec = cast(s); - return sec->getParent() && sec->isNeeded(); - }); + // Remove unused synthetic sections from inputSections; + DenseSet unused; + auto end = + std::remove_if(start, inputSections.end(), [&](InputSectionBase *s) { + auto *sec = cast(s); + if (sec->getParent() && sec->isNeeded()) + return false; + unused.insert(sec); + return true; + }); + inputSections.erase(end, inputSections.end()); // Remove unused synthetic sections from the corresponding input section // description and orphanSections. - DenseSet unused(end, inputSections.end()); - for (auto it = end; it != inputSections.end(); ++it) - if (OutputSection *osec = cast(*it)->getParent()) + for (auto *sec : unused) + if (OutputSection *osec = cast(sec)->getParent()) for (SectionCommand *cmd : osec->commands) if (auto *isd = dyn_cast(cmd)) llvm::erase_if(isd->sections, [&](InputSection *isec) { @@ -1856,9 +1860,6 @@ static void removeUnusedSyntheticSections() { llvm::erase_if(script->orphanSections, [&](const InputSectionBase *sec) { return unused.count(sec); }); - - // Erase unused synthetic sections. - inputSections.erase(end, inputSections.end()); } // Create output section objects and add them to OutputSections.