Skip to content

Commit f943ab1

Browse files
author
Ruoyu Qiu
committed
Fix tests about the change of ShOffset overriding timing
Signed-off-by: Ruoyu Qiu <[email protected]>
1 parent 2b7f229 commit f943ab1

File tree

3 files changed

+52
-37
lines changed

3 files changed

+52
-37
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191

9292
## Case D: the same as "Case C", but for a 32-bit object.
9393

94-
# RUN: yaml2obj %s -DBITS=32 -DOFFSET=0xffffffff -o %t5
94+
# RUN: yaml2obj %s -DBITS=32 -DFILESIZE=8 -DOFFSET=0xffffffff -o %t5
9595
# RUN: llvm-readobj %t5 --dynamic-table 2>&1 | FileCheck -DFILE=%t5 %s \
9696
# RUN: --check-prefix=WARN5 --implicit-check-not=warning:
9797
# RUN: llvm-readelf %t5 --dynamic-table 2>&1 | FileCheck -DFILE=%t5 %s \
@@ -101,7 +101,7 @@
101101
# 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)
102102
# WARN5: warning: '[[FILE]]': no valid dynamic table was found
103103

104-
# RUN: yaml2obj %s -DNOHEADERS=true -DBITS=32 -DOFFSET=0xffffffff -o %t5.noheaders
104+
# RUN: yaml2obj %s -DNOHEADERS=true -DBITS=32 -DFILESIZE=8 -DOFFSET=0xffffffff -o %t5.noheaders
105105
# RUN: llvm-readobj %t5.noheaders --dynamic-table 2>&1 | \
106106
# RUN: FileCheck -DFILE=%t5.noheaders %s --check-prefix=WARN5-NOHEADERS
107107
# RUN: llvm-readelf %t5.noheaders --dynamic-table 2>&1 | \
@@ -133,14 +133,13 @@ Sections:
133133
Type: SHT_DYNAMIC
134134
Address: 0x1000
135135
Offset: 0x1000
136+
ShOffset: [[OFFSET=0x1000]]
136137
Entries:
137138
- Tag: DT_NULL
138139
Value: 0
139140
- Type: SectionHeaderTable
140141
NoHeaders: [[NOHEADERS=false]]
141142
ProgramHeaders:
142143
- Type: PT_DYNAMIC
143-
FileSize: [[FILESIZE=<none>]]
144-
Offset: [[OFFSET=<none>]]
145-
FirstSec: .dynamic
146-
LastSec: .dynamic
144+
FileSize: [[FILESIZE=0x10]]
145+
Offset: [[OFFSET=0x1000]]

llvm/test/tools/obj2yaml/ELF/program-headers.yaml

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -436,28 +436,38 @@ Sections:
436436
# NOBITS-NEXT: Flags: [ PF_W, PF_R ]
437437
# NOBITS-NEXT: FirstSec: .bss
438438
# NOBITS-NEXT: LastSec: .bss
439-
# NOBITS-NEXT: Offset: 0x159
439+
# NOBITS-NEXT: VAddr: 0x1001
440+
# NOBITS-NEXT: Offset: 0x191
440441
# NOBITS-NEXT: - Type: PT_LOAD
441442
# NOBITS-NEXT: Flags: [ PF_W, PF_R ]
442443
# NOBITS-NEXT: FirstSec: .data.1
443444
# NOBITS-NEXT: LastSec: .bss
444-
# NOBITS-NEXT: Offset: 0x158
445+
# NOBITS-NEXT: VAddr: 0x1000
446+
# NOBITS-NEXT: Offset: 0x190
445447
# NOBITS-NEXT: - Type: PT_LOAD
446448
# NOBITS-NEXT: Flags: [ PF_W, PF_R ]
447449
# NOBITS-NEXT: FirstSec: .data.1
448450
# NOBITS-NEXT: LastSec: .data.2
449-
# NOBITS-NEXT: Offset: 0x158
451+
# NOBITS-NEXT: VAddr: 0x1000
452+
# NOBITS-NEXT: Offset: 0x190
450453
# NOBITS-NEXT: - Type: PT_LOAD
451454
# NOBITS-NEXT: Flags: [ PF_W, PF_R ]
452455
# NOBITS-NEXT: FirstSec: .bss
453456
# NOBITS-NEXT: LastSec: .data.2
454-
# NOBITS-NEXT: Offset: 0x159
457+
# NOBITS-NEXT: VAddr: 0x1001
458+
# NOBITS-NEXT: Offset: 0x191
455459
# NOBITS-NEXT: - Type: PT_LOAD
456460
# NOBITS-NEXT: Flags: [ PF_W, PF_R ]
457461
# NOBITS-NEXT: FirstSec: .foo.bss
458462
# NOBITS-NEXT: LastSec: .bar.bss
459463
# NOBITS-NEXT: VAddr: 0x200000000
460-
# NOBITS-NEXT: Offset: 0x15A
464+
# NOBITS-NEXT: Offset: 0x193
465+
# NOBITS-NEXT: - Type: PT_LOAD
466+
# NOBITS-NEXT: Flags: [ PF_W, PF_R ]
467+
# NOBITS-NEXT: FirstSec: .data.3
468+
# NOBITS-NEXT: LastSec: .bss.large
469+
# NOBITS-NEXT: VAddr: 0x200000030
470+
# NOBITS-NEXT: Offset: 0x193
461471
# NOBITS-NEXT: Sections:
462472

463473
--- !ELF
@@ -471,27 +481,37 @@ ProgramHeaders:
471481
Flags: [ PF_W, PF_R ]
472482
FirstSec: .bss
473483
LastSec: .bss
484+
VAddr: 0x1001
474485
## Case 2: the SHT_NOBITS section is the last section in the segment.
475486
- Type: PT_LOAD
476487
Flags: [ PF_W, PF_R ]
477488
FirstSec: .data.1
478489
LastSec: .bss
490+
VAddr: 0x1000
479491
## Case 3: the SHT_NOBITS section is in the middle of the segment.
480492
- Type: PT_LOAD
481493
Flags: [ PF_W, PF_R ]
482494
FirstSec: .data.1
483495
LastSec: .data.2
496+
VAddr: 0x1000
484497
## Case 4: the SHT_NOBITS section is the first section in the segment.
485498
- Type: PT_LOAD
486499
Flags: [ PF_W, PF_R ]
487500
FirstSec: .bss
488501
LastSec: .data.2
502+
VAddr: 0x1001
489503
## Case 5: another two SHT_NOBITS sections in a different segment.
490504
- Type: PT_LOAD
491505
Flags: [ PF_W, PF_R ]
492506
FirstSec: .foo.bss
493507
LastSec: .bar.bss
494508
VAddr: 0x200000000
509+
## Case 6: a SHT_NOBITS section following a normal section, where the SHT_NOBITS size points past the end of the program header.
510+
- Type: PT_LOAD
511+
Flags: [ PF_W, PF_R ]
512+
FirstSec: .data.3
513+
LastSec: .bss.large
514+
VAddr: 0x200000030
495515
Sections:
496516
- Name: .data.1
497517
Type: SHT_PROGBITS
@@ -502,13 +522,13 @@ Sections:
502522
- Name: .bss
503523
Type: SHT_NOBITS
504524
Flags: [ SHF_WRITE, SHF_ALLOC ]
505-
## Use a size that is larger than the file size.
506-
ShSize: 0x00000000FFFFFFFF
507-
- Name: .data.2
508-
Type: SHT_PROGBITS
509-
Flags: [ SHF_WRITE, SHF_ALLOC ]
525+
## Use an arbitrary non-zero size.
526+
Size: 0x1
527+
- Name: .data.2
528+
Type: SHT_PROGBITS
529+
Flags: [ SHF_WRITE, SHF_ALLOC ]
510530
## Use an arbitrary size.
511-
Size: 0x1
531+
Size: 0x1
512532
- Name: .foo.bss
513533
Type: SHT_NOBITS
514534
Flags: [ SHF_WRITE, SHF_ALLOC ]
@@ -523,14 +543,26 @@ Sections:
523543
## Use an arbitrary size that is different to the size of
524544
## the previous section.
525545
Size: 0x20
546+
- Name: .data.3
547+
Type: SHT_PROGBITS
548+
Flags: [ SHF_WRITE, SHF_ALLOC ]
549+
# Use an abitrary size. Also use an address that is larger than the previous
550+
# section, because the tools expect segment addresses to be in order.
551+
Size: 0x1
552+
Address: 0x200000030
553+
- Name: .bss.large
554+
Type: SHT_NOBITS
555+
Flags: [ SHF_WRITE, SHF_ALLOC ]
556+
## Use a size that is larger than the file size.
557+
Size: 0x00000000FFFFFFFF
558+
Address: 0x200000031
526559

527560
## Check that we require sections in a program header
528561
## declaration to be sorted by their offsets.
529562
# RUN: not yaml2obj --docnum=6 %s -o %t6 2>&1 | \
530563
# RUN: FileCheck %s --check-prefix=UNSORTED --implicit-check-not="error:"
531564

532565
# UNSORTED: error: program header with index 0: the section index of .bar is greater than the index of .foo
533-
# UNSORTED-NEXT: error: sections in the program header with index 3 are not sorted by their file offset
534566

535567
--- !ELF
536568
FileHeader:
@@ -552,15 +584,6 @@ ProgramHeaders:
552584
FirstSec: .foo
553585
LastSec: .bar
554586
VAddr: 0x1000
555-
## Case 2: the .bar section is placed before the .zed section in the file,
556-
## but the sh_offset of .zed is less than the sh_offset of
557-
## the .bar section because of the "ShOffset" property.
558-
## Document we report an error for such a case.
559-
- Type: PT_LOAD
560-
Flags: [ PF_R ]
561-
FirstSec: .bar
562-
LastSec: .zed
563-
VAddr: 0x1001
564587
Sections:
565588
- Name: .foo
566589
Type: SHT_PROGBITS
@@ -571,11 +594,6 @@ Sections:
571594
Type: SHT_PROGBITS
572595
Flags: [ SHF_ALLOC ]
573596
Size: 0x1
574-
- Name: .zed
575-
Type: SHT_PROGBITS
576-
Flags: [ SHF_ALLOC ]
577-
Size: 0x1
578-
ShOffset: 0x0
579597

580598
## Check how we dump segments which contain empty sections.
581599
# RUN: yaml2obj --docnum=7 %s -o %t7

llvm/test/tools/yaml2obj/ELF/program-header-size-offset.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,12 @@ ProgramHeaders:
180180

181181
# INVALID-OFFSET: yaml2obj: error: 'Offset' for segment with index 1 must be less than or equal to the minimum file offset of all included sections (0x78)
182182

183-
## Document that the "Offset" value should be checked before the section offset is overriden using "ShOffset".
184-
## And the offset of the first section in a segment should not greater than the offset of the segment.
183+
## Check "Offset" is used before the section offset is overriden using "ShOffset".
185184
# RUN: yaml2obj --docnum=4 %s -o %t5
186185
# RUN: llvm-readelf %t5 --sections --program-headers | FileCheck %s --check-prefix=SHOFFSET
187186

188187
# SHOFFSET: [Nr] Name Type Address Off
189-
# SHOFFSET: [ 1] .foo PROGBITS 0000000000000000 0000ff
188+
# SHOFFSET: [ 1] .foo PROGBITS 0000000000000000 ffffffff
190189

191190
# SHOFFSET: Type Offset
192191
# SHOFFSET-NEXT: LOAD 0x000078
@@ -203,10 +202,9 @@ Sections:
203202
Size: 0x1
204203
## Note: the real .foo offset is much less than 0xFFFFFFFF or
205204
## 0xFFFFFF00, but no error is reported.
206-
ShOffset: 0xFF
205+
ShOffset: 0xFFFFFFFF
207206
ProgramHeaders:
208207
- Type: PT_LOAD
209208
Offset: 0x78
210209
FirstSec: .foo
211210
LastSec: .foo
212-

0 commit comments

Comments
 (0)