diff --git a/test/Object/Inputs/COFF/i386.yaml b/test/Object/Inputs/COFF/i386.yaml index ca902220c13..aec7a5813cf 100644 --- a/test/Object/Inputs/COFF/i386.yaml +++ b/test/Object/Inputs/COFF/i386.yaml @@ -1,5 +1,6 @@ header: !Header Machine: IMAGE_FILE_MACHINE_I386 # (0x14c) + Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ] sections: - !Section diff --git a/test/Object/yaml2obj-readobj.test b/test/Object/yaml2obj-readobj.test new file mode 100644 index 00000000000..545ccc48aa4 --- /dev/null +++ b/test/Object/yaml2obj-readobj.test @@ -0,0 +1,5 @@ +RUN: yaml2obj %p/Inputs/COFF/i386.yaml | llvm-readobj -file-headers - | FileCheck %s --check-prefix COFF-I386 + +// COFF-I386: Characteristics [ (0x200) +// COFF-I386-NEXT: IMAGE_FILE_DEBUG_STRIPPED (0x200) +// COFF-I386-NEXT: ] diff --git a/utils/yaml2obj/yaml2obj.cpp b/utils/yaml2obj/yaml2obj.cpp index 2f01d198600..17b65ae870d 100644 --- a/utils/yaml2obj/yaml2obj.cpp +++ b/utils/yaml2obj/yaml2obj.cpp @@ -129,6 +129,7 @@ namespace COFFYAML { struct Header { COFF::MachineTypes Machine; + std::vector Characteristics; }; struct Symbol { @@ -159,6 +160,18 @@ struct COFFParser { StringTable.append(4, 0); } + void parseHeader() { + Header.Machine = Obj.HeaderData.Machine; + + const std::vector &Characteristics = + Obj.HeaderData.Characteristics; + for (std::vector::const_iterator I = + Characteristics.begin(), E = Characteristics.end(); I != E; ++I) { + uint16_t Characteristic = *I; + Header.Characteristics |= Characteristic; + } + } + bool parseSections() { for (std::vector::iterator i = Obj.Sections.begin(), e = Obj.Sections.end(); i != e; ++i) { @@ -239,7 +252,7 @@ struct COFFParser { } bool parse() { - Header.Machine = Obj.HeaderData.Machine; + parseHeader(); if (!parseSections()) return false; if (!parseSymbols()) @@ -409,6 +422,7 @@ void writeCOFF(COFFParser &CP, raw_ostream &OS) { LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation) LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::SectionCharacteristics) +LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::Characteristics) LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section) LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol) @@ -510,6 +524,27 @@ struct ScalarEnumerationTraits { } }; +template <> +struct ScalarEnumerationTraits { + static void enumeration(IO &IO, COFF::Characteristics &Value) { + ECase(IMAGE_FILE_RELOCS_STRIPPED); + ECase(IMAGE_FILE_EXECUTABLE_IMAGE); + ECase(IMAGE_FILE_LINE_NUMS_STRIPPED); + ECase(IMAGE_FILE_LOCAL_SYMS_STRIPPED); + ECase(IMAGE_FILE_AGGRESSIVE_WS_TRIM); + ECase(IMAGE_FILE_LARGE_ADDRESS_AWARE); + ECase(IMAGE_FILE_BYTES_REVERSED_LO); + ECase(IMAGE_FILE_32BIT_MACHINE); + ECase(IMAGE_FILE_DEBUG_STRIPPED); + ECase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP); + ECase(IMAGE_FILE_NET_RUN_FROM_SWAP); + ECase(IMAGE_FILE_SYSTEM); + ECase(IMAGE_FILE_DLL); + ECase(IMAGE_FILE_UP_SYSTEM_ONLY); + ECase(IMAGE_FILE_BYTES_REVERSED_HI); + } +}; + template <> struct ScalarEnumerationTraits { static void enumeration(IO &IO, COFF::SectionCharacteristics &Value) { @@ -605,6 +640,7 @@ template <> struct MappingTraits { static void mapping(IO &IO, COFFYAML::Header &H) { IO.mapRequired("Machine", H.Machine); + IO.mapOptional("Characteristics", H.Characteristics); } };