diff --git a/include/llvm/Object/ELFYAML.h b/include/llvm/Object/ELFYAML.h index fca965f3dbf..1eba6602082 100644 --- a/include/llvm/Object/ELFYAML.h +++ b/include/llvm/Object/ELFYAML.h @@ -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 { static void enumeration(IO &IO, ELFYAML::ELF_ELFOSABI &Value); }; +template <> +struct ScalarBitSetTraits { + static void bitset(IO &IO, ELFYAML::ELF_EF &Value); +}; + template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, ELFYAML::ELF_SHT &Value); diff --git a/lib/Object/ELFYAML.cpp b/lib/Object/ELFYAML.cpp index 2f35cf9b103..d51367026a6 100644 --- a/lib/Object/ELFYAML.cpp +++ b/lib/Object/ELFYAML.cpp @@ -237,6 +237,48 @@ void ScalarEnumerationTraits::enumeration( #undef ECase } +void ScalarBitSetTraits::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::enumeration( IO &IO, ELFYAML::ELF_SHT &Value) { #define ECase(X) IO.enumCase(Value, #X, ELF::X); @@ -299,6 +341,7 @@ void MappingTraits::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)); } diff --git a/test/Object/yaml2obj-elf-file-headers-with-e_flags.yaml b/test/Object/yaml2obj-elf-file-headers-with-e_flags.yaml new file mode 100644 index 00000000000..19cc91e235c --- /dev/null +++ b/test/Object/yaml2obj-elf-file-headers-with-e_flags.yaml @@ -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: ] diff --git a/tools/yaml2obj/yaml2elf.cpp b/tools/yaml2obj/yaml2elf.cpp index bc0cd317813..e79ddcd8242 100644 --- a/tools/yaml2obj/yaml2elf.cpp +++ b/tools/yaml2obj/yaml2elf.cpp @@ -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.