diff options
author | Georgii Rymar <grimar@accesssoftek.com> | 2019-12-10 17:06:16 +0300 |
---|---|---|
committer | Georgii Rymar <grimar@accesssoftek.com> | 2019-12-12 12:21:58 +0300 |
commit | fff9f049b2e91ce6e670d767866ee4670a4fed31 (patch) | |
tree | 86bfb694ff92fd79321ed61cea85791de41f7b7f /llvm/test/tools/llvm-readobj/ELF | |
parent | 756db63af9642f56138e2ab6ac26627205c1992e (diff) | |
download | bcm5719-llvm-fff9f049b2e91ce6e670d767866ee4670a4fed31.tar.gz bcm5719-llvm-fff9f049b2e91ce6e670d767866ee4670a4fed31.zip |
[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
Diffstat (limited to 'llvm/test/tools/llvm-readobj/ELF')
-rw-r--r-- | llvm/test/tools/llvm-readobj/ELF/basic.test | 19 | ||||
-rw-r--r-- | llvm/test/tools/llvm-readobj/ELF/hex-dump.test | 54 | ||||
-rw-r--r-- | llvm/test/tools/llvm-readobj/ELF/relocations.test | 375 | ||||
-rw-r--r-- | llvm/test/tools/llvm-readobj/ELF/sections-ext.test | 110 | ||||
-rw-r--r-- | llvm/test/tools/llvm-readobj/ELF/sections.test | 76 | ||||
-rw-r--r-- | llvm/test/tools/llvm-readobj/ELF/symbols.test | 42 |
6 files changed, 676 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-readobj/ELF/basic.test b/llvm/test/tools/llvm-readobj/ELF/basic.test new file mode 100644 index 00000000000..1d273b8b927 --- /dev/null +++ b/llvm/test/tools/llvm-readobj/ELF/basic.test @@ -0,0 +1,19 @@ +## Test the case where no switches are specified. + +# RUN: yaml2obj %s -o %t.trivial.obj.elf-x86-64 +# RUN: llvm-readobj %t.trivial.obj.elf-x86-64 | FileCheck --check-prefix=HEADER %s +# RUN: llvm-readelf %t.trivial.obj.elf-x86-64 | FileCheck --check-prefix=NO-OUTPUT --allow-empty %s + +# HEADER: File: {{.*}}trivial.obj.elf-x86-64 +# HEADER: Format: ELF64-x86-64 +# HEADER: Arch: x86_64 +# HEADER: AddressSize: 64bit + +# NO-OUTPUT-NOT: {{.}} + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 diff --git a/llvm/test/tools/llvm-readobj/ELF/hex-dump.test b/llvm/test/tools/llvm-readobj/ELF/hex-dump.test new file mode 100644 index 00000000000..968ed910e33 --- /dev/null +++ b/llvm/test/tools/llvm-readobj/ELF/hex-dump.test @@ -0,0 +1,54 @@ +## Test that the -x alias can be used flexibly. Create a baseline and ensure +## all other combinations are identical. +# RUN: llvm-readelf --file-header --hex-dump=.text \ +# RUN: %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.out +# RUN: llvm-readelf -h --hex-dump .text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.1 +# RUN: llvm-readelf -h -x .text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.2 +# RUN: llvm-readelf -h -x=.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.3 +# RUN: llvm-readelf -h -x.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.4 +# RUN: llvm-readelf -hx .text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.5 +# RUN: llvm-readelf -hx=.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.6 +# RUN: llvm-readelf -hx.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.7 + +# RUN: cmp %t.hexdump.out %t.hexdump.1 +# RUN: cmp %t.hexdump.out %t.hexdump.2 +# RUN: cmp %t.hexdump.out %t.hexdump.3 +# RUN: cmp %t.hexdump.out %t.hexdump.4 +# RUN: cmp %t.hexdump.out %t.hexdump.5 +# RUN: cmp %t.hexdump.out %t.hexdump.6 +# RUN: cmp %t.hexdump.out %t.hexdump.7 + +# RUN: llvm-readelf -S %p/Inputs/trivial.obj.elf-x86-64 | FileCheck %s --check-prefix=ELF-SEC + +## Both 9 and .strtab refer to .strtab. Test we dump the section only once. +# RUN: llvm-readobj -x 9 -x 9 -x .strtab -x .strtab %p/Inputs/trivial.obj.elf-x86-64 2>&1 | \ +# RUN: FileCheck %s --check-prefix=ELF +# RUN: llvm-readobj -x 9 -x .strtab -x 10 -x not_exist \ +# RUN: %p/Inputs/trivial.obj.elf-x86-64 2>&1 | FileCheck %s -DFILE=%p/Inputs/trivial.obj.elf-x86-64 --check-prefixes=ELF-WARN,ELF + +# ELF-SEC: [ 9] .strtab + +# ELF-WARN: warning: '[[FILE]]': could not find section 'not_exist' +# ELF-WARN: warning: '[[FILE]]': could not find section 10 +# ELF: Hex dump of section '.strtab': +# ELF-NEXT: 0x00000000 00747269 7669616c 2e6c6c00 6d61696e .trivial.ll.main +# ELF-NEXT: 0x00000010 002e4c2e 73747200 70757473 00536f6d ..L.str.puts.Som +# ELF-NEXT: 0x00000020 654f7468 65724675 6e637469 6f6e005f eOtherFunction._ +# ELF-NEXT: 0x00000030 474c4f42 414c5f4f 46465345 545f5441 GLOBAL_OFFSET_TA +# ELF-NEXT: 0x00000040 424c455f 00 BLE_. +# ELF-NOT: {{.}} + +## This test shows that we include the tool name in an error/warning message. + +# RUN: yaml2obj %s -o %t +# RUN: llvm-readelf -x 10 %t 2>&1 | FileCheck --check-prefix=WARN %s -DTOOL=readelf +# RUN: llvm-readobj -x 10 %t 2>&1 | FileCheck --check-prefix=WARN %s -DTOOL=readobj + +# WARN: llvm-[[TOOL]]{{(\.exe)?}}: warning: '{{.*}}': could not find section 10 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_RISCV diff --git a/llvm/test/tools/llvm-readobj/ELF/relocations.test b/llvm/test/tools/llvm-readobj/ELF/relocations.test new file mode 100644 index 00000000000..1b02ad1725a --- /dev/null +++ b/llvm/test/tools/llvm-readobj/ELF/relocations.test @@ -0,0 +1,375 @@ +## Check llvm-readobj and llvm-readelf print relocations as expected. + +## Show that ELF64 is dumped correctly. +# RUN: yaml2obj %s --docnum=1 -o %t64 +# RUN: llvm-readobj -r %t64 \ +# RUN: | FileCheck %s --check-prefix=LLVM-64 --strict-whitespace --match-full-lines +# RUN: llvm-readobj --relocs %t64 \ +# RUN: | FileCheck %s --check-prefix=LLVM-64 --strict-whitespace --match-full-lines +# RUN: llvm-readobj --relocations %t64 \ +# RUN: | FileCheck %s --check-prefix=LLVM-64 --strict-whitespace --match-full-lines + +# LLVM-64:Relocations [ +# LLVM-64-NEXT: Section (2) .rel.text { +# LLVM-64-NEXT: 0x0 R_X86_64_NONE rel_0 0x0 +# LLVM-64-NEXT: 0x1 R_X86_64_PC32 rel_neg 0x0 +# LLVM-64-NEXT: 0x5 R_X86_64_PLT32 rel_pos 0x0 +# LLVM-64-NEXT: 0x9 R_X86_64_64 rel_64 0x0 +# LLVM-64-NEXT: } +# LLVM-64-NEXT: Section (3) .rela.text { +# LLVM-64-NEXT: 0x0 R_X86_64_NONE rela_0 0x0 +# LLVM-64-NEXT: 0x1 R_X86_64_PC32 rela_neg 0xFFFFFFFFFFFFFFFF +# LLVM-64-NEXT: 0x5 R_X86_64_PLT32 rela_pos 0x2 +# LLVM-64-NEXT: 0xFFFFFFFFFFFFFFFF R_X86_64_64 rela_minneg 0x8000000000000000 +# LLVM-64-NEXT: 0x9 R_X86_64_32S rela_maxpos 0x7FFFFFFFFFFFFFFF +# LLVM-64-NEXT: } +# LLVM-64-NEXT:] + +# RUN: llvm-readelf -r %t64 \ +# RUN: | FileCheck %s --check-prefix=GNU-64 --strict-whitespace --match-full-lines +# RUN: llvm-readelf --relocs %t64 \ +# RUN: | FileCheck %s --check-prefix=GNU-64 --strict-whitespace --match-full-lines +# RUN: llvm-readelf --relocations %t64 \ +# RUN: | FileCheck %s --check-prefix=GNU-64 --strict-whitespace --match-full-lines + +# GNU-64:Relocation section '.rel.text' at offset 0x51 contains 4 entries: +# GNU-64-NEXT: Offset Info Type Symbol's Value Symbol's Name +# GNU-64-NEXT:0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 rel_0 +# GNU-64-NEXT:0000000000000001 0000000200000002 R_X86_64_PC32 0000000000000001 rel_neg +# GNU-64-NEXT:0000000000000005 0000000300000004 R_X86_64_PLT32 0000000000000002 rel_pos +# GNU-64-NEXT:0000000000000009 0000000400000001 R_X86_64_64 ffffffffffffffff rel_64 +# GNU-64-EMPTY: +# GNU-64-NEXT:Relocation section '.rela.text' at offset 0x91 contains 5 entries: +# GNU-64-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend +# GNU-64-NEXT:0000000000000000 0000000500000000 R_X86_64_NONE 0000000000000000 rela_0 + 0 +# GNU-64-NEXT:0000000000000001 0000000600000002 R_X86_64_PC32 0000000000000001 rela_neg - 1 +# GNU-64-NEXT:0000000000000005 0000000700000004 R_X86_64_PLT32 0000000000000002 rela_pos + 2 +# GNU-64-NEXT:ffffffffffffffff 0000000800000001 R_X86_64_64 0000000000000003 rela_minneg - 8000000000000000 +# GNU-64-NEXT:0000000000000009 000000090000000b R_X86_64_32S ffffffffffffffff rela_maxpos + 7fffffffffffffff + +## Show that --expand-relocs expands the relocation dump for LLVM style only +## (and not GNU). +# RUN: llvm-readobj -r --expand-relocs %t64 \ +# RUN: | FileCheck %s --check-prefix=LLVM-EXPAND-64 --match-full-lines --strict-whitespace +# RUN: llvm-readelf -r --expand-relocs %t64 \ +# RUN: | FileCheck %s --check-prefix=GNU-64 --match-full-lines --strict-whitespace + +# LLVM-EXPAND-64:Relocations [ +# LLVM-EXPAND-64-NEXT: Section (2) .rel.text { +# LLVM-EXPAND-64-NEXT: Relocation { +# LLVM-EXPAND-64-NEXT: Offset: 0x0 +# LLVM-EXPAND-64-NEXT: Type: R_X86_64_NONE (0) +# LLVM-EXPAND-64-NEXT: Symbol: rel_0 (1) +# LLVM-EXPAND-64-NEXT: Addend: 0x0 +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: Relocation { +# LLVM-EXPAND-64-NEXT: Offset: 0x1 +# LLVM-EXPAND-64-NEXT: Type: R_X86_64_PC32 (2) +# LLVM-EXPAND-64-NEXT: Symbol: rel_neg (2) +# LLVM-EXPAND-64-NEXT: Addend: 0x0 +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: Relocation { +# LLVM-EXPAND-64-NEXT: Offset: 0x5 +# LLVM-EXPAND-64-NEXT: Type: R_X86_64_PLT32 (4) +# LLVM-EXPAND-64-NEXT: Symbol: rel_pos (3) +# LLVM-EXPAND-64-NEXT: Addend: 0x0 +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: Relocation { +# LLVM-EXPAND-64-NEXT: Offset: 0x9 +# LLVM-EXPAND-64-NEXT: Type: R_X86_64_64 (1) +# LLVM-EXPAND-64-NEXT: Symbol: rel_64 (4) +# LLVM-EXPAND-64-NEXT: Addend: 0x0 +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: Section (3) .rela.text { +# LLVM-EXPAND-64-NEXT: Relocation { +# LLVM-EXPAND-64-NEXT: Offset: 0x0 +# LLVM-EXPAND-64-NEXT: Type: R_X86_64_NONE (0) +# LLVM-EXPAND-64-NEXT: Symbol: rela_0 (5) +# LLVM-EXPAND-64-NEXT: Addend: 0x0 +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: Relocation { +# LLVM-EXPAND-64-NEXT: Offset: 0x1 +# LLVM-EXPAND-64-NEXT: Type: R_X86_64_PC32 (2) +# LLVM-EXPAND-64-NEXT: Symbol: rela_neg (6) +# LLVM-EXPAND-64-NEXT: Addend: 0xFFFFFFFFFFFFFFFF +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: Relocation { +# LLVM-EXPAND-64-NEXT: Offset: 0x5 +# LLVM-EXPAND-64-NEXT: Type: R_X86_64_PLT32 (4) +# LLVM-EXPAND-64-NEXT: Symbol: rela_pos (7) +# LLVM-EXPAND-64-NEXT: Addend: 0x2 +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: Relocation { +# LLVM-EXPAND-64-NEXT: Offset: 0xFFFFFFFFFFFFFFFF +# LLVM-EXPAND-64-NEXT: Type: R_X86_64_64 (1) +# LLVM-EXPAND-64-NEXT: Symbol: rela_minneg (8) +# LLVM-EXPAND-64-NEXT: Addend: 0x8000000000000000 +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: Relocation { +# LLVM-EXPAND-64-NEXT: Offset: 0x9 +# LLVM-EXPAND-64-NEXT: Type: R_X86_64_32S (11) +# LLVM-EXPAND-64-NEXT: Symbol: rela_maxpos (9) +# LLVM-EXPAND-64-NEXT: Addend: 0x7FFFFFFFFFFFFFFF +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT: } +# LLVM-EXPAND-64-NEXT:] + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Content: '00FFFFFFFF020000001234567890ABCDEF' + - Name: .rel.text + Type: SHT_REL + Info: .text + Relocations: + - Offset: 0x0 + Symbol: rel_0 + Type: R_X86_64_NONE + - Offset: 0x1 + Symbol: rel_neg + Type: R_X86_64_PC32 + - Offset: 0x5 + Symbol: rel_pos + Type: R_X86_64_PLT32 + - Offset: 0x9 + Symbol: rel_64 + Type: R_X86_64_64 + - Name: .rela.text + Type: SHT_RELA + Info: .text + Relocations: + - Offset: 0x0 + Symbol: rela_0 + Type: R_X86_64_NONE + Addend: 0 + - Offset: 0x1 + Symbol: rela_neg + Type: R_X86_64_PC32 + Addend: -1 + - Offset: 0x5 + Symbol: rela_pos + Type: R_X86_64_PLT32 + Addend: 2 + - Offset: 0xFFFFFFFFFFFFFFFF + Symbol: rela_minneg + Type: R_X86_64_64 + Addend: -9223372036854775808 ## Min 64-bit signed. + - Offset: 0x9 + Symbol: rela_maxpos + Type: R_X86_64_32S + Addend: 9223372036854775807 ## Max 64-bit signed. +Symbols: + - Name: rel_0 + Section: .text + Value: 0 + - Name: rel_neg + Section: .text + Value: 1 + - Name: rel_pos + Section: .text + Value: 2 + - Name: rel_64 + Section: .text + Value: 0xFFFFFFFFFFFFFFFF + - Name: rela_0 + Section: .text + Value: 0 + - Name: rela_neg + Section: .text + Value: 1 + - Name: rela_pos + Section: .text + Value: 2 + - Name: rela_minneg + Section: .text + Value: 3 + - Name: rela_maxpos + Section: .text + Value: 0xFFFFFFFFFFFFFFFF + +## Show that ELF32 is dumped correctly. +# RUN: yaml2obj %s --docnum=2 -o %t32 +# RUN: llvm-readobj -r %t32 \ +# RUN: | FileCheck %s --check-prefix=LLVM-32 --strict-whitespace --match-full-lines +# RUN: llvm-readobj --relocs %t32 \ +# RUN: | FileCheck %s --check-prefix=LLVM-32 --strict-whitespace --match-full-lines +# RUN: llvm-readobj --relocations %t32 \ +# RUN: | FileCheck %s --check-prefix=LLVM-32 --strict-whitespace --match-full-lines + +# LLVM-32:Relocations [ +# LLVM-32-NEXT: Section (2) .rel.text { +# LLVM-32-NEXT: 0x0 R_386_NONE rel_0 0x0 +# LLVM-32-NEXT: 0x1 R_386_PC32 rel_neg 0x0 +# LLVM-32-NEXT: 0x5 R_386_PLT32 rel_pos 0x0 +# LLVM-32-NEXT: } +# LLVM-32-NEXT: Section (3) .rela.text { +# LLVM-32-NEXT: 0x0 R_386_NONE rela_0 0x0 +# LLVM-32-NEXT: 0x1 R_386_PC32 rela_neg 0xFFFFFFFF +# LLVM-32-NEXT: 0x5 R_386_PLT32 rela_pos 0x2 +# LLVM-32-NEXT: 0xFFFFFFFF R_386_32 rela_minneg 0x80000000 +# LLVM-32-NEXT: 0x9 R_386_GOT32 rela_maxpos 0x7FFFFFFF +# LLVM-32-NEXT: } +# LLVM-32-NEXT:] + +# RUN: llvm-readelf -r %t32 \ +# RUN: | FileCheck %s --check-prefix=GNU-32 --strict-whitespace --match-full-lines +# RUN: llvm-readelf --relocs %t32 \ +# RUN: | FileCheck %s --check-prefix=GNU-32 --strict-whitespace --match-full-lines +# RUN: llvm-readelf --relocations %t32 \ +# RUN: | FileCheck %s --check-prefix=GNU-32 --strict-whitespace --match-full-lines + +# GNU-32:Relocation section '.rel.text' at offset 0x3d contains 3 entries: +# GNU-32-NEXT: Offset Info Type Sym. Value Symbol's Name +# GNU-32-NEXT:00000000 00000100 R_386_NONE 00000000 rel_0 +# GNU-32-NEXT:00000001 00000202 R_386_PC32 00000001 rel_neg +# GNU-32-NEXT:00000005 00000304 R_386_PLT32 ffffffff rel_pos +# GNU-32-EMPTY: +# GNU-32-NEXT:Relocation section '.rela.text' at offset 0x55 contains 5 entries: +# GNU-32-NEXT: Offset Info Type Sym. Value Symbol's Name + Addend +# GNU-32-NEXT:00000000 00000400 R_386_NONE 00000000 rela_0 + 0 +# GNU-32-NEXT:00000001 00000502 R_386_PC32 00000001 rela_neg - 1 +# GNU-32-NEXT:00000005 00000604 R_386_PLT32 00000002 rela_pos + 2 +# GNU-32-NEXT:ffffffff 00000701 R_386_32 00000003 rela_minneg - 80000000 +# GNU-32-NEXT:00000009 00000803 R_386_GOT32 ffffffff rela_maxpos + 7fffffff + +## Show that --expand-relocs expands the relocation dump for LLVM style only +## (and not GNU). +# RUN: llvm-readobj -r --expand-relocs %t32 \ +# RUN: | FileCheck %s --check-prefix=LLVM-EXPAND-32 --strict-whitespace --match-full-lines +# RUN: llvm-readelf -r --expand-relocs %t32 \ +# RUN: | FileCheck %s --check-prefix=GNU-32 --strict-whitespace --match-full-lines + +# LLVM-EXPAND-32:Relocations [ +# LLVM-EXPAND-32-NEXT: Section (2) .rel.text { +# LLVM-EXPAND-32-NEXT: Relocation { +# LLVM-EXPAND-32-NEXT: Offset: 0x0 +# LLVM-EXPAND-32-NEXT: Type: R_386_NONE (0) +# LLVM-EXPAND-32-NEXT: Symbol: rel_0 (1) +# LLVM-EXPAND-32-NEXT: Addend: 0x0 +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT: Relocation { +# LLVM-EXPAND-32-NEXT: Offset: 0x1 +# LLVM-EXPAND-32-NEXT: Type: R_386_PC32 (2) +# LLVM-EXPAND-32-NEXT: Symbol: rel_neg (2) +# LLVM-EXPAND-32-NEXT: Addend: 0x0 +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT: Relocation { +# LLVM-EXPAND-32-NEXT: Offset: 0x5 +# LLVM-EXPAND-32-NEXT: Type: R_386_PLT32 (4) +# LLVM-EXPAND-32-NEXT: Symbol: rel_pos (3) +# LLVM-EXPAND-32-NEXT: Addend: 0x0 +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT: Section (3) .rela.text { +# LLVM-EXPAND-32-NEXT: Relocation { +# LLVM-EXPAND-32-NEXT: Offset: 0x0 +# LLVM-EXPAND-32-NEXT: Type: R_386_NONE (0) +# LLVM-EXPAND-32-NEXT: Symbol: rela_0 (4) +# LLVM-EXPAND-32-NEXT: Addend: 0x0 +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT: Relocation { +# LLVM-EXPAND-32-NEXT: Offset: 0x1 +# LLVM-EXPAND-32-NEXT: Type: R_386_PC32 (2) +# LLVM-EXPAND-32-NEXT: Symbol: rela_neg (5) +# LLVM-EXPAND-32-NEXT: Addend: 0xFFFFFFFF +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT: Relocation { +# LLVM-EXPAND-32-NEXT: Offset: 0x5 +# LLVM-EXPAND-32-NEXT: Type: R_386_PLT32 (4) +# LLVM-EXPAND-32-NEXT: Symbol: rela_pos (6) +# LLVM-EXPAND-32-NEXT: Addend: 0x2 +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT: Relocation { +# LLVM-EXPAND-32-NEXT: Offset: 0xFFFFFFFF +# LLVM-EXPAND-32-NEXT: Type: R_386_32 (1) +# LLVM-EXPAND-32-NEXT: Symbol: rela_minneg (7) +# LLVM-EXPAND-32-NEXT: Addend: 0x80000000 +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT: Relocation { +# LLVM-EXPAND-32-NEXT: Offset: 0x9 +# LLVM-EXPAND-32-NEXT: Type: R_386_GOT32 (3) +# LLVM-EXPAND-32-NEXT: Symbol: rela_maxpos (8) +# LLVM-EXPAND-32-NEXT: Addend: 0x7FFFFFFF +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT: } +# LLVM-EXPAND-32-NEXT:] + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_386 +Sections: + - Name: .text + Type: SHT_PROGBITS + Content: '00FFFFFFFF02000000' + - Name: .rel.text + Type: SHT_REL + Info: .text + Relocations: + - Offset: 0x0 + Symbol: rel_0 + Type: R_386_NONE + - Offset: 0x1 + Symbol: rel_neg + Type: R_386_PC32 + - Offset: 0x5 + Symbol: rel_pos + Type: R_386_PLT32 + - Name: .rela.text + Type: SHT_RELA + Info: .text + Relocations: + - Offset: 0x0 + Symbol: rela_0 + Type: R_386_NONE + Addend: 0 + - Offset: 0x1 + Symbol: rela_neg + Type: R_386_PC32 + Addend: -1 + - Offset: 0x5 + Symbol: rela_pos + Type: R_386_PLT32 + Addend: 2 + - Offset: 0xFFFFFFFF + Symbol: rela_minneg + Type: R_386_32 + Addend: -2147483648 ## Min 32-bit signed. + - Offset: 0x9 + Symbol: rela_maxpos + Type: R_386_GOT32 + Addend: 2147483647 ## Max 32-bit signed. +Symbols: + - Name: rel_0 + Section: .text + Value: 0 + - Name: rel_neg + Section: .text + Value: 1 + - Name: rel_pos + Section: .text + Value: 0xFFFFFFFF + - Name: rela_0 + Section: .text + Value: 0 + - Name: rela_neg + Section: .text + Value: 1 + - Name: rela_pos + Section: .text + Value: 2 + - Name: rela_minneg + Section: .text + Value: 3 + - Name: rela_maxpos + Section: .text + Value: 0xFFFFFFFF diff --git a/llvm/test/tools/llvm-readobj/ELF/sections-ext.test b/llvm/test/tools/llvm-readobj/ELF/sections-ext.test new file mode 100644 index 00000000000..8e3bc2a7e24 --- /dev/null +++ b/llvm/test/tools/llvm-readobj/ELF/sections-ext.test @@ -0,0 +1,110 @@ +## This is a test case for --section-symbols, --section-relocations and +## --section-data command line flags and their aliases. + +# RUN: llvm-readobj -S --st --sr --sd %p/Inputs/trivial.obj.elf-i386 + +## Check the two-letter aliases above (--st, --sr, --sd) are equivalent to their +## full flag names. + +# RUN: llvm-readobj -S --st %p/Inputs/trivial.obj.elf-i386 > %t.readobj-st-alias +# RUN: llvm-readobj -S --section-symbols %p/Inputs/trivial.obj.elf-i386 > %t.readobj-st-no-alias +# RUN: diff %t.readobj-st-alias %t.readobj-st-no-alias + +# RUN: llvm-readobj -S --sr %p/Inputs/trivial.obj.elf-i386 > %t.readobj-sr-alias +# RUN: llvm-readobj -S --section-relocations %p/Inputs/trivial.obj.elf-i386 > %t.readobj-sr-no-alias +# RUN: diff %t.readobj-sr-alias %t.readobj-sr-no-alias + +# RUN: llvm-readobj -S --sd %p/Inputs/trivial.obj.elf-i386 > %t.readobj-sd-alias +# RUN: llvm-readobj -S --section-data %p/Inputs/trivial.obj.elf-i386 > %t.readobj-sd-no-alias +# RUN: diff %t.readobj-sd-alias %t.readobj-sd-no-alias + +# CHECK: Sections [ +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: 0 +# CHECK-NEXT: Name: (0) +# CHECK-NEXT: Type: SHT_NULL (0x0) +# CHECK-NEXT: Flags [ (0x0) +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x0 +# CHECK-NEXT: Offset: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 0 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: Relocations [ +# CHECK-NEXT: ] +# CHECK-NEXT: Symbols [ +# CHECK-NEXT: ] +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: ) +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: 1 +# CHECK-NEXT: Name: .text (5) +# CHECK-NEXT: Type: SHT_PROGBITS (0x1) +# CHECK-NEXT: Flags [ (0x6) +# CHECK-NEXT: SHF_ALLOC (0x2) +# CHECK-NEXT: SHF_EXECINSTR (0x4) +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x0 +# CHECK-NEXT: Offset: 0x40 +# CHECK-NEXT: Size: 42 +# CHECK-NEXT: Link: 0 +# CHECK-NEXT: Info: 0 +# CHECK-NEXT: AddressAlignment: 16 +# CHECK-NEXT: EntrySize: 0 +# CHECK-NEXT: Relocations [ +# CHECK-NEXT: ] +# CHECK-NEXT: Symbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: .text (0) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Local (0x0) +# CHECK-NEXT: Type: Section (0x3) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x1) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: main (12) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 42 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x1) +# CHECK-NEXT: } +# CHECK-NEXT: ] +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 5383EC08 E8000000 005B81C3 03000000 |S........[......| +# CHECK-NEXT: 0010: 8D830000 00008904 24E8FCFF FFFFE8FC |........$.......| +# CHECK-NEXT: 0020: FFFFFF31 C083C408 5BC3 |...1....[.| +# CHECK-NEXT: ) +# CHECK-NEXT: } +# CHECK-NEXT: Section { +# CHECK-NEXT: Index: 2 +# CHECK-NEXT: Name: .rel.text (1) +# CHECK-NEXT: Type: SHT_REL (0x9) +# CHECK-NEXT: Flags [ (0x0) +# CHECK-NEXT: ] +# CHECK-NEXT: Address: 0x0 +# CHECK-NEXT: Offset: 0x360 +# CHECK-NEXT: Size: 32 +# CHECK-NEXT: Link: 8 +# CHECK-NEXT: Info: 1 +# CHECK-NEXT: AddressAlignment: 4 +# CHECK-NEXT: EntrySize: 8 +# CHECK-NEXT: Relocations [ +# CHECK-NEXT: 0xC R_386_GOTPC _GLOBAL_OFFSET_TABLE_ 0x0 +# CHECK-NEXT: 0x12 R_386_GOTOFF .L.str 0x0 +# CHECK-NEXT: 0x1A R_386_PLT32 puts 0x0 +# CHECK-NEXT: 0x1F R_386_PLT32 SomeOtherFunction 0x0 +# CHECK-NEXT: ] +# CHECK-NEXT: Symbols [ +# CHECK-NEXT: ] +# CHECK-NEXT: SectionData ( +# CHECK-NEXT: 0000: 0C000000 0A0A0000 12000000 09020000 |................| +# CHECK-NEXT: 0010: 1A000000 040B0000 1F000000 04090000 |................| +# CHECK-NEXT: ) +# CHECK-NEXT: } diff --git a/llvm/test/tools/llvm-readobj/ELF/sections.test b/llvm/test/tools/llvm-readobj/ELF/sections.test new file mode 100644 index 00000000000..9eecd18545b --- /dev/null +++ b/llvm/test/tools/llvm-readobj/ELF/sections.test @@ -0,0 +1,76 @@ +## Check how we print sections. + +# RUN: llvm-readobj --sections %p/Inputs/trivial.obj.elf-i386 \ +# RUN: | FileCheck %s --check-prefix ELF +# RUN: llvm-readobj --sections %p/Inputs/trivial.obj.elf-mipsel \ +# RUN: | FileCheck %s --check-prefix ELF-MIPSEL + +## Check flag aliases produce identical output. +# RUN: llvm-readobj --sections %p/Inputs/trivial.obj.elf-i386 > %t.sections +# RUN: llvm-readobj -S %p/Inputs/trivial.obj.elf-i386 > %t.uppers +# RUN: cmp %t.sections %t.uppers +# RUN: llvm-readobj -S %p/Inputs/trivial.obj.elf-i386 > %t.lowers +# RUN: cmp %t.sections %t.lowers + +# ELF: Sections [ +# ELF-NEXT: Section { +# ELF-NEXT: Index: 0 +# ELF-NEXT: Name: (0) +# ELF-NEXT: Type: SHT_NULL (0x0) +# ELF-NEXT: Flags [ (0x0) +# ELF-NEXT: ] +# ELF-NEXT: Address: 0x0 +# ELF-NEXT: Offset: 0x0 +# ELF-NEXT: Size: 0 +# ELF-NEXT: Link: 0 +# ELF-NEXT: Info: 0 +# ELF-NEXT: AddressAlignment: 0 +# ELF-NEXT: EntrySize: 0 +# ELF-NEXT: } +# ELF-NEXT: Section { +# ELF-NEXT: Index: 1 +# ELF-NEXT: Name: .text (5) +# ELF-NEXT: Type: SHT_PROGBITS (0x1) +# ELF-NEXT: Flags [ (0x6) +# ELF-NEXT: SHF_ALLOC (0x2) +# ELF-NEXT: SHF_EXECINSTR (0x4) +# ELF-NEXT: ] +# ELF-NEXT: Address: 0x0 +# ELF-NEXT: Offset: 0x40 +# ELF-NEXT: Size: 42 +# ELF-NEXT: Link: 0 +# ELF-NEXT: Info: 0 +# ELF-NEXT: AddressAlignment: 16 +# ELF-NEXT: EntrySize: 0 +# ELF-NEXT: } + +# ELF-MIPSEL: Section { +# ELF-MIPSEL: Index: 4 +# ELF-MIPSEL-NEXT: Name: .reginfo (27) +# ELF-MIPSEL-NEXT: Type: SHT_MIPS_REGINFO (0x70000006) +# ELF-MIPSEL-NEXT: Flags [ (0x2) +# ELF-MIPSEL-NEXT: SHF_ALLOC (0x2) +# ELF-MIPSEL-NEXT: ] +# ELF-MIPSEL-NEXT: Address: 0x0 +# ELF-MIPSEL-NEXT: Offset: 0x34 +# ELF-MIPSEL-NEXT: Size: 24 +# ELF-MIPSEL-NEXT: Link: 0 +# ELF-MIPSEL-NEXT: Info: 0 +# ELF-MIPSEL-NEXT: AddressAlignment: 1 +# ELF-MIPSEL-NEXT: EntrySize: 0 +# ELF-MIPSEL-NEXT: } +# ELF-MIPSEL-NEXT: Section { +# ELF-MIPSEL-NEXT: Index: 5 +# ELF-MIPSEL-NEXT: Name: .MIPS.abiflags (12) +# ELF-MIPSEL-NEXT: Type: SHT_MIPS_ABIFLAGS (0x7000002A) +# ELF-MIPSEL-NEXT: Flags [ (0x2) +# ELF-MIPSEL-NEXT: SHF_ALLOC (0x2) +# ELF-MIPSEL-NEXT: ] +# ELF-MIPSEL-NEXT: Address: 0x0 +# ELF-MIPSEL-NEXT: Offset: 0x50 +# ELF-MIPSEL-NEXT: Size: 24 +# ELF-MIPSEL-NEXT: Link: 0 +# ELF-MIPSEL-NEXT: Info: 0 +# ELF-MIPSEL-NEXT: AddressAlignment: 8 +# ELF-MIPSEL-NEXT: EntrySize: 0 +# ELF-MIPSEL-NEXT: } diff --git a/llvm/test/tools/llvm-readobj/ELF/symbols.test b/llvm/test/tools/llvm-readobj/ELF/symbols.test new file mode 100644 index 00000000000..31bb9ae7b2f --- /dev/null +++ b/llvm/test/tools/llvm-readobj/ELF/symbols.test @@ -0,0 +1,42 @@ +## This is a general test for --symbols option and its aliases. +## There are also other symbols* tests that check specific things. + +# RUN: llvm-readobj --symbols %p/Inputs/trivial.obj.elf-i386 | FileCheck %s + +## Check flag aliases produce identical output. +# RUN: llvm-readobj --symbols %p/Inputs/trivial.obj.elf-i386 > %t.symbols +# RUN: llvm-readobj --syms %p/Inputs/trivial.obj.elf-i386 > %t.syms +# RUN: cmp %t.symbols %t.syms +# RUN: llvm-readobj -t %p/Inputs/trivial.obj.elf-i386 > %t.t +# RUN: cmp %t.symbols %t.t +# RUN: llvm-readelf -s --elf-output-style LLVM %p/Inputs/trivial.obj.elf-i386 > %t.lowers +# RUN: cmp %t.symbols %t.lowers + +# CHECK: Symbols [ +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: (0) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Local (0x0) +# CHECK-NEXT: Type: None (0x0) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Undefined (0x0) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: trivial.ll (1) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Local (0x0) +# CHECK-NEXT: Type: File (0x4) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: Absolute (0xFFF1) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: .L.str (39) +# CHECK-NEXT: Value: 0x0 +# CHECK-NEXT: Size: 13 +# CHECK-NEXT: Binding: Local (0x0) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .rodata.str1.1 (0x5) +# CHECK-NEXT: } |