1 ## If the offset and/or size fields of the PT_DYNAMIC field become corrupted,
2 ## we should report a sensible message.
4 ## Case A: Test case where the size of the PT_DYNAMIC header is too large to fit in the file,
5 ## but the start is within the file.
7 ## Case A.1: the section header table is present in the object. Check that we report a warning about the
8 ## broken PT_DYNAMIC header, check we dump the dynamic table.
9 # RUN: yaml2obj %s -DFILESIZE=0x131 -o %t1
10 # RUN: llvm-readobj %t1 --dynamic-table 2>&1 | FileCheck -DFILE=%t1 %s --check-prefixes=WARN1,WARN1-LLVM
11 # RUN: llvm-readelf %t1 --dynamic-table 2>&1 | FileCheck -DFILE=%t1 %s --check-prefixes=WARN1,WARN1-GNU
13 # WARN1: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0x131) exceeds the size of the file (0x1130)
15 # WARN1-LLVM: DynamicSection [ (1 entries)
16 # WARN1-LLVM-NEXT: Tag Type Name/Value
17 # WARN1-LLVM-NEXT: 0x0000000000000000 NULL 0x0
20 # WARN1-GNU: Dynamic section at offset 0x1000 contains 1 entries:
21 # WARN1-GNU-NEXT: Tag Type Name/Value
22 # WARN1-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
24 ## Case A.2: in this case we drop section headers. The dynamic table is not dumped.
25 # RUN: yaml2obj %s -DFILESIZE=0x12 -DNOHEADERS=true -o %t1.noheaders
26 # RUN: llvm-readobj %t1.noheaders --dynamic-table 2>&1 | FileCheck -DFILE=%t1.noheaders %s \
27 # RUN: --check-prefix=WARN1-NOHEADERS --implicit-check-not="DynamicSection ["
28 # RUN: llvm-readelf %t1.noheaders --dynamic-table 2>&1 | FileCheck -DFILE=%t1.noheaders %s \
29 # RUN: --check-prefix=WARN1-NOHEADERS --implicit-check-not="Dynamic section"
31 # WARN1-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0x12) exceeds the size of the file (0x1011)
33 ## Case B: Test case where the offset of the PT_DYNAMIC header is too large to be in the file.
35 ## Case B.1: the section header table is present in the object. Check that we report a warning about the
36 ## broken PT_DYNAMIC header. Check we also report a warning about broken fields of the SHT_DYNAMIC section.
37 # RUN: yaml2obj %s -DOFFSET=0x1131 -o %t2
38 # RUN: llvm-readobj %t2 --dynamic-table 2>&1 | FileCheck -DFILE=%t2 %s \
39 # RUN: --check-prefix=WARN2 --implicit-check-not=warning:
40 # RUN: llvm-readelf %t2 --dynamic-table 2>&1 | FileCheck -DFILE=%t2 %s \
41 # RUN: --check-prefix=WARN2 --implicit-check-not=warning:
43 # WARN2: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1131) + file size (0x10) exceeds the size of the file (0x1130)
44 # WARN2: warning: '[[FILE]]': unable to read the dynamic table from SHT_DYNAMIC section with index 1: offset (0x1131) + size (0x10) is greater than the file size (0x1130)
45 # WARN2: warning: '[[FILE]]': no valid dynamic table was found
47 ## Case B.2: in this case we drop section headers. The dynamic table is not dumped.
48 # RUN: yaml2obj %s -DOFFSET=0x1112 -DNOHEADERS=true -o %t2.noheaders
49 # RUN: llvm-readobj %t2.noheaders --dynamic-table 2>&1 | FileCheck -DFILE=%t2.noheaders %s \
50 # RUN: --check-prefix=WARN2-NOHEADERS --implicit-check-not="DynamicSection ["
51 # RUN: llvm-readelf %t2.noheaders --dynamic-table 2>&1 | FileCheck -DFILE=%t2.noheaders %s \
52 # RUN: --check-prefix=WARN2-NOHEADERS --implicit-check-not="Dynamic section"
54 # WARN2-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1112) + file size (0x10) exceeds the size of the file (0x1011)
56 ## Case C: test we report a warning when the offset + the file size of the PT_DYNAMIC is so large a
57 ## value that it overflows the platform address size type. Check we also report a warning about
58 ## broken fields of the SHT_DYNAMIC section.
60 # RUN: yaml2obj %s -DOFFSET=0xffffffffffffffff -o %t3
61 # RUN: llvm-readobj %t3 --dynamic-table 2>&1 | FileCheck -DFILE=%t3 %s \
62 # RUN: --check-prefix=WARN3 --implicit-check-not=warning:
63 # RUN: llvm-readelf %t3 --dynamic-table 2>&1 | FileCheck -DFILE=%t3 %s \
64 # RUN: --check-prefix=WARN3 --implicit-check-not=warning:
66 # WARN3: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffffffffffffffff) + file size (0x10) exceeds the size of the file (0x1130)
67 # WARN3: warning: '[[FILE]]': unable to read the dynamic table from SHT_DYNAMIC section with index 1: offset (0xffffffffffffffff) + size (0x10) is greater than the file size (0x1130)
68 # WARN3: warning: '[[FILE]]': no valid dynamic table was found
70 # RUN: yaml2obj %s -DNOHEADERS=true -DOFFSET=0xffffffffffffffff -o %t3.noheaders
71 # RUN: llvm-readobj %t3.noheaders --dynamic-table 2>&1 | \
72 # RUN: FileCheck -DFILE=%t3.noheaders %s --check-prefix=WARN3-NOHEADERS
73 # RUN: llvm-readelf %t3.noheaders --dynamic-table 2>&1 | \
74 # RUN: FileCheck -DFILE=%t3.noheaders %s --check-prefix=WARN3-NOHEADERS
76 # WARN3-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffffffffffffffff) + file size (0x10) exceeds the size of the file (0x1011)
78 # RUN: yaml2obj %s -DFILESIZE=0xffffffffffffffff -o %t4
79 # RUN: llvm-readobj %t4 --dynamic-table 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=WARN4
80 # RUN: llvm-readelf %t4 --dynamic-table 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=WARN4
82 # WARN4: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0xffffffffffffffff) exceeds the size of the file (0x1130)
84 # RUN: yaml2obj %s -DNOHEADERS=true -DFILESIZE=0xffffffffffffffff -o %t4.noheaders
85 # RUN: llvm-readobj %t4.noheaders --dynamic-table 2>&1 | \
86 # RUN: FileCheck -DFILE=%t4.noheaders %s --check-prefix=WARN4-NOHEADERS
87 # RUN: llvm-readelf %t4.noheaders --dynamic-table 2>&1 | \
88 # RUN: FileCheck -DFILE=%t4.noheaders %s --check-prefix=WARN4-NOHEADERS
90 # WARN4-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0xffffffffffffffff) exceeds the size of the file (0x1011)
92 ## Case D: the same as "Case C", but for a 32-bit object.
94 # RUN: yaml2obj %s -DBITS=32 -DOFFSET=0xffffffff -o %t5
95 # RUN: llvm-readobj %t5 --dynamic-table 2>&1 | FileCheck -DFILE=%t5 %s \
96 # RUN: --check-prefix=WARN5 --implicit-check-not=warning:
97 # RUN: llvm-readelf %t5 --dynamic-table 2>&1 | FileCheck -DFILE=%t5 %s \
98 # RUN: --check-prefix=WARN5 --implicit-check-not=warning:
100 # WARN5: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffffffff) + file size (0x8) exceeds the size of the file (0x10c8)
101 # WARN5: warning: '[[FILE]]': unable to read the dynamic table from SHT_DYNAMIC section with index 1: offset (0xffffffff) + size (0x8) is greater than the file size (0x10c8)
102 # WARN5: warning: '[[FILE]]': no valid dynamic table was found
104 # RUN: yaml2obj %s -DNOHEADERS=true -DBITS=32 -DOFFSET=0xffffffff -o %t5.noheaders
105 # RUN: llvm-readobj %t5.noheaders --dynamic-table 2>&1 | \
106 # RUN: FileCheck -DFILE=%t5.noheaders %s --check-prefix=WARN5-NOHEADERS
107 # RUN: llvm-readelf %t5.noheaders --dynamic-table 2>&1 | \
108 # RUN: FileCheck -DFILE=%t5.noheaders %s --check-prefix=WARN5-NOHEADERS
110 # WARN5-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0xffffffff) + file size (0x8) exceeds the size of the file (0x1009)
112 # RUN: yaml2obj %s -DBITS=32 -DFILESIZE=0xffffffff -o %t6
113 # RUN: llvm-readobj %t6 --dynamic-table 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=WARN6
114 # RUN: llvm-readelf %t6 --dynamic-table 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=WARN6
116 # WARN6: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0xffffffff) exceeds the size of the file (0x10c8)
118 # RUN: yaml2obj %s -DNOHEADERS=true -DBITS=32 -DFILESIZE=0xffffffff -o %t6.noheaders
119 # RUN: llvm-readobj %t6.noheaders --dynamic-table 2>&1 | \
120 # RUN: FileCheck -DFILE=%t6.noheaders %s --check-prefix=WARN6-NOHEADERS
121 # RUN: llvm-readelf %t6.noheaders --dynamic-table 2>&1 | \
122 # RUN: FileCheck -DFILE=%t6.noheaders %s --check-prefix=WARN6-NOHEADERS
124 # WARN6-NOHEADERS: warning: '[[FILE]]': PT_DYNAMIC segment offset (0x1000) + file size (0xffffffff) exceeds the size of the file (0x1009)
128 Class: ELFCLASS[[BITS=64]]
136 ShOffset: [[OFFSET=<none>]]
140 - Type: SectionHeaderTable
141 NoHeaders: [[NOHEADERS=false]]
144 FileSize: [[FILESIZE=<none>]]