[yaml2obj/obj2yaml/llvm-readobj] Support printing and parsing AVR-specific e_flags

The `e_flags` contains a mixture of bitfields and regular ones, ensure all of them can be serialized and deserialized.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D100250
This commit is contained in:
LemonBoy 2021-04-15 15:52:54 +02:00
parent 9345f9fa5d
commit 24185541ca
5 changed files with 80 additions and 19 deletions
llvm
include/llvm/BinaryFormat
lib/ObjectYAML
test
Object
tools/llvm-readobj/ELF
tools/llvm-readobj

View File

@ -485,7 +485,12 @@ enum : unsigned {
EF_AVR_ARCH_XMEGA4 = 104,
EF_AVR_ARCH_XMEGA5 = 105,
EF_AVR_ARCH_XMEGA6 = 106,
EF_AVR_ARCH_XMEGA7 = 107
EF_AVR_ARCH_XMEGA7 = 107,
EF_AVR_ARCH_MASK = 0x7f, // EF_AVR_ARCH_xxx selection mask
EF_AVR_LINKRELAX_PREPARED = 0x80, // The file is prepared for linker
// relaxation to be applied
};
// ELF Relocation types for AVR

View File

@ -473,23 +473,25 @@ void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
BCase(EF_HEXAGON_ISA_V68);
break;
case ELF::EM_AVR:
BCase(EF_AVR_ARCH_AVR1);
BCase(EF_AVR_ARCH_AVR2);
BCase(EF_AVR_ARCH_AVR25);
BCase(EF_AVR_ARCH_AVR3);
BCase(EF_AVR_ARCH_AVR31);
BCase(EF_AVR_ARCH_AVR35);
BCase(EF_AVR_ARCH_AVR4);
BCase(EF_AVR_ARCH_AVR51);
BCase(EF_AVR_ARCH_AVR6);
BCase(EF_AVR_ARCH_AVRTINY);
BCase(EF_AVR_ARCH_XMEGA1);
BCase(EF_AVR_ARCH_XMEGA2);
BCase(EF_AVR_ARCH_XMEGA3);
BCase(EF_AVR_ARCH_XMEGA4);
BCase(EF_AVR_ARCH_XMEGA5);
BCase(EF_AVR_ARCH_XMEGA6);
BCase(EF_AVR_ARCH_XMEGA7);
BCaseMask(EF_AVR_ARCH_AVR1, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVR2, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVR25, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVR3, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVR31, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVR35, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVR4, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVR5, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVR51, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVR6, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_AVRTINY, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_XMEGA1, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_XMEGA2, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_XMEGA3, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_XMEGA4, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_XMEGA5, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_XMEGA6, EF_AVR_ARCH_MASK);
BCaseMask(EF_AVR_ARCH_XMEGA7, EF_AVR_ARCH_MASK);
BCase(EF_AVR_LINKRELAX_PREPARED);
break;
case ELF::EM_RISCV:
BCase(EF_RISCV_RVC);

View File

@ -685,7 +685,7 @@ Symbols:
# ELF-AVR-NEXT: Data: ELFDATA2LSB
# ELF-AVR-NEXT: Type: ET_EXEC
# ELF-AVR-NEXT: Machine: EM_AVR
# ELF-AVR-NEXT: Flags: [ EF_AVR_ARCH_AVR2 ]
# ELF-AVR-NEXT: Flags: [ EF_AVR_ARCH_AVR2, EF_AVR_LINKRELAX_PREPARED ]
# ELF-AVR-NEXT: ProgramHeaders:
# ELF-AVR-NEXT: - Type: PT_LOAD
# ELF-AVR-NEXT: Flags: [ PF_X, PF_R ]

View File

@ -0,0 +1,25 @@
# RUN: yaml2obj %s -o %t -DFLAG_NAME=EF_AVR_ARCH_AVR51
# RUN: llvm-readobj -h %t | FileCheck %s -DFLAG_NAME=EF_AVR_ARCH_AVR51 -DFLAG_VALUE=0x33
# RUN: yaml2obj %s -o %t -DFLAG_NAME="EF_AVR_ARCH_AVR2, EF_AVR_LINKRELAX_PREPARED"
# RUN: llvm-readobj -h %t | FileCheck %s --check-prefixes=DOUBLE -DFLAG0_NAME=EF_AVR_ARCH_AVR2 -DFLAG1_NAME=EF_AVR_LINKRELAX_PREPARED -DFLAG_VALUE=0x82
--- !ELF
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
OSABI: ELFOSABI_NONE
ABIVersion: 0
Type: ET_REL
Machine: EM_AVR
Flags: [ [[FLAG_NAME]] ]
# CHECK: Flags [ ([[FLAG_VALUE]])
# CHECK-NEXT: [[FLAG_NAME]] ([[FLAG_VALUE]])
# CHECK-NEXT: ]
# DOUBLE: Flags [ ([[FLAG_VALUE]])
# DOUBLE-NEXT: [[FLAG0_NAME]]
# DOUBLE-NEXT: [[FLAG1_NAME]]
# DOUBLE-NEXT: ]

View File

@ -1544,6 +1544,29 @@ static const EnumEntry<unsigned> ElfHeaderRISCVFlags[] = {
ENUM_ENT(EF_RISCV_RVE, "RVE")
};
static const EnumEntry<unsigned> ElfHeaderAVRFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR1),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR2),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR25),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR3),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR31),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR35),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR4),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR5),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR51),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR6),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVRTINY),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_XMEGA1),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_XMEGA2),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_XMEGA3),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_XMEGA4),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_XMEGA5),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_XMEGA6),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_XMEGA7),
ENUM_ENT(EF_AVR_LINKRELAX_PREPARED, "relaxable"),
};
static const EnumEntry<unsigned> ElfSymOtherFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, STV_INTERNAL),
LLVM_READOBJ_ENUM_ENT(ELF, STV_HIDDEN),
@ -3229,6 +3252,9 @@ template <class ELFT> void GNUELFDumper<ELFT>::printFileHeaders() {
unsigned(ELF::EF_MIPS_MACH));
else if (e.e_machine == EM_RISCV)
ElfFlags = printFlags(e.e_flags, makeArrayRef(ElfHeaderRISCVFlags));
else if (e.e_machine == EM_AVR)
ElfFlags = printFlags(e.e_flags, makeArrayRef(ElfHeaderAVRFlags),
unsigned(ELF::EF_AVR_ARCH_MASK));
Str = "0x" + to_hexString(e.e_flags);
if (!ElfFlags.empty())
Str = Str + ", " + ElfFlags;
@ -6210,6 +6236,9 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printFileHeaders() {
}
} else if (E.e_machine == EM_RISCV)
W.printFlags("Flags", E.e_flags, makeArrayRef(ElfHeaderRISCVFlags));
else if (E.e_machine == EM_AVR)
W.printFlags("Flags", E.e_flags, makeArrayRef(ElfHeaderAVRFlags),
unsigned(ELF::EF_AVR_ARCH_MASK));
else
W.printFlags("Flags", E.e_flags);
W.printNumber("HeaderSize", E.e_ehsize);