[yaml2obj] Add support for ELF e_flags.

Summary:
The FileHeader mapping now accepts an optional Flags sequence that accepts
the EF_<arch>_<flag> constants. When not given, Flags defaults to zero.

Reviewers: atanasyan

Reviewed By: atanasyan

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D3213

llvm-svn: 205173
This commit is contained in:
Daniel Sanders 2014-03-31 09:44:05 +00:00
parent ae43aae96a
commit 9cf3d3b764
4 changed files with 68 additions and 0 deletions

View File

@ -37,6 +37,8 @@ LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_EM)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFCLASS)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFDATA)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_ELFOSABI)
// Just use 64, since it can hold 32-bit values too.
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_EF)
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_SHT)
// Just use 64, since it can hold 32-bit values too.
LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
@ -50,6 +52,7 @@ struct FileHeader {
ELF_ELFOSABI OSABI;
ELF_ET Type;
ELF_EM Machine;
ELF_EF Flags;
llvm::yaml::Hex64 Entry;
};
struct Symbol {
@ -117,6 +120,11 @@ struct ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI> {
static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value);
};
template <>
struct ScalarBitSetTraits<ELFYAML::ELF_EF> {
static void bitset(IO &IO, ELFYAML::ELF_EF &Value);
};
template <>
struct ScalarEnumerationTraits<ELFYAML::ELF_SHT> {
static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value);

View File

@ -237,6 +237,48 @@ void ScalarEnumerationTraits<ELFYAML::ELF_ELFOSABI>::enumeration(
#undef ECase
}
void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO,
ELFYAML::ELF_EF &Value) {
#define BCase(X) IO.bitSetCase(Value, #X, ELF::X);
BCase(EF_ARM_SOFT_FLOAT)
BCase(EF_ARM_VFP_FLOAT)
BCase(EF_ARM_EABI_UNKNOWN)
BCase(EF_ARM_EABI_VER1)
BCase(EF_ARM_EABI_VER2)
BCase(EF_ARM_EABI_VER3)
BCase(EF_ARM_EABI_VER4)
BCase(EF_ARM_EABI_VER5)
BCase(EF_ARM_EABIMASK)
BCase(EF_MIPS_NOREORDER)
BCase(EF_MIPS_PIC)
BCase(EF_MIPS_CPIC)
BCase(EF_MIPS_ABI2)
BCase(EF_MIPS_32BITMODE)
BCase(EF_MIPS_ABI_O32)
BCase(EF_MIPS_MICROMIPS)
BCase(EF_MIPS_ARCH_ASE_M16)
BCase(EF_MIPS_ARCH_1)
BCase(EF_MIPS_ARCH_2)
BCase(EF_MIPS_ARCH_3)
BCase(EF_MIPS_ARCH_4)
BCase(EF_MIPS_ARCH_5)
BCase(EF_MIPS_ARCH_32)
BCase(EF_MIPS_ARCH_64)
BCase(EF_MIPS_ARCH_32R2)
BCase(EF_MIPS_ARCH_64R2)
BCase(EF_MIPS_ARCH)
BCase(EF_HEXAGON_MACH_V2)
BCase(EF_HEXAGON_MACH_V3)
BCase(EF_HEXAGON_MACH_V4)
BCase(EF_HEXAGON_MACH_V5)
BCase(EF_HEXAGON_ISA_MACH)
BCase(EF_HEXAGON_ISA_V2)
BCase(EF_HEXAGON_ISA_V3)
BCase(EF_HEXAGON_ISA_V4)
BCase(EF_HEXAGON_ISA_V5)
#undef BCase
}
void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
IO &IO, ELFYAML::ELF_SHT &Value) {
#define ECase(X) IO.enumCase(Value, #X, ELF::X);
@ -299,6 +341,7 @@ void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
IO.mapOptional("OSABI", FileHdr.OSABI, ELFYAML::ELF_ELFOSABI(0));
IO.mapRequired("Type", FileHdr.Type);
IO.mapRequired("Machine", FileHdr.Machine);
IO.mapOptional("Flags", FileHdr.Flags, ELFYAML::ELF_EF(0));
IO.mapOptional("Entry", FileHdr.Entry, Hex64(0));
}

View File

@ -0,0 +1,16 @@
# RUN: yaml2obj -format=elf %s | llvm-readobj -file-headers - | FileCheck %s
!ELF
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_MIPS
Flags: [ EF_MIPS_NOREORDER, EF_MIPS_ABI_O32 ]
# CHECK: Format: ELF32-mips
# CHECK: Arch: mipsel
# CHECK: Machine: EM_MIPS
# CHECK: Flags [ (0x1001)
# CHECK-NEXT: 0x1
# CHECK-NEXT: 0x1000
# CHECK-NEXT: ]

View File

@ -261,6 +261,7 @@ static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) {
Header.e_machine = Hdr.Machine;
Header.e_version = EV_CURRENT;
Header.e_entry = Hdr.Entry;
Header.e_flags = Hdr.Flags;
Header.e_ehsize = sizeof(Elf_Ehdr);
// TODO: Flesh out section header support.