diff options
author | Rui Ueyama <ruiu@google.com> | 2016-08-12 01:24:53 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2016-08-12 01:24:53 +0000 |
commit | f34d0e0875ce48c68ccc746c873a5f379e6cb1b4 (patch) | |
tree | a27e27fe1d30587b76cf3d04dd252fd0937ba242 | |
parent | bdf836db1b40e3513e510f9a8967901d09a86695 (diff) | |
download | bcm5719-llvm-f34d0e0875ce48c68ccc746c873a5f379e6cb1b4.tar.gz bcm5719-llvm-f34d0e0875ce48c68ccc746c873a5f379e6cb1b4.zip |
Allocate LayoutInputSections using SpecificBumpPtrAllocator.
llvm-svn: 278453
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 34 | ||||
-rw-r--r-- | lld/ELF/LinkerScript.h | 5 |
2 files changed, 19 insertions, 20 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 5fc7e35ecac..f6712d32043 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -89,6 +89,9 @@ template <class ELFT> static bool isDiscarded(InputSectionBase<ELFT> *S) { return !S || !S->Live; } +template <class ELFT> LinkerScript<ELFT>::LinkerScript() {} +template <class ELFT> LinkerScript<ELFT>::~LinkerScript() {} + template <class ELFT> bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) { for (StringRef Pat : Opt.KeptSections) @@ -132,8 +135,6 @@ LinkerScript<ELFT>::getInputSections(const InputSectionDescription *I) { return Ret; } -namespace { - // You can define new symbols using linker scripts. For example, // ".text { abc.o(.text); foo = .; def.o(.text); }" defines symbol // foo just after abc.o's text section contents. This class is to @@ -143,9 +144,10 @@ namespace { // keep symbol definitions in output sections. Because output sections // can contain only input sections, we wrap symbol definitions // with dummy input sections. This class serves that purpose. -template <class ELFT> class LayoutInputSection : public InputSectionBase<ELFT> { +template <class ELFT> +class elf::LayoutInputSection : public InputSectionBase<ELFT> { public: - LayoutInputSection(SymbolAssignment *Cmd); + explicit LayoutInputSection(SymbolAssignment *Cmd); static bool classof(const InputSectionBase<ELFT> *S); SymbolAssignment *Cmd; @@ -155,6 +157,7 @@ private: // Helper class, which builds output section list, also // creating symbol sections, when needed +namespace { template <class ELFT> class OutputSectionBuilder { public: OutputSectionBuilder(OutputSectionFactory<ELFT> &F, @@ -162,9 +165,7 @@ public: : Factory(F), OutputSections(Out) {} void addSection(StringRef OutputName, InputSectionBase<ELFT> *I); - void addSymbol(SymbolAssignment *Cmd) { - PendingSymbols.emplace_back(new LayoutInputSection<ELFT>(Cmd)); - } + void addSymbol(LayoutInputSection<ELFT> *S) { PendingSymbols.push_back(S); } void flushSymbols(); void flushSection(); @@ -172,14 +173,8 @@ private: OutputSectionFactory<ELFT> &Factory; std::vector<OutputSectionBase<ELFT> *> *OutputSections; OutputSectionBase<ELFT> *Current = nullptr; - std::vector<std::unique_ptr<LayoutInputSection<ELFT>>> PendingSymbols; - static std::vector<std::unique_ptr<LayoutInputSection<ELFT>>> OwningSections; + std::vector<LayoutInputSection<ELFT> *> PendingSymbols; }; - -template <class ELFT> -std::vector<std::unique_ptr<LayoutInputSection<ELFT>>> - OutputSectionBuilder<ELFT>::OwningSections; - } // anonymous namespace template <class T> static T *zero(T *Val) { @@ -215,14 +210,12 @@ void OutputSectionBuilder<ELFT>::addSection(StringRef OutputName, template <class ELFT> void OutputSectionBuilder<ELFT>::flushSymbols() { // Only regular output sections are supported. if (dyn_cast_or_null<OutputSection<ELFT>>(Current)) { - for (std::unique_ptr<LayoutInputSection<ELFT>> &I : PendingSymbols) { + for (LayoutInputSection<ELFT> *I : PendingSymbols) { if (I->Cmd->Name == ".") { - Current->addSection(I.get()); - OwningSections.push_back(std::move(I)); + Current->addSection(I); } else if (shouldDefine<ELFT>(I->Cmd)) { addSynthetic<ELFT>(I->Cmd, Current); - Current->addSection(I.get()); - OwningSections.push_back(std::move(I)); + Current->addSection(I); } } } @@ -282,7 +275,8 @@ void LinkerScript<ELFT>::createSections( } for (const std::unique_ptr<BaseCommand> &Base2 : Cmd->Commands) { if (auto *Cmd2 = dyn_cast<SymbolAssignment>(Base2.get())) { - Builder.addSymbol(Cmd2); + Builder.addSymbol(new (LAlloc.Allocate()) + LayoutInputSection<ELFT>(Cmd2)); continue; } auto *Cmd2 = cast<InputSectionDescription>(Base2.get()); diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index acc8e483950..866326ab82e 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -25,6 +25,7 @@ template <class ELFT> class InputSectionBase; template <class ELFT> class OutputSectionBase; template <class ELFT> class OutputSectionFactory; template <class ELFT> class DefinedCommon; +template <class ELFT> class LayoutInputSection; typedef std::function<uint64_t(uint64_t)> Expr; @@ -138,6 +139,8 @@ template <class ELFT> class LinkerScript { typedef typename ELFT::uint uintX_t; public: + LinkerScript(); + ~LinkerScript(); void createSections(OutputSectionFactory<ELFT> &Factory); std::vector<PhdrEntry<ELFT>> createPhdrs(); @@ -167,6 +170,8 @@ private: std::vector<size_t> getPhdrIndices(StringRef SectionName); size_t getPhdrIndex(StringRef PhdrName); + llvm::SpecificBumpPtrAllocator<LayoutInputSection<ELFT>> LAlloc; + uintX_t Dot; }; |