Files
clang-p2996/llvm/test/tools/llvm-objcopy/ELF/empty-section.test
Georgii Rymar a7a447be0f [yaml2obj] - ProgramHeaders: introduce FirstSec/LastSec instead of Sections list.
Imagine we have a YAML declaration of few sections: `foo1`, `<unnamed 2>`, `foo3`, `foo4`.

To put them into segment we can do (1*):

```
Sections:
 - Section: foo1
 - Section: foo4
```

or we can use (2*):

```
Sections:
 - Section: foo1
 - Section: foo3
 - Section: foo4
```

or (3*) :

```
Sections:
 - Section: foo1
## "(index 2)" here is a name that we automatically created for a unnamed section.
 - Section: (index 2)
 - Section: foo3
 - Section: foo4
```

It looks really confusing that we don't have to list all of sections.

At first I've tried to make this rule stricter and report an error when there is a gap
(i.e. when a section is included into segment, but not listed explicitly).
This did not work perfect, because such approach conflicts with unnamed sections/fills (see (3*)).

This patch drops "Sections" key and introduces 2 keys instead: `FirstSec` and `LastSec`.
Both are optional.

Differential revision: https://reviews.llvm.org/D90458
2020-11-09 13:00:50 +03:00

92 lines
2.8 KiB
Plaintext

## .empty is not covered by a segment. Its offset is moved to 0x200 to fill the gap.
# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-objcopy %t1 %t1.out
# RUN: llvm-readelf -S %t1.out | FileCheck --check-prefix=CHECK1 %s
# CHECK1: Name Type Address Off
# CHECK1-NEXT: NULL 0000000000000000 000000
# CHECK1-NEXT: .foo PROGBITS 0000000000000000 000100
# CHECK1-NEXT: .empty PROGBITS 0000000000001000 000200
# CHECK1-NEXT: .baz PROGBITS 0000000000001000 001000
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: gap
Type: Fill
Size: 0xE00
- Name: .foo
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x100
Address: 0
Size: 0x100
- Name: .empty
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
Address: 0x1000
- Name: .baz
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x1000
Address: 0x1000
Size: 0x100
## Test that we attribute .empty to the second segment. Its offset is assigned according to
## the p_offset of the second segment.
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-objcopy %t2 %t2.out
# RUN: llvm-readelf -S -l %t2.out | FileCheck --check-prefix=CHECK2 %s
# CHECK2: Name Type Address Off
# CHECK2-NEXT: NULL 0000000000000000 000000
# CHECK2-NEXT: .foo PROGBITS 0000000000000000 000100
# CHECK2-NEXT: .empty PROGBITS 0000000000001000 001000
# CHECK2-NEXT: .baz PROGBITS 0000000000001000 001000
# CHECK2: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
# CHECK2-NEXT: LOAD 0x000100 0x0000000000000000 0x0000000000000000 0x000100 0x000100 0x100
# CHECK2-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000100 0x000100 0x1000
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: gap
Type: Fill
Size: 0xE00
- Name: .foo
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x100
Address: 0
Size: 0x100
- Name: .empty
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
Address: 0x1000
- Name: .baz
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x1000
Address: 0x1000
Size: 0x100
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0
Align: 0x100
FirstSec: .foo
LastSec: .foo
- Type: PT_LOAD
VAddr: 0x1000
Align: 0x1000
FirstSec: .empty
LastSec: .baz