Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -15,6 +15,7 @@ #include "llvm/ADT/StringSet.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/ELF.h" +#include "llvm/Support/Endian.h" #include @@ -206,6 +207,12 @@ bool isMips64EL() const { return EMachine == llvm::ELF::EM_MIPS && EKind == ELF64LEKind; } + + llvm::support::endianness getEndian() const { + return (EKind == ELF32LEKind || EKind == ELF64LEKind) + ? llvm::support::endianness::little + : llvm::support::endianness::big; + } }; // The only instance of Configuration struct. Index: ELF/SyntheticSections.h =================================================================== --- ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -135,7 +135,7 @@ }; // .note.gnu.build-id section. -template class BuildIdSection : public SyntheticSection { +class BuildIdSection : public SyntheticSection { // First 16 bytes are a header. static const unsigned HeaderSize = 16; @@ -760,7 +760,7 @@ // Linker generated sections which can be used as inputs. template struct In { static InputSection *ARMAttributes; - static BuildIdSection *BuildId; + static BuildIdSection *BuildId; static BssSection *Bss; static BssSection *BssRelRo; static InputSection *Common; @@ -794,7 +794,7 @@ template InputSection *In::ARMAttributes; template BssSection *In::Bss; template BssSection *In::BssRelRo; -template BuildIdSection *In::BuildId; +template BuildIdSection *In::BuildId; template InputSection *In::Common; template DynamicSection *In::Dynamic; template StringTableSection *In::DynStrTab; Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -330,16 +330,15 @@ } } -template -BuildIdSection::BuildIdSection() +BuildIdSection::BuildIdSection() : SyntheticSection(SHF_ALLOC, SHT_NOTE, 1, ".note.gnu.build-id"), HashSize(getHashSize()) {} -template void BuildIdSection::writeTo(uint8_t *Buf) { - const endianness E = ELFT::TargetEndianness; - write32(Buf, 4); // Name size - write32(Buf + 4, HashSize); // Content size - write32(Buf + 8, NT_GNU_BUILD_ID); // Type +void BuildIdSection::writeTo(uint8_t *Buf) { + const endianness E = Config->getEndian(); + write32(Buf, 4, E); // Name size + write32(Buf + 4, HashSize, E); // Content size + write32(Buf + 8, NT_GNU_BUILD_ID, E); // Type memcpy(Buf + 12, "GNU", 4); // Name string HashBuf = Buf + 16; } @@ -361,8 +360,7 @@ // In order to utilize multiple cores, we first split data into 1MB // chunks, compute a hash for each chunk, and then compute a hash value // of the hash values. -template -void BuildIdSection::computeHash( +void BuildIdSection::computeHash( llvm::ArrayRef Data, std::function Arr)> HashFn) { std::vector> Chunks = split(Data, 1024 * 1024); @@ -385,8 +383,7 @@ return this->Size - Size; } -template -void BuildIdSection::writeBuildId(ArrayRef Buf) { +void BuildIdSection::writeBuildId(ArrayRef Buf) { switch (Config->BuildId) { case BuildIdKind::Fast: computeHash(Buf, [](uint8_t *Dest, ArrayRef Arr) { @@ -2302,11 +2299,6 @@ template class elf::MipsReginfoSection; template class elf::MipsReginfoSection; -template class elf::BuildIdSection; -template class elf::BuildIdSection; -template class elf::BuildIdSection; -template class elf::BuildIdSection; - template class elf::GotSection; template class elf::GotSection; template class elf::GotSection; Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -357,7 +357,7 @@ } if (Config->BuildId != BuildIdKind::None) { - In::BuildId = make>(); + In::BuildId = make(); Add(In::BuildId); }