Skip to content

Commit 2e0d0d3

Browse files
committed
[llvm-objdump]Improve testing of some switches #1
This is the first in a set of patches I have to improve testing of llvm-objdump. This patch targets --all-headers, --section, and --full-contents. In the --section case, it deletes a pre-canned binary which is only used by the one test and replaces it with yaml. Reviewed by: grimar, MaskRay Differential Revision: https://reviews.llvm.org/D61941 llvm-svn: 360893
1 parent e183340 commit 2e0d0d3

File tree

4 files changed

+255
-34
lines changed

4 files changed

+255
-34
lines changed
Binary file not shown.

llvm/test/tools/llvm-objdump/all-headers.test

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# RUN: yaml2obj %s > %t
22
# RUN: llvm-objdump --all-headers %t | FileCheck %s
33

4-
## Check we print file format, architecture and start address before
5-
## anything else when using --all-headers.
4+
## Check we print file format, architecture and start address followed by the
5+
## other data when using --all-headers.
66

77
# CHECK: file format ELF64-x86-64
88
# CHECK-EMPTY:
99
# CHECK-NEXT: architecture: x86_64
1010
# CHECK-NEXT: start address: 0x0000000000000000
1111
# CHECK-EMPTY:
1212
# CHECK-NEXT: Sections:
13+
# CHECK: SYMBOL TABLE:
14+
# CHECK: Program Header:
15+
# CHECK: Dynamic Section:
1316

1417
## Check how we dump the archives.
1518
## Check we dump the appropriate headers for each file in the archive.

llvm/test/tools/llvm-objdump/full-contents.test

+26-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
# RUN: llvm-objdump --full-contents %t > %t.out1
33
# RUN: llvm-objdump -s %t > %t.out2
44
# RUN: cmp %t.out1 %t.out2
5-
# RUN: FileCheck %s --input-file=%t.out1
5+
# RUN: FileCheck %s --input-file=%t.out1 --implicit-check-not=.empty-progbits \
6+
# RUN: --implicit-check-not=.empty-nobits
67

78
# CHECK: .bss
8-
# CHECK-NEXT: <skipping contents of bss section at [0000, 0040)>
9+
# CHECK-NEXT: <skipping contents of bss section at [1000, 1040)>
910
# CHECK: .text
10-
# CHECK-NEXT: 0000 01234567 .#Eg
11+
# CHECK-NEXT: 1010 01234567 .#Eg
1112
# CHECK: .user-defined
12-
# CHECK-NEXT: 0000 76543210 vT2.
13-
# CHECK: .empty-section
14-
# CHECK-NEXT: <skipping contents of bss section at [0000, 0020)>
13+
# CHECK-NEXT: 1020 76543210 vT2.
14+
# CHECK: .nobits-section
15+
# CHECK-NEXT: <skipping contents of bss section at [1030, 1050)>
16+
# CHECK: .non-alloc
17+
# CHECK: 0000 11112222 ..""
1518
# CHECK: .symtab
1619
# CHECK: .strtab
1720
# CHECK: .shstrtab
@@ -26,23 +29,38 @@ Sections:
2629
- Name: .bss
2730
Type: SHT_NOBITS
2831
Flags: [ SHF_ALLOC ]
32+
Address: 0x1000
2933
AddressAlign: 0x0000000000000010
3034
Size: 64
3135
- Name: .text
3236
Type: SHT_PROGBITS
3337
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
38+
Address: 0x1010
3439
AddressAlign: 0x0000000000000010
3540
Content: "01234567"
3641
Size: 4
3742
- Name: .user-defined
3843
Type: SHT_PROGBITS
3944
Flags: [ SHF_ALLOC ]
45+
Address: 0x1020
4046
AddressAlign: 0x0000000000000010
4147
Content: "76543210"
4248
Size: 4
43-
- Name: .empty-section
49+
- Name: .nobits-section
4450
Type: SHT_NOBITS
4551
Flags: [ SHF_ALLOC ]
52+
Address: 0x1030
4653
AddressAlign: 0x0000000000000010
4754
Size: 32
48-
55+
- Name: .empty-progbits
56+
Type: SHT_PROGBITS
57+
Address: 0x1040
58+
Flags: [ SHF_ALLOC ]
59+
- Name: .empty-nobits
60+
Type: SHT_NOBITS
61+
Address: 0x1050
62+
Flags: [ SHF_ALLOC ]
63+
- Name: .non-alloc
64+
Type: SHT_PROGBITS
65+
Flags: [ ]
66+
Content: '11112222'
+224-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,224 @@
1-
// This test checks that --section works correctly.
2-
// RUN: llvm-objdump -h %p/Inputs/section-filter.obj -j=.text \
3-
// RUN: --section=.bss | FileCheck %s
4-
5-
// CHECK: .text
6-
// CHECK-NOT: .data
7-
// CHECK: .bss
8-
9-
// Test that the -j alias can be used flexibly. Create a baseline and ensure
10-
// all other combinations are identical.
11-
// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s --section .symtab > %t.full
12-
// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s -j .symtab > %t.1
13-
// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s -j=.symtab > %t.2
14-
// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s -j.symtab > %t.3
15-
// RUN: llvm-objdump %p/Inputs/section-filter.obj -hsj .symtab > %t.4
16-
// RUN: llvm-objdump %p/Inputs/section-filter.obj -hsj=.symtab > %t.5
17-
// RUN: llvm-objdump %p/Inputs/section-filter.obj -hsj.symtab > %t.6
18-
19-
// RUN: cmp %t.full %t.1
20-
// RUN: cmp %t.full %t.2
21-
// RUN: cmp %t.full %t.3
22-
// RUN: cmp %t.full %t.4
23-
// RUN: cmp %t.full %t.5
24-
// RUN: cmp %t.full %t.6
1+
## Test that --section works correctly for -h.
2+
## We test the LMA here too, because the code at the time of writing uses the
3+
## value of --section when looking up section LMAs.
4+
# RUN: yaml2obj %s --docnum=1 -o %t.h.elf
5+
# RUN: llvm-objdump -h %t.h.elf -j=.text --section=.bss \
6+
# RUN: | FileCheck %s --check-prefix=SHDRS --implicit-check-not=.data --implicit-check-not=.text2
7+
8+
# SHDRS: Name Size VMA LMA
9+
# SHDRS: .text 00000001 0000000000000400 0000000000001000
10+
# SHDRS: .bss 00000001 0000000000000420 0000000000003000
11+
12+
--- !ELF
13+
FileHeader:
14+
Class: ELFCLASS64
15+
Data: ELFDATA2LSB
16+
Type: ET_EXEC
17+
Machine: EM_X86_64
18+
Sections:
19+
- Name: .text
20+
Type: SHT_PROGBITS
21+
Flags: [SHF_ALLOC, SHF_EXECINSTR]
22+
Address: 0x400
23+
AddressAlign: 0x10
24+
Content: 'c3'
25+
- Name: .text2
26+
Type: SHT_PROGBITS
27+
Flags: [SHF_ALLOC, SHF_EXECINSTR]
28+
Address: 0x401
29+
Content: '90'
30+
- Name: .data
31+
Type: SHT_PROGBITS
32+
Flags: [SHF_ALLOC, SHF_WRITE]
33+
Address: 0x410
34+
AddressAlign: 0x10
35+
Content: '42'
36+
- Name: .bss
37+
Type: SHT_NOBITS
38+
Flags: [SHF_ALLOC, SHF_WRITE]
39+
Address: 0x420
40+
AddressAlign: 0x10
41+
Size: 1
42+
ProgramHeaders:
43+
- Type: PT_LOAD
44+
VAddr: 0x400
45+
PAddr: 0x1000
46+
Sections:
47+
- Section: .text
48+
- Section: .text2
49+
- Type: PT_LOAD
50+
VAddr: 0x410
51+
PAddr: 0x2000
52+
Sections:
53+
- Section: .data
54+
- Type: PT_LOAD
55+
VAddr: 0x420
56+
PAddr: 0x3000
57+
Sections:
58+
- Section: .bss
59+
60+
## Test that --section works correctly for -d with -r.
61+
## FIXME: Inline relocations are only printed if the relocation section itself is
62+
## specified with --section. This test just characterizes the existing behavior.
63+
## See https://bugs.llvm.org/show_bug.cgi?id=41886
64+
# RUN: yaml2obj %s --docnum=2 -o %t.o
65+
66+
## Show non-executable sections are not disassembled even if specified,
67+
## and that only the specified executable sections are disassembled.
68+
## Also show that no relocation sections are dumped because none are
69+
## specified.
70+
## FIXME: This is different behaviour to GNU objdump, which dumps the non-
71+
## executable sections if requested explicitly.
72+
## See https://bugs.llvm.org/show_bug.cgi?id=41897.
73+
# RUN: llvm-objdump -d -r %t.o --section=.text --section=.rodata \
74+
# RUN: | FileCheck %s --check-prefix=DISASM --implicit-check-not=.text2 \
75+
# RUN: --implicit-check-not=.rodata --implicit-check-not=R_X86_64
76+
77+
## Show that only the specified relocation sections that patch the
78+
## disassembled sections are dumped.
79+
# RUN: llvm-objdump -d -r %t.o --section=.text \
80+
# RUN: --section=.rela.text --section=.rela.text2 \
81+
# RUN: | FileCheck %s --check-prefixes=DISASM,RELOC --implicit-check-not=.text2 \
82+
# RUN: --implicit-check-not=R_X86_64
83+
84+
# DISASM: Disassembly of section .text:
85+
# DISASM-EMPTY:
86+
# DISASM-NEXT: 0000000000000400 .text:
87+
# DISASM-NEXT: 400: e8 00 00 00 00 callq 0 <.text+0x5>
88+
# RELOC-NEXT: 00000401: R_X86_64_PC32 foo+1
89+
90+
--- !ELF
91+
FileHeader:
92+
Class: ELFCLASS64
93+
Data: ELFDATA2LSB
94+
Type: ET_REL
95+
Machine: EM_X86_64
96+
Sections:
97+
- Name: .text
98+
Type: SHT_PROGBITS
99+
Flags: [SHF_ALLOC, SHF_EXECINSTR]
100+
Address: 0x400
101+
AddressAlign: 0x10
102+
Content: 'e800000000'
103+
- Name: .text2
104+
Type: SHT_PROGBITS
105+
Flags: [SHF_ALLOC, SHF_EXECINSTR]
106+
Address: 0x401
107+
Content: '90e800000000'
108+
- Name: .rela.text
109+
Type: SHT_RELA
110+
Info: .text
111+
Relocations:
112+
- Offset: 1
113+
Symbol: foo
114+
Addend: 1
115+
Type: R_X86_64_PC32
116+
- Name: .another.rela.text
117+
Type: SHT_RELA
118+
Info: .text
119+
Relocations:
120+
- Offset: 1
121+
Symbol: foo
122+
Type: R_X86_64_GOT32
123+
- Name: .rela.text2
124+
Type: SHT_RELA
125+
Info: .text2
126+
Relocations:
127+
- Offset: 1
128+
Symbol: foo
129+
Addend: 2
130+
Type: R_X86_64_PLT32
131+
- Name: .rodata
132+
Type: SHT_PROGBITS
133+
Flags: [SHF_ALLOC]
134+
Size: 4
135+
- Name: .rela.rodata
136+
Type: SHT_RELA
137+
Info: .rodata
138+
Relocations:
139+
- Offset: 0
140+
Symbol: foo
141+
Type: R_X86_64_NONE
142+
Symbols:
143+
- Name: foo
144+
145+
## Test that --section works when dumping relocation sections.
146+
# RUN: llvm-objdump -r %t.o --section=.another.rela.text --section=.rela.rodata \
147+
# RUN: | FileCheck %s --check-prefix=DUMP-RELOCS --implicit-check-not=R_X86_64 \
148+
# RUN: --implicit-check-not="RELOCATION RECORDS"
149+
150+
# DUMP-RELOCS: RELOCATION RECORDS FOR [.text]:
151+
# DUMP-RELOCS: 00000001 R_X86_64_GOT32 foo
152+
# DUMP-RELOCS: RELOCATION RECORDS FOR [.rodata]:
153+
# DUMP-RELOCS: 00000000 R_X86_64_NONE foo
154+
155+
## Test that --section works with --full-contents.
156+
# RUN: llvm-objdump -s %t.o --section=.text --section=.rela.text2 \
157+
# RUN: | FileCheck %s --check-prefix=CONTENTS \
158+
# RUN: --implicit-check-not=.text \
159+
# RUN: --implicit-check-not=.rodata
160+
161+
# CONTENTS: Contents of section .text:
162+
# CONTENTS: Contents of section .rela.text2:
163+
164+
## Test that --section works with --fault-map-section.
165+
# RUN: yaml2obj %s --docnum=3 -o %t2.o
166+
# RUN: llvm-objdump %t2.o --fault-map-section -j __clangast \
167+
# RUN: | FileCheck %s --check-prefixes=FAULTMAP,NO-FAULTMAP
168+
# RUN: llvm-objdump %t2.o --fault-map-section -j .llvm_faultmaps \
169+
# RUN: | FileCheck %s --check-prefixes=FAULTMAP,WITH-FAULTMAP
170+
171+
# FAULTMAP: FaultMap table:
172+
# NO-FAULTMAP-NEXT: <not found>
173+
# WITH-FAULTMAP-NEXT: Version: 0x1
174+
# WITH-FAULTMAP-NEXT: NumFunctions: 0
175+
176+
## Test that --section works with --raw-clang-ast.
177+
# RUN: llvm-objdump %t2.o --raw-clang-ast -j .llvm_faultmaps \
178+
# RUN: | FileCheck %s --check-prefix=NO-AST --allow-empty
179+
# RUN: llvm-objdump %t2.o --raw-clang-ast -j __clangast \
180+
# RUN: | FileCheck %s --check-prefix=CLANG-AST
181+
182+
# NO-AST-NOT: {{.}}
183+
# CLANG-AST: foobar
184+
185+
--- !ELF
186+
FileHeader:
187+
Class: ELFCLASS64
188+
Data: ELFDATA2LSB
189+
Type: ET_REL
190+
Machine: EM_X86_64
191+
Sections:
192+
- Name: .llvm_faultmaps
193+
Type: SHT_PROGBITS
194+
Content: '0100000000000000'
195+
- Name: __clangast
196+
Type: SHT_PROGBITS
197+
Content: '666f6f626172' # "foobar"
198+
199+
## Test that the -j alias can be used flexibly. Create a baseline and ensure
200+
## all other combinations are identical.
201+
# RUN: llvm-objdump %t.h.elf -h -s --section .symtab > %t.full
202+
# RUN: llvm-objdump %t.h.elf -h -s -j .symtab > %t.1
203+
# RUN: llvm-objdump %t.h.elf -h -s -j=.symtab > %t.2
204+
# RUN: llvm-objdump %t.h.elf -h -s -j.symtab > %t.3
205+
# RUN: llvm-objdump %t.h.elf -hsj .symtab > %t.4
206+
# RUN: llvm-objdump %t.h.elf -hsj=.symtab > %t.5
207+
# RUN: llvm-objdump %t.h.elf -hsj.symtab > %t.6
208+
209+
# RUN: cmp %t.full %t.1
210+
# RUN: cmp %t.full %t.2
211+
# RUN: cmp %t.full %t.3
212+
# RUN: cmp %t.full %t.4
213+
# RUN: cmp %t.full %t.5
214+
# RUN: cmp %t.full %t.6
215+
216+
## Test that an unknown section name causes all section output to be suppressed.
217+
## TODO: Add a warning for this case.
218+
## See https://bugs.llvm.org/show_bug.cgi?id=41898.
219+
# RUN: llvm-objdump %t.h.elf -h --section foobar \
220+
# RUN: | FileCheck %s --check-prefix=NO-SECTION
221+
222+
# NO-SECTION: Sections:
223+
# NO-SECTION-NEXT: Idx Name Size VMA Type
224+
# NO-SECTION-NOT: {{.}}

0 commit comments

Comments
 (0)