// 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.
: 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;
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
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();
// 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.
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>;
};
InputSection *createInterpSection();
-template <class ELFT> MergeInputSection *createCommentSection();
+MergeInputSection *createCommentSection();
void decompressSections();
void mergeSections();