Index: llvm/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml +++ llvm/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml @@ -51,10 +51,9 @@ # INVALID: --- !ELF # INVALID-NEXT: FileHeader: -# INVALID-NEXT: Class: ELFCLASS32 -# INVALID-NEXT: Data: ELFDATA2MSB -# INVALID-NEXT: Type: ET_DYN -# INVALID-NEXT: Machine: EM_NONE +# INVALID-NEXT: Class: ELFCLASS32 +# INVALID-NEXT: Data: ELFDATA2MSB +# INVALID-NEXT: Type: ET_DYN # INVALID-NEXT: Sections: # INVALID-NEXT: - Name: .empty # INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE Index: llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml +++ llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml @@ -24,10 +24,9 @@ # CASE1: --- !ELF # CASE1-NEXT: FileHeader: -# CASE1-NEXT: Class: ELFCLASS64 -# CASE1-NEXT: Data: ELFDATA2LSB -# CASE1-NEXT: Type: ET_REL -# CASE1-NEXT: Machine: EM_NONE +# CASE1-NEXT: Class: ELFCLASS64 +# CASE1-NEXT: Data: ELFDATA2LSB +# CASE1-NEXT: Type: ET_REL # CASE1-NEXT: Sections: # CASE1-NEXT: - Name: .foo # CASE1-NEXT: Type: SHT_PROGBITS Index: llvm/test/tools/obj2yaml/ELF/emachine.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/emachine.yaml +++ llvm/test/tools/obj2yaml/ELF/emachine.yaml @@ -2,38 +2,36 @@ ## Check it dumps an unknown e_machine as a number. -# RUN: yaml2obj --docnum=1 %s -o %t1 -# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=UNKNOWN +# RUN: yaml2obj -DMACHINE=0x1234 %s -o %t1 +# RUN: obj2yaml %t1 | FileCheck %s -DMACHINE=0x1234 -# UNKNOWN: --- !ELF -# UNKNOWN-NEXT: FileHeader: -# UNKNOWN-NEXT: Class: ELFCLASS64 -# UNKNOWN-NEXT: Data: ELFDATA2MSB -# UNKNOWN-NEXT: Type: ET_REL -# UNKNOWN-NEXT: Machine: 0x1234 +# CHECK: --- !ELF +# CHECK-NEXT: FileHeader: +# CHECK-NEXT: Class: ELFCLASS64 +# CHECK-NEXT: Data: ELFDATA2MSB +# CHECK-NEXT: Type: ET_REL +# CHECK-NEXT: Machine: [[MACHINE]] --- !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2MSB Type: ET_REL - Machine: 0x1234 + Machine: [[MACHINE]] ## Check it dumps a known e_machine value as an enum string. -# RUN: yaml2obj --docnum=2 %s -o %t2 -# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=KNOWN +# RUN: yaml2obj %s -DMACHINE=0x1 -o %t2 +# RUN: obj2yaml %t2 | FileCheck %s -DMACHINE=EM_M32 -# KNOWN: --- !ELF -# KNOWN-NEXT: FileHeader: -# KNOWN-NEXT: Class: ELFCLASS64 -# KNOWN-NEXT: Data: ELFDATA2MSB -# KNOWN-NEXT: Type: ET_REL -# KNOWN-NEXT: Machine: EM_NONE +## Check it doesn't dump e_machine when it is EM_NONE (0). ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2MSB - Type: ET_REL - Machine: 0 +# RUN: yaml2obj %s -DMACHINE=0x0 -o %t3 +# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=DEFAULT + +# DEFAULT: --- !ELF +# DEFAULT-NEXT: FileHeader: +# DEFAULT-NEXT: Class: ELFCLASS64 +# DEFAULT-NEXT: Data: ELFDATA2MSB +# DEFAULT-NEXT: Type: ET_REL +# DEFAULT-NEXT: ... Index: llvm/test/tools/obj2yaml/ELF/gnu-unique-symbols.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/gnu-unique-symbols.yaml +++ llvm/test/tools/obj2yaml/ELF/gnu-unique-symbols.yaml @@ -5,11 +5,10 @@ # CHECK: --- !ELF # CHECK-NEXT: FileHeader: -# CHECK-NEXT: Class: ELFCLASS64 -# CHECK-NEXT: Data: ELFDATA2LSB -# CHECK-NEXT: OSABI: ELFOSABI_GNU -# CHECK-NEXT: Type: ET_REL -# CHECK-NEXT: Machine: EM_NONE +# CHECK-NEXT: Class: ELFCLASS64 +# CHECK-NEXT: Data: ELFDATA2LSB +# CHECK-NEXT: OSABI: ELFOSABI_GNU +# CHECK-NEXT: Type: ET_REL # CHECK-NEXT: Symbols: # CHECK-NEXT: - Name: foo # CHECK-NEXT: Type: STT_OBJECT Index: llvm/test/tools/obj2yaml/ELF/implicit-sections-order.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/implicit-sections-order.yaml +++ llvm/test/tools/obj2yaml/ELF/implicit-sections-order.yaml @@ -34,10 +34,9 @@ # OUTPUT: --- !ELF # OUTPUT-NEXT: FileHeader: -# OUTPUT-NEXT: Class: ELFCLASS64 -# OUTPUT-NEXT: Data: ELFDATA2LSB -# OUTPUT-NEXT: Type: ET_DYN -# OUTPUT-NEXT: Machine: EM_NONE +# OUTPUT-NEXT: Class: ELFCLASS64 +# OUTPUT-NEXT: Data: ELFDATA2LSB +# OUTPUT-NEXT: Type: ET_DYN # OUTPUT-NEXT: Sections: # OUTPUT-NEXT: - Name: .foo.1 # OUTPUT-NEXT: Type: SHT_PROGBITS @@ -124,10 +123,9 @@ ## SHT_STRTAB/SHT_SYMTAB/SHT_DYNSYM sections. # OUTPUT2: --- !ELF # OUTPUT2-NEXT: FileHeader: -# OUTPUT2-NEXT: Class: ELFCLASS64 -# OUTPUT2-NEXT: Data: ELFDATA2LSB -# OUTPUT2-NEXT: Type: ET_DYN -# OUTPUT2-NEXT: Machine: EM_NONE +# OUTPUT2-NEXT: Class: ELFCLASS64 +# OUTPUT2-NEXT: Data: ELFDATA2LSB +# OUTPUT2-NEXT: Type: ET_DYN # OUTPUT2-NEXT: Sections: # OUTPUT2-NEXT: - Name: .foo.1 # OUTPUT2-NEXT: Type: SHT_PROGBITS Index: llvm/test/tools/obj2yaml/ELF/invalid-section-name.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/invalid-section-name.yaml +++ llvm/test/tools/obj2yaml/ELF/invalid-section-name.yaml @@ -8,10 +8,9 @@ # CHECK: --- !ELF # CHECK-NEXT: FileHeader: -# CHECK-NEXT: Class: ELFCLASS64 -# CHECK-NEXT: Data: ELFDATA2LSB -# CHECK-NEXT: Type: ET_REL -# CHECK-NEXT: Machine: EM_NONE +# CHECK-NEXT: Class: ELFCLASS64 +# CHECK-NEXT: Data: ELFDATA2LSB +# CHECK-NEXT: Type: ET_REL # CHECK-NEXT: Sections: # CHECK-NEXT: - Name: "{{.*}}" # CHECK-NEXT: Type: SHT_PROGBITS Index: llvm/test/tools/obj2yaml/ELF/no-symtab.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/no-symtab.yaml +++ llvm/test/tools/obj2yaml/ELF/no-symtab.yaml @@ -6,10 +6,9 @@ # NOSYMTAB: --- !ELF # NOSYMTAB-NEXT: FileHeader: -# NOSYMTAB-NEXT: Class: ELFCLASS64 -# NOSYMTAB-NEXT: Data: ELFDATA2LSB -# NOSYMTAB-NEXT: Type: ET_DYN -# NOSYMTAB-NEXT: Machine: EM_NONE +# NOSYMTAB-NEXT: Class: ELFCLASS64 +# NOSYMTAB-NEXT: Data: ELFDATA2LSB +# NOSYMTAB-NEXT: Type: ET_DYN # NOSYMTAB-NEXT: ... --- !ELF @@ -26,10 +25,9 @@ # SYMTAB: --- !ELF # SYMTAB-NEXT: FileHeader: -# SYMTAB-NEXT: Class: ELFCLASS64 -# SYMTAB-NEXT: Data: ELFDATA2LSB -# SYMTAB-NEXT: Type: ET_DYN -# SYMTAB-NEXT: Machine: EM_NONE +# SYMTAB-NEXT: Class: ELFCLASS64 +# SYMTAB-NEXT: Data: ELFDATA2LSB +# SYMTAB-NEXT: Type: ET_DYN # SYMTAB-NEXT: Symbols: [] # SYMTAB-NEXT: ... Index: llvm/test/tools/obj2yaml/ELF/null-section.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/null-section.yaml +++ llvm/test/tools/obj2yaml/ELF/null-section.yaml @@ -6,10 +6,9 @@ # FIRST-SEC: --- !ELF # FIRST-SEC-NEXT: FileHeader: -# FIRST-SEC-NEXT: Class: ELFCLASS64 -# FIRST-SEC-NEXT: Data: ELFDATA2LSB -# FIRST-SEC-NEXT: Type: ET_REL -# FIRST-SEC-NEXT: Machine: EM_NONE +# FIRST-SEC-NEXT: Class: ELFCLASS64 +# FIRST-SEC-NEXT: Data: ELFDATA2LSB +# FIRST-SEC-NEXT: Type: ET_REL # FIRST-SEC-NEXT: Sections: # FIRST-SEC-NEXT: - Type: SHT_NULL # FIRST-SEC-NEXT: Flags: [ SHF_ALLOC ] @@ -48,10 +47,9 @@ # SECOND-SEC: --- !ELF # SECOND-SEC-NEXT: FileHeader: -# SECOND-SEC-NEXT: Class: ELFCLASS64 -# SECOND-SEC-NEXT: Data: ELFDATA2LSB -# SECOND-SEC-NEXT: Type: ET_REL -# SECOND-SEC-NEXT: Machine: EM_NONE +# SECOND-SEC-NEXT: Class: ELFCLASS64 +# SECOND-SEC-NEXT: Data: ELFDATA2LSB +# SECOND-SEC-NEXT: Type: ET_REL # SECOND-SEC-NEXT: Sections: # SECOND-SEC-NEXT: - Name: .foo # SECOND-SEC-NEXT: Type: SHT_PROGBITS @@ -91,10 +89,9 @@ # NULL-SEC: --- !ELF # NULL-SEC-NEXT: FileHeader: -# NULL-SEC-NEXT: Class: ELFCLASS64 -# NULL-SEC-NEXT: Data: ELFDATA2LSB -# NULL-SEC-NEXT: Type: ET_REL -# NULL-SEC-NEXT: Machine: EM_NONE +# NULL-SEC-NEXT: Class: ELFCLASS64 +# NULL-SEC-NEXT: Data: ELFDATA2LSB +# NULL-SEC-NEXT: Type: ET_REL # NULL-SEC-NEXT: Sections: # NULL-SEC-NEXT: - Name: .foo # NULL-SEC-NEXT: Type: SHT_PROGBITS @@ -118,10 +115,9 @@ # NULL-SEC-MIDDLE: --- !ELF # NULL-SEC-MIDDLE-NEXT: FileHeader: -# NULL-SEC-MIDDLE-NEXT: Class: ELFCLASS64 -# NULL-SEC-MIDDLE-NEXT: Data: ELFDATA2LSB -# NULL-SEC-MIDDLE-NEXT: Type: ET_REL -# NULL-SEC-MIDDLE-NEXT: Machine: EM_NONE +# NULL-SEC-MIDDLE-NEXT: Class: ELFCLASS64 +# NULL-SEC-MIDDLE-NEXT: Data: ELFDATA2LSB +# NULL-SEC-MIDDLE-NEXT: Type: ET_REL # NULL-SEC-MIDDLE-NEXT: Sections: # NULL-SEC-MIDDLE-NEXT: - Name: .foo # NULL-SEC-MIDDLE-NEXT: Type: SHT_PROGBITS Index: llvm/test/tools/obj2yaml/ELF/sht-symtab-shndx.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/sht-symtab-shndx.yaml +++ llvm/test/tools/obj2yaml/ELF/sht-symtab-shndx.yaml @@ -7,10 +7,9 @@ # CASE1: --- !ELF # CASE1-NEXT: FileHeader: -# CASE1-NEXT: Class: ELFCLASS64 -# CASE1-NEXT: Data: ELFDATA2LSB -# CASE1-NEXT: Type: ET_REL -# CASE1-NEXT: Machine: EM_NONE +# CASE1-NEXT: Class: ELFCLASS64 +# CASE1-NEXT: Data: ELFDATA2LSB +# CASE1-NEXT: Type: ET_REL # CASE1-NEXT: Sections: # CASE1-NEXT: - Name: bar # CASE1-NEXT: Type: SHT_PROGBITS Index: llvm/test/tools/obj2yaml/ELF/stack-sizes.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/stack-sizes.yaml +++ llvm/test/tools/obj2yaml/ELF/stack-sizes.yaml @@ -8,10 +8,9 @@ # VALID: --- !ELF # VALID-NEXT: FileHeader: -# VALID-NEXT: Class: ELFCLASS64 -# VALID-NEXT: Data: ELFDATA2LSB -# VALID-NEXT: Type: ET_EXEC -# VALID-NEXT: Machine: EM_NONE +# VALID-NEXT: Class: ELFCLASS64 +# VALID-NEXT: Data: ELFDATA2LSB +# VALID-NEXT: Type: ET_EXEC # VALID-NEXT: Sections: # VALID-NEXT: - Name: .stack_sizes # VALID-NEXT: Type: SHT_PROGBITS @@ -39,10 +38,9 @@ # INVALID: --- !ELF # INVALID-NEXT: FileHeader: -# INVALID-NEXT: Class: ELFCLASS64 -# INVALID-NEXT: Data: ELFDATA2LSB -# INVALID-NEXT: Type: ET_EXEC -# INVALID-NEXT: Machine: EM_NONE +# INVALID-NEXT: Class: ELFCLASS64 +# INVALID-NEXT: Data: ELFDATA2LSB +# INVALID-NEXT: Type: ET_EXEC # INVALID-NEXT: Sections: # INVALID-NEXT: - Name: .stack_sizes # INVALID-NEXT: Type: SHT_PROGBITS @@ -65,10 +63,9 @@ # EMPTY: --- !ELF # EMPTY-NEXT: FileHeader: -# EMPTY-NEXT: Class: ELFCLASS64 -# EMPTY-NEXT: Data: ELFDATA2LSB -# EMPTY-NEXT: Type: ET_EXEC -# EMPTY-NEXT: Machine: EM_NONE +# EMPTY-NEXT: Class: ELFCLASS64 +# EMPTY-NEXT: Data: ELFDATA2LSB +# EMPTY-NEXT: Type: ET_EXEC # EMPTY-NEXT: Sections: # EMPTY-NEXT: - Name: .stack_sizes # EMPTY-NEXT: Type: SHT_PROGBITS @@ -91,10 +88,9 @@ # MULTI: --- !ELF # MULTI-NEXT: FileHeader: -# MULTI-NEXT: Class: ELFCLASS64 -# MULTI-NEXT: Data: ELFDATA2LSB -# MULTI-NEXT: Type: ET_EXEC -# MULTI-NEXT: Machine: EM_NONE +# MULTI-NEXT: Class: ELFCLASS64 +# MULTI-NEXT: Data: ELFDATA2LSB +# MULTI-NEXT: Type: ET_EXEC # MULTI-NEXT: Sections: # MULTI-NEXT: - Name: .stack_sizes # MULTI-NEXT: Type: SHT_PROGBITS Index: llvm/test/tools/obj2yaml/ELF/symbol-visibility.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/symbol-visibility.yaml +++ llvm/test/tools/obj2yaml/ELF/symbol-visibility.yaml @@ -4,10 +4,9 @@ # CHECK: --- !ELF # CHECK-NEXT: FileHeader: -# CHECK-NEXT: Class: ELFCLASS64 -# CHECK-NEXT: Data: ELFDATA2LSB -# CHECK-NEXT: Type: ET_REL -# CHECK-NEXT: Machine: EM_NONE +# CHECK-NEXT: Class: ELFCLASS64 +# CHECK-NEXT: Data: ELFDATA2LSB +# CHECK-NEXT: Type: ET_REL # CHECK-NEXT: Symbols: # CHECK-NEXT: - Name: default # CHECK-NEXT: - Name: internal Index: llvm/test/tools/obj2yaml/ELF/versym-section.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/versym-section.yaml +++ llvm/test/tools/obj2yaml/ELF/versym-section.yaml @@ -5,11 +5,10 @@ # CHECK: --- !ELF # CHECK-NEXT: FileHeader: -# CHECK-NEXT: Class: ELFCLASS64 -# CHECK-NEXT: Data: ELFDATA2LSB -# CHECK-NEXT: Type: ET_EXEC -# CHECK-NEXT: Machine: EM_NONE -# CHECK-NEXT: Entry: 0x0000000000201000 +# CHECK-NEXT: Class: ELFCLASS64 +# CHECK-NEXT: Data: ELFDATA2LSB +# CHECK-NEXT: Type: ET_EXEC +# CHECK-NEXT: Entry: 0x0000000000201000 # CHECK-NEXT: Sections: # CHECK-NEXT: - Name: .gnu.version # CHECK-NEXT: Type: SHT_GNU_versym Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -240,7 +240,8 @@ Y->Header.OSABI = Obj.getHeader().e_ident[ELF::EI_OSABI]; Y->Header.ABIVersion = Obj.getHeader().e_ident[ELF::EI_ABIVERSION]; Y->Header.Type = Obj.getHeader().e_type; - Y->Header.Machine = ELFYAML::ELF_EM(Obj.getHeader().e_machine); + if (Obj.getHeader().e_machine != 0) + Y->Header.Machine = ELFYAML::ELF_EM(Obj.getHeader().e_machine); Y->Header.Flags = Obj.getHeader().e_flags; Y->Header.Entry = Obj.getHeader().e_entry;