From f34d0e0875ce48c68ccc746c873a5f379e6cb1b4 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 12 Aug 2016 01:24:53 +0000 Subject: [PATCH] Allocate LayoutInputSections using SpecificBumpPtrAllocator. llvm-svn: 278453 --- lld/ELF/LinkerScript.cpp | 34 ++++++++++++++-------------------- 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 5fc7e35..f6712d3 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -89,6 +89,9 @@ template static bool isDiscarded(InputSectionBase *S) { return !S || !S->Live; } +template LinkerScript::LinkerScript() {} +template LinkerScript::~LinkerScript() {} + template bool LinkerScript::shouldKeep(InputSectionBase *S) { for (StringRef Pat : Opt.KeptSections) @@ -132,8 +135,6 @@ LinkerScript::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 LayoutInputSection : public InputSectionBase { +template +class elf::LayoutInputSection : public InputSectionBase { public: - LayoutInputSection(SymbolAssignment *Cmd); + explicit LayoutInputSection(SymbolAssignment *Cmd); static bool classof(const InputSectionBase *S); SymbolAssignment *Cmd; @@ -155,6 +157,7 @@ private: // Helper class, which builds output section list, also // creating symbol sections, when needed +namespace { template class OutputSectionBuilder { public: OutputSectionBuilder(OutputSectionFactory &F, @@ -162,9 +165,7 @@ public: : Factory(F), OutputSections(Out) {} void addSection(StringRef OutputName, InputSectionBase *I); - void addSymbol(SymbolAssignment *Cmd) { - PendingSymbols.emplace_back(new LayoutInputSection(Cmd)); - } + void addSymbol(LayoutInputSection *S) { PendingSymbols.push_back(S); } void flushSymbols(); void flushSection(); @@ -172,14 +173,8 @@ private: OutputSectionFactory &Factory; std::vector *> *OutputSections; OutputSectionBase *Current = nullptr; - std::vector>> PendingSymbols; - static std::vector>> OwningSections; + std::vector *> PendingSymbols; }; - -template -std::vector>> - OutputSectionBuilder::OwningSections; - } // anonymous namespace template static T *zero(T *Val) { @@ -215,14 +210,12 @@ void OutputSectionBuilder::addSection(StringRef OutputName, template void OutputSectionBuilder::flushSymbols() { // Only regular output sections are supported. if (dyn_cast_or_null>(Current)) { - for (std::unique_ptr> &I : PendingSymbols) { + for (LayoutInputSection *I : PendingSymbols) { if (I->Cmd->Name == ".") { - Current->addSection(I.get()); - OwningSections.push_back(std::move(I)); + Current->addSection(I); } else if (shouldDefine(I->Cmd)) { addSynthetic(I->Cmd, Current); - Current->addSection(I.get()); - OwningSections.push_back(std::move(I)); + Current->addSection(I); } } } @@ -282,7 +275,8 @@ void LinkerScript::createSections( } for (const std::unique_ptr &Base2 : Cmd->Commands) { if (auto *Cmd2 = dyn_cast(Base2.get())) { - Builder.addSymbol(Cmd2); + Builder.addSymbol(new (LAlloc.Allocate()) + LayoutInputSection(Cmd2)); continue; } auto *Cmd2 = cast(Base2.get()); diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index acc8e48..866326a 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -25,6 +25,7 @@ template class InputSectionBase; template class OutputSectionBase; template class OutputSectionFactory; template class DefinedCommon; +template class LayoutInputSection; typedef std::function Expr; @@ -138,6 +139,8 @@ template class LinkerScript { typedef typename ELFT::uint uintX_t; public: + LinkerScript(); + ~LinkerScript(); void createSections(OutputSectionFactory &Factory); std::vector> createPhdrs(); @@ -167,6 +170,8 @@ private: std::vector getPhdrIndices(StringRef SectionName); size_t getPhdrIndex(StringRef PhdrName); + llvm::SpecificBumpPtrAllocator> LAlloc; + uintX_t Dot; }; -- 2.7.4