[llvm] 279943e - [obj2yaml] - Don't emit EM_NONE.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 06:00:33 PDT 2020
Author: Georgii Rymar
Date: 2020-09-17T15:58:44+03:00
New Revision: 279943edf87887403fce72c505f9760764e416f0
URL: https://github.com/llvm/llvm-project/commit/279943edf87887403fce72c505f9760764e416f0
DIFF: https://github.com/llvm/llvm-project/commit/279943edf87887403fce72c505f9760764e416f0.diff
LOG: [obj2yaml] - Don't emit EM_NONE.
When ELF header's `e_machine == 0`, we emit:
```
Machine: EM_NONE
```
We can avoid doing this, because yaml2obj sets the
`e_machine` field to `EM_NONE` by default.
Differential revision: https://reviews.llvm.org/D87829
Added:
Modified:
llvm/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml
llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml
llvm/test/tools/obj2yaml/ELF/emachine.yaml
llvm/test/tools/obj2yaml/ELF/gnu-unique-symbols.yaml
llvm/test/tools/obj2yaml/ELF/implicit-sections-order.yaml
llvm/test/tools/obj2yaml/ELF/invalid-section-name.yaml
llvm/test/tools/obj2yaml/ELF/no-symtab.yaml
llvm/test/tools/obj2yaml/ELF/null-section.yaml
llvm/test/tools/obj2yaml/ELF/sht-symtab-shndx.yaml
llvm/test/tools/obj2yaml/ELF/stack-sizes.yaml
llvm/test/tools/obj2yaml/ELF/symbol-visibility.yaml
llvm/test/tools/obj2yaml/ELF/versym-section.yaml
llvm/tools/obj2yaml/elf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml b/llvm/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml
index bc8b631beea8..2e3fcd98065b 100644
--- a/llvm/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml
@@ -51,10 +51,9 @@ Symbols:
# 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
diff --git a/llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml b/llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml
index bea942327a5b..9e6b8fca67ac 100644
--- a/llvm/test/tools/obj2yaml/ELF/duplicate-symbol-and-section-names.yaml
+++ b/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
diff --git a/llvm/test/tools/obj2yaml/ELF/emachine.yaml b/llvm/test/tools/obj2yaml/ELF/emachine.yaml
index d351505aa284..10d72bed87f4 100644
--- a/llvm/test/tools/obj2yaml/ELF/emachine.yaml
+++ b/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: ...
diff --git a/llvm/test/tools/obj2yaml/ELF/gnu-unique-symbols.yaml b/llvm/test/tools/obj2yaml/ELF/gnu-unique-symbols.yaml
index 2668dad25fb4..c34ab3e3fc0a 100644
--- a/llvm/test/tools/obj2yaml/ELF/gnu-unique-symbols.yaml
+++ b/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
diff --git a/llvm/test/tools/obj2yaml/ELF/implicit-sections-order.yaml b/llvm/test/tools/obj2yaml/ELF/implicit-sections-order.yaml
index 502b8e62688b..e400d00eb541 100644
--- a/llvm/test/tools/obj2yaml/ELF/implicit-sections-order.yaml
+++ b/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 @@ DynamicSymbols:
## 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
diff --git a/llvm/test/tools/obj2yaml/ELF/invalid-section-name.yaml b/llvm/test/tools/obj2yaml/ELF/invalid-section-name.yaml
index 3f46563b980a..40667b57a974 100644
--- a/llvm/test/tools/obj2yaml/ELF/invalid-section-name.yaml
+++ b/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
diff --git a/llvm/test/tools/obj2yaml/ELF/no-symtab.yaml b/llvm/test/tools/obj2yaml/ELF/no-symtab.yaml
index 1566693339cd..8f9fb8285645 100644
--- a/llvm/test/tools/obj2yaml/ELF/no-symtab.yaml
+++ b/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 @@ FileHeader:
# 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: ...
diff --git a/llvm/test/tools/obj2yaml/ELF/null-section.yaml b/llvm/test/tools/obj2yaml/ELF/null-section.yaml
index 4d1e6ee1e7db..abba576fb4c7 100644
--- a/llvm/test/tools/obj2yaml/ELF/null-section.yaml
+++ b/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 @@ Sections:
# 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 @@ Sections:
# 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 @@ Sections:
# 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
diff --git a/llvm/test/tools/obj2yaml/ELF/sht-symtab-shndx.yaml b/llvm/test/tools/obj2yaml/ELF/sht-symtab-shndx.yaml
index cc20a036daaa..27decbe76d92 100644
--- a/llvm/test/tools/obj2yaml/ELF/sht-symtab-shndx.yaml
+++ b/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
diff --git a/llvm/test/tools/obj2yaml/ELF/stack-sizes.yaml b/llvm/test/tools/obj2yaml/ELF/stack-sizes.yaml
index 98a5c5ae88aa..a2ef5f1f3770 100644
--- a/llvm/test/tools/obj2yaml/ELF/stack-sizes.yaml
+++ b/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 @@ Sections:
# 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 @@ Sections:
# 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 @@ Sections:
# 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
diff --git a/llvm/test/tools/obj2yaml/ELF/symbol-visibility.yaml b/llvm/test/tools/obj2yaml/ELF/symbol-visibility.yaml
index 7659def7eb9f..0c6020062fab 100644
--- a/llvm/test/tools/obj2yaml/ELF/symbol-visibility.yaml
+++ b/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
diff --git a/llvm/test/tools/obj2yaml/ELF/versym-section.yaml b/llvm/test/tools/obj2yaml/ELF/versym-section.yaml
index e394c325af0f..fd63f553dc40 100644
--- a/llvm/test/tools/obj2yaml/ELF/versym-section.yaml
+++ b/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
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index d7ce08af1a9a..75f63795cb08 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -240,7 +240,8 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() {
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;
More information about the llvm-commits
mailing list