[llvm-readobj][test] - Cleanup and split tests in tools/llvm-readobj folder.
tools/llvm-readobj currently contains tests that are either general for
all file types or that mix file types inside. This patch refactors
these test and leaves only general tests in that folder. All other
tests were moved to ELF/COFF/MachO and wasm accordingly.
I tried to minimize amount of changes, so most of the test parts
remained unchanged. Any further refactorings and improvements for
particular tests should be done independently from this patch.
Differential revision: https://reviews.llvm.org/D71269
diff --git a/llvm/test/tools/llvm-readobj/wasm/hex-dump.test b/llvm/test/tools/llvm-readobj/wasm/hex-dump.test
new file mode 100644
index 0000000..7a47b65
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/wasm/hex-dump.test
@@ -0,0 +1,8 @@
+## Test that --hex-dump/-x can be used to display the contents
+## of the indicated section as hexadecimal bytes.
+
+# RUN: llvm-readobj -x 1 %p/Inputs/trivial.obj.wasm | FileCheck %s
+# RUN: llvm-readobj --hex-dump 1 %p/Inputs/trivial.obj.wasm | FileCheck %s
+
+# CHECK: 0x00000000 04600001 7f60017f 017f6000 0060017f .`...`....`..`..
+# CHECK: 0x00000010 00 .
diff --git a/llvm/test/tools/llvm-readobj/wasm/relocations.test b/llvm/test/tools/llvm-readobj/wasm/relocations.test
new file mode 100644
index 0000000..b245593
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/wasm/relocations.test
@@ -0,0 +1,30 @@
+## Check how we print relocations.
+
+# RUN: llvm-readobj -r --expand-relocs %p/Inputs/trivial.obj.wasm \
+# RUN: | FileCheck %s --check-prefix WASM
+
+# WASM: Relocations [
+# WASM-NEXT: Section (4) CODE {
+# WASM-NEXT: Relocation {
+# WASM-NEXT: Type: R_WASM_MEMORY_ADDR_SLEB (4)
+# WASM-NEXT: Offset: 0x4
+# WASM-NEXT: Symbol: .L.str
+# WASM-NEXT: Addend: 0
+# WASM-NEXT: }
+# WASM-NEXT: Relocation {
+# WASM-NEXT: Type: R_WASM_FUNCTION_INDEX_LEB (0)
+# WASM-NEXT: Offset: 0xA
+# WASM-NEXT: Symbol: puts
+# WASM-NEXT: }
+# WASM-NEXT: Relocation {
+# WASM-NEXT: Type: R_WASM_FUNCTION_INDEX_LEB (0)
+# WASM-NEXT: Offset: 0x11
+# WASM-NEXT: Symbol: .LSomeOtherFunction_bitcast
+# WASM-NEXT: }
+# WASM-NEXT: Relocation {
+# WASM-NEXT: Type: R_WASM_FUNCTION_INDEX_LEB (0)
+# WASM-NEXT: Offset: 0x1E
+# WASM-NEXT: Symbol: SomeOtherFunction
+# WASM-NEXT: }
+# WASM-NEXT: }
+# WASM-NEXT: ]
diff --git a/llvm/test/tools/llvm-readobj/wasm/sections.test b/llvm/test/tools/llvm-readobj/wasm/sections.test
new file mode 100644
index 0000000..8b8a526
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/wasm/sections.test
@@ -0,0 +1,50 @@
+## Check how we print sections.
+
+# RUN: llvm-readobj --sections %p/Inputs/trivial.obj.wasm | FileCheck %s
+
+# CHECK: Sections [
+# CHECK-NEXT: Section {
+# CHECK-NEXT: Type: TYPE (0x1)
+# CHECK-NEXT: Size: 17
+# CHECK-NEXT: Offset: 8
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT: Type: IMPORT (0x2)
+# CHECK-NEXT: Size: 93
+# CHECK-NEXT: Offset: 31
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT: Type: FUNCTION (0x3)
+# CHECK-NEXT: Size: 3
+# CHECK-NEXT: Offset: 130
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT: Type: CODE (0xA)
+# CHECK-NEXT: Size: 36
+# CHECK-NEXT: Offset: 139
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT: Type: DATA (0xB)
+# CHECK-NEXT: Size: 19
+# CHECK-NEXT: Offset: 181
+# CHECK-NEXT: Segments [
+# CHECK-NEXT: Segment {
+# CHECK-NEXT: Name: .rodata..L.str
+# CHECK-NEXT: Size: 13
+# CHECK-NEXT: Offset: 0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT: Type: CUSTOM (0x0)
+# CHECK-NEXT: Size: 89
+# CHECK-NEXT: Offset: 206
+# CHECK-NEXT: Name: linking
+# CHECK-NEXT: }
+# CHECK-NEXT: Section {
+# CHECK-NEXT: Type: CUSTOM (0x0)
+# CHECK-NEXT: Size: 15
+# CHECK-NEXT: Offset: 309
+# CHECK-NEXT: Name: reloc.CODE
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
diff --git a/llvm/test/tools/llvm-readobj/wasm/symbols.test b/llvm/test/tools/llvm-readobj/wasm/symbols.test
new file mode 100644
index 0000000..c552853
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/wasm/symbols.test
@@ -0,0 +1,51 @@
+## This is the test for the --symbols option and its aliases.
+
+# RUN: llvm-readobj --symbols %p/Inputs/trivial.obj.wasm | FileCheck %s
+
+# CHECK: Symbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: main
+# CHECK-NEXT: Type: FUNCTION (0x0)
+# CHECK-NEXT: Flags [ (0x0)
+# CHECK-NEXT: ]
+# CHECK-NEXT: ElementIndex: 0x2
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: .L.str
+# CHECK-NEXT: Type: DATA (0x1)
+# CHECK-NEXT: Flags [ (0x2)
+# CHECK-NEXT: BINDING_LOCAL (0x2)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Offset: 0x0
+# CHECK-NEXT: Segment: 0x0
+# CHECK-NEXT: Size: 0xD
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: puts
+# CHECK-NEXT: Type: FUNCTION (0x0)
+# CHECK-NEXT: Flags [ (0x10)
+# CHECK-NEXT: UNDEFINED (0x10)
+# CHECK-NEXT: ]
+# CHECK-NEXT: ImportName: puts
+# CHECK-NEXT: ImportModule: env
+# CHECK-NEXT: ElementIndex: 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: .LSomeOtherFunction_bitcast
+# CHECK-NEXT: Type: FUNCTION (0x0)
+# CHECK-NEXT: Flags [ (0x2)
+# CHECK-NEXT: BINDING_LOCAL (0x2)
+# CHECK-NEXT: ]
+# CHECK-NEXT: ElementIndex: 0x3
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: SomeOtherFunction
+# CHECK-NEXT: Type: FUNCTION (0x0)
+# CHECK-NEXT: Flags [ (0x10)
+# CHECK-NEXT: UNDEFINED (0x10)
+# CHECK-NEXT: ]
+# CHECK-NEXT: ImportName: SomeOtherFunction
+# CHECK-NEXT: ImportModule: env
+# CHECK-NEXT: ElementIndex: 0x1
+# CHECK-NEXT: }
+# CHECK-NEXT: ]