1 ## Test handling of a dynamic section size which is not a multiple of its entry size.
2 ## Test the full output to demonstrate how we print the warnings.
4 # RUN: yaml2obj %s --docnum=1 -o %t.bad-size
5 # RUN: llvm-readobj --all %t.bad-size 2>&1 \
6 # RUN: | FileCheck %s -DFILE=%t.bad-size --implicit-check-not=warning: --check-prefix WARN
7 # RUN: llvm-readelf --all %t.bad-size 2>&1 \
8 # RUN: | FileCheck %s -DFILE=%t.bad-size --implicit-check-not=warning: --check-prefix WARN-GNU
10 # WARN: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x4){{$}}
11 # WARN: warning: '[[FILE]]': SHT_DYNAMIC section with index 1 has invalid size (0x4){{$}}
12 # WARN: warning: '[[FILE]]': no valid dynamic table was found
15 # WARN: ProgramHeaders [
19 # WARN-GNU: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x4){{$}}
20 # WARN-GNU: warning: '[[FILE]]': SHT_DYNAMIC section with index 1 has invalid size (0x4){{$}}
21 # WARN-GNU: warning: '[[FILE]]': no valid dynamic table was found
22 # WARN-GNU-NEXT: ELF Header:
23 # WARN-GNU: Symbol table '.symtab' contains 1 entries:
47 ## Test handling of a .dynamic section with an invalid entsize (i.e. not 2 * sizeof(Elf_Dyn)).
48 # RUN: yaml2obj %s --docnum=2 -o %t.bad-entsize
49 # RUN: llvm-readobj --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-LLVM
50 # RUN: llvm-readelf --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-GNU
52 # BAD-ENTSIZE-LLVM: DynamicSection [ (2 entries)
53 # BAD-ENTSIZE-LLVM-NEXT: Tag Type Name/Value
54 # BAD-ENTSIZE-LLVM-NEXT: 0x0000000000000015 DEBUG 0x0
55 # BAD-ENTSIZE-LLVM-NEXT: 0x0000000000000000 NULL 0x0
56 # BAD-ENTSIZE-LLVM-NEXT: ]
58 # BAD-ENTSIZE-GNU: Dynamic section at offset 0x{{.*}} contains 2 entries:
59 # BAD-ENTSIZE-GNU-NEXT: Tag Type Name/Value
60 # BAD-ENTSIZE-GNU-NEXT: 0x0000000000000015 (DEBUG) 0x0
61 # BAD-ENTSIZE-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
89 ## Test handling of string references pointing past the end of the dynamic string table.
90 # RUN: yaml2obj %s --docnum=3 -o %t.bad-string
91 # RUN: llvm-readobj --dynamic-table %t.bad-string 2>&1 | \
92 # RUN: FileCheck %s --implicit-check-not=warning: --check-prefix BAD-STRING-LLVM -DFILE=%t.bad-string
93 # RUN: llvm-readelf --dynamic-table %t.bad-string 2>&1 | \
94 # RUN: FileCheck %s --implicit-check-not=warning: --check-prefix BAD-STRING-GNU -DFILE=%t.bad-string
96 # 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)
97 # BAD-STRING-LLVM: LoadName: <?>
98 # BAD-STRING-LLVM: DynamicSection [ (10 entries)
99 # BAD-STRING-LLVM-NEXT: Tag Type Name/Value
100 # BAD-STRING-LLVM-NEXT: 0x0000000000000005 STRTAB 0x1000
101 # BAD-STRING-LLVM-NEXT: 0x000000000000000A STRSZ 1 (bytes)
102 # 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)
103 # BAD-STRING-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
104 # 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)
105 # BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFF FILTER Filter library: [<?>]
106 # 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)
107 # BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [<?>]
108 # 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)
109 # BAD-STRING-LLVM-NEXT: 0x000000007FFFFFFE USED Not needed object: [<?>]
110 ## Note: there is no "string table at offset 0xb0..." warning here, because it was printed earlier.
111 # BAD-STRING-LLVM-NEXT: 0x000000000000000E SONAME Library soname: [<?>]
112 # 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)
113 # BAD-STRING-LLVM-NEXT: 0x000000000000000F RPATH Library rpath: [<?>]
114 # 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)
115 # BAD-STRING-LLVM-NEXT: 0x000000000000001D RUNPATH Library runpath: [<?>]
116 # BAD-STRING-LLVM-NEXT: 0x0000000000000000 NULL 0x0
117 # BAD-STRING-LLVM-NEXT: ]
119 # BAD-STRING-GNU: Dynamic section at offset 0xb1 contains 10 entries:
120 # BAD-STRING-GNU-NEXT: Tag Type Name/Value
121 # BAD-STRING-GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000
122 # BAD-STRING-GNU-NEXT: 0x000000000000000a (STRSZ) 1 (bytes)
123 # 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)
124 # BAD-STRING-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
125 # 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)
126 # BAD-STRING-GNU-NEXT: 0x000000007fffffff (FILTER) Filter library: [<?>]
127 # 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)
128 # BAD-STRING-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [<?>]
129 # 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)
130 # BAD-STRING-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [<?>]
131 # BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6: it goes past the end of the table (0xb1)
132 # BAD-STRING-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [<?>]
133 # 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)
134 # BAD-STRING-GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [<?>]
135 # 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)
136 # BAD-STRING-GNU-NEXT: 0x000000000000001d (RUNPATH) Library runpath: [<?>]
137 # BAD-STRING-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
183 ## Test handling of DT_STRTAB pointing outside the file's address space.
184 # RUN: yaml2obj %s --docnum=4 -o %t.bad-strtab
186 # RUN: llvm-readobj --dynamic-table %t.bad-strtab 2>&1 >/dev/null | \
187 # RUN: FileCheck -DFILE=%t.bad-strtab %s --implicit-check-not=warning: --check-prefix=BAD-STRTAB-ERR
188 # RUN: llvm-readelf --dynamic-table %t.bad-strtab 2>&1 >/dev/null | \
189 # RUN: FileCheck -DFILE=%t.bad-strtab %s --implicit-check-not=warning: --check-prefix=BAD-STRTAB-ERR
190 # BAD-STRTAB-ERR: warning: '[[FILE]]': unable to parse DT_STRTAB: virtual address is not in any segment: 0x2000000
191 # BAD-STRTAB-ERR: warning: '[[FILE]]': string table was not found
192 # BAD-STRTAB-ERR-NOT:{{.}}
194 # RUN: llvm-readobj --dynamic-table --needed-libs %t.bad-strtab 2>&1 | \
195 # RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR2,BAD-STRTAB,BAD-STRTAB-LLVM
196 # RUN: llvm-readelf --dynamic-table --needed-libs %t.bad-strtab 2>&1 | \
197 # RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR2,BAD-STRTAB,BAD-STRTAB-GNU
199 # BAD-STRTAB-ERR2: warning: '[[FILE]]': unable to parse DT_STRTAB: virtual address is not in any segment: 0x2000000
200 # BAD-STRTAB-LLVM: LoadName: <Not found>
201 # BAD-STRTAB: warning: '[[FILE]]': string table was not found
202 # BAD-STRTAB-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
203 # BAD-STRTAB-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
204 # BAD-STRTAB: NeededLibraries [
218 ## Two DT_STRTAB entries are needed to check that we don't report it twice.
240 ## Test handling of other d_ptr tags pointing outside the file's address space.
241 # RUN: yaml2obj %s --docnum=5 -o %t.bad-rela
242 # RUN: llvm-readobj --dynamic-table %t.bad-rela 2>&1 | FileCheck -DFILE=%t.bad-rela %s --check-prefixes=CHECK,BAD-RELA
243 # RUN: llvm-readelf --dynamic-table %t.bad-rela 2>&1 | FileCheck -DFILE=%t.bad-rela %s --check-prefixes=CHECK,BAD-RELA-GNU
245 # CHECK: warning: '[[FILE]]': unable to parse DT_RELA: virtual address is not in any segment: 0x1000000
247 # BAD-RELA: DynamicSection [ (2 entries)
248 # BAD-RELA-NEXT: Tag Type Name/Value
249 # BAD-RELA-NEXT: 0x0000000000000007 RELA 0x1000000
250 # BAD-RELA-NEXT: 0x0000000000000000 NULL 0x0
252 # BAD-RELA-GNU: Dynamic section at offset 0xb0 contains 2 entries:
253 # BAD-RELA-GNU-NEXT: Tag Type Name/Value
254 # BAD-RELA-GNU-NEXT: 0x0000000000000007 (RELA) 0x1000000
255 # BAD-RELA-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
282 ## Check how we handle cases when the dynamic string table is not null-terminated.
284 ## Case A: the value of the DT_STRSZ tag is equal to the size of
285 ## the not null-terminated dynamic string table.
286 # RUN: yaml2obj %s -DSTRSZ=7 --docnum=6 -o %t6
287 # RUN: llvm-readobj --dynamic-table %t6 2>&1 | \
288 # RUN: FileCheck %s -DFILE=%t6 --implicit-check-not=warning: \
289 # RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-LLVM,NOT-TERMINATED-GREQ
290 # RUN: llvm-readelf --dynamic-table %t6 2>&1 | \
291 # RUN: FileCheck %s -DFILE=%t6 --implicit-check-not=warning: \
292 # RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GNU,NOT-TERMINATED-GREQ
294 ## Case B: the value of the DT_STRSZ tag is less than the size of
295 ## the not null-terminated dynamic string table.
296 # RUN: yaml2obj %s -DSTRSZ=6 --docnum=6 -o %t7
297 # RUN: llvm-readobj --dynamic-table %t7 2>&1 | \
298 # RUN: FileCheck %s -DFILE=%t7 --implicit-check-not=warning: \
299 # RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-LLVM,NOT-TERMINATED-LESS
300 # RUN: llvm-readelf --dynamic-table %t7 2>&1 | \
301 # RUN: FileCheck %s -DFILE=%t7 --implicit-check-not=warning: \
302 # RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GNU,NOT-TERMINATED-LESS
304 ## Case C: the value of the DT_STRSZ tag is one byte larger than the size of
305 ## the not null-terminated dynamic string table.
306 # RUN: yaml2obj %s -DSTRSZ=8 --docnum=6 -o %t8
307 # RUN: llvm-readobj --dynamic-table %t8 2>&1 | \
308 # RUN: FileCheck %s -DFILE=%t8 --implicit-check-not=warning: \
309 # RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-LLVM,NOT-TERMINATED-GREQ
310 # RUN: llvm-readelf --dynamic-table %t8 2>&1 | \
311 # RUN: FileCheck %s -DFILE=%t8 --implicit-check-not=warning: \
312 # RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GNU,NOT-TERMINATED-GREQ
314 # NOT-TERMINATED-LLVM: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4: the string table is not null-terminated
315 # NOT-TERMINATED: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb0: the string table is not null-terminated
316 # NOT-TERMINATED-NEXT: {{[(]?}}NEEDED{{[)]?}} Shared library: [<?>]
317 # NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb1: the string table is not null-terminated
318 # NOT-TERMINATED-NEXT: {{[(]?}}FILTER{{[)]?}} Filter library: [<?>]
319 # NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb2: the string table is not null-terminated
320 # NOT-TERMINATED-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: [<?>]
321 # NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb3: the string table is not null-terminated
322 # NOT-TERMINATED-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: [<?>]
323 # NOT-TERMINATED-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4: the string table is not null-terminated
324 # NOT-TERMINATED-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: [<?>]
325 # NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5: the string table is not null-terminated
326 # NOT-TERMINATED-NEXT: {{[(]?}}RPATH{{[)]?}} Library rpath: [<?>]
327 # NOT-TERMINATED-GREQ-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6: the string table is not null-terminated
328 # NOT-TERMINATED-LESS-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6: it goes past the end of the table (0xb6)
329 # NOT-TERMINATED-NEXT: {{[(]?}}RUNPATH{{[)]?}} Library runpath: [<?>]
330 # NOT-TERMINATED-NEXT: {{[(]?}}NULL{{[)]?}} 0x0
341 Content: '746573742e736f' ## "test.so", not null terminated.
343 Pattern: "61626300" ## 'a', 'b', 'c', '\0'.
379 ## Check that we emit an appropriate warning when the dynamic string table ends past the end of the file.
381 ## Case A: the value of DT_STRSZ tag is set so that the string table ends
382 ## right before the EOF. No warning should be emitted.
383 # RUN: yaml2obj %s -DSTRSZ=0x210 --docnum=6 -o %t9.1
384 # RUN: llvm-readobj --dynamic-table %t9.1 | \
385 # RUN: FileCheck %s --implicit-check-not=warning: --check-prefix=BEFORE-THE-EOF
386 # RUN: llvm-readelf --dynamic-table %t9.1 | \
387 # RUN: FileCheck %s --implicit-check-not=warning: --check-prefix=BEFORE-THE-EOF
389 ## Note: The code reads the data in [DT_STRTAB, DT_STRTAB + DT_STRSZ] as the string table
390 ## as normal. Since the file ends with a zero byte, strings are dumped, but if it didn't,
391 ## we'd get <?> printed instead. The important bit is that we don't get the past the end warning.
393 # BEFORE-THE-EOF: {{[(]?}}NEEDED{{[)]?}} Shared library: [test.soabc]
394 # BEFORE-THE-EOF-NEXT: {{[(]?}}FILTER{{[)]?}} Filter library: [est.soabc]
395 # BEFORE-THE-EOF-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: [st.soabc]
396 # BEFORE-THE-EOF-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: [t.soabc]
397 # BEFORE-THE-EOF-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: [.soabc]
398 # BEFORE-THE-EOF-NEXT: {{[(]?}}RPATH{{[)]?}} Library rpath: [soabc]
399 # BEFORE-THE-EOF-NEXT: {{[(]?}}RUNPATH{{[)]?}} Library runpath: [oabc]
400 # BEFORE-THE-EOF-NEXT: {{[(]?}}NULL{{[)]?}} 0x0
402 ## Case B: the value of DT_STRSZ tag is set so that the string table goes 1 byte past the EOF.
403 # RUN: yaml2obj %s -DSTRSZ=0x211 --docnum=6 -o %t9.2
404 # RUN: llvm-readobj --dynamic-table %t9.2 2>&1 | FileCheck %s -DFILE=%t9.2 --check-prefix=PAST-THE-EOF
405 # RUN: llvm-readelf --dynamic-table %t9.2 2>&1 | FileCheck %s -DFILE=%t9.2 --check-prefix=PAST-THE-EOF
407 # PAST-THE-EOF: warning: '[[FILE]]': the dynamic string table at 0xb0 goes past the end of the file (0x2c0) with DT_STRSZ = 0x211
408 # PAST-THE-EOF: warning: '[[FILE]]': string table was not found
409 # PAST-THE-EOF: {{[(]?}}NEEDED{{[)]?}} Shared library: [<?>]
410 # PAST-THE-EOF-NEXT: {{[(]?}}FILTER{{[)]?}} Filter library: [<?>]
411 # PAST-THE-EOF-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: [<?>]
412 # PAST-THE-EOF-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: [<?>]
413 # PAST-THE-EOF-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: [<?>]
414 # PAST-THE-EOF-NEXT: {{[(]?}}RPATH{{[)]?}} Library rpath: [<?>]
415 # PAST-THE-EOF-NEXT: {{[(]?}}RUNPATH{{[)]?}} Library runpath: [<?>]
416 # PAST-THE-EOF-NEXT: {{[(]?}}NULL{{[)]?}} 0x0
418 ## Check that we report a warning when we try to map an address, but loadable
419 ## segments appear unsorted by the p_vaddr member. In this case we are still
420 ## able to map an address.
422 # RUN: yaml2obj %s --docnum=7 -o %t10
423 # RUN: llvm-readobj --dynamic-table %t10 2>&1 | \
424 # RUN: FileCheck %s -DFILE=%t10 --implicit-check-not=warning: --check-prefixes=OUT-OF-ORDER,OUT-OF-ORDER-LLVM
425 # RUN: llvm-readelf --dynamic-table %t10 2>&1 | \
426 # RUN: FileCheck %s -DFILE=%t10 --implicit-check-not=warning: --check-prefixes=OUT-OF-ORDER,OUT-OF-ORDER-GNU
428 # OUT-OF-ORDER: warning: '[[FILE]]': loadable segments are unsorted by virtual address
430 # OUT-OF-ORDER-LLVM: DynamicSection [ (2 entries)
431 # OUT-OF-ORDER-LLVM-NEXT: Tag Type Name/Value
432 # OUT-OF-ORDER-LLVM-NEXT: 0x0000000000000005 STRTAB 0x1000
433 # OUT-OF-ORDER-LLVM-NEXT: 0x0000000000000000 NULL 0x0
434 # OUT-OF-ORDER-LLVM-NEXT: ]
436 # OUT-OF-ORDER-GNU: Dynamic section at offset 0xe9 contains 2 entries:
437 # OUT-OF-ORDER-GNU-NEXT: Tag Type Name/Value
438 # OUT-OF-ORDER-GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000
439 # OUT-OF-ORDER-GNU-NEXT: 0x0000000000000000 (NULL) 0x0