xref: /llvm-project/llvm/test/tools/yaml2obj/ELF/program-header.yaml (revision a7a447be0fa934505f0c423fb97b91a68c1cc715)
163f0f54cSFangrui Song# RUN: yaml2obj --docnum=1 %s -o %t
263f0f54cSFangrui Song# RUN: llvm-readobj -l %t | FileCheck %s
363f0f54cSFangrui Song
463f0f54cSFangrui Song--- !ELF
563f0f54cSFangrui SongFileHeader:
663f0f54cSFangrui Song  Class: ELFCLASS64
763f0f54cSFangrui Song  Data:  ELFDATA2LSB
863f0f54cSFangrui Song  Type:  ET_EXEC
963f0f54cSFangrui SongSections:
1063f0f54cSFangrui Song  - Name:            .text
1163f0f54cSFangrui Song    Type:            SHT_PROGBITS
1263f0f54cSFangrui Song    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
1363f0f54cSFangrui Song    AddressAlign:    0x0000000000001000
1463f0f54cSFangrui Song    Content:         "00000000"
1563f0f54cSFangrui Song  - Name:            .init
1663f0f54cSFangrui Song    Type:            SHT_PROGBITS
1763f0f54cSFangrui Song    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
1863f0f54cSFangrui Song    Content:         "00000000"
1963f0f54cSFangrui Song    AddressAlign:    0x0000000000000010
2063f0f54cSFangrui Song  - Name:            .data
2163f0f54cSFangrui Song    Type:            SHT_PROGBITS
2263f0f54cSFangrui Song    Flags:           [ SHF_ALLOC ]
2363f0f54cSFangrui Song    Content:         "00000000"
2463f0f54cSFangrui Song    AddressAlign:    0x0000000000001000
2563f0f54cSFangrui SongProgramHeaders:
2663f0f54cSFangrui Song  - Type:     PT_LOAD
2763f0f54cSFangrui Song    Flags:    [ PF_X, PF_R ]
2863f0f54cSFangrui Song    VAddr:    0xAAAA1000
2963f0f54cSFangrui Song    PAddr:    0xFFFF1000
30*a7a447beSGeorgii Rymar    FirstSec: .text
31*a7a447beSGeorgii Rymar    LastSec:  .init
3263f0f54cSFangrui Song  - Type:     PT_LOAD
3363f0f54cSFangrui Song    Flags:    [ PF_R ]
3463f0f54cSFangrui Song    VAddr:    0xAAAA2000
3563f0f54cSFangrui Song    PAddr:    0xFFFF2000
36*a7a447beSGeorgii Rymar    FirstSec: .data
37*a7a447beSGeorgii Rymar    LastSec:  .data
3863f0f54cSFangrui Song  - Type: PT_GNU_EH_FRAME
3963f0f54cSFangrui Song  - Type: PT_GNU_STACK
4063f0f54cSFangrui Song  - Type: PT_GNU_RELRO
412120612eSPeter Smith  - Type: PT_GNU_PROPERTY
4263f0f54cSFangrui Song
4363f0f54cSFangrui Song#CHECK:     ProgramHeaders [
4463f0f54cSFangrui Song#CHECK-NEXT:   ProgramHeader {
4563f0f54cSFangrui Song#CHECK-NEXT:    Type: PT_LOAD
4663f0f54cSFangrui Song#CHECK-NEXT:    Offset: 0x1000
4763f0f54cSFangrui Song#CHECK-NEXT:    VirtualAddress: 0xAAAA1000
4863f0f54cSFangrui Song#CHECK-NEXT:    PhysicalAddress: 0xFFFF1000
4963f0f54cSFangrui Song#CHECK-NEXT:    FileSize: 20
5063f0f54cSFangrui Song#CHECK-NEXT:    MemSize: 20
5163f0f54cSFangrui Song#CHECK-NEXT:    Flags [
5263f0f54cSFangrui Song#CHECK-NEXT:      PF_R
5363f0f54cSFangrui Song#CHECK-NEXT:      PF_X
5463f0f54cSFangrui Song#CHECK-NEXT:    ]
5563f0f54cSFangrui Song#CHECK-NEXT:    Alignment: 4096
5663f0f54cSFangrui Song#CHECK-NEXT:  }
5763f0f54cSFangrui Song#CHECK-NEXT:  ProgramHeader {
5863f0f54cSFangrui Song#CHECK-NEXT:    Type: PT_LOAD
5963f0f54cSFangrui Song#CHECK-NEXT:    Offset: 0x2000
6063f0f54cSFangrui Song#CHECK-NEXT:    VirtualAddress: 0xAAAA2000
6163f0f54cSFangrui Song#CHECK-NEXT:    PhysicalAddress: 0xFFFF2000
6263f0f54cSFangrui Song#CHECK-NEXT:    FileSize: 4
6363f0f54cSFangrui Song#CHECK-NEXT:    MemSize: 4
6463f0f54cSFangrui Song#CHECK-NEXT:    Flags [
6563f0f54cSFangrui Song#CHECK-NEXT:      PF_R
6663f0f54cSFangrui Song#CHECK-NEXT:    ]
6763f0f54cSFangrui Song#CHECK-NEXT:    Alignment: 4096
6863f0f54cSFangrui Song#CHECK-NEXT:  }
6963f0f54cSFangrui Song#CHECK-NEXT:  ProgramHeader {
7063f0f54cSFangrui Song#CHECK-NEXT:    Type: PT_GNU_EH_FRAME (0x6474E550)
7163f0f54cSFangrui Song#CHECK:       }
7263f0f54cSFangrui Song#CHECK-NEXT:  ProgramHeader {
7363f0f54cSFangrui Song#CHECK-NEXT:    Type: PT_GNU_STACK (0x6474E551)
7463f0f54cSFangrui Song#CHECK:       }
7563f0f54cSFangrui Song#CHECK-NEXT:  ProgramHeader {
7663f0f54cSFangrui Song#CHECK-NEXT:    Type: PT_GNU_RELRO (0x6474E552)
7763f0f54cSFangrui Song#CHECK:       }
782120612eSPeter Smith#CHECK-NEXT:  ProgramHeader {
792120612eSPeter Smith#CHECK-NEXT:    Type: PT_GNU_PROPERTY (0x6474E553)
802120612eSPeter Smith#CHECK:       }
8163f0f54cSFangrui Song#CHECK-NEXT:]
8263f0f54cSFangrui Song
8363f0f54cSFangrui Song## Check we do not allow referencing sections that do not exist.
84*a7a447beSGeorgii Rymar# RUN: not yaml2obj -DFIRST=".unknown1" -DLAST=".unknown2" --docnum=2 %s 2>&1 | \
85*a7a447beSGeorgii Rymar# RUN:   FileCheck %s --check-prefix=UNKNOWN-ERR
8663f0f54cSFangrui Song
87*a7a447beSGeorgii Rymar# UNKNOWN-ERR: error: unknown section or fill referenced: '.unknown1' by the 'FirstSec' key of the program header with index 0
88*a7a447beSGeorgii Rymar# UNKNOWN-ERR: error: unknown section or fill referenced: '.unknown2' by the 'LastSec' key of the program header with index 0
8963f0f54cSFangrui Song
9063f0f54cSFangrui Song--- !ELF
9163f0f54cSFangrui SongFileHeader:
9263f0f54cSFangrui Song  Class: ELFCLASS64
9363f0f54cSFangrui Song  Data:  ELFDATA2LSB
9463f0f54cSFangrui Song  Type:  ET_EXEC
95*a7a447beSGeorgii RymarSections:
96*a7a447beSGeorgii Rymar  - Name:   .foo
97*a7a447beSGeorgii Rymar    Type:   SHT_PROGBITS
98*a7a447beSGeorgii Rymar    Offset: 0x100
99*a7a447beSGeorgii Rymar    Size:   0x10
100*a7a447beSGeorgii Rymar  - Name:   .bar
101*a7a447beSGeorgii Rymar    Type:   SHT_PROGBITS
102*a7a447beSGeorgii Rymar    Offset: 0x200
103*a7a447beSGeorgii Rymar    Size:   0x20
104*a7a447beSGeorgii Rymar  - Name:   .zed
105*a7a447beSGeorgii Rymar    Type:   SHT_PROGBITS
106*a7a447beSGeorgii Rymar    Offset: 0x300
107*a7a447beSGeorgii Rymar    Size:   0x30
108*a7a447beSGeorgii Rymar  - Name:   .fill1
109*a7a447beSGeorgii Rymar    Type:   Fill
110*a7a447beSGeorgii Rymar    Offset: 0x400
111*a7a447beSGeorgii Rymar    Size:   0x40
112*a7a447beSGeorgii Rymar  - Name:   .fill2
113*a7a447beSGeorgii Rymar    Type:   Fill
114*a7a447beSGeorgii Rymar    Offset: 0x500
115*a7a447beSGeorgii Rymar    Size:   0x50
11663f0f54cSFangrui SongProgramHeaders:
11763f0f54cSFangrui Song  - Type:     PT_LOAD
118*a7a447beSGeorgii Rymar    FirstSec: [[FIRST=<none>]]
119*a7a447beSGeorgii Rymar    LastSec:  [[LAST=<none>]]
120*a7a447beSGeorgii Rymar
121*a7a447beSGeorgii Rymar## Check we report an error when the index of the section specified by the "FirstSec" key
122*a7a447beSGeorgii Rymar## is greater than the index of the section specified by the "LastSec" key.
123*a7a447beSGeorgii Rymar
124*a7a447beSGeorgii Rymar# RUN: not yaml2obj -DFIRST=".bar" -DLAST=".foo" --docnum=2 %s 2>&1 | \
125*a7a447beSGeorgii Rymar# RUN:   FileCheck %s --check-prefix=ORDER-ERR
126*a7a447beSGeorgii Rymar
127*a7a447beSGeorgii Rymar# ORDER-ERR: error: program header with index 0: the section index of .bar is greater than the index of .foo
128*a7a447beSGeorgii Rymar
129*a7a447beSGeorgii Rymar## Check that we can't use the "LastSec" key without the "FirstSec" key.
130*a7a447beSGeorgii Rymar
131*a7a447beSGeorgii Rymar# RUN: not yaml2obj -DLAST=".foo" --docnum=2 %s 2>&1 | \
132*a7a447beSGeorgii Rymar# RUN:   FileCheck %s --check-prefix=ONLY-LAST-ERR
133*a7a447beSGeorgii Rymar
134*a7a447beSGeorgii Rymar# ONLY-LAST-ERR: error: the "LastSec" key can't be used without the "FirstSec" key
135*a7a447beSGeorgii Rymar
136*a7a447beSGeorgii Rymar## Check that we can't use the "FirstSec" key without the "LastSec" key.
137*a7a447beSGeorgii Rymar
138*a7a447beSGeorgii Rymar# RUN: not yaml2obj -DFIRST=".foo" --docnum=2 %s 2>&1 | \
139*a7a447beSGeorgii Rymar# RUN:   FileCheck %s --check-prefix=ONLY-FIRST-ERR
140*a7a447beSGeorgii Rymar
141*a7a447beSGeorgii Rymar# ONLY-FIRST-ERR: error: the "FirstSec" key can't be used without the "LastSec" key
142*a7a447beSGeorgii Rymar
143*a7a447beSGeorgii Rymar## Check we create an empty segment when neither "FirstSec" nor "LastSec" are specified.
144*a7a447beSGeorgii Rymar
145*a7a447beSGeorgii Rymar# RUN: yaml2obj --docnum=2 %s -o %t3
146*a7a447beSGeorgii Rymar# RUN: llvm-readelf --program-headers %t3 | FileCheck %s --check-prefix=EMPTY-SEGMENT
147*a7a447beSGeorgii Rymar
148*a7a447beSGeorgii Rymar# EMPTY-SEGMENT:       Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
149*a7a447beSGeorgii Rymar# EMPTY-SEGMENT:       LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000
150*a7a447beSGeorgii Rymar# EMPTY-SEGMENT-EMPTY:
151*a7a447beSGeorgii Rymar
152*a7a447beSGeorgii Rymar## Check that we include all sections between FirstSec and LastSec in the segment when both keys are used.
153*a7a447beSGeorgii Rymar
154*a7a447beSGeorgii Rymar# RUN: yaml2obj --docnum=2 -DFIRST=".foo" -DLAST=".zed" %s -o %t4
155*a7a447beSGeorgii Rymar# RUN: llvm-readelf --program-headers %t4 | FileCheck %s --check-prefix=BOTH
156*a7a447beSGeorgii Rymar
157*a7a447beSGeorgii Rymar# BOTH:      Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
158*a7a447beSGeorgii Rymar# BOTH-NEXT: LOAD 0x000100 0x0000000000000000 0x0000000000000000 0x000230 0x000230
159*a7a447beSGeorgii Rymar
160*a7a447beSGeorgii Rymar## Check that we include fills that are between FirstSec and LastSec in the segment when both keys are used.
161*a7a447beSGeorgii Rymar
162*a7a447beSGeorgii Rymar# RUN: yaml2obj --docnum=2 -DFIRST=".foo" -DLAST=".fill1" %s -o %t5a
163*a7a447beSGeorgii Rymar# RUN: llvm-readelf --program-headers %t5a | FileCheck %s --check-prefix=FILL1
164*a7a447beSGeorgii Rymar
165*a7a447beSGeorgii Rymar# FILL1: Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
166*a7a447beSGeorgii Rymar# FILL1: LOAD 0x000100 0x0000000000000000 0x0000000000000000 0x000340 0x000340
167*a7a447beSGeorgii Rymar
168*a7a447beSGeorgii Rymar# RUN: yaml2obj --docnum=2 -DFIRST=".foo" -DLAST=".fill2" %s -o %t5b
169*a7a447beSGeorgii Rymar# RUN: llvm-readelf --program-headers %t5b | FileCheck %s --check-prefix=FILL2
170*a7a447beSGeorgii Rymar
171*a7a447beSGeorgii Rymar# FILL2: Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
172*a7a447beSGeorgii Rymar# FILL2: LOAD 0x000100 0x0000000000000000 0x0000000000000000 0x000450 0x000450
173