From bdf836db1b40e3513e510f9a8967901d09a86695 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 12 Aug 2016 01:10:17 +0000 Subject: [PATCH] Simplify output section ownership management. One reason why we are (ab)using OutputSectionFactory class is because it owns output sections. Technically there's no need to have it own sections. So, this patch transfers the ownership to Out. llvm-svn: 278452 --- lld/ELF/OutputSections.cpp | 2 +- lld/ELF/OutputSections.h | 7 ++++++- lld/ELF/Writer.cpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 3485737..8371fe4 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 e915127..cf1f2f0 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 ac716c5..416ef76 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 -- 2.7.4