@@ -1836,18 +1836,22 @@ static void removeUnusedSyntheticSections() {
1836
1836
})
1837
1837
.base ();
1838
1838
1839
- // Mark unused synthetic sections for deletion
1840
- auto end = std::stable_partition (start, inputSections.end (),
1841
- [&](InputSectionBase *s) {
1842
- auto *sec = cast<SyntheticSection>(s);
1843
- return sec->getParent () && sec->isNeeded ();
1844
- });
1839
+ // Remove unused synthetic sections from inputSections;
1840
+ DenseSet<InputSectionBase *> unused;
1841
+ auto end =
1842
+ std::remove_if (start, inputSections.end (), [&](InputSectionBase *s) {
1843
+ auto *sec = cast<SyntheticSection>(s);
1844
+ if (sec->getParent () && sec->isNeeded ())
1845
+ return false ;
1846
+ unused.insert (sec);
1847
+ return true ;
1848
+ });
1849
+ inputSections.erase (end, inputSections.end ());
1845
1850
1846
1851
// Remove unused synthetic sections from the corresponding input section
1847
1852
// description and orphanSections.
1848
- DenseSet<InputSectionBase *> unused (end, inputSections.end ());
1849
- for (auto it = end; it != inputSections.end (); ++it)
1850
- if (OutputSection *osec = cast<SyntheticSection>(*it)->getParent ())
1853
+ for (auto *sec : unused)
1854
+ if (OutputSection *osec = cast<SyntheticSection>(sec)->getParent ())
1851
1855
for (SectionCommand *cmd : osec->commands )
1852
1856
if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
1853
1857
llvm::erase_if (isd->sections , [&](InputSection *isec) {
@@ -1856,9 +1860,6 @@ static void removeUnusedSyntheticSections() {
1856
1860
llvm::erase_if (script->orphanSections , [&](const InputSectionBase *sec) {
1857
1861
return unused.count (sec);
1858
1862
});
1859
-
1860
- // Erase unused synthetic sections.
1861
- inputSections.erase (end, inputSections.end ());
1862
1863
}
1863
1864
1864
1865
// Create output section objects and add them to OutputSections.
0 commit comments