@@ -1836,33 +1836,26 @@ static void removeUnusedSyntheticSections() {
1836
1836
})
1837
1837
.base ();
1838
1838
1839
- DenseSet<InputSectionDescription *> isdSet;
1840
1839
// Mark unused synthetic sections for deletion
1841
- auto end = std::stable_partition (
1842
- start, inputSections.end (), [&](InputSectionBase *s) {
1843
- SyntheticSection *ss = dyn_cast<SyntheticSection>(s);
1844
- OutputSection *os = ss->getParent ();
1845
- if (!os || ss->isNeeded ())
1846
- return true ;
1847
-
1848
- // If we reach here, then ss is an unused synthetic section and we want
1849
- // to remove it from the corresponding input section description, and
1850
- // orphanSections.
1851
- for (SectionCommand *b : os->commands )
1852
- if (auto *isd = dyn_cast<InputSectionDescription>(b))
1853
- isdSet.insert (isd);
1854
-
1855
- llvm::erase_if (
1856
- script->orphanSections ,
1857
- [=](const InputSectionBase *isec) { return isec == ss; });
1858
-
1859
- return false ;
1860
- });
1861
-
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
+ });
1845
+
1846
+ // Remove unused synthetic sections from the corresponding input section
1847
+ // description and orphanSections.
1862
1848
DenseSet<InputSectionBase *> unused (end, inputSections.end ());
1863
- for (auto *isd : isdSet)
1864
- llvm::erase_if (isd->sections ,
1865
- [=](InputSection *isec) { return unused.count (isec); });
1849
+ for (auto it = end; it != inputSections.end (); ++it)
1850
+ if (OutputSection *osec = cast<SyntheticSection>(*it)->getParent ())
1851
+ for (SectionCommand *cmd : osec->commands )
1852
+ if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
1853
+ llvm::erase_if (isd->sections , [&](InputSection *isec) {
1854
+ return unused.count (isec);
1855
+ });
1856
+ llvm::erase_if (script->orphanSections , [&](const InputSectionBase *sec) {
1857
+ return unused.count (sec);
1858
+ });
1866
1859
1867
1860
// Erase unused synthetic sections.
1868
1861
inputSections.erase (end, inputSections.end ());
0 commit comments