[lld] r278452 - Simplify output section ownership management.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 11 18:10:18 PDT 2016
Author: ruiu
Date: Thu Aug 11 20:10:17 2016
New Revision: 278452
URL: http://llvm.org/viewvc/llvm-project?rev=278452&view=rev
Log:
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<ELFT>.
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/OutputSections.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=278452&r1=278451&r2=278452&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Aug 11 20:10:17 2016
@@ -1765,7 +1765,7 @@ OutputSectionFactory<ELFT>::create(Input
case InputSectionBase<ELFT>::Layout:
llvm_unreachable("Invalid section type");
}
- OwningSections.emplace_back(Sec);
+ Out<ELFT>::Pool.emplace_back(Sec);
return {Sec, true};
}
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=278452&r1=278451&r2=278452&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Thu Aug 11 20:10:17 2016
@@ -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<
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
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=278452&r1=278451&r2=278452&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Aug 11 20:10:17 2016
@@ -221,6 +221,7 @@ template <class ELFT> void elf::writeRes
Out<ELFT>::FiniArray = nullptr;
Writer<ELFT>().run();
+ Out<ELFT>::Pool.clear();
}
template <class ELFT>
More information about the llvm-commits
mailing list