Skip to content

Commit 416603e

Browse files
committed
[llvm-readobj]Add additional testing for various ELF features
This patch adds testing of areas of the code that are not fully tested, in particular dynamic table printing, ELF type printing, handling of edge cases where things are missing/empty (relocations/program header tables/section header table), and the --string-dump switch. Reviewed by: grimar, higuoxing, rupprecht Differential Revision: https://reviews.llvm.org/D58677 llvm-svn: 355003
1 parent 8c436ce commit 416603e

11 files changed

+1152
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Show that llvm-readobj can handle an empty .dynamic section.
2+
3+
# RUN: yaml2obj %s -o %t.o
4+
# RUN: llvm-readobj --dynamic-table %t.o | FileCheck %s --check-prefix LLVM
5+
# RUN: llvm-readelf --dynamic-table %t.o | FileCheck %s --check-prefix GNU --allow-empty
6+
7+
# LLVM: File: {{.*}}.o
8+
# LLVM-NOT: DynamicSection
9+
# GNU-NOT: {{.}}
10+
11+
!ELF
12+
FileHeader:
13+
Class: ELFCLASS64
14+
Data: ELFDATA2LSB
15+
Type: ET_EXEC
16+
Machine: EM_X86_64
17+
Sections:
18+
- Name: .dynamic
19+
Type: SHT_DYNAMIC
20+
Address: 0x1000
21+
ProgramHeaders:
22+
- Type: PT_LOAD
23+
VAddr: 0x1000
24+
Sections:
25+
- Section: .dynamic
26+
- Type: PT_DYNAMIC
27+
VAddr: 0x1000
28+
Sections:
29+
- Section: .dynamic
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Test handling of a dynamic section size which is not a multiple of its entry size.
2+
# RUN: yaml2obj %s --docnum=1 -o %t.bad-size
3+
# RUN: not llvm-readobj --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE
4+
# RUN: not llvm-readelf --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE
5+
6+
# ERR-SIZE: Error reading file: Invalid entity size.
7+
8+
--- !ELF
9+
FileHeader:
10+
Class: ELFCLASS64
11+
Data: ELFDATA2LSB
12+
Type: ET_EXEC
13+
Machine: EM_X86_64
14+
Sections:
15+
- Name: .dynamic
16+
Type: SHT_DYNAMIC
17+
Address: 0x1000
18+
Content: "01234567"
19+
ProgramHeaders:
20+
- Type: PT_LOAD
21+
VAddr: 0x1000
22+
Sections:
23+
- Section: .dynamic
24+
- Type: PT_DYNAMIC
25+
VAddr: 0x1000
26+
Sections:
27+
- Section: .dynamic
28+
29+
# Test handling of a .dynamic section with an invalid entsize (i.e. not 2 * sizeof(Elf_Dyn)).
30+
# RUN: yaml2obj %s --docnum=2 -o %t.bad-entsize
31+
# RUN: llvm-readobj --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE
32+
# RUN: llvm-readelf --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE
33+
34+
# BAD-ENTSIZE: DynamicSection [ (2 entries)
35+
# BAD-ENTSIZE-NEXT: Tag Type Name/Value
36+
# BAD-ENTSIZE-NEXT: 0x0000000000000015 DEBUG 0x0
37+
# BAD-ENTSIZE-NEXT: 0x0000000000000000 NULL 0x0
38+
# BAD-ENTSIZE-NEXT: ]
39+
40+
--- !ELF
41+
FileHeader:
42+
Class: ELFCLASS64
43+
Data: ELFDATA2LSB
44+
Type: ET_EXEC
45+
Machine: EM_X86_64
46+
Sections:
47+
- Name: .dynamic
48+
Type: SHT_DYNAMIC
49+
Address: 0x1000
50+
EntSize: 0x2
51+
Entries:
52+
- Tag: DT_DEBUG
53+
Value: 0
54+
- Tag: DT_NULL
55+
Value: 0
56+
ProgramHeaders:
57+
- Type: PT_LOAD
58+
VAddr: 0x1000
59+
Sections:
60+
- Section: .dynamic
61+
- Type: PT_DYNAMIC
62+
VAddr: 0x1000
63+
Sections:
64+
- Section: .dynamic
65+
66+
# Test handling of string references pointing past the end of the dynamic string table. In this case,
67+
# we have a DT_NEEDED tag pointing at offset 1 in a 1-byte string table.
68+
# RUN: yaml2obj %s --docnum=3 -o %t.bad-string
69+
# RUN: not llvm-readobj --dynamic-table %t.bad-string 2>&1 | FileCheck %s --check-prefix BAD-STRING
70+
# RUN: not llvm-readelf --dynamic-table %t.bad-string 2>&1 | FileCheck %s --check-prefix BAD-STRING
71+
72+
# BAD-STRING: Error reading file: Invalid dynamic string table reference.
73+
74+
--- !ELF
75+
FileHeader:
76+
Class: ELFCLASS64
77+
Data: ELFDATA2LSB
78+
Type: ET_EXEC
79+
Machine: EM_X86_64
80+
Sections:
81+
- Name: .dynstr
82+
Type: SHT_STRTAB
83+
Address: 0x1000
84+
- Name: .dynamic
85+
Type: SHT_DYNAMIC
86+
Address: 0x1010
87+
Entries:
88+
- Tag: DT_STRTAB
89+
Value: 0x1000
90+
- Tag: DT_STRSZ
91+
Value: 1
92+
- Tag: DT_NEEDED
93+
Value: 1
94+
- Tag: DT_NULL
95+
Value: 0
96+
ProgramHeaders:
97+
- Type: PT_LOAD
98+
VAddr: 0x1000
99+
Sections:
100+
- Section: .dynstr
101+
- Section: .dynamic
102+
- Type: PT_DYNAMIC
103+
VAddr: 0x1010
104+
Sections:
105+
- Section: .dynamic
106+
107+
# Test handling of DT_STRTAB pointing outside the file's address space.
108+
# RUN: yaml2obj %s --docnum=4 -o %t.bad-strtab
109+
# RUN: not llvm-readobj --dynamic-table %t.bad-strtab 2>&1 | FileCheck %s --check-prefix BAD-STRTAB
110+
# RUN: not llvm-readelf --dynamic-table %t.bad-strtab 2>&1 | FileCheck %s --check-prefix BAD-STRTAB
111+
112+
# BAD-STRTAB: LLVM ERROR: Virtual address is not in any segment
113+
114+
--- !ELF
115+
FileHeader:
116+
Class: ELFCLASS64
117+
Data: ELFDATA2LSB
118+
Type: ET_EXEC
119+
Machine: EM_X86_64
120+
Sections:
121+
- Name: .dynamic
122+
Type: SHT_DYNAMIC
123+
Address: 0x1000
124+
Entries:
125+
- Tag: DT_STRTAB
126+
Value: 0x2000000
127+
- Tag: DT_STRSZ
128+
Value: 10
129+
- Tag: DT_NEEDED
130+
Value: 1
131+
- Tag: DT_NULL
132+
Value: 0x0
133+
ProgramHeaders:
134+
- Type: PT_LOAD
135+
VAddr: 0x1000
136+
Sections:
137+
- Section: .dynamic
138+
- Type: PT_DYNAMIC
139+
VAddr: 0x1000
140+
Sections:
141+
- Section: .dynamic
142+
143+
# Test handling of other d_ptr tags pointing outside the file's address space.
144+
# RUN: yaml2obj %s --docnum=5 -o %t.bad-rela
145+
# RUN: not llvm-readobj --dynamic-table %t.bad-rela 2>&1 | FileCheck %s --check-prefix BAD-RELA
146+
# RUN: not llvm-readelf --dynamic-table %t.bad-rela 2>&1 | FileCheck %s --check-prefix BAD-RELA
147+
148+
# BAD-RELA: LLVM ERROR: Virtual address is not in any segment
149+
150+
--- !ELF
151+
FileHeader:
152+
Class: ELFCLASS64
153+
Data: ELFDATA2LSB
154+
Type: ET_EXEC
155+
Machine: EM_X86_64
156+
Sections:
157+
- Name: .dynamic
158+
Type: SHT_DYNAMIC
159+
Address: 0x1000
160+
Entries:
161+
- Tag: DT_RELA
162+
Value: 0x1000000
163+
- Tag: DT_NULL
164+
Value: 0x0
165+
ProgramHeaders:
166+
- Type: PT_LOAD
167+
VAddr: 0x1000
168+
Sections:
169+
- Section: .dynamic
170+
- Type: PT_DYNAMIC
171+
VAddr: 0x1000
172+
Sections:
173+
- Section: .dynamic
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Show that no dumping occurs if there is no PT_DYNAMIC header.
2+
# RUN: yaml2obj %s -o %t.no-phdr
3+
# RUN: llvm-readobj --dynamic-table %t.no-phdr | FileCheck %s --check-prefix=LLVM
4+
# RUN: llvm-readelf --dynamic-table %t.no-phdr | FileCheck %s --check-prefix=GNU --allow-empty
5+
6+
# LLVM: File: {{.*}}.no-phdr
7+
# LLVM-NEXT: Format: ELF64-x86-64
8+
# LLVM-NEXT: Arch: x86_64
9+
# LLVM-NEXT: AddressSize: 64bit
10+
# LLVM-NEXT: LoadName:{{ *}}
11+
# LLVM-NOT: {{.}}
12+
13+
# GNU-NOT: {{.}}
14+
15+
--- !ELF
16+
FileHeader:
17+
Class: ELFCLASS64
18+
Data: ELFDATA2LSB
19+
Type: ET_EXEC
20+
Machine: EM_X86_64
21+
Sections:
22+
- Name: .dynamic
23+
Type: SHT_DYNAMIC
24+
Address: 0x1000
25+
Entries:
26+
- Tag: DT_NULL
27+
Value: 0
28+
ProgramHeaders:
29+
- Type: PT_LOAD
30+
VAddr: 0x1000
31+
Sections:
32+
- Section: .dynamic

0 commit comments

Comments
 (0)