Skip to content

Commit 7fc599c

Browse files
author
Georgii Rymar
committed
[llvm-readobj] - Introduce warnings for cases when unable to read strings from string tables.
Currently we have no dedicated warnings, but we return error message instead of a result. It is generally not consistent with another warnings we have. This change was suggested and discussed here: https://reviews.llvm.org/D77216#1954873 This change refines error messages we report and also I had to update the API to implement it. Differential revision: https://reviews.llvm.org/D77399
1 parent e268ec8 commit 7fc599c

File tree

4 files changed

+167
-113
lines changed

4 files changed

+167
-113
lines changed

llvm/test/tools/llvm-readobj/ELF/dynamic-malformed.test

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,54 @@ ProgramHeaders:
9090

9191
## Test handling of string references pointing past the end of the dynamic string table.
9292
# RUN: yaml2obj %s --docnum=3 -o %t.bad-string
93-
# RUN: llvm-readobj --dynamic-table %t.bad-string | FileCheck %s --check-prefix BAD-STRING-LLVM
94-
# RUN: llvm-readelf --dynamic-table %t.bad-string | FileCheck %s --check-prefix BAD-STRING-GNU
95-
96-
# BAD-STRING-LLVM: 0x000000000000000A STRSZ 1 (bytes)
97-
# BAD-STRING-LLVM: 0x0000000000000001 NEEDED Shared library: [<Invalid offset 0x1>]
98-
# BAD-STRING-LLVM: 0x000000007FFFFFFF FILTER Filter library: [<Invalid offset 0x1>]
99-
# BAD-STRING-LLVM: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [<Invalid offset 0x1>]
100-
# BAD-STRING-LLVM: 0x000000007FFFFFFE USED Not needed object: [<Invalid offset 0x1>]
101-
# BAD-STRING-LLVM: 0x000000000000000E SONAME Library soname: [<Invalid offset 0x1>]
102-
# BAD-STRING-LLVM: 0x000000000000000F RPATH Library rpath: [<Invalid offset 0x1>]
103-
# BAD-STRING-LLVM: 0x000000000000001D RUNPATH Library runpath: [<Invalid offset 0x1>]
104-
105-
# BAD-STRING-GNU: 0x000000000000000a (STRSZ) 1 (bytes)
106-
# BAD-STRING-GNU: 0x0000000000000001 (NEEDED) Shared library: [<Invalid offset 0x1>]
107-
# BAD-STRING-GNU: 0x000000007fffffff (FILTER) Filter library: [<Invalid offset 0x1>]
108-
# BAD-STRING-GNU: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [<Invalid offset 0x1>]
109-
# BAD-STRING-GNU: 0x000000007ffffffe (USED) Not needed object: [<Invalid offset 0x1>]
110-
# BAD-STRING-GNU: 0x000000000000000e (SONAME) Library soname: [<Invalid offset 0x1>]
111-
# BAD-STRING-GNU: 0x000000000000000f (RPATH) Library rpath: [<Invalid offset 0x1>]
112-
# BAD-STRING-GNU: 0x000000000000001d (RUNPATH) Library runpath: [<Invalid offset 0x1>]
93+
# RUN: llvm-readobj --dynamic-table %t.bad-string 2>&1 | \
94+
# RUN: FileCheck %s --implicit-check-not=warning: --check-prefix BAD-STRING-LLVM -DFILE=%t.bad-string
95+
# RUN: llvm-readelf --dynamic-table %t.bad-string 2>&1 | \
96+
# RUN: FileCheck %s --implicit-check-not=warning: --check-prefix BAD-STRING-GNU -DFILE=%t.bad-string
97+
98+
# BAD-STRING-LLVM: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6, it goes past the end of the table (0xb1)
99+
# BAD-STRING-LLVM: LoadName: <?>
100+
# BAD-STRING-LLVM: DynamicSection [ (10 entries)
101+
# BAD-STRING-LLVM-NEXT: Tag Type Name/Value
102+
# BAD-STRING-LLVM-NEXT: 0x0000000000000005 STRTAB 0x1000
103+
# BAD-STRING-LLVM-NEXT: 0x000000000000000A STRSZ 1 (bytes)
104+
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb2, it goes past the end of the table (0xb1)
105+
# BAD-STRING-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
106+
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb3, it goes past the end of the table (0xb1)
107+
# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: [<?>]
108+
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4, it goes past the end of the table (0xb1)
109+
# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [<?>]
110+
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5, it goes past the end of the table (0xb1)
111+
# BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: [<?>]
112+
## Note: there is no "string table at offset 0xb0..." warning here, because it was printed earlier.
113+
# BAD-STRING-LLVM-NEXT: 0x000000000000000E SONAME Library soname: [<?>]
114+
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb7, it goes past the end of the table (0xb1)
115+
# BAD-STRING-LLVM-NEXT: 0x000000000000000F RPATH Library rpath: [<?>]
116+
# BAD-STRING-LLVM-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb8, it goes past the end of the table (0xb1)
117+
# BAD-STRING-LLVM-NEXT: 0x000000000000001D RUNPATH Library runpath: [<?>]
118+
# BAD-STRING-LLVM-NEXT: 0x0000000000000000 NULL 0x0
119+
# BAD-STRING-LLVM-NEXT: ]
120+
121+
# BAD-STRING-GNU: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6, it goes past the end of the table (0xb1)
122+
# BAD-STRING-GNU-NEXT: Dynamic section at offset 0xb1 contains 10 entries:
123+
# BAD-STRING-GNU-NEXT: Tag Type Name/Value
124+
# BAD-STRING-GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000
125+
# BAD-STRING-GNU-NEXT: 0x000000000000000a (STRSZ) 1 (bytes)
126+
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb2, it goes past the end of the table (0xb1)
127+
# BAD-STRING-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
128+
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb3, it goes past the end of the table (0xb1)
129+
# BAD-STRING-GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [<?>]
130+
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4, it goes past the end of the table (0xb1)
131+
# BAD-STRING-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [<?>]
132+
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5, it goes past the end of the table (0xb1)
133+
# BAD-STRING-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [<?>]
134+
## Note: there is no "string table at offset 0xb6..." warning here, because it was printed earlier.
135+
# BAD-STRING-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [<?>]
136+
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb7, it goes past the end of the table (0xb1)
137+
# BAD-STRING-GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [<?>]
138+
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb8, it goes past the end of the table (0xb1)
139+
# BAD-STRING-GNU-NEXT: 0x000000000000001d (RUNPATH) Library runpath: [<?>]
140+
# BAD-STRING-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
113141

114142
--- !ELF
115143
FileHeader:
@@ -130,19 +158,19 @@ Sections:
130158
- Tag: DT_STRSZ
131159
Value: 1
132160
- Tag: DT_NEEDED
133-
Value: 1
161+
Value: 2
134162
- Tag: DT_FILTER
135-
Value: 1
163+
Value: 3
136164
- Tag: DT_AUXILIARY
137-
Value: 1
165+
Value: 4
138166
- Tag: DT_USED
139-
Value: 1
167+
Value: 5
140168
- Tag: DT_SONAME
141-
Value: 1
169+
Value: 6
142170
- Tag: DT_RPATH
143-
Value: 1
171+
Value: 7
144172
- Tag: DT_RUNPATH
145-
Value: 1
173+
Value: 8
146174
- Tag: DT_NULL
147175
Value: 0
148176
Symbols: []
@@ -160,17 +188,23 @@ ProgramHeaders:
160188
## Test handling of DT_STRTAB pointing outside the file's address space.
161189
# RUN: yaml2obj %s --docnum=4 -o %t.bad-strtab
162190

163-
# RUN: llvm-readobj --dynamic-table %t.bad-strtab 2>&1 >/dev/null | FileCheck -DFILE=%t.bad-strtab %s --check-prefix BAD-STRTAB-ERR
164-
# RUN: llvm-readelf --dynamic-table %t.bad-strtab 2>&1 >/dev/null | FileCheck -DFILE=%t.bad-strtab %s --check-prefix BAD-STRTAB-ERR
191+
# RUN: llvm-readobj --dynamic-table %t.bad-strtab 2>&1 >/dev/null | \
192+
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefix BAD-STRTAB-ERR
193+
# RUN: llvm-readelf --dynamic-table %t.bad-strtab 2>&1 >/dev/null | \
194+
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefix BAD-STRTAB-ERR
165195
# BAD-STRTAB-ERR: warning: '[[FILE]]': Unable to parse DT_STRTAB: virtual address is not in any segment: 0x2000000
196+
# BAD-STRTAB-ERR: warning: '[[FILE]]': string table was not found
197+
198+
# RUN: llvm-readobj --dynamic-table --needed-libs %t.bad-strtab 2>&1 | \
199+
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR,BAD-STRTAB,BAD-STRTAB-LLVM
200+
# RUN: llvm-readelf --dynamic-table --needed-libs %t.bad-strtab 2>&1 | \
201+
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR,BAD-STRTAB,BAD-STRTAB-GNU
166202

167-
# RUN: llvm-readobj --dynamic-table --needed-libs %t.bad-strtab | FileCheck %s --check-prefixes=BAD-STRTAB,BAD-STRTAB-LLVM
168-
# RUN: llvm-readelf --dynamic-table --needed-libs %t.bad-strtab | FileCheck %s --check-prefixes=BAD-STRTAB,BAD-STRTAB-GNU
169-
# BAD-STRTAB-LLVM: LoadName: <String table is empty or was not found>
170-
# BAD-STRTAB-LLVM: 0x0000000000000001 NEEDED Shared library: [<String table is empty or was not found>]
171-
# BAD-STRTAB-GNU: 0x0000000000000001 (NEEDED) Shared library: [<String table is empty or was not found>]
203+
# BAD-STRTAB-LLVM: LoadName: <?>
204+
# BAD-STRTAB-LLVM: 0x0000000000000001 NEEDED Shared library: [<?>]
205+
# BAD-STRTAB-GNU: 0x0000000000000001 (NEEDED) Shared library: [<?>]
172206
# BAD-STRTAB: NeededLibraries [
173-
# BAD-STRTAB: <String table is empty or was not found>
207+
# BAD-STRTAB: <?>
174208
# BAD-STRTAB: ]
175209

176210
--- !ELF

llvm/test/tools/llvm-readobj/ELF/loadname.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@ ProgramHeaders:
6161
# RUN: llvm-readelf --dynamic-table %t.err.1.o 2>&1 | FileCheck %s -DFILE=%t.err.1.o --check-prefixes=BROKEN-OFFSET,BROKEN-OFFSET-GNU
6262

6363
# BROKEN-OFFSET: warning: '[[FILE]]': Unable to parse DT_STRTAB: can't map virtual address 0xfffe to the segment with index 1: the segment ends at 0x10077, which is greater than the file size (0x228)
64-
# BROKEN-OFFSET-LLVM: LoadName: <String table is empty or was not found>
65-
# BROKEN-OFFSET-GNU: 0x000000000000000e (SONAME) Library soname: [<String table is empty or was not found>]
64+
# BROKEN-OFFSET: warning: '[[FILE]]': string table was not found
65+
# BROKEN-OFFSET-LLVM: LoadName: <?>
66+
# BROKEN-OFFSET-GNU: 0x000000000000000e (SONAME) Library soname: [<?>]

llvm/test/tools/llvm-readobj/ELF/needed-libs.test

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
## In this test we check the --needed-libs option.
22

33
# RUN: yaml2obj %s --docnum=1 -o %t1
4-
# RUN: llvm-readobj --needed-libs %t1 \
5-
# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=NEEDED-LIBS
6-
# RUN: llvm-readelf --needed-libs %t1 \
7-
# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=NEEDED-LIBS
4+
# RUN: llvm-readobj --needed-libs %t1 2>&1 \
5+
# RUN: | FileCheck %s -DFILE=%t1 --implicit-check-not=warning: --strict-whitespace --check-prefix=NEEDED-LIBS
6+
# RUN: llvm-readelf --needed-libs %t1 2>&1 \
7+
# RUN: | FileCheck %s -DFILE=%t1 --implicit-check-not=warning: --strict-whitespace --check-prefix=NEEDED-LIBS
88

99
## Check that library names are sorted when printed.
1010
## Document that we also sort error entries.
1111

12-
# NEEDED-LIBS:NeededLibraries [
13-
# NEEDED-LIBS-NEXT: <Invalid offset 0x1111111>
14-
# NEEDED-LIBS-NEXT: <Invalid offset 0x9999999>
15-
# NEEDED-LIBS-NEXT: aaa
16-
# NEEDED-LIBS-NEXT: bbb
17-
# NEEDED-LIBS-NEXT: ccc
18-
# NEEDED-LIBS-NEXT:]
12+
# NEEDED-LIBS:{{^}}NeededLibraries [{{$}}
13+
# NEEDED-LIBS-NEXT: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x9999a11, it goes past the end of the table (0x85){{$}}
14+
# NEEDED-LIBS-NEXT: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x1111189, it goes past the end of the table (0x85){{$}}
15+
# NEEDED-LIBS-NEXT:{{^}} <?>{{$}}
16+
# NEEDED-LIBS-NEXT:{{^}} <?>{{$}}
17+
# NEEDED-LIBS-NEXT:{{^}} aaa{{$}}
18+
# NEEDED-LIBS-NEXT:{{^}} bbb{{$}}
19+
# NEEDED-LIBS-NEXT:{{^}} ccc{{$}}
20+
# NEEDED-LIBS-NEXT:{{^}}]{{$}}
1921

2022
--- !ELF
2123
FileHeader:
@@ -56,11 +58,18 @@ ProgramHeaders:
5658

5759
## Check what we print when the dynamic string table is empty.
5860
# RUN: yaml2obj %s --docnum=2 -o %t2
59-
# RUN: llvm-readobj --needed-libs %t2 | FileCheck %s --check-prefix=EMPTY-DYNSTR
60-
# RUN: llvm-readelf --needed-libs %t2 | FileCheck %s --check-prefix=EMPTY-DYNSTR
61+
# RUN: llvm-readobj --needed-libs %t2 2>&1 | \
62+
# RUN: FileCheck %s -DFILE=%t2 --implicit-check-not=warning: --check-prefixes=EMPTY-DYNSTR,EMPTY-DYNSTR-LLVM
63+
# RUN: llvm-readelf --needed-libs %t2 2>&1 | \
64+
# RUN: FileCheck %s -DFILE=%t2 --implicit-check-not=warning: --check-prefix=EMPTY-DYNSTR
6165

66+
# EMPTY-DYNSTR: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x78, it goes past the end of the table (0x78)
67+
# EMPTY-DYNSTR-LLVM: LoadName: <?>
6268
# EMPTY-DYNSTR: NeededLibraries [
63-
# EMPTY-DYNSTR-NEXT: <String table is empty or was not found>
69+
# EMPTY-DYNSTR-NEXT: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x79, it goes past the end of the table (0x78)
70+
# EMPTY-DYNSTR-NEXT: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x7a, it goes past the end of the table (0x78)
71+
# EMPTY-DYNSTR-NEXT: <?>
72+
# EMPTY-DYNSTR-NEXT: <?>
6473
# EMPTY-DYNSTR-NEXT: ]
6574

6675
--- !ELF
@@ -82,6 +91,8 @@ Sections:
8291
Value: 0x0000000000000000
8392
- Tag: DT_NEEDED
8493
Value: 1
94+
- Tag: DT_NEEDED
95+
Value: 2
8596
- Tag: DT_STRSZ
8697
Value: 0x0
8798
- Tag: DT_NULL

0 commit comments

Comments
 (0)