diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 3485737a4ce4..8371fe473ba8 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -1765,7 +1765,7 @@ OutputSectionFactory::create(InputSectionBase *C, case InputSectionBase::Layout: llvm_unreachable("Invalid section type"); } - OwningSections.emplace_back(Sec); + Out::Pool.emplace_back(Sec); return {Sec, true}; } diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index e915127c5a39..cf1f2f0cd9ca 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -752,6 +752,9 @@ template struct Out { static OutputSectionBase *PreinitArray; static OutputSectionBase *InitArray; static OutputSectionBase *FiniArray; + + // This pool owns dynamically-allocated output sections. + static std::vector>> Pool; }; template struct SectionKey { @@ -779,7 +782,6 @@ private: Key createKey(InputSectionBase *C, StringRef OutsecName); llvm::SmallDenseMap *> Map; - std::vector>> OwningSections; }; template BuildIdSection *Out::BuildId; @@ -813,6 +815,9 @@ template OutputSectionBase *Out::PreinitArray; template OutputSectionBase *Out::InitArray; template OutputSectionBase *Out::FiniArray; +template +std::vector>> Out::Pool; + } // namespace elf } // namespace lld diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index ac716c5ec6be..416ef76a45d3 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -221,6 +221,7 @@ template void elf::writeResult() { Out::FiniArray = nullptr; Writer().run(); + Out::Pool.clear(); } template