Simplify output section ownership management.
authorRui Ueyama <ruiu@google.com>
Fri, 12 Aug 2016 01:10:17 +0000 (01:10 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 12 Aug 2016 01:10:17 +0000 (01:10 +0000)
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<ELFT>.

llvm-svn: 278452

lld/ELF/OutputSections.cpp
lld/ELF/OutputSections.h
lld/ELF/Writer.cpp

index 3485737..8371fe4 100644 (file)
@@ -1765,7 +1765,7 @@ OutputSectionFactory<ELFT>::create(InputSectionBase<ELFT> *C,
   case InputSectionBase<ELFT>::Layout:
     llvm_unreachable("Invalid section type");
   }
-  OwningSections.emplace_back(Sec);
+  Out<ELFT>::Pool.emplace_back(Sec);
   return {Sec, true};
 }
 
index e915127..cf1f2f0 100644 (file)
@@ -752,6 +752,9 @@ template <class ELFT> struct Out {
   static OutputSectionBase<ELFT> *PreinitArray;
   static OutputSectionBase<ELFT> *InitArray;
   static OutputSectionBase<ELFT> *FiniArray;
+
+  // This pool owns dynamically-allocated output sections.
+  static std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> Pool;
 };
 
 template <bool Is64Bits> struct SectionKey {
@@ -779,7 +782,6 @@ private:
   Key createKey(InputSectionBase<ELFT> *C, StringRef OutsecName);
 
   llvm::SmallDenseMap<Key, OutputSectionBase<ELFT> *> Map;
-  std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> OwningSections;
 };
 
 template <class ELFT> BuildIdSection<ELFT> *Out<ELFT>::BuildId;
@@ -813,6 +815,9 @@ template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::PreinitArray;
 template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::InitArray;
 template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::FiniArray;
 
+template <class ELFT>
+std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> Out<ELFT>::Pool;
+
 } // namespace elf
 } // namespace lld
 
index ac716c5..416ef76 100644 (file)
@@ -221,6 +221,7 @@ template <class ELFT> void elf::writeResult() {
   Out<ELFT>::FiniArray = nullptr;
 
   Writer<ELFT>().run();
+  Out<ELFT>::Pool.clear();
 }
 
 template <class ELFT>