Skip to content

Commit

Permalink
[Object,ELFType] Rename TargetEndianness to Endianness (#86604)
Browse files Browse the repository at this point in the history
`TargetEndianness` is long and unwieldy. "Target" in the name is confusing. Rename it to "Endianness".

I cannot find noticeable out-of-tree users of `TargetEndianness`, but
keep `TargetEndianness` to make this patch safer. `TargetEndianness`
will be removed by a subsequent change.
  • Loading branch information
MaskRay authored Mar 28, 2024
1 parent 7789ec0 commit 2763353
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 138 deletions.
6 changes: 3 additions & 3 deletions lld/ELF/Arch/Mips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ bool MIPS<ELFT>::needsThunk(RelExpr expr, RelType type, const InputFile *file,

template <class ELFT>
int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *buf, RelType type) const {
const endianness e = ELFT::TargetEndianness;
const endianness e = ELFT::Endianness;
switch (type) {
case R_MIPS_32:
case R_MIPS_REL32:
Expand Down Expand Up @@ -521,7 +521,7 @@ static uint64_t fixupCrossModeJump(uint8_t *loc, RelType type, uint64_t val) {
// to a microMIPS target and vice versa. In that cases jump
// instructions need to be replaced by their "cross-mode"
// equivalents.
const endianness e = ELFT::TargetEndianness;
const endianness e = ELFT::Endianness;
bool isMicroTgt = val & 0x1;
bool isCrossJump = (isMicroTgt && isBranchReloc(type)) ||
(!isMicroTgt && isMicroBranchReloc(type));
Expand Down Expand Up @@ -567,7 +567,7 @@ static uint64_t fixupCrossModeJump(uint8_t *loc, RelType type, uint64_t val) {
template <class ELFT>
void MIPS<ELFT>::relocate(uint8_t *loc, const Relocation &rel,
uint64_t val) const {
const endianness e = ELFT::TargetEndianness;
const endianness e = ELFT::Endianness;
RelType type = rel.type;

if (ELFT::Is64Bits || config->mipsN32Abi)
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/DWARF.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject {
StringRef getLineStrSection() const override { return lineStrSection; }

bool isLittleEndian() const override {
return ELFT::TargetEndianness == llvm::endianness::little;
return ELFT::Endianness == llvm::endianness::little;
}

std::optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec,
Expand Down
6 changes: 3 additions & 3 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ template <class ELFT> static uint32_t readAndFeatures(const InputSection &sec) {
const uint8_t *place = desc.data();
if (desc.size() < 8)
reportFatal(place, "program property is too short");
uint32_t type = read32<ELFT::TargetEndianness>(desc.data());
uint32_t size = read32<ELFT::TargetEndianness>(desc.data() + 4);
uint32_t type = read32<ELFT::Endianness>(desc.data());
uint32_t size = read32<ELFT::Endianness>(desc.data() + 4);
desc = desc.slice(8);
if (desc.size() < size)
reportFatal(place, "program property is too short");
Expand All @@ -983,7 +983,7 @@ template <class ELFT> static uint32_t readAndFeatures(const InputSection &sec) {
// accumulate the bits set.
if (size < 4)
reportFatal(place, "FEATURE_1_AND entry is too short");
featuresSet |= read32<ELFT::TargetEndianness>(desc.data());
featuresSet |= read32<ELFT::Endianness>(desc.data());
}

// Padding is present in the note descriptor, if necessary.
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/InputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,10 +1258,10 @@ void EhInputSection::split(ArrayRef<RelTy> rels) {
msg = "CIE/FDE too small";
break;
}
uint64_t size = endian::read32<ELFT::TargetEndianness>(d.data());
uint64_t size = endian::read32<ELFT::Endianness>(d.data());
if (size == 0) // ZERO terminator
break;
uint32_t id = endian::read32<ELFT::TargetEndianness>(d.data() + 4);
uint32_t id = endian::read32<ELFT::Endianness>(d.data() + 4);
size += 4;
if (LLVM_UNLIKELY(size > d.size())) {
// If it is 0xFFFFFFFF, the next 8 bytes contain the size instead,
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void EhFrameSection::addRecords(EhInputSection *sec, ArrayRef<RelTy> rels) {
for (EhSectionPiece &cie : sec->cies)
offsetToCie[cie.inputOff] = addCie<ELFT>(cie, rels);
for (EhSectionPiece &fde : sec->fdes) {
uint32_t id = endian::read32<ELFT::TargetEndianness>(fde.data().data() + 4);
uint32_t id = endian::read32<ELFT::Endianness>(fde.data().data() + 4);
CieRecord *rec = offsetToCie[fde.inputOff + 4 - id];
if (!rec)
fatal(toString(sec) + ": invalid CIE reference");
Expand Down Expand Up @@ -448,7 +448,7 @@ void EhFrameSection::iterateFDEWithLSDAAux(
if (hasLSDA(cie))
ciesWithLSDA.insert(cie.inputOff);
for (EhSectionPiece &fde : sec.fdes) {
uint32_t id = endian::read32<ELFT::TargetEndianness>(fde.data().data() + 4);
uint32_t id = endian::read32<ELFT::Endianness>(fde.data().data() + 4);
if (!ciesWithLSDA.contains(fde.inputOff + 4 - id))
continue;

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class DLLImportDefinitionGenerator : public DefinitionGenerator {
: ES(ES), L(L) {}

static Expected<unsigned> getTargetPointerSize(const Triple &TT);
static Expected<llvm::endianness> getTargetEndianness(const Triple &TT);
static Expected<llvm::endianness> getEndianness(const Triple &TT);
Expected<std::unique_ptr<jitlink::LinkGraph>>
createStubsGraph(const SymbolMap &Resolved);

Expand Down
16 changes: 7 additions & 9 deletions llvm/include/llvm/Object/ELFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
if (Contents[0] != ELFAttrs::Format_Version || Contents.size() == 1)
return Error::success();

if (Error E = Attributes.parse(Contents, ELFT::TargetEndianness))
if (Error E = Attributes.parse(Contents, ELFT::Endianness))
return E;
break;
}
Expand Down Expand Up @@ -482,7 +482,7 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
bool isDyldType() const { return isDyldELFObject; }
static bool classof(const Binary *v) {
return v->getType() ==
getELFType(ELFT::TargetEndianness == llvm::endianness::little,
getELFType(ELFT::Endianness == llvm::endianness::little,
ELFT::Is64Bits);
}

Expand Down Expand Up @@ -1155,10 +1155,9 @@ ELFObjectFile<ELFT>::ELFObjectFile(MemoryBufferRef Object, ELFFile<ELFT> EF,
const Elf_Shdr *DotDynSymSec,
const Elf_Shdr *DotSymtabSec,
const Elf_Shdr *DotSymtabShndx)
: ELFObjectFileBase(
getELFType(ELFT::TargetEndianness == llvm::endianness::little,
ELFT::Is64Bits),
Object),
: ELFObjectFileBase(getELFType(ELFT::Endianness == llvm::endianness::little,
ELFT::Is64Bits),
Object),
EF(EF), DotDynSymSec(DotDynSymSec), DotSymtabSec(DotSymtabSec),
DotSymtabShndxSec(DotSymtabShndx) {}

Expand Down Expand Up @@ -1226,8 +1225,7 @@ uint8_t ELFObjectFile<ELFT>::getBytesInAddress() const {

template <class ELFT>
StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
constexpr bool IsLittleEndian =
ELFT::TargetEndianness == llvm::endianness::little;
constexpr bool IsLittleEndian = ELFT::Endianness == llvm::endianness::little;
switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
case ELF::ELFCLASS32:
switch (EF.getHeader().e_machine) {
Expand Down Expand Up @@ -1305,7 +1303,7 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
}

template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
bool IsLittleEndian = ELFT::TargetEndianness == llvm::endianness::little;
bool IsLittleEndian = ELFT::Endianness == llvm::endianness::little;
switch (EF.getHeader().e_machine) {
case ELF::EM_68K:
return Triple::m68k;
Expand Down
101 changes: 51 additions & 50 deletions llvm/include/llvm/Object/ELFTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ template <endianness E, bool Is64> struct ELFType {

public:
static const endianness TargetEndianness = E;
static const endianness Endianness = E;
static const bool Is64Bits = Is64;

using uint = std::conditional_t<Is64, uint64_t, uint32_t>;
Expand Down Expand Up @@ -145,9 +146,9 @@ using ELF64BE = ELFType<llvm::endianness::big, true>;
// Section header.
template <class ELFT> struct Elf_Shdr_Base;

template <endianness TargetEndianness>
struct Elf_Shdr_Base<ELFType<TargetEndianness, false>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
template <endianness Endianness>
struct Elf_Shdr_Base<ELFType<Endianness, false>> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
Elf_Word sh_name; // Section name (index into string table)
Elf_Word sh_type; // Section type (SHT_*)
Elf_Word sh_flags; // Section flags (SHF_*)
Expand All @@ -160,9 +161,9 @@ struct Elf_Shdr_Base<ELFType<TargetEndianness, false>> {
Elf_Word sh_entsize; // Size of records contained within the section
};

template <endianness TargetEndianness>
struct Elf_Shdr_Base<ELFType<TargetEndianness, true>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
template <endianness Endianness>
struct Elf_Shdr_Base<ELFType<Endianness, true>> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
Elf_Word sh_name; // Section name (index into string table)
Elf_Word sh_type; // Section type (SHT_*)
Elf_Xword sh_flags; // Section flags (SHF_*)
Expand Down Expand Up @@ -190,9 +191,9 @@ struct Elf_Shdr_Impl : Elf_Shdr_Base<ELFT> {

template <class ELFT> struct Elf_Sym_Base;

template <endianness TargetEndianness>
struct Elf_Sym_Base<ELFType<TargetEndianness, false>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
template <endianness Endianness>
struct Elf_Sym_Base<ELFType<Endianness, false>> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
Elf_Word st_name; // Symbol name (index into string table)
Elf_Addr st_value; // Value or address associated with the symbol
Elf_Word st_size; // Size of the symbol
Expand All @@ -201,9 +202,9 @@ struct Elf_Sym_Base<ELFType<TargetEndianness, false>> {
Elf_Half st_shndx; // Which section (header table index) it's defined in
};

template <endianness TargetEndianness>
struct Elf_Sym_Base<ELFType<TargetEndianness, true>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
template <endianness Endianness>
struct Elf_Sym_Base<ELFType<Endianness, true>> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
Elf_Word st_name; // Symbol name (index into string table)
unsigned char st_info; // Symbol's type and binding attributes
unsigned char st_other; // Must be zero; reserved
Expand Down Expand Up @@ -349,19 +350,19 @@ struct Elf_Vernaux_Impl {
/// table section (.dynamic) look like.
template <class ELFT> struct Elf_Dyn_Base;

template <endianness TargetEndianness>
struct Elf_Dyn_Base<ELFType<TargetEndianness, false>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
template <endianness Endianness>
struct Elf_Dyn_Base<ELFType<Endianness, false>> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
Elf_Sword d_tag;
union {
Elf_Word d_val;
Elf_Addr d_ptr;
} d_un;
};

template <endianness TargetEndianness>
struct Elf_Dyn_Base<ELFType<TargetEndianness, true>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
template <endianness Endianness>
struct Elf_Dyn_Base<ELFType<Endianness, true>> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
Elf_Sxword d_tag;
union {
Elf_Xword d_val;
Expand All @@ -381,9 +382,9 @@ struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> {
uintX_t getPtr() const { return d_un.d_ptr; }
};

template <endianness TargetEndianness>
struct Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
template <endianness Endianness>
struct Elf_Rel_Impl<ELFType<Endianness, false>, false> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
static const bool IsRela = false;
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
Elf_Word r_info; // Symbol table index and type of relocation to apply
Expand Down Expand Up @@ -416,17 +417,17 @@ struct Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
}
};

template <endianness TargetEndianness>
struct Elf_Rel_Impl<ELFType<TargetEndianness, false>, true>
: public Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
template <endianness Endianness>
struct Elf_Rel_Impl<ELFType<Endianness, false>, true>
: public Elf_Rel_Impl<ELFType<Endianness, false>, false> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
static const bool IsRela = true;
Elf_Sword r_addend; // Compute value for relocatable field by adding this
};

template <endianness TargetEndianness>
struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
template <endianness Endianness>
struct Elf_Rel_Impl<ELFType<Endianness, true>, false> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
static const bool IsRela = false;
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
Elf_Xword r_info; // Symbol table index and type of relocation to apply
Expand Down Expand Up @@ -469,10 +470,10 @@ struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
}
};

template <endianness TargetEndianness>
struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, true>
: public Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
template <endianness Endianness>
struct Elf_Rel_Impl<ELFType<Endianness, true>, true>
: public Elf_Rel_Impl<ELFType<Endianness, true>, false> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
static const bool IsRela = true;
Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
};
Expand Down Expand Up @@ -504,9 +505,9 @@ struct Elf_Ehdr_Impl {
unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; }
};

template <endianness TargetEndianness>
struct Elf_Phdr_Impl<ELFType<TargetEndianness, false>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
template <endianness Endianness>
struct Elf_Phdr_Impl<ELFType<Endianness, false>> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
Elf_Word p_type; // Type of segment
Elf_Off p_offset; // FileOffset where segment is located, in bytes
Elf_Addr p_vaddr; // Virtual Address of beginning of segment
Expand All @@ -517,9 +518,9 @@ struct Elf_Phdr_Impl<ELFType<TargetEndianness, false>> {
Elf_Word p_align; // Segment alignment constraint
};

template <endianness TargetEndianness>
struct Elf_Phdr_Impl<ELFType<TargetEndianness, true>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
template <endianness Endianness>
struct Elf_Phdr_Impl<ELFType<Endianness, true>> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
Elf_Word p_type; // Type of segment
Elf_Word p_flags; // Segment flags
Elf_Off p_offset; // FileOffset where segment is located, in bytes
Expand Down Expand Up @@ -574,17 +575,17 @@ struct Elf_GnuHash_Impl {

// Compressed section headers.
// http://www.sco.com/developers/gabi/latest/ch4.sheader.html#compression_header
template <endianness TargetEndianness>
struct Elf_Chdr_Impl<ELFType<TargetEndianness, false>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
template <endianness Endianness>
struct Elf_Chdr_Impl<ELFType<Endianness, false>> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
Elf_Word ch_type;
Elf_Word ch_size;
Elf_Word ch_addralign;
};

template <endianness TargetEndianness>
struct Elf_Chdr_Impl<ELFType<TargetEndianness, true>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
template <endianness Endianness>
struct Elf_Chdr_Impl<ELFType<Endianness, true>> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
Elf_Word ch_type;
Elf_Word ch_reserved;
Elf_Xword ch_size;
Expand Down Expand Up @@ -742,17 +743,17 @@ template <class ELFT> struct Elf_CGProfile_Impl {
template <class ELFT>
struct Elf_Mips_RegInfo;

template <llvm::endianness TargetEndianness>
struct Elf_Mips_RegInfo<ELFType<TargetEndianness, false>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
template <llvm::endianness Endianness>
struct Elf_Mips_RegInfo<ELFType<Endianness, false>> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
Elf_Word ri_gprmask; // bit-mask of used general registers
Elf_Word ri_cprmask[4]; // bit-mask of used co-processor registers
Elf_Addr ri_gp_value; // gp register value
};

template <llvm::endianness TargetEndianness>
struct Elf_Mips_RegInfo<ELFType<TargetEndianness, true>> {
LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
template <llvm::endianness Endianness>
struct Elf_Mips_RegInfo<ELFType<Endianness, true>> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
Elf_Word ri_gprmask; // bit-mask of used general registers
Elf_Word ri_pad; // unused padding field
Elf_Word ri_cprmask[4]; // bit-mask of used co-processor registers
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ ELFLinkGraphBuilder<ELFT>::ELFLinkGraphBuilder(
StringRef FileName, LinkGraph::GetEdgeKindNameFunction GetEdgeKindName)
: ELFLinkGraphBuilderBase(std::make_unique<LinkGraph>(
FileName.str(), Triple(std::move(TT)), std::move(Features),
ELFT::Is64Bits ? 8 : 4, llvm::endianness(ELFT::TargetEndianness),
ELFT::Is64Bits ? 8 : 4, llvm::endianness(ELFT::Endianness),
std::move(GetEdgeKindName))),
Obj(Obj) {
LLVM_DEBUG(
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ DLLImportDefinitionGenerator::getTargetPointerSize(const Triple &TT) {
}

Expected<llvm::endianness>
DLLImportDefinitionGenerator::getTargetEndianness(const Triple &TT) {
DLLImportDefinitionGenerator::getEndianness(const Triple &TT) {
switch (TT.getArch()) {
case Triple::x86_64:
return llvm::endianness::little;
Expand All @@ -562,7 +562,7 @@ DLLImportDefinitionGenerator::createStubsGraph(const SymbolMap &Resolved) {
auto PointerSize = getTargetPointerSize(TT);
if (!PointerSize)
return PointerSize.takeError();
auto Endianness = getTargetEndianness(TT);
auto Endianness = getEndianness(TT);
if (!Endianness)
return Endianness.takeError();

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/InterfaceStub/ELFObjHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void initELFHeader(typename ELFT::Ehdr &ElfHeader, uint16_t Machine) {
ElfHeader.e_ident[EI_MAG2] = ElfMagic[EI_MAG2];
ElfHeader.e_ident[EI_MAG3] = ElfMagic[EI_MAG3];
ElfHeader.e_ident[EI_CLASS] = ELFT::Is64Bits ? ELFCLASS64 : ELFCLASS32;
bool IsLittleEndian = ELFT::TargetEndianness == llvm::endianness::little;
bool IsLittleEndian = ELFT::Endianness == llvm::endianness::little;
ElfHeader.e_ident[EI_DATA] = IsLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
ElfHeader.e_ident[EI_VERSION] = EV_CURRENT;
ElfHeader.e_ident[EI_OSABI] = ELFOSABI_NONE;
Expand Down
Loading

0 comments on commit 2763353

Please sign in to comment.