|
1 | 1 | ## Show that yaml2obj properly emits program headers with explicit file size,
|
2 | 2 | ## memory size and offset parameters.
|
3 | 3 |
|
4 |
| -# RUN: yaml2obj %s -o %t |
5 |
| -# RUN: llvm-readobj %t --program-headers | FileCheck %s |
| 4 | +# RUN: yaml2obj --docnum=1 %s -o %t1 |
| 5 | +# RUN: llvm-readobj %t1 --program-headers | FileCheck %s |
6 | 6 |
|
7 | 7 | # CHECK: ProgramHeaders [
|
8 | 8 | # CHECK: Offset: 0x1234
|
|
34 | 34 | # CHECK: MemSize: 6
|
35 | 35 | # CHECK: ]
|
36 | 36 |
|
37 |
| -!ELF |
| 37 | +--- !ELF |
38 | 38 | FileHeader:
|
39 | 39 | Class: ELFCLASS64
|
40 | 40 | Data: ELFDATA2LSB
|
@@ -92,17 +92,125 @@ ProgramHeaders:
|
92 | 92 | MemSize: 9
|
93 | 93 | Sections:
|
94 | 94 | - Section: .text
|
95 |
| - # Program header with sections, invalid properties. |
| 95 | + # Program header with invalid properties. |
96 | 96 | - Type: 0x6abcdef0
|
97 | 97 | Offset: 0x3000
|
98 | 98 | FileSize: 3
|
99 | 99 | MemSize: 2
|
100 |
| - Sections: |
101 |
| - - Section: .data |
102 | 100 | # Program header with 2 SHT_NOBITS sections.
|
103 | 101 | - Type: 0x6abcdef0
|
104 | 102 | Offset: 0x2004
|
105 | 103 | Sections:
|
106 | 104 | - Section: .data
|
107 | 105 | - Section: .nobits1
|
108 | 106 | - Section: .nobits2
|
| 107 | + |
| 108 | +## Test the "Offset" property. |
| 109 | + |
| 110 | +## Check that by default the p_offset field of a segment is set to the |
| 111 | +## offset of the section with the minimum offset. |
| 112 | +# RUN: yaml2obj --docnum=2 %s -o %t2 |
| 113 | +# RUN: llvm-readelf %t2 --sections --program-headers | \ |
| 114 | +# RUN: FileCheck %s --check-prefixes=DEFAULT-OFFSET |
| 115 | + |
| 116 | +# DEFAULT-OFFSET: [Nr] Name Type Address Off |
| 117 | +# DEFAULT-OFFSET: [ 1] .foo PROGBITS 0000000000001000 0000b0 |
| 118 | +# DEFAULT-OFFSET-NEXT: [ 2] .bar PROGBITS 0000000000001001 0000b1 |
| 119 | + |
| 120 | +# DEFAULT-OFFSET: Type Offset |
| 121 | +# DEFAULT-OFFSET-NEXT: LOAD 0x0000b0 |
| 122 | +# DEFAULT-OFFSET-NEXT: LOAD 0x0000b1 |
| 123 | + |
| 124 | +--- !ELF |
| 125 | +FileHeader: |
| 126 | + Class: ELFCLASS64 |
| 127 | + Data: ELFDATA2LSB |
| 128 | + Type: ET_EXEC |
| 129 | + Machine: EM_X86_64 |
| 130 | +Sections: |
| 131 | + - Name: .foo |
| 132 | + Type: SHT_PROGBITS |
| 133 | + Flags: [ SHF_ALLOC ] |
| 134 | + Size: 0x1 |
| 135 | + Address: 0x1000 |
| 136 | + - Name: .bar |
| 137 | + Type: SHT_PROGBITS |
| 138 | + Flags: [ SHF_ALLOC ] |
| 139 | + Size: 0x1 |
| 140 | +ProgramHeaders: |
| 141 | + - Type: PT_LOAD |
| 142 | + Sections: |
| 143 | + - Section: .foo |
| 144 | + - Section: .bar |
| 145 | + - Type: PT_LOAD |
| 146 | + Sections: |
| 147 | + - Section: .bar |
| 148 | + |
| 149 | +## Check we can set the "Offset" value explicitly to be less than or equal to |
| 150 | +## the offset of a section in the segment. |
| 151 | +# RUN: yaml2obj --docnum=3 -DOFFSET=0x77 %s -o %t3 |
| 152 | +# RUN: llvm-readelf %t3 --sections --program-headers | \ |
| 153 | +# RUN: FileCheck %s --check-prefixes=VALID-OFFSET,VALID-OFFSET-LESS |
| 154 | +# RUN: yaml2obj --docnum=3 -DOFFSET=0x78 %s -o %t4 |
| 155 | +# RUN: llvm-readelf %t4 --sections --program-headers | \ |
| 156 | +# RUN: FileCheck %s --check-prefixes=VALID-OFFSET,VALID-OFFSET-EQ |
| 157 | + |
| 158 | +# VALID-OFFSET: [Nr] Name Type Address Off |
| 159 | +# VALID-OFFSET: [ 1] .foo PROGBITS 0000000000000000 000078 |
| 160 | + |
| 161 | +# VALID-OFFSET: Type Offset |
| 162 | +# VALID-OFFSET-EQ: LOAD 0x000078 |
| 163 | +# VALID-OFFSET-LESS: LOAD 0x000077 |
| 164 | + |
| 165 | +--- !ELF |
| 166 | +FileHeader: |
| 167 | + Class: ELFCLASS64 |
| 168 | + Data: ELFDATA2LSB |
| 169 | + Type: ET_EXEC |
| 170 | + Machine: EM_X86_64 |
| 171 | +Sections: |
| 172 | + - Name: .foo |
| 173 | + Type: SHT_PROGBITS |
| 174 | + Flags: [ SHF_ALLOC ] |
| 175 | + Size: 0x1 |
| 176 | +ProgramHeaders: |
| 177 | + - Type: PT_LOAD |
| 178 | + Offset: [[OFFSET]] |
| 179 | + Sections: |
| 180 | + - Section: .foo |
| 181 | + |
| 182 | +## Check we report an error when the "Offset" value is larger than the offset of a section in the segment. |
| 183 | +# RUN: not yaml2obj --docnum=3 -DOFFSET=0x79 %s -o /dev/null 2>&1 | \ |
| 184 | +# RUN: FileCheck %s --check-prefix=INVALID-OFFSET |
| 185 | + |
| 186 | +# 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) |
| 187 | + |
| 188 | +## Document that the "Offset" value is checked after the section offset is overriden using "ShOffset". |
| 189 | +# RUN: yaml2obj --docnum=4 %s -o %t5 |
| 190 | +# RUN: llvm-readelf %t5 --sections --program-headers | FileCheck %s --check-prefix=SHOFFSET |
| 191 | + |
| 192 | +# SHOFFSET: [Nr] Name Type Address Off |
| 193 | +# SHOFFSET: [ 1] .foo PROGBITS 0000000000000000 ffffffff |
| 194 | + |
| 195 | +# SHOFFSET: Type Offset |
| 196 | +# SHOFFSET-NEXT: LOAD 0xffffff00 |
| 197 | + |
| 198 | +--- !ELF |
| 199 | +FileHeader: |
| 200 | + Class: ELFCLASS64 |
| 201 | + Data: ELFDATA2LSB |
| 202 | + Type: ET_EXEC |
| 203 | + Machine: EM_X86_64 |
| 204 | +Sections: |
| 205 | + - Name: .foo |
| 206 | + Type: SHT_PROGBITS |
| 207 | + Flags: [ SHF_ALLOC ] |
| 208 | + Size: 0x1 |
| 209 | +## Note: the real .foo offset is much less than 0xFFFFFFFF or |
| 210 | +## 0xFFFFFF00, but no error is reported. |
| 211 | + ShOffset: 0xFFFFFFFF |
| 212 | +ProgramHeaders: |
| 213 | + - Type: PT_LOAD |
| 214 | + Offset: 0xFFFFFF00 |
| 215 | + Sections: |
| 216 | + - Section: .foo |
0 commit comments