brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.8 KiB · 47970a0 Raw
302 lines · yaml
1## Check how the "Offset" field is dumped by obj2yaml.2## For each section we calulate the expected offset.3## When it does not match the actual offset, we emit the "Offset" key.4 5# RUN: yaml2obj %s -o %t1.o6# RUN: obj2yaml %t1.o | FileCheck %s --check-prefix=BASIC7 8#   BASIC:      --- !ELF9#   BASIC-NEXT: FileHeader:10#   BASIC-NEXT:   Class: ELFCLASS6411#   BASIC-NEXT:   Data:  ELFDATA2LSB12#   BASIC-NEXT:   Type:  ET_REL13#   BASIC-NEXT: Sections:14#   BASIC-NEXT:   - Name:         .foo115#   BASIC-NEXT:     Type:         SHT_PROGBITS16#   BASIC-NEXT:     Content:      '00'17#   BASIC-NEXT:   - Name:         .foo218#   BASIC-NEXT:     Type:         SHT_PROGBITS19#   BASIC-NEXT:     Content:      '00'20#   BASIC-NEXT:   - Name:         .foo321#   BASIC-NEXT:     Type:         SHT_PROGBITS22#   BASIC-NEXT:     Content:      '00'23#   BASIC-NEXT:   - Name:         .bar124#   BASIC-NEXT:     Type:         SHT_PROGBITS25#   BASIC-NEXT:     Offset:       0x10026#   BASIC-NEXT:     Content:      '00'27#   BASIC-NEXT:   - Name:         .bar228#   BASIC-NEXT:     Type:         SHT_PROGBITS29#   BASIC-NEXT:     AddressAlign: 0x1030#   BASIC-NEXT:     Content:      '00'31#   BASIC-NEXT:   - Name:         .bar332#   BASIC-NEXT:     Type:         SHT_PROGBITS33#   BASIC-NEXT:     AddressAlign: 0x1034#   BASIC-NEXT:     Offset:       0x20035#   BASIC-NEXT:   - Name:         .bar436#   BASIC-NEXT:     Type:         SHT_PROGBITS37#   BASIC-NEXT:     AddressAlign: 0x10000000038#   BASIC-NEXT:     Offset:       0x21039# HEADERS-NEXT:   - Type: SectionHeaderTable40# HEADERS-NEXT:     Sections:41# HEADERS-NEXT:       - Name: .bar442# HEADERS-NEXT:       - Name: .bar343# HEADERS-NEXT:       - Name: .bar244# HEADERS-NEXT:       - Name: .bar145# HEADERS-NEXT:       - Name: .foo346# HEADERS-NEXT:       - Name: .foo247# HEADERS-NEXT:       - Name: .foo148# HEADERS-NEXT:       - Name: .strtab49# HEADERS-NEXT:       - Name: .shstrtab50# BASIC-NEXT: ...51 52--- !ELF53FileHeader:54  Class: ELFCLASS6455  Data:  ELFDATA2LSB56  Type:  ET_REL57Sections:58## The offset of .foo1 by default is 0x40, because it is placed right59## after the ELF header. In this case we don't dump the "Offset" key,60## because the file offset is naturally expected.61  - Name:         .foo162    Type:         SHT_PROGBITS63    Size:         164    Offset:       [[FIRSTOFF=<none>]]65    AddressAlign: [[FIRSTADDRALIGN=0]]66## Offset of .foo2 == offset of .foo1 + size of .foo1.67## We don't dump the "Offset" key in this case.68## sh_offset of .foo2 is 0x41.69  - Name: .foo270    Type: SHT_PROGBITS71    Size: 172## Offset of .foo3 == offset of .foo2 + size of .foo2,73## We don't dump the "Offset" key in this case.74## sh_offset of .foo3 is 0x42.75  - Name: .foo376    Type: SHT_PROGBITS77    Size: 178## Offset of .bar1 != offset of .foo3 + size of .foo3.79## We dump the "Offset" key in this case.80## sh_offset of .bar1 is 0x100.81  - Name:   .bar182    Type:   SHT_PROGBITS83    Offset: 0x10084    Size: 185## [Offset of .bar1 + size of .bar1] aligned by 0x10 is equal to the offset86## of .bar2. We don't dump the "Offset" key in this case.87## sh_offset of .bar2 is 0x110.88  - Name:         .bar289    Type:         SHT_PROGBITS90    AddressAlign: 0x1091    Offset:       0x11092    Size:         193## [Offset of .bar2 + size of .bar2] aligned by 0x10 is not equal to the offset94## of .bar3. We dump the "Offset" key in this case.95## sh_offset of .bar3 is 0x200.96  - Name:         .bar397    Type:         SHT_PROGBITS98    AddressAlign: 0x1099    Offset:       0x200100## A case where AddressAlign > MAX_UINT32 and (uint32_t)AddressAlign == 0.101## Check we dump an offset in this case properly.102  - Name:         .bar4103    Type:         SHT_PROGBITS104    AddressAlign: 0x100000000105    Offset:       0x210106  - Type: SectionHeaderTable107    Sections:108## By default we have the same order of sections as defined by the "Sections" key.109      - Name: [[SEC1=.foo1]]110      - Name: [[SEC2=.foo2]]111      - Name: [[SEC3=.foo3]]112      - Name: [[SEC4=.bar1]]113      - Name: [[SEC5=.bar2]]114      - Name: [[SEC6=.bar3]]115      - Name: [[SEC7=.bar4]]116      - Name: .strtab117      - Name: .shstrtab118 119## In this case we change the order of sections in the section header table.120## Check that we still dump offsets correctly.121 122# RUN: yaml2obj %s -DSEC1=.bar4 -DSEC2=.bar3 -DSEC3=.bar2 \123# RUN:   -DSEC4=.bar1 -DSEC5=.foo3 -DSEC6=.foo2 -DSEC7=.foo1 -o %t1-sechdr.o124# RUN: obj2yaml %t1-sechdr.o | FileCheck --check-prefixes=BASIC,HEADERS %s125 126## Show we dump the "Offset" key for the first section when127## it has an unexpected file offset.128 129# RUN: yaml2obj %s -DFIRSTOFF=0x40 -o %t2a.o130# RUN: obj2yaml %t2a.o | FileCheck %s --check-prefix=BASIC131# RUN: yaml2obj %s -DFIRSTOFF=0x41 -o %t2b.o132# RUN: obj2yaml %t2b.o | FileCheck %s --check-prefix=FIRSTSEC133 134# FIRSTSEC:      Sections:135# FIRSTSEC-NEXT:   - Name:    .foo1136# FIRSTSEC-NEXT:     Type:    SHT_PROGBITS137# FIRSTSEC-NEXT:     Offset:  0x41138# FIRSTSEC-NEXT:     Content: '00'139 140## Test that we take the alignment of the first section into account141## when calculating the expected offset for it. In this case we don't142## dump the "Offset", because it is expected.143 144# RUN: yaml2obj %s -DFIRSTOFF=0x80 -DFIRSTADDRALIGN=0x80 -o %t3.o145# RUN: obj2yaml %t3.o | FileCheck %s --check-prefix=FIRSTSECALIGN146 147# FIRSTSECALIGN:      - Name:         .foo1148# FIRSTSECALIGN-NEXT:   Type:         SHT_PROGBITS149# FIRSTSECALIGN-NEXT:   AddressAlign: 0x80150# FIRSTSECALIGN-NEXT:   Content:      '00'151# FIRSTSECALIGN-NEXT: - Name:152 153## Test that we take the program headers offset and size into account when calculating154## the expected file offset of the first section.155 156# RUN: yaml2obj %s --docnum=2 -o %t4a.o157# RUN: obj2yaml %t4a.o | FileCheck %s --check-prefix=FIRSTSECPHDRS158## The expected file offset of the first section is:159## 0x40 (start of program headers) + 0x38 (size of program headers) * 2(number of program headers) = 0xB0160# RUN: yaml2obj %s --docnum=2 -DFIRSTOFF=0xB0 -o %t4b.o161# RUN: obj2yaml %t4b.o | FileCheck %s --check-prefix=FIRSTSECPHDRS162# RUN: yaml2obj %s --docnum=2 -DFIRSTOFF=0xB1 -o %t4c.o163# RUN: obj2yaml %t4c.o | FileCheck %s --check-prefixes=FIRSTSECPHDRS,FIRSTSECPHDRSOFFSET164 165#       FIRSTSECPHDRS:      Sections:166#       FIRSTSECPHDRS-NEXT:   - Name:   .foo167#       FIRSTSECPHDRS-NEXT:     Type:   SHT_PROGBITS168# FIRSTSECPHDRSOFFSET-NEXT:     Offset: 0xB1169#       FIRSTSECPHDRS-NEXT:   ...170 171--- !ELF172FileHeader:173  Class: ELFCLASS64174  Data:  ELFDATA2LSB175  Type:  ET_REL176Sections:177  - Name:   .foo178    Type:   SHT_PROGBITS179    Offset: [[FIRSTOFF=<none>]]180ProgramHeaders:181  - Type: PT_LOAD182  - Type: PT_LOAD183 184## Test that when there are no program headers in the file, we don't take SHT_NOBITS185## section sizes into account, but respect their alignment when calculating the expected186## section offsets.187 188# RUN: yaml2obj %s --docnum=3 -o %t5.o189# RUN: obj2yaml %t5.o | FileCheck %s --check-prefix=NOBITS190 191# NOBITS:      Sections:192# NOBITS-NEXT:   - Name:         .progbits1193# NOBITS-NEXT:     Type:         SHT_PROGBITS194# NOBITS-NEXT:     Content:      '00'195# NOBITS-NEXT:   - Name:         .nobits1196# NOBITS-NEXT:     Type:         SHT_NOBITS197# NOBITS-NEXT:     Size:         0x10198# NOBITS-NEXT:   - Name:         .progbits2199# NOBITS-NEXT:     Type:         SHT_PROGBITS200# NOBITS-NEXT:     Content:      '0000'201# NOBITS-NEXT:   - Name:         .nobits2202# NOBITS-NEXT:     Type:         SHT_NOBITS203# NOBITS-NEXT:     AddressAlign: 0x100204# NOBITS-NEXT:     Size:         0x100205# NOBITS-NEXT:   - Name:         .progbits3206# NOBITS-NEXT:     Type:         SHT_PROGBITS207# NOBITS-NEXT:     Content:      '000000'208# NOBITS-NEXT: ...209 210--- !ELF211FileHeader:212  Class: ELFCLASS64213  Data:  ELFDATA2LSB214  Type:  ET_REL215Sections:216## sh_offset == 0x40.217  - Name: .progbits1218    Type: SHT_PROGBITS219    Size: 0x1220## sh_offset == 0x41.221  - Name: .nobits1222    Type: SHT_NOBITS223    Size: 0x10224## sh_offset == 0x41.225  - Name: .progbits2226    Type: SHT_PROGBITS227    Size: 0x2228## sh_offset == 0x100.229  - Name:         .nobits2230    Type:         SHT_NOBITS231    Size:         0x100232    AddressAlign: 0x100233## sh_offset == 0x100.234  - Name: .progbits3235    Type: SHT_PROGBITS236    Size: 0x3237 238## Check that we might take sizes of SHT_NOBITS sections into account when calculating239## the expected offsets when there are program headers in the file. The rule is the following:240## we assume that the file space is allocated for the SHT_NOBITS section when there are241## other non-nobits sections in the same segment that follows it.242 243# RUN: yaml2obj %s --docnum=4 -o %t6.o244# RUN: obj2yaml %t6.o | FileCheck %s --check-prefix=NOBITS-PHDRS245 246# NOBITS-PHDRS:      Sections:247# NOBITS-PHDRS-NEXT:   - Name:    .nobits1248# NOBITS-PHDRS-NEXT:     Type:    SHT_NOBITS249# NOBITS-PHDRS-NEXT:     Size:    0x1250# NOBITS-PHDRS-NEXT:   - Name:    .progbits251# NOBITS-PHDRS-NEXT:     Type:    SHT_PROGBITS252# NOBITS-PHDRS-NEXT:     Content: '0000'253# NOBITS-PHDRS-NEXT:   - Name:    .nobits3254# NOBITS-PHDRS-NEXT:     Type:    SHT_NOBITS255# NOBITS-PHDRS-NEXT:     Size:    0x100256# NOBITS-PHDRS-NEXT:   - Name:    .nobits4257# NOBITS-PHDRS-NEXT:     Type:    SHT_NOBITS258# NOBITS-PHDRS-NEXT:     Size:    0x200259# NOBITS-PHDRS-NEXT:   - Name:    .nobits5260# NOBITS-PHDRS-NEXT:     Type:    SHT_NOBITS261# NOBITS-PHDRS-NEXT:     Offset:  0x100262# NOBITS-PHDRS-NEXT:     Size:    0x300263# NOBITS-PHDRS-NEXT: ...264 265--- !ELF266FileHeader:267  Class: ELFCLASS64268  Data:  ELFDATA2LSB269  Type:  ET_REL270Sections:271## sh_offset == 0xe8.272  - Name: .nobits1273    Type: SHT_NOBITS274    Size: 0x1275## sh_offset == 0xe9.276  - Name: .progbits277    Type: SHT_PROGBITS278    Size: 0x2279## sh_offset == 0xeb.280  - Name: .nobits3281    Type: SHT_NOBITS282    Size: 0x100283## sh_offset == 0xeb.284  - Name: .nobits4285    Type: SHT_NOBITS286    Size: 0x200287## sh_offset == 0x100.288  - Name:   .nobits5289    Type:   SHT_NOBITS290    Size:   0x300291    Offset: 0x100292ProgramHeaders:293  - Type:     PT_LOAD294    FirstSec: .nobits1295    LastSec:  .progbits296  - Type:     PT_LOAD297    FirstSec: .nobits3298    LastSec:  .nobits4299  - Type:     PT_LOAD300    FirstSec: .nobits5301    LastSec:  .nobits5302