section-headers-exclude.yaml
14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
## Check how we can use the "Excluded" key of the "SectionHeaderTable" tag to exclude
## entries from the section header table.
## Check we can use the "Excluded" key to omit a section from the section header table.
## Check we do not include the name of the excluded section in the string table.
# RUN: yaml2obj %s -DINCLUDED=.foo -DEXCLUDED=.bar --docnum=1 -o %t1
# RUN: llvm-readelf --section-headers -p .shstrtab %t1 | \
# RUN: FileCheck %s -DSEC=.foo --check-prefixes=INCLUDE-SEC,INCLUDE-FOO
# RUN: yaml2obj %s -DINCLUDED=.bar -DEXCLUDED=.foo --docnum=1 -o %t2
# RUN: llvm-readelf --section-headers -p .shstrtab %t2 | \
# RUN: FileCheck %s -DSEC=.bar --check-prefixes=INCLUDE-SEC,INCLUDE-BAR
# INCLUDE-SEC: [Nr] Name
# INCLUDE-SEC: [ 1] [[SEC]]
# INCLUDE-SEC-NEXT: [ 2] .strtab
# INCLUDE-SEC-NEXT: [ 3] .shstrtab
# INCLUDE-SEC: String dump of section '.shstrtab':
# INCLUDE-FOO-NEXT: [ 1] .foo
# INCLUDE-BAR-NEXT: [ 1] .bar
# INCLUDE-SEC-NEXT: [ 6] .shstrtab
# INCLUDE-SEC-NEXT: [ 10] .strtab
# INCLUDE-SEC-NOT: {{.}}
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .foo
Type: SHT_PROGBITS
- Name: .bar
Type: SHT_PROGBITS
SectionHeaderTable:
Sections:
- Name: [[INCLUDED]]
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: [[EXCLUDED]]
## Check we report an error when a section is in both the "Sections" and "Excluded" lists at the same time.
## Also check that we report an error if a section is missing from the lists.
# RUN: not yaml2obj %s -DINCLUDED=.bar -DEXCLUDED=.strtab --docnum=1 -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=EXCLUDE-INCLUDED
# EXCLUDE-INCLUDED: error: repeated section name: '.strtab' in the section header description
# EXCLUDE-INCLUDED: error: section '.foo' should be present in the 'Sections' or 'Excluded' lists
## Check we report an error when the `Excluded` key mentions an unknown section.
# RUN: not yaml2obj %s -DINCLUDED=.bar -DEXCLUDED=.unknown --docnum=1 -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=EXCLUDE-UNKNOWN
# EXCLUDE-UNKNOWN: error: section '.foo' should be present in the 'Sections' or 'Excluded' lists
# EXCLUDE-UNKNOWN: error: section header contains undefined section '.unknown'
## Check we report an error when the `Excluded` key mentions a section more than once.
# RUN: not yaml2obj %s --docnum=2 -o /dev/null 2>&1 | FileCheck %s --check-prefix=EXCLUDE-TWICE
# EXCLUDE-TWICE: error: repeated section name: '.strtab' in the section header description
# EXCLUDE-TWICE: error: repeated section name: '.strtab' in the section header description
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SectionHeaderTable:
Sections:
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .strtab
- Name: .strtab
## Check that we are able to exclude all sections, except the implicit
## null section, with the use of the "Excluded" key.
## Case A: the "Sections" key is present, but empty.
# RUN: yaml2obj %s --docnum=3 -o %t3
# RUN: llvm-readelf --section-headers %t3 | FileCheck %s --check-prefix=NO-SECTIONS
# NO-SECTIONS: There are 1 section headers, starting at offset 0x48:
# NO-SECTIONS: Section Headers:
# NO-SECTIONS-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
# NO-SECTIONS-NEXT: [ 0] <no-strings> NULL 0000000000000000 000000 000000 00 0 0 0
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SectionHeaderTable:
Sections: []
Excluded:
- Name: .strtab
- Name: .shstrtab
## Case B: the "Sections" key is not present.
# RUN: yaml2obj %s --docnum=4 -o %t4
# RUN: llvm-readelf --section-headers %t4 | FileCheck %s --check-prefix=NO-SECTIONS
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SectionHeaderTable:
Excluded:
- Name: .strtab
- Name: .shstrtab
## Check how we handle cases when a section is excluded, but its section index is needed.
## The general rule is: when a section is explicitly linked with another section, which is
## excluded, then we report an error. In the case when it is linked implicitly with an excluded
## section, we use 0 as index value.
## Case A: check we report an error when a regular section has a Link field which
## points to an excluded section.
# RUN: not yaml2obj %s --docnum=5 -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=LINK -DSEC=.foo -DTARGET=.bar
# LINK: error: unable to link '[[SEC]]' to excluded section '[[TARGET]]'
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .foo
Type: SHT_PROGBITS
Link: .bar
- Name: .bar
Type: SHT_PROGBITS
SectionHeaderTable:
Sections:
- Name: .foo
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .bar
## Case B.1: check we report an error when a symbol table section has a Link field which
## points to an excluded section.
# RUN: not yaml2obj %s --docnum=6 -DNAME=.symtab -DTYPE=SHT_SYMTAB -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=LINK -DSEC=.symtab -DTARGET=.foo
# RUN: not yaml2obj %s --docnum=6 -DNAME=.dynsym -DTYPE=SHT_DYNSYM -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=LINK -DSEC=.dynsym -DTARGET=.foo
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: [[NAME]]
Type: [[TYPE]]
Link: .foo
- Name: .foo
Type: SHT_PROGBITS
SectionHeaderTable:
Sections:
- Name: [[NAME]]
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .foo
## Case B.2: check we do not link .dynsym with .dynstr implicitly when the latter is excluded.
# RUN: yaml2obj %s --docnum=7 -o %t5
# RUN: llvm-readelf %t5 --section-headers | FileCheck %s --check-prefix=LINK-DYNSYM
# LINK-DYNSYM: [Nr] Name Type Address Off Size ES Flg Lk
# LINK-DYNSYM: [ 1] .dynsym DYNSYM 0000000000000000 000040 000018 18 A 0
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .dynsym
Type: SHT_DYNSYM
- Name: .dynstr
Type: SHT_PROGBITS
SectionHeaderTable:
Sections:
- Name: .dynsym
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .dynstr
## Case B.3: check we do not link .symtab with .strtab implicitly when the latter is excluded.
# RUN: yaml2obj %s --docnum=8 -o %t6
# RUN: llvm-readelf %t6 --section-headers | FileCheck %s --check-prefix=LINK-SYMTAB
# LINK-SYMTAB: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
# LINK-SYMTAB: [ 1] .symtab SYMTAB 0000000000000000 000040 000018 18 0 1 0
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .symtab
Type: SHT_SYMTAB
- Name: .strtab
Type: SHT_PROGBITS
SectionHeaderTable:
Sections:
- Name: .symtab
- Name: .shstrtab
Excluded:
- Name: .strtab
## Case C: check we report an error when a debug section has a Link field which
## points to an excluded section.
# RUN: not yaml2obj %s --docnum=9 -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=LINK -DSEC=.debug_unknown -DTARGET=.strtab
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .debug_unknown
Type: SHT_PROGBITS
Link: .strtab
SectionHeaderTable:
Sections:
- Name: .debug_unknown
- Name: .shstrtab
Excluded:
- Name: .strtab
## Case D.1: check we report an error when a relocatable section has an Info field which
## points to an excluded section.
# RUN: not yaml2obj %s --docnum=10 -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=LINK -DSEC=.rela -DTARGET=.strtab
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .rela
Type: SHT_RELA
Info: .strtab
Relocations: []
SectionHeaderTable:
Sections:
- Name: .rela
- Name: .shstrtab
Excluded:
- Name: .strtab
## Case D.2: check we report an error when the SHT_REL[A] section is linked
## with an excluded section explicitly.
# RUN: not yaml2obj %s --docnum=11 -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=LINK -DSEC=.rela -DTARGET=.symtab
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .rela
Type: SHT_RELA
Link: .symtab
Relocations: []
- Name: .symtab
Type: SHT_PROGBITS
SectionHeaderTable:
Sections:
- Name: .rela
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .symtab
## Case E: check we report an error when a symbol references an excluded section.
# RUN: not yaml2obj %s --docnum=12 -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=SYMBOL-SECTION
# SYMBOL-SECTION: error: excluded section referenced: '.foo' by symbol 'foo'
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .foo
Type: SHT_PROGBITS
Symbols:
- Name: foo
Type: STT_OBJECT
Section: .foo
SectionHeaderTable:
Sections:
- Name: .symtab
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .foo
## Case F.1: check we report an error when a group section
## contains an excluded section member.
# RUN: not yaml2obj %s --docnum=13 -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=LINK -DSEC=.group -DTARGET=.strtab
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .group
Type: SHT_GROUP
Members:
- SectionOrType: .strtab
SectionHeaderTable:
Sections:
- Name: .group
- Name: .shstrtab
Excluded:
- Name: .strtab
## Case F.2: check we report an error when the group section is linked
## to an excluded section explicitly.
# RUN: not yaml2obj %s --docnum=14 -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=LINK -DSEC=.group -DTARGET=.symtab
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .group
Type: SHT_GROUP
Link: .symtab
Members: []
- Name: .symtab
Type: SHT_SYMTAB
SectionHeaderTable:
Sections:
- Name: .group
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .symtab
## Case G: check we do not link SHT_LLVM_CALL_GRAPH_PROFILE/SHT_LLVM_ADDRSIG/SHT_GROUP/SHT_REL[A] sections
## with .symtab implicitly when the latter is excluded.
# RUN: yaml2obj %s --docnum=15 -o %t7
# RUN: llvm-readelf %t7 --section-headers | FileCheck %s --check-prefix=LINK-IMPLICIT
# LINK-IMPLICIT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
# LINK-IMPLICIT: [ 1] .cgp LLVM_CALL_GRAPH_PROFILE 0000000000000000 000040 000000 10 0 0 0
# LINK-IMPLICIT-NEXT: [ 2] .llvm_addrsig LLVM_ADDRSIG 0000000000000000 000040 000000 00 0 0 0
# LINK-IMPLICIT-NEXT: [ 3] .group GROUP 0000000000000000 000040 000000 04 0 0 0
# LINK-IMPLICIT-NEXT: [ 4] .rela RELA 0000000000000000 000040 000000 18 0 0 0
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .cgp
Type: SHT_LLVM_CALL_GRAPH_PROFILE
Content: ""
- Name: .llvm_addrsig
Type: SHT_LLVM_ADDRSIG
Content: ""
- Name: .group
Type: SHT_GROUP
Members: []
- Name: .rela
Type: SHT_RELA
Relocations: []
- Name: .symtab
Type: SHT_SYMTAB
SectionHeaderTable:
Sections:
- Name: .cgp
- Name: .llvm_addrsig
- Name: .group
- Name: .rela
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .symtab
## Case H: check we do not link SHT_HASH/SHT_GNU_HASH sections with .dynsym
## implicitly when the latter is excluded.
# RUN: yaml2obj %s --docnum=16 -o %t8
# RUN: llvm-readelf %t8 --section-headers | FileCheck %s --check-prefix=LINK-HASH
# LINK-HASH: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
# LINK-HASH: [ 1] .hash HASH 0000000000000000 000040 000000 00 0 0 0
# LINK-HASH-NEXT: [ 2] .gnu_hash GNU_HASH 0000000000000000 000040 000000 00 0 0 0
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .hash
Type: SHT_HASH
Content: ""
- Name: .gnu_hash
Type: SHT_GNU_HASH
Content: ""
- Name: .dynsym
Type: SHT_DYNSYM
SectionHeaderTable:
Sections:
- Name: .hash
- Name: .gnu_hash
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .dynsym
## Case I: document the case when an excluded section is explicitly linked to another excluded section.
## We report an error in this case, because:
## 1) It is a reasonable behavior, as it is perhaps usually a result of a mistake
## in a YAML description.
## 2) Helps to keep the code simpler.
# RUN: not yaml2obj %s --docnum=17 -o /dev/null 2>&1 | FileCheck %s --check-prefix=CROSS-LINK
# CROSS-LINK: error: unable to link '.foo' to excluded section '.bar'
# CROSS-LINK-NEXT: error: unable to link '.bar' to excluded section '.foo'
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .foo
Type: SHT_PROGBITS
Link: .bar
- Name: .bar
Type: SHT_PROGBITS
Link: .foo
SectionHeaderTable:
Sections:
- Name: .strtab
- Name: .shstrtab
Excluded:
- Name: .foo
- Name: .bar
## Check we set e_shstrndx field to 0 when the section header string table is excluded.
## Check that the e_shnum field is adjusted properly when a section is removed.
# RUN: yaml2obj --docnum=18 %s -o %t9
# RUN: llvm-readelf --file-headers %t9 | FileCheck %s --check-prefix=SHSTRTAB
# SHSTRTAB: Number of section headers: 2
# SHSTRTAB: Section header string table index: 0
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SectionHeaderTable:
Sections:
- Name: .strtab
Excluded:
- Name: .shstrtab
## Check we do not allow using "Excluded" together with "NoHeaders".
# RUN: not yaml2obj %s --docnum=19 -DNOHEADERS=true -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOHEADERS
# RUN: not yaml2obj %s --docnum=19 -DNOHEADERS=false -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOHEADERS
# NOHEADERS: NoHeaders can't be used together with Sections/Excluded
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SectionHeaderTable:
NoHeaders: [[NOHEADERS]]
Excluded: []