-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm-objdump][test] Improve testing of some switches #3
This is the third commit in a series of patches to improve test coverage of llvm-objdump. In this patch I have added a number of tests testing various aspects of disassembly. Reviewed by: MaskRay, grimar, rupprecht Differential Revision: https://reviews.llvm.org/D62255 llvm-svn: 361489
- Loading branch information
Showing
14 changed files
with
604 additions
and
34 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
llvm/test/tools/llvm-objdump/X86/disasm-specific-funcs-mangled-name.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## Show that the --disassemble-functions switch takes mangled names, not | ||
## demangled names. | ||
|
||
# RUN: yaml2obj %s -o %t.o | ||
# RUN: llvm-objdump -d --disassemble-functions=_Z3foov %t.o | FileCheck %s | ||
# RUN: llvm-objdump -d --disassemble-functions='foo()' %t.o | FileCheck %s --check-prefix=NOFOO | ||
# RUN: llvm-objdump -d -C --disassemble-functions='foo()' %t.o | FileCheck %s --check-prefix=NOFOO | ||
# RUN: llvm-objdump -d --disassemble-functions=foo %t.o | FileCheck %s --check-prefix=NOFOO | ||
|
||
# CHECK: _Z3foov: | ||
|
||
# NOFOO-NOT: foo | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Content: '90' | ||
Symbols: | ||
- Name: _Z3foov | ||
Section: .text |
44 changes: 24 additions & 20 deletions
44
llvm/test/tools/llvm-objdump/X86/disasm-specific-funcs.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
// RUN: yaml2obj -o %t.out %p/Inputs/simple-executable-x86_64.yaml | ||
// RUN: llvm-objdump -d %t.out -disassemble-functions=main | FileCheck %s | ||
## Show that the --diassemble-functions switch disassembles only the specified | ||
## functions. | ||
|
||
// CHECK: Disassembly of section .anothertext: | ||
// CHECK-EMPTY: | ||
// CHECK-NEXT: main: | ||
// CHECK-NEXT: 10: 55 pushq %rbp | ||
// CHECK-NEXT: 11: 48 89 e5 movq %rsp, %rbp | ||
// CHECK-NEXT: 14: 48 83 ec 20 subq $32, %rsp | ||
// CHECK-NEXT: 18: 48 8d 04 25 a8 00 00 00 leaq 168, %rax | ||
// CHECK-NEXT: 20: c7 45 fc 00 00 00 00 movl $0, -4(%rbp) | ||
// CHECK-NEXT: 27: 48 89 45 f0 movq %rax, -16(%rbp) | ||
// CHECK-NEXT: 2b: 48 8b 45 f0 movq -16(%rbp), %rax | ||
// CHECK-NEXT: 2f: 8b 08 movl (%rax), %ecx | ||
// CHECK-NEXT: 31: 89 4d ec movl %ecx, -20(%rbp) | ||
// CHECK-NEXT: 34: e8 c7 ff ff ff callq -57 | ||
// CHECK-NEXT: 39: 8b 4d ec movl -20(%rbp), %ecx | ||
// CHECK-NEXT: 3c: 01 c1 addl %eax, %ecx | ||
// CHECK-NEXT: 3e: 89 c8 movl %ecx, %eax | ||
// CHECK-NEXT: 40: 48 83 c4 20 addq $32, %rsp | ||
// CHECK-NEXT: 44: 5d popq %rbp | ||
# RUN: yaml2obj -o %t.out %p/Inputs/simple-executable-x86_64.yaml | ||
# RUN: llvm-objdump -d %t.out --disassemble-functions=main \ | ||
# RUN: | FileCheck %s --check-prefix=MAIN --implicit-check-not=foo --implicit-check-not=somedata | ||
# RUN: llvm-objdump -d %t.out --disassemble-functions=main,foo \ | ||
# RUN: | FileCheck %s --check-prefixes=MAIN,FOO --implicit-check-not=somedata | ||
|
||
# FOO: foo: | ||
# MAIN: main: | ||
|
||
## Unknown symbol name. | ||
# RUN: llvm-objdump -d %t.out --disassemble-functions=baz \ | ||
# RUN: | FileCheck %s --implicit-check-not=Disassembly | ||
|
||
## Data symbol. | ||
# RUN: llvm-objdump -d %t.out --disassemble-functions=a \ | ||
# RUN: | FileCheck %s --implicit-check-not=Disassembly | ||
|
||
## Data symbol + --disassemble-all. | ||
# RUN: llvm-objdump -D %t.out --disassemble-functions=a \ | ||
# RUN: | FileCheck %s --check-prefix=DATA | ||
|
||
# DATA: a: |
20 changes: 20 additions & 0 deletions
20
llvm/test/tools/llvm-objdump/X86/disassemble-invalid-byte-sequences.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## Show that llvm-objdump handles invalid byte sequences, and continues. | ||
|
||
# RUN: yaml2obj %s -o %t.o | ||
# RUN: llvm-objdump %t.o -d | FileCheck %s | ||
|
||
# CHECK: 0000000000000000 .text: | ||
# CHECK: 0: d9 e2 <unknown> | ||
# CHECK-NEXT: 2: 90 nop | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Content: 'd9e290' |
17 changes: 17 additions & 0 deletions
17
llvm/test/tools/llvm-objdump/X86/disassemble-long-instructions.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## This test shows that llvm-objdump can disassemble a long instruction. | ||
# RUN: yaml2obj %s -o %t.o | ||
# RUN: llvm-objdump -d %t.o | FileCheck %s --strict-whitespace | ||
|
||
# CHECK: 0: 66 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 nopw %cs:(%rax,%rax) | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Content: '6666666666662E0F1F840000000000' # 15-byte nop |
99 changes: 99 additions & 0 deletions
99
llvm/test/tools/llvm-objdump/X86/elf-disassemble-dynamic-symbols.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
## Show the disassembly behaviour when dynamic symbols are present. | ||
# RUN: yaml2obj %s -o %t | ||
|
||
## Case 1: Both static and dynamic symbols are present. Only static | ||
## symbols are displayed. | ||
# RUN: llvm-objdump -d %t | FileCheck %s --check-prefixes=CHECK,STATIC | ||
|
||
## Case 2: Only the dynamic symbols are present. These should be displayed, if | ||
## they meet the necessary criteria. | ||
# RUN: llvm-objcopy --strip-all %t %t2 | ||
# RUN: llvm-objdump -d %t2 | FileCheck %s --check-prefixes=CHECK,DYN | ||
|
||
# CHECK: Disassembly of section .text: | ||
# CHECK-EMPTY: | ||
# STATIC-NEXT: 0000000000001000 .text: | ||
# DYN-NEXT: 0000000000001000 only_dyn: | ||
# CHECK-NEXT: 1000: | ||
# CHECK-EMPTY: | ||
# STATIC-NEXT: 0000000000001001 both_static: | ||
# DYN-NEXT: 0000000000001001 both_dyn: | ||
# CHECK-NEXT: 1001: | ||
# STATIC-EMPTY: | ||
# STATIC-NEXT: 0000000000001002 only_static: | ||
# CHECK-NEXT: 1002: | ||
# CHECK-NEXT: 1003: | ||
# CHECK-NEXT: 1004: | ||
# CHECK-NEXT: 1005:{{.*}} | ||
# CHECK-NOT: {{.}} | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_DYN | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Address: 0x1000 | ||
Content: 909090909090 | ||
ProgramHeaders: | ||
- Type: PT_LOAD | ||
VAddr: 0x1000 | ||
Sections: | ||
- Section: .text | ||
Symbols: | ||
- Name: both_static | ||
Value: 0x1001 | ||
Section: .text | ||
Binding: STB_GLOBAL | ||
- Name: only_static | ||
Value: 0x1002 | ||
Section: .text | ||
Binding: STB_GLOBAL | ||
DynamicSymbols: | ||
- Name: only_dyn | ||
Value: 0x1000 | ||
Section: .text | ||
Size: 1 | ||
Type: STT_FUNC | ||
Binding: STB_GLOBAL | ||
- Name: both_dyn | ||
Value: 0x1001 | ||
Section: .text | ||
Size: 1 | ||
Type: STT_FUNC | ||
Binding: STB_GLOBAL | ||
## The rest of the dynamic symbols won't be used for various reasons. | ||
## FIXME: the first two symbols here should be dumped. | ||
## See https://bugs.llvm.org/show_bug.cgi?id=41947 | ||
- Name: not_func | ||
Value: 0x1003 | ||
Section: .text | ||
Type: STT_OBJECT | ||
Binding: STB_GLOBAL | ||
- Name: zero_sized | ||
Value: 0x1004 | ||
Section: .text | ||
Type: STT_FUNC | ||
Binding: STB_GLOBAL | ||
- Name: '' # No name | ||
Value: 0x1005 | ||
Section: .text | ||
Size: 1 | ||
Type: STT_FUNC | ||
Binding: STB_GLOBAL | ||
- Name: absolute | ||
Value: 0x1005 | ||
Index: SHN_ABS | ||
Size: 1 | ||
Type: STT_FUNC | ||
Binding: STB_GLOBAL | ||
- Name: undefined | ||
Value: 0x1005 | ||
Index: SHN_UNDEF | ||
Size: 1 | ||
Type: STT_FUNC | ||
Binding: STB_GLOBAL |
24 changes: 24 additions & 0 deletions
24
llvm/test/tools/llvm-objdump/X86/elf-disassemble-no-symtab.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Show that llvm-objdump can handle a missing symbol table when printing | ||
## references and labels. | ||
|
||
# RUN: yaml2obj %s -o %t | ||
# RUN: llvm-objcopy -R .symtab %t | ||
# RUN: llvm-objdump %t -d | FileCheck %s | ||
|
||
# CHECK: Disassembly of section .text: | ||
# CHECK-EMPTY: | ||
# CHECK-NEXT: 0000000000004000 .text: | ||
# CHECK-NEXT: 4000: e8 42 00 00 00 callq 66 <.text+0x47> | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Address: 0x4000 | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Content: 'e842000000' |
42 changes: 42 additions & 0 deletions
42
llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Show that --disassemble + --reloc prints relocations inline and does not dump | ||
## the relocation sections. | ||
|
||
# RUN: yaml2obj %s -o %t.o | ||
# RUN: llvm-objdump %t.o -d -r | FileCheck %s --implicit-check-not="RELOCATION RECORDS" | ||
|
||
# CHECK: 0: e8 00 00 00 00 callq 0 <.text+0x5> | ||
# CHECK-NEXT: 0000000000000001: R_X86_64_PC32 foo-4 | ||
# CHECK-NEXT: 0000000000000002: R_X86_64_NONE bar+8 | ||
# CHECK-NEXT: 5: e8 00 00 00 00 callq 0 <.text+0xa> | ||
# CHECK-NEXT: 0000000000000006: R_X86_64_PLT32 foo+1 | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Content: 'e800000000e800000000' | ||
- Name: .rela.text | ||
Type: SHT_RELA | ||
Info: .text | ||
Relocations: | ||
- Offset: 1 | ||
Symbol: foo | ||
Type: R_X86_64_PC32 | ||
Addend: -4 | ||
- Offset: 2 | ||
Symbol: bar | ||
Type: R_X86_64_NONE | ||
Addend: 8 | ||
- Offset: 6 | ||
Symbol: foo | ||
Type: R_X86_64_PLT32 | ||
Addend: 1 | ||
Symbols: | ||
- Name: foo | ||
- Name: bar |
54 changes: 54 additions & 0 deletions
54
llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbol-labels-exec.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Show which labels are printed in disassembly of an executable. | ||
|
||
# RUN: yaml2obj %s -o %t | ||
# RUN: llvm-objdump %t -d | FileCheck %s --implicit-check-not=stt_section \ | ||
# RUN: --implicit-check-not=fourth \ | ||
# RUN: --implicit-check-not=absolute \ | ||
# RUN: --implicit-check-not=other | ||
|
||
# CHECK: 0000000000004000 first: | ||
# CHECK: 0000000000004001 second: | ||
# CHECK: 0000000000004002 third: | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_EXEC | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Address: 0x4000 | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Content: '9090909090' | ||
- Name: .text2 | ||
Type: SHT_PROGBITS | ||
Address: 0x4004 | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Size: 0 | ||
Symbols: | ||
- Name: first # Shows, with second, that symbol sizes are not used to delineate functions. | ||
Value: 0x4000 | ||
Section: .text | ||
Size: 0x2 | ||
- Name: second | ||
Value: 0x4001 | ||
Size: 0x1 | ||
Section: .text | ||
- Name: third # Shows, with fourth, that first symbol is picked. | ||
Value: 0x4002 | ||
Section: .text | ||
- Name: fourth | ||
Value: 0x4002 | ||
Section: .text | ||
- Name: stt_section # Shows that STT_SECTION symbols are ignored even if no other symbol present. | ||
Value: 0x4003 | ||
Type: STT_SECTION | ||
Section: .text | ||
- Name: absolute # Show that absolute symbols are ignored. | ||
Value: 0x4004 | ||
Index: SHN_ABS | ||
- Name: other # Show that symbols from other sections are ignored. | ||
Value: 0x4004 | ||
Section: .text2 |
58 changes: 58 additions & 0 deletions
58
llvm/test/tools/llvm-objdump/X86/elf-disassemble-symbol-labels-rel.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
## Show which labels are printed in disassembly of a relocatable object. | ||
|
||
# RUN: yaml2obj %s -o %t | ||
# RUN: llvm-objdump %t -d | FileCheck %s --implicit-check-not=stt_section \ | ||
# RUN: --implicit-check-not=first \ | ||
# RUN: --implicit-check-not=second \ | ||
# RUN: --implicit-check-not=third \ | ||
# RUN: --implicit-check-not=fourth \ | ||
# RUN: --implicit-check-not=absolute \ | ||
# RUN: --implicit-check-not=other | ||
|
||
# CHECK: Disassembly of section .text: | ||
# CHECK: 0000000000000000 first: | ||
# CHECK: 0000000000000001 second: | ||
# CHECK: 0000000000000002 third: | ||
# CHECK: Disassembly of section .text2: | ||
# CHECK: 0000000000000004 other: | ||
|
||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Content: '909090909090' | ||
- Name: .text2 | ||
Type: SHT_PROGBITS | ||
Flags: [SHF_ALLOC, SHF_EXECINSTR] | ||
Content: '9090909090' | ||
Symbols: | ||
- Name: first | ||
Value: 0 | ||
Section: .text | ||
Size: 2 | ||
- Name: second # Shows, with first, that symbol sizes are not used to delineate functions. | ||
Value: 1 | ||
Size: 1 | ||
Section: .text | ||
- Name: third # Shows, with fourth, that first symbol is picked. | ||
Value: 2 | ||
Section: .text | ||
- Name: fourth | ||
Value: 2 | ||
Section: .text | ||
- Name: stt_section # Shows that STT_SECTION symbols are ignored even if no other symbol present. | ||
Value: 3 | ||
Type: STT_SECTION | ||
Section: .text | ||
- Name: absolute # Show that absolute symbols are ignored. | ||
Value: 4 | ||
Index: SHN_ABS | ||
- Name: other # Show that symbols in other sections are ignored. | ||
Value: 4 | ||
Section: .text2 |
Oops, something went wrong.