diff options
-rw-r--r-- | lld/ELF/Driver.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/InputSection.cpp | 20 | ||||
-rw-r--r-- | lld/ELF/InputSection.h | 3 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 19 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.h | 2 |
5 files changed, 21 insertions, 25 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 2b6925031b0..6b94fed7385 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1111,7 +1111,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { // 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. diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index a2b3e642e55..6ce31cf2d53 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -88,6 +88,12 @@ InputSectionBase::InputSectionBase(InputFile *File, uint64_t Flags, : 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 diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index dfd78a8fb45..7bddb22da1c 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -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(); diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 25dc250df51..5538254a145 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -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<ELF32BE>(Symbol &Sym); 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>; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index deca7154766..ea7a2ca6e7b 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -812,7 +812,7 @@ private: }; InputSection *createInterpSection(); -template <class ELFT> MergeInputSection *createCommentSection(); +MergeInputSection *createCommentSection(); void decompressSections(); void mergeSections(); |