132 lines · yaml
1## Check we are able to set an offset field for sections using the 'Offset' key.2 3## Show how the 'Offset' field key can be used.4## Show that it can affect the layout of the rest of the file.5 6# RUN: yaml2obj --docnum=1 %s -o %t17# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=DEFAULT8 9# DEFAULT: [Nr] Name Type Address Off10# DEFAULT: [ 1] .foo PROGBITS 0000000000000000 00004011# DEFAULT-NEXT: [ 2] .bar PROGBITS 0000000000000000 00004812# DEFAULT-NEXT: [ 3] .strtab STRTAB 0000000000000000 00005813# DEFAULT-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 00005914 15--- !ELF16FileHeader:17 Class: ELFCLASS6418 Data: ELFDATA2LSB19 Type: ET_REL20Sections:21 - Name: .foo22 Type: SHT_PROGBITS23 Size: 0x824 - Name: .bar25 Type: SHT_PROGBITS26 Size: 0x1027## It is a no-op. We set it to reduce amount28## of differences with the second YAML below.29 AddressAlign: 0x030 31## The same as previous, but an arbitrary 'Offset' is set for the .bar section.32# RUN: yaml2obj --docnum=2 %s -o %t2 -DOFFSET=0x50 -DALIGN=0x033# RUN: llvm-readelf --sections %t2 | FileCheck %s --check-prefix=OFFSET34 35# OFFSET: [Nr] Name Type Address Off36# OFFSET: [ 1] .foo PROGBITS 0000000000000000 00004037# OFFSET-NEXT: [ 2] .bar PROGBITS 0000000000000000 00005038# OFFSET-NEXT: [ 3] .strtab STRTAB 0000000000000000 00006039# OFFSET-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 00006140 41--- !ELF42FileHeader:43 Class: ELFCLASS6444 Data: ELFDATA2LSB45 Type: ET_REL46Sections:47 - Name: .foo48 Type: SHT_PROGBITS49 Size: 0x850 - Name: .bar51 Type: SHT_PROGBITS52 Size: 0x1053 Offset: [[OFFSET]]54 AddressAlign: [[ALIGN]]55 56## Set the 'Offset' to the same value as was set by default to show57## that there is no difference in the output in this case.58# RUN: yaml2obj --docnum=2 %s -o %t3 -DOFFSET=0x48 -DALIGN=0x059# RUN: cmp %t1 %t360 61## Show that we can set an offset and an address alignment independently for a section.62# RUN: yaml2obj --docnum=2 %s -o %t4 -DOFFSET=0x48 -DALIGN=0x563# RUN: llvm-readelf --sections %t4 | FileCheck %s --check-prefix=OFFSET-AND-ALIGN64 65# OFFSET-AND-ALIGN: [Nr] Name Type Address Off Size ES Flg Lk Inf Al66# OFFSET-AND-ALIGN: [ 2] .bar PROGBITS 0000000000000000 000048 000010 00 0 0 567 68## Show we do not allow an 'Offset' to go backward.69# RUN: not yaml2obj --docnum=2 %s -DOFFSET=0x47 -DALIGN=0x0 2>&1 | \70# RUN: FileCheck %s --check-prefix=ERR-BACKWARD71 72# ERR-BACKWARD: error: the 'Offset' value (0x47) goes backward73 74## Show that the 'Offset' key can be used together with the 'ShOffset' key.75 76## Case 1: set the same value for 'Offset' and 'ShOffset' keys.77# RUN: yaml2obj --docnum=3 %s -o %t5 -DSHOFFSET=0x100 -DOFFSET=0x10078# RUN: llvm-readelf --headers --sections %t5 | FileCheck %s --check-prefix=BOTH-SAME79 80## The same offset as in the Case 3.81# BOTH-SAME: Start of section headers: 288 (bytes into file)82 83# BOTH-SAME: [Nr] Name Type Address Off84# BOTH-SAME: [ 1] .foo PROGBITS 0000000000000000 00010085# BOTH-SAME-NEXT: [ 2] .bar PROGBITS 0000000000000000 00010186# BOTH-SAME-NEXT: [ 3] .strtab STRTAB 0000000000000000 00010287 88## Case 2: set the 'Offset' value to be less than the 'ShOffset'.89 90# RUN: yaml2obj --docnum=3 %s -o %t6 -DSHOFFSET=0x100 -DOFFSET=0x9091# RUN: llvm-readelf --headers --sections %t6 | FileCheck %s --check-prefix=BOTH-A92 93## 176 < 288 (start of section headers in Case 1).94# BOTH-A: Start of section headers: 176 (bytes into file)95 96## Show that the 'Offset' field sets the physical offset in a file and the `ShOffset`97## field only overrides the sh_offset value of the .foo section.98# BOTH-A: [Nr] Name Type Address Off99# BOTH-A: [ 1] .foo PROGBITS 0000000000000000 000100100# BOTH-A-NEXT: [ 2] .bar PROGBITS 0000000000000000 000091101# BOTH-A-NEXT: [ 3] .strtab STRTAB 0000000000000000 000092102 103## Case 3: set the 'Offset' value to be greater than the 'ShOffset' value.104 105# RUN: yaml2obj --docnum=3 %s -o %t7 -DSHOFFSET=0x90 -DOFFSET=0x100106# RUN: llvm-readelf --sections --headers %t7 | FileCheck %s --check-prefix=BOTH-B107 108## The same offset as in Case 1.109# BOTH-B: Start of section headers: 288 (bytes into file)110 111## Show that the 'Offset' field sets the physical offset in file and `ShOffset`112## field only affects the sh_offset value of the .foo section (overrides it).113# BOTH-B: [Nr] Name Type Address Off114# BOTH-B: [ 1] .foo PROGBITS 0000000000000000 000090115# BOTH-B-NEXT: [ 2] .bar PROGBITS 0000000000000000 000101116# BOTH-B-NEXT: [ 3] .strtab STRTAB 0000000000000000 000102117 118--- !ELF119FileHeader:120 Class: ELFCLASS64121 Data: ELFDATA2LSB122 Type: ET_REL123Sections:124 - Name: .foo125 Type: SHT_PROGBITS126 Size: 0x1127 ShOffset: [[SHOFFSET]]128 Offset: [[OFFSET]]129 - Name: .bar130 Type: SHT_PROGBITS131 Size: 0x1132