[lld] r321235 - Detemplate createCommentSection.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 20 17:21:59 PST 2017
Author: rafael
Date: Wed Dec 20 17:21:59 2017
New Revision: 321235
URL: http://llvm.org/viewvc/llvm-project?rev=321235&view=rev
Log:
Detemplate createCommentSection.
It was only templated so it could create a dummy section header that
was immediately parsed back.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/SyntheticSections.h
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=321235&r1=321234&r2=321235&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Dec 20 17:21:59 2017
@@ -1111,7 +1111,7 @@ template <class ELFT> void LinkerDriver:
// before decompressAndMergeSections because the .comment section is a
// mergeable section.
if (!Config->Relocatable)
- InputSections.push_back(createCommentSection<ELFT>());
+ InputSections.push_back(createCommentSection());
// Do size optimizations: garbage collection, merging of SHF_MERGE sections
// and identical code folding.
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=321235&r1=321234&r2=321235&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Dec 20 17:21:59 2017
@@ -88,6 +88,12 @@ InputSectionBase::InputSectionBase(Input
: SectionBase(SectionKind, Name, Flags, Entsize, Alignment, Type, Info,
Link),
File(File), Data(Data) {
+ // In order to reduce memory allocation, we assume that mergeable
+ // sections are smaller than 4 GiB, which is not an unreasonable
+ // assumption as of 2017.
+ if (SectionKind == SectionBase::Merge && Data.size() > UINT32_MAX)
+ error(toString(this) + ": section too large");
+
NumRelocations = 0;
AreRelocsRela = false;
@@ -911,13 +917,13 @@ template <class ELFT>
MergeInputSection::MergeInputSection(ObjFile<ELFT> *F,
const typename ELFT::Shdr *Header,
StringRef Name)
- : InputSectionBase(F, Header, Name, InputSectionBase::Merge) {
- // In order to reduce memory allocation, we assume that mergeable
- // sections are smaller than 4 GiB, which is not an unreasonable
- // assumption as of 2017.
- if (Data.size() > UINT32_MAX)
- error(toString(this) + ": section too large");
-}
+ : InputSectionBase(F, Header, Name, InputSectionBase::Merge) {}
+
+MergeInputSection::MergeInputSection(uint64_t Flags, uint32_t Type,
+ uint64_t Entsize, ArrayRef<uint8_t> Data,
+ StringRef Name)
+ : InputSectionBase(nullptr, Flags, Type, Entsize, /*Link*/ 0, /*Info*/ 0,
+ /*Alignment*/ Entsize, Data, Name, SectionBase::Merge) {}
// This function is called after we obtain a complete list of input sections
// that need to be linked. This is responsible to split section contents
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=321235&r1=321234&r2=321235&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Dec 20 17:21:59 2017
@@ -218,6 +218,9 @@ public:
template <class ELFT>
MergeInputSection(ObjFile<ELFT> *F, const typename ELFT::Shdr *Header,
StringRef Name);
+ MergeInputSection(uint64_t Flags, uint32_t Type, uint64_t Entsize,
+ ArrayRef<uint8_t> Data, StringRef Name);
+
static bool classof(const SectionBase *S) { return S->kind() == Merge; }
void splitIntoPieces();
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=321235&r1=321234&r2=321235&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Dec 20 17:21:59 2017
@@ -81,17 +81,9 @@ static ArrayRef<uint8_t> getVersion() {
// With this feature, you can identify LLD-generated binaries easily
// by "readelf --string-dump .comment <file>".
// The returned object is a mergeable string section.
-template <class ELFT> MergeInputSection *elf::createCommentSection() {
- typename ELFT::Shdr Hdr = {};
- Hdr.sh_flags = SHF_MERGE | SHF_STRINGS;
- Hdr.sh_type = SHT_PROGBITS;
- Hdr.sh_entsize = 1;
- Hdr.sh_addralign = 1;
-
- auto *Ret =
- make<MergeInputSection>((ObjFile<ELFT> *)nullptr, &Hdr, ".comment");
- Ret->Data = getVersion();
- return Ret;
+MergeInputSection *elf::createCommentSection() {
+ return make<MergeInputSection>(SHF_MERGE | SHF_STRINGS, SHT_PROGBITS, 1,
+ getVersion(), ".comment");
}
// .MIPS.abiflags section.
@@ -2649,11 +2641,6 @@ template void PltSection::addEntry<ELF32
template void PltSection::addEntry<ELF64LE>(Symbol &Sym);
template void PltSection::addEntry<ELF64BE>(Symbol &Sym);
-template MergeInputSection *elf::createCommentSection<ELF32LE>();
-template MergeInputSection *elf::createCommentSection<ELF32BE>();
-template MergeInputSection *elf::createCommentSection<ELF64LE>();
-template MergeInputSection *elf::createCommentSection<ELF64BE>();
-
template class elf::MipsAbiFlagsSection<ELF32LE>;
template class elf::MipsAbiFlagsSection<ELF32BE>;
template class elf::MipsAbiFlagsSection<ELF64LE>;
Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=321235&r1=321234&r2=321235&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Wed Dec 20 17:21:59 2017
@@ -812,7 +812,7 @@ private:
};
InputSection *createInterpSection();
-template <class ELFT> MergeInputSection *createCommentSection();
+MergeInputSection *createCommentSection();
void decompressSections();
void mergeSections();
More information about the llvm-commits
mailing list