OSDN Git Service

[llvm-readelf] Print "File: lib.a(file.o)" info when dumping archive files.
[android-x86/external-llvm.git] / test / tools / llvm-readobj / elf-dynamic-malformed.test
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.
3
4 # RUN: yaml2obj %s --docnum=1 -o %t.bad-size
5 # RUN: llvm-readobj --all %t.bad-size 2>&1 \
6 # RUN:   | FileCheck %s --implicit-check-not=warning --check-prefix WARN
7 # RUN: llvm-readelf --all %t.bad-size 2>&1 \
8 # RUN:   | FileCheck %s --implicit-check-not=warning --check-prefix WARN-GNU
9
10 # WARN-NOT: warning
11 # WARN: warning: invalid section size (4) or entity size (16)
12 # WARN-EMPTY:
13 # WARN-NEXT: File:
14 # WARN:      Symbols [
15 # WARN:      ]
16 # WARN-EMPTY:
17 ## A warning is printed at the place where a normal dynamic table should be. 
18 # WARN-NEXT: warning: invalid section size (4) or entity size (16)
19 # WARN-NEXT: ProgramHeaders [
20
21 # WARN-GNU-NOT:  warning
22 # WARN-GNU:      warning: invalid section size (4) or entity size (16)
23 # WARN-GNU-EMPTY:
24 # WARN-GNU-NEXT: ELF Header:
25 # WARN-GNU:      Symbol table '.symtab' contains 1 entries:
26 # WARN-GNU:        0:
27 # WARN-GNU-EMPTY:
28 ## A warning is printed at the place where a normal dynamic table should be. 
29 # WARN-GNU:      warning: invalid section size (4) or entity size (16)
30 # WARN-GNU-EMPTY:
31
32 --- !ELF
33 FileHeader:
34   Class:   ELFCLASS64
35   Data:    ELFDATA2LSB
36   Type:    ET_EXEC
37   Machine: EM_X86_64
38 Sections:
39   - Name:    .dynamic
40     Type:    SHT_DYNAMIC
41     Address: 0x1000
42     Content: "01234567"
43 ProgramHeaders:
44   - Type: PT_LOAD
45     VAddr: 0x1000
46     Sections:
47       - Section: .dynamic
48   - Type: PT_DYNAMIC
49     VAddr: 0x1000
50     Sections:
51       - Section: .dynamic
52
53 ## Test handling of a .dynamic section with an invalid entsize (i.e. not 2 * sizeof(Elf_Dyn)).
54 # RUN: yaml2obj %s --docnum=2 -o %t.bad-entsize
55 # RUN: llvm-readobj --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-LLVM
56 # RUN: llvm-readelf --dynamic-table %t.bad-entsize | FileCheck %s --check-prefix BAD-ENTSIZE-GNU
57
58 # BAD-ENTSIZE-LLVM:      DynamicSection [ (2 entries)
59 # BAD-ENTSIZE-LLVM-NEXT:   Tag                Type                 Name/Value
60 # BAD-ENTSIZE-LLVM-NEXT:   0x0000000000000015 DEBUG                0x0
61 # BAD-ENTSIZE-LLVM-NEXT:   0x0000000000000000 NULL                 0x0
62 # BAD-ENTSIZE-LLVM-NEXT: ]
63
64 # BAD-ENTSIZE-GNU:      Dynamic section at offset 0x{{.*}} contains 2 entries:
65 # BAD-ENTSIZE-GNU-NEXT:   Tag                Type                 Name/Value
66 # BAD-ENTSIZE-GNU-NEXT:   0x0000000000000015 (DEBUG)              0x0
67 # BAD-ENTSIZE-GNU-NEXT:   0x0000000000000000 (NULL)               0x0
68
69 --- !ELF
70 FileHeader:
71   Class:   ELFCLASS64
72   Data:    ELFDATA2LSB
73   Type:    ET_EXEC
74   Machine: EM_X86_64
75 Sections:
76   - Name:    .dynamic
77     Type:    SHT_DYNAMIC
78     Address: 0x1000
79     EntSize: 0x2
80     Entries:
81       - Tag:   DT_DEBUG
82         Value: 0
83       - Tag:   DT_NULL
84         Value: 0
85 ProgramHeaders:
86   - Type: PT_LOAD
87     VAddr: 0x1000
88     Sections:
89       - Section: .dynamic
90   - Type: PT_DYNAMIC
91     VAddr: 0x1000
92     Sections:
93       - Section: .dynamic
94
95 ## Test handling of string references pointing past the end of the dynamic string table.
96 # RUN: yaml2obj %s --docnum=3 -o %t.bad-string
97 # RUN: llvm-readobj --dynamic-table %t.bad-string | FileCheck %s --check-prefix BAD-STRING-LLVM
98 # RUN: llvm-readelf --dynamic-table %t.bad-string | FileCheck %s --check-prefix BAD-STRING-GNU
99
100 # BAD-STRING-LLVM: 0x000000000000000A STRSZ         1 (bytes)
101 # BAD-STRING-LLVM: 0x0000000000000001 NEEDED        Shared library: <Invalid offset 0x1>
102 # BAD-STRING-LLVM: 0x000000007FFFFFFF FILTER        Filter library: <Invalid offset 0x1>
103 # BAD-STRING-LLVM: 0x000000007FFFFFFD AUXILIARY     Auxiliary library: <Invalid offset 0x1>
104 # BAD-STRING-LLVM: 0x000000007FFFFFFE USED          Not needed object: <Invalid offset 0x1>
105 # BAD-STRING-LLVM: 0x000000000000000E SONAME        Library soname: <Invalid offset 0x1>
106 # BAD-STRING-LLVM: 0x000000000000000F RPATH         Library rpath: <Invalid offset 0x1>
107 # BAD-STRING-LLVM: 0x000000000000001D RUNPATH       Library runpath: <Invalid offset 0x1>
108
109 # BAD-STRING-GNU:  0x000000000000000a (STRSZ)       1 (bytes)
110 # BAD-STRING-GNU:  0x0000000000000001 (NEEDED)      Shared library: <Invalid offset 0x1>
111 # BAD-STRING-GNU:  0x000000007fffffff (FILTER)      Filter library: <Invalid offset 0x1>
112 # BAD-STRING-GNU:  0x000000007ffffffd (AUXILIARY)   Auxiliary library: <Invalid offset 0x1>
113 # BAD-STRING-GNU:  0x000000007ffffffe (USED)        Not needed object: <Invalid offset 0x1>
114 # BAD-STRING-GNU:  0x000000000000000e (SONAME)      Library soname: <Invalid offset 0x1>
115 # BAD-STRING-GNU:  0x000000000000000f (RPATH)       Library rpath: <Invalid offset 0x1>
116 # BAD-STRING-GNU:  0x000000000000001d (RUNPATH)     Library runpath: <Invalid offset 0x1>
117
118 --- !ELF
119 FileHeader:
120   Class:   ELFCLASS64
121   Data:    ELFDATA2LSB
122   Type:    ET_EXEC
123   Machine: EM_X86_64
124 Sections:
125   - Name:    .dynstr
126     Type:    SHT_STRTAB
127     Address: 0x1000
128   - Name:    .dynamic
129     Type:    SHT_DYNAMIC
130     Address: 0x1010
131     Entries:
132       - Tag:   DT_STRTAB
133         Value: 0x1000
134       - Tag:   DT_STRSZ
135         Value: 1
136       - Tag:   DT_NEEDED
137         Value: 1
138       - Tag:   DT_FILTER
139         Value: 1
140       - Tag:   DT_AUXILIARY
141         Value: 1
142       - Tag:   DT_USED
143         Value: 1
144       - Tag:   DT_SONAME
145         Value: 1
146       - Tag:   DT_RPATH
147         Value: 1
148       - Tag:   DT_RUNPATH
149         Value: 1
150       - Tag:   DT_NULL
151         Value: 0
152 ProgramHeaders:
153   - Type: PT_LOAD
154     VAddr: 0x1000
155     Sections:
156       - Section: .dynstr
157       - Section: .dynamic
158   - Type: PT_DYNAMIC
159     VAddr: 0x1010
160     Sections:
161       - Section: .dynamic
162
163 ## Test handling of DT_STRTAB pointing outside the file's address space.
164 # RUN: yaml2obj %s --docnum=4 -o %t.bad-strtab
165
166 # RUN: llvm-readobj --dynamic-table %t.bad-strtab 2>&1 >/dev/null | FileCheck %s --check-prefix BAD-STRTAB-ERR
167 # RUN: llvm-readelf --dynamic-table %t.bad-strtab 2>&1 >/dev/null | FileCheck %s --check-prefix BAD-STRTAB-ERR
168 # BAD-STRTAB-ERR: warning: Unable to parse DT_STRTAB: virtual address is not in any segment: 0x2000000
169
170 # RUN: llvm-readobj --dynamic-table --needed-libs %t.bad-strtab | FileCheck %s --check-prefixes=BAD-STRTAB,BAD-STRTAB-LLVM
171 # RUN: llvm-readelf --dynamic-table --needed-libs %t.bad-strtab | FileCheck %s --check-prefixes=BAD-STRTAB,BAD-STRTAB-GNU
172 # BAD-STRTAB-LLVM: LoadName: <Not found>
173 # BAD-STRTAB-LLVM: 0x0000000000000001  NEEDED   Shared library: <String table is empty or was not found>
174 # BAD-STRTAB-GNU:  0x0000000000000001 (NEEDED)  Shared library: <String table is empty or was not found>
175 # BAD-STRTAB:      NeededLibraries [
176 # BAD-STRTAB:        <Library name index out of range>
177 # BAD-STRTAB:      ]
178
179 --- !ELF
180 FileHeader:
181   Class:   ELFCLASS64
182   Data:    ELFDATA2LSB
183   Type:    ET_EXEC
184   Machine: EM_X86_64
185 Sections:
186   - Name:    .dynamic
187     Type:    SHT_DYNAMIC
188     Address: 0x1000
189     Entries:
190       - Tag:   DT_STRTAB
191         Value: 0x2000000
192       - Tag:   DT_STRSZ
193         Value: 10
194       - Tag:   DT_NEEDED
195         Value: 1
196       - Tag:   DT_NULL
197         Value: 0x0
198 ProgramHeaders:
199   - Type: PT_LOAD
200     VAddr: 0x1000
201     Sections:
202       - Section: .dynamic
203   - Type: PT_DYNAMIC
204     VAddr: 0x1000
205     Sections:
206       - Section: .dynamic
207
208 ## Test handling of other d_ptr tags pointing outside the file's address space.
209 # RUN: yaml2obj %s --docnum=5 -o %t.bad-rela
210 # RUN: llvm-readobj --dynamic-table %t.bad-rela 2>&1 | FileCheck %s --check-prefixes=CHECK,BAD-RELA
211 # RUN: llvm-readelf --dynamic-table %t.bad-rela 2>&1 | FileCheck %s --check-prefixes=CHECK,BAD-RELA-GNU
212
213 # CHECK: warning: Unable to parse DT_RELA: virtual address is not in any segment: 0x1000000
214
215 # BAD-RELA:      DynamicSection [ (2 entries)
216 # BAD-RELA-NEXT:   Tag                Type Name/Value
217 # BAD-RELA-NEXT:   0x0000000000000007 RELA 0x1000000
218 # BAD-RELA-NEXT:   0x0000000000000000 NULL 0x0
219 # BAD-RELA-NEXT: ]
220 # BAD-RELA-GNU:      Dynamic section at offset 0x1f0 contains 2 entries:
221 # BAD-RELA-GNU-NEXT: Tag                Type   Name/Value
222 # BAD-RELA-GNU-NEXT: 0x0000000000000007 (RELA) 0x1000000
223 # BAD-RELA-GNU-NEXT: 0x0000000000000000 (NULL) 0x0
224
225 --- !ELF
226 FileHeader:
227   Class:   ELFCLASS64
228   Data:    ELFDATA2LSB
229   Type:    ET_EXEC
230   Machine: EM_X86_64
231 Sections:
232   - Name:    .dynamic
233     Type:    SHT_DYNAMIC
234     Address: 0x1000
235     Entries:
236       - Tag:   DT_RELA
237         Value: 0x1000000
238       - Tag:   DT_NULL
239         Value: 0x0
240 ProgramHeaders:
241   - Type: PT_LOAD
242     VAddr: 0x1000
243     Sections:
244       - Section: .dynamic
245   - Type: PT_DYNAMIC
246     VAddr: 0x1000
247     Sections:
248       - Section: .dynamic