[lld] r256437 - Do not use SpecificBumpPtrAllocator to create output sections.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 25 23:01:27 PST 2015
Author: ruiu
Date: Sat Dec 26 01:01:26 2015
New Revision: 256437
URL: http://llvm.org/viewvc/llvm-project?rev=256437&view=rev
Log:
Do not use SpecificBumpPtrAllocator to create output sections.
The number of output sections is usually limited, so the cost
of allocating them is not a bottleneck. This patch simplifies
the code by removing the allocators.
Modified:
lld/trunk/ELF/OutputSections.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=256437&r1=256436&r2=256437&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Sat Dec 26 01:01:26 2015
@@ -107,11 +107,11 @@ public:
virtual void finalize() {}
virtual void writeTo(uint8_t *Buf) = 0;
+ virtual ~OutputSectionBase() = default;
protected:
StringRef Name;
Elf_Shdr Header;
- ~OutputSectionBase() = default;
};
template <class ELFT> class GotSection final : public OutputSectionBase<ELFT> {
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=256437&r1=256436&r2=256437&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sat Dec 26 01:01:26 2015
@@ -76,12 +76,9 @@ private:
std::unique_ptr<llvm::FileOutputBuffer> Buffer;
- SpecificBumpPtrAllocator<OutputSection<ELFT>> SecAlloc;
- SpecificBumpPtrAllocator<MergeOutputSection<ELFT>> MSecAlloc;
- SpecificBumpPtrAllocator<EHOutputSection<ELFT>> EHSecAlloc;
- SpecificBumpPtrAllocator<MipsReginfoOutputSection<ELFT>> MReginfoSecAlloc;
BumpPtrAllocator Alloc;
std::vector<OutputSectionBase<ELFT> *> OutputSections;
+ std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> OwningSections;
unsigned getNumSections() const { return OutputSections.size() + 1; }
void addStartStopSymbols(OutputSectionBase<ELFT> *Sec);
@@ -468,8 +465,9 @@ static bool compareOutputSections(Output
template <class ELFT> OutputSection<ELFT> *Writer<ELFT>::getBSS() {
if (!Out<ELFT>::Bss) {
- Out<ELFT>::Bss = new (SecAlloc.Allocate())
- OutputSection<ELFT>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
+ Out<ELFT>::Bss =
+ new OutputSection<ELFT>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
+ OwningSections.emplace_back(Out<ELFT>::Bss);
OutputSections.push_back(Out<ELFT>::Bss);
}
return Out<ELFT>::Bss;
@@ -625,14 +623,13 @@ Writer<ELFT>::createOutputSection(InputS
uintX_t Type, uintX_t Flags) {
switch (C->SectionKind) {
case InputSectionBase<ELFT>::Regular:
- return new (SecAlloc.Allocate()) OutputSection<ELFT>(Name, Type, Flags);
+ return new OutputSection<ELFT>(Name, Type, Flags);
case InputSectionBase<ELFT>::EHFrame:
- return new (EHSecAlloc.Allocate()) EHOutputSection<ELFT>(Name, Type, Flags);
+ return new EHOutputSection<ELFT>(Name, Type, Flags);
case InputSectionBase<ELFT>::Merge:
- return new (MSecAlloc.Allocate())
- MergeOutputSection<ELFT>(Name, Type, Flags);
+ return new MergeOutputSection<ELFT>(Name, Type, Flags);
case InputSectionBase<ELFT>::MipsReginfo:
- return new (MReginfoSecAlloc.Allocate()) MipsReginfoOutputSection<ELFT>();
+ return new MipsReginfoOutputSection<ELFT>();
}
llvm_unreachable("Unknown output section type");
}
@@ -668,6 +665,7 @@ template <class ELFT> void Writer<ELFT>:
OutputSectionBase<ELFT> *&Sec = Map[Key];
if (!Sec) {
Sec = createOutputSection(C, Key.Name, Key.Type, Key.Flags);
+ OwningSections.emplace_back(Sec);
OutputSections.push_back(Sec);
RegularSections.push_back(Sec);
}
@@ -793,10 +791,11 @@ template <class ELFT> void Writer<ELFT>:
// See "Dynamic section" in Chapter 5 in the following document:
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
if (Config->EMachine == EM_MIPS && !Config->Shared) {
- Out<ELFT>::MipsRldMap = new (SecAlloc.Allocate())
- OutputSection<ELFT>(".rld_map", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ Out<ELFT>::MipsRldMap = new OutputSection<ELFT>(".rld_map", SHT_PROGBITS,
+ SHF_ALLOC | SHF_WRITE);
Out<ELFT>::MipsRldMap->setSize(ELFT::Is64Bits ? 8 : 4);
Out<ELFT>::MipsRldMap->updateAlign(ELFT::Is64Bits ? 8 : 4);
+ OwningSections.emplace_back(Out<ELFT>::MipsRldMap);
OutputSections.push_back(Out<ELFT>::MipsRldMap);
}
}
More information about the llvm-commits
mailing list