[llvm] 7391885 - [yaml2obj][obj2yaml][Object][test] - Improve testing of relocation types.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 6 02:43:50 PST 2020
Author: Georgii Rymar
Date: 2020-03-06T13:38:01+03:00
New Revision: 7391885d5c51e6026a137b2683cb4ebc259a9833
URL: https://github.com/llvm/llvm-project/commit/7391885d5c51e6026a137b2683cb4ebc259a9833
DIFF: https://github.com/llvm/llvm-project/commit/7391885d5c51e6026a137b2683cb4ebc259a9833.diff
LOG: [yaml2obj][obj2yaml][Object][test] - Improve testing of relocation types.
The intention was to remove the `Object/X86/yaml-elf-x86-rel-broken.yaml test`,
This test is at the wrong place.
`yaml-elf-x86-rel-broken.yaml` was introduced in
rG892c6c86ea25dc97668ff1f1b7bf1108e85fa5ec to check that
yaml2obj can use an arbitrary `Hex32` value as a relocation type.
We have tests that check the similar functionality.
I've improved them and removed the `yaml-elf-x86-rel-broken.yaml`
Differential revision: https://reviews.llvm.org/D75679
Added:
llvm/test/tools/obj2yaml/relocation-type.yaml
llvm/test/tools/yaml2obj/ELF/relocation-type.yaml
Modified:
Removed:
llvm/test/Object/X86/yaml-elf-x86-rel-broken.yaml
llvm/test/tools/obj2yaml/relocation-unsupported-machine.yaml
llvm/test/tools/yaml2obj/ELF/relocation-unsupported-machine.yaml
################################################################################
diff --git a/llvm/test/Object/X86/yaml-elf-x86-rel-broken.yaml b/llvm/test/Object/X86/yaml-elf-x86-rel-broken.yaml
deleted file mode 100644
index 7121a2886394..000000000000
--- a/llvm/test/Object/X86/yaml-elf-x86-rel-broken.yaml
+++ /dev/null
@@ -1,32 +0,0 @@
-# RUN: yaml2obj %s -o %t
-# RUN: obj2yaml %t | FileCheck %s
-
-# CHECK: Relocations:
-# CHECK-NEXT: - Offset:
-# CHECK-NEXT: Symbol:
-# CHECK-NEXT: Type: 0x000000FF
-
-!ELF
-FileHeader:
- Class: ELFCLASS32
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_386
-Sections:
- - Type: SHT_PROGBITS
- Name: .text
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- AddressAlign: 0x04
- Content: 0000000000000000
- - Type: SHT_REL
- Name: .rel.text
- Link: .symtab
- Info: .text
- AddressAlign: 0x04
- Relocations:
- - Offset: 0
- Symbol: main
- Type: 0xFF
-Symbols:
- - Name: main
- Binding: STB_GLOBAL
diff --git a/llvm/test/tools/obj2yaml/relocation-type.yaml b/llvm/test/tools/obj2yaml/relocation-type.yaml
new file mode 100644
index 000000000000..6ab8e9c462ea
--- /dev/null
+++ b/llvm/test/tools/obj2yaml/relocation-type.yaml
@@ -0,0 +1,52 @@
+## Show how obj2yaml dumps relocation types.
+
+## Show that obj2yaml is able to dump relocation types when `e_machine` kind is unknown.
+# RUN: yaml2obj %s -o %t1 -DMACHINE=0x1234
+# RUN: obj2yaml %t1 | FileCheck %s -DMACHINE=0x1234 -DFIRST=0x00000000 -DSECOND=0x00000001
+
+# CHECK: --- !ELF
+# CHECK-NEXT: FileHeader:
+# CHECK-NEXT: Class: ELFCLASS64
+# CHECK-NEXT: Data: ELFDATA2MSB
+# CHECK-NEXT: Type: ET_REL
+# CHECK-NEXT: Machine: [[MACHINE]]
+# CHECK-NEXT: Sections:
+# CHECK-NEXT: - Name: .rela.text
+# CHECK-NEXT: Type: SHT_RELA
+# CHECK-NEXT: EntSize: 0x0000000000000018
+# CHECK-NEXT: Relocations:
+# CHECK-NEXT: - Offset: 0x0000000000000009
+# CHECK-NEXT: Type: [[FIRST]]
+# CHECK-NEXT: - Offset: 0x0000000000000008
+# CHECK-NEXT: Type: [[SECOND]]
+# CHECK-NEXT: - Offset: 0x0000000000000007
+# CHECK-NEXT: Type: 0x0000007F
+# CHECK-NEXT: - Offset: 0x0000000000000006
+# CHECK-NEXT: Type: 0x000000FF
+# CHECK-NEXT: ...
+
+## Show how obj2yaml dumps relocation types when `e_machine` kind is known.
+## In this case unknown relocation types are dumped as hex values.
+## All known relocation types are printed as strings representing relocation names.
+# RUN: yaml2obj %s -o %t2 -DMACHINE=EM_X86_64
+# RUN: obj2yaml %t2 | FileCheck %s -DMACHINE=EM_X86_64 -DFIRST=R_X86_64_NONE -DSECOND=R_X86_64_64
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: [[MACHINE]]
+Sections:
+ - Name: .rela.text
+ Type: SHT_RELA
+ Relocations:
+## Test a few noticeable possible values: 0, 1, max(int8_t)=127, max(uint8_t)=0xFF=-1
+ - Offset: 0x9
+ Type: 0x0
+ - Offset: 0x8
+ Type: 0x1
+ - Offset: 0x7
+ Type: 0x7F
+ - Offset: 0x6
+ Type: 0xFF
diff --git a/llvm/test/tools/obj2yaml/relocation-unsupported-machine.yaml b/llvm/test/tools/obj2yaml/relocation-unsupported-machine.yaml
deleted file mode 100644
index 84e5c13b53d6..000000000000
--- a/llvm/test/tools/obj2yaml/relocation-unsupported-machine.yaml
+++ /dev/null
@@ -1,35 +0,0 @@
-## Show that obj2yaml is able to dump relocations when `e_machine` is unknown.
-
-# RUN: yaml2obj %s -o %t1
-# RUN: obj2yaml %t1 | FileCheck %s
-
-# CHECK: --- !ELF
-# CHECK-NEXT: FileHeader:
-# CHECK-NEXT: Class: ELFCLASS64
-# CHECK-NEXT: Data: ELFDATA2MSB
-# CHECK-NEXT: Type: ET_REL
-# CHECK-NEXT: Machine: 0x1234
-# CHECK-NEXT: Sections:
-# CHECK-NEXT: - Name: .rela.text
-# CHECK-NEXT: Type: SHT_RELA
-# CHECK-NEXT: EntSize: 0x0000000000000018
-# CHECK-NEXT: Relocations:
-# CHECK-NEXT: - Offset: 0x0000000000000001
-# CHECK-NEXT: Type: 0x00000002
-# CHECK-NEXT: - Offset: 0x0000000000000003
-# CHECK-NEXT: Type: 0x00000004
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2MSB
- Type: ET_REL
- Machine: 0x1234
-Sections:
- - Name: .rela.text
- Type: SHT_RELA
- Relocations:
- - Offset: 0x1
- Type: 0x2
- - Offset: 0x3
- Type: 0x4
diff --git a/llvm/test/tools/yaml2obj/ELF/relocation-type.yaml b/llvm/test/tools/yaml2obj/ELF/relocation-type.yaml
new file mode 100644
index 000000000000..67d451df2f7f
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/ELF/relocation-type.yaml
@@ -0,0 +1,36 @@
+## Here we test that an arbitrary hex value can be used for a relocation type.
+
+## Show that yaml2obj is able to produce relocations for an unknown e_machine kind properly.
+# RUN: yaml2obj %s -o %t1 -DMACHINE=0x1234
+# RUN: llvm-readelf %t1 --relocations | FileCheck %s -DFIRST=Unknown -DSECOND=Unknown
+
+# CHECK: Relocation section '.rela.text' at offset 0x40 contains 4 entries:
+# CHECK: Offset Info Type
+# CHECK-NEXT: 0000000000000009 0000000000000000 [[FIRST]] 0
+# CHECK-NEXT: 0000000000000008 0000000000000001 [[SECOND]] 0
+# CHECK-NEXT: 0000000000000007 000000000000007f Unknown 0
+# CHECK-NEXT: 0000000000000006 00000000000000ff Unknown 0
+
+## Show that yaml2obj is able to produce relocations for an arbitrary known e_machine kind properly.
+# RUN: yaml2obj %s -o %t2 -DMACHINE=EM_X86_64
+# RUN: llvm-readelf %t2 --relocations | FileCheck %s -DFIRST=R_X86_64_NONE -DSECOND=R_X86_64_64
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: [[MACHINE]]
+Sections:
+ - Name: .rela.text
+ Type: SHT_RELA
+ Relocations:
+## Test a few noticeable possible values: 0, 1, max(int8_t)=127, max(uint8_t)=0xFF=-1
+ - Offset: 0x9
+ Type: 0x0
+ - Offset: 0x8
+ Type: 0x1
+ - Offset: 0x7
+ Type: 0x7F
+ - Offset: 0x6
+ Type: 0xFF
diff --git a/llvm/test/tools/yaml2obj/ELF/relocation-unsupported-machine.yaml b/llvm/test/tools/yaml2obj/ELF/relocation-unsupported-machine.yaml
deleted file mode 100644
index 3943e64d14ef..000000000000
--- a/llvm/test/tools/yaml2obj/ELF/relocation-unsupported-machine.yaml
+++ /dev/null
@@ -1,24 +0,0 @@
-## Show that yaml2obj is able to write relocations for an unknown e_machine properly.
-
-# RUN: yaml2obj %s -o %t1
-# RUN: llvm-readelf %t1 --relocations | FileCheck %s
-
-# CHECK: Relocation section '.rela.text' at offset 0x40 contains 2 entries:
-# CHECK: Offset Info Type Symbol's Value Symbol's Name + Addend
-# CHECK-NEXT: 0000000000000001 0000000000000002 Unknown 0
-# CHECK-NEXT: 0000000000000003 0000000000000004 Unknown 0
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2MSB
- Type: ET_REL
- Machine: 0x1234
-Sections:
- - Name: .rela.text
- Type: SHT_RELA
- Relocations:
- - Offset: 0x1
- Type: 0x2
- - Offset: 0x3
- Type: 0x4
More information about the llvm-commits
mailing list