diff options
-rw-r--r-- | lld/ELF/Config.h | 4 | ||||
-rw-r--r-- | lld/ELF/Driver.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 8 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 8 |
4 files changed, 12 insertions, 10 deletions
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 60e2c0941f4..084d58a32a3 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -16,6 +16,7 @@ #include "llvm/Support/CachePruning.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/ELF.h" +#include "llvm/Support/Endian.h" #include <vector> @@ -175,6 +176,9 @@ struct Configuration { // True if the target is little-endian. False if the target is big-endian. bool IsLE; + // endianness::little if IsLE is true. endianness::big otherwise. + llvm::support::endianness Endianness; + // True if the target is the little-endian MIPS64. // // The reason why we have this variable only for the MIPS is because diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 1689c8e9002..53e28b37acd 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -715,6 +715,8 @@ static void setConfigs() { Config->CopyRelocs = (Config->Relocatable || Config->EmitRelocs); Config->IsLE = (Kind == ELF32LEKind || Kind == ELF64LEKind); + Config->Endianness = + Config->IsLE ? support::endianness::little : support::endianness::big; Config->IsMips64EL = (Kind == ELF64LEKind && Machine == EM_MIPS); Config->IsRela = Is64 || IsX32 || Config->MipsN32Abi; Config->Pic = Config->Pie || Config->Shared; diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index c36d55236ff..b80b8135621 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -945,20 +945,18 @@ uint32_t LinkerScriptBase::getFiller(StringRef Name) { } static void writeInt(uint8_t *Buf, uint64_t Data, uint64_t Size) { - const endianness E = Config->IsLE ? endianness::little : endianness::big; - switch (Size) { case 1: *Buf = (uint8_t)Data; break; case 2: - write16(Buf, Data, E); + write16(Buf, Data, Config->Endianness); break; case 4: - write32(Buf, Data, E); + write32(Buf, Data, Config->Endianness); break; case 8: - write64(Buf, Data, E); + write64(Buf, Data, Config->Endianness); break; default: llvm_unreachable("unsupported Size argument"); diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 03e2d99f82d..08af575a374 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -324,7 +324,7 @@ BuildIdSection::BuildIdSection() HashSize(getHashSize()) {} void BuildIdSection::writeTo(uint8_t *Buf) { - const endianness E = Config->IsLE ? endianness::little : endianness::big; + endianness E = Config->Endianness; write32(Buf, 4, E); // Name size write32(Buf + 4, HashSize, E); // Content size write32(Buf + 8, NT_GNU_BUILD_ID, E); // Type @@ -846,12 +846,10 @@ uint64_t MipsGotSection::getGp() const { } static void writeUint(uint8_t *Buf, uint64_t Val) { - support::endianness E = - Config->IsLE ? support::endianness::little : support::endianness::big; if (Config->Wordsize == 8) - write64(Buf, Val, E); + write64(Buf, Val, Config->Endianness); else - write32(Buf, Val, E); + write32(Buf, Val, Config->Endianness); } void MipsGotSection::writeTo(uint8_t *Buf) { |