[llvm] 2418554 - [yaml2obj/obj2yaml/llvm-readobj] Support printing and parsing AVR-specific e_flags
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 15 06:54:36 PDT 2021
Author: LemonBoy
Date: 2021-04-15T15:54:28+02:00
New Revision: 24185541ca48bd7ed089a4dbf57bdcb91e290508
URL: https://github.com/llvm/llvm-project/commit/24185541ca48bd7ed089a4dbf57bdcb91e290508
DIFF: https://github.com/llvm/llvm-project/commit/24185541ca48bd7ed089a4dbf57bdcb91e290508.diff
LOG: [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
Added:
llvm/test/tools/llvm-readobj/ELF/avr-elf-headers.test
Modified:
llvm/include/llvm/BinaryFormat/ELF.h
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/Object/obj2yaml.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index 0118b55524ce2..7dd8cfd279819 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -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
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index cdeb37f9a6d26..70dc2d10735d8 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -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);
diff --git a/llvm/test/Object/obj2yaml.test b/llvm/test/Object/obj2yaml.test
index f0f25ace3c1a0..05860471e9126 100644
--- a/llvm/test/Object/obj2yaml.test
+++ b/llvm/test/Object/obj2yaml.test
@@ -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 ]
diff --git a/llvm/test/tools/llvm-readobj/ELF/avr-elf-headers.test b/llvm/test/tools/llvm-readobj/ELF/avr-elf-headers.test
new file mode 100644
index 0000000000000..928c5f064556b
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/avr-elf-headers.test
@@ -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: ]
+
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 55162dd8f2df5..45c61a61b0284 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -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);
More information about the llvm-commits
mailing list