brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · 16395cf Raw
209 lines · yaml
1## Show that yaml2obj properly emits program headers with explicit file size,2## memory size and offset parameters.3 4# RUN: yaml2obj --docnum=1 %s -o %t15# RUN: llvm-readobj %t1 --program-headers | FileCheck %s6 7# CHECK: ProgramHeaders [8# CHECK:    Offset: 0x12349# CHECK:    FileSize: 111110# CHECK:    MemSize: 999911 12# CHECK:    Offset: 0x200013# CHECK:    FileSize: 614# CHECK:    MemSize: 415 16# CHECK:    Offset: 0x200017# CHECK:    FileSize: 418# CHECK:    MemSize: 619 20# CHECK:    Offset: 0x1FFF21# CHECK:    FileSize: 522# CHECK:    MemSize: 523 24# CHECK:    Offset: 0xFFE25# CHECK:    FileSize: 726# CHECK:    MemSize: 927 28# CHECK:    Offset: 0x300029# CHECK:    FileSize: 330# CHECK:    MemSize: 231 32# CHECK:    Offset: 0x200433## Offset of .nobits2 (0x2009) - offset of .data (0x2004) == 0x5.34# CHECK:    FileSize: 535# CHECK:    MemSize: 636# CHECK: ]37 38--- !ELF39FileHeader:40  Class: ELFCLASS6441  Data:  ELFDATA2LSB42  Type:  ET_EXEC43Sections:44  - Name: .text45    Type: SHT_PROGBITS46    Size: 447    Offset: 0x100048    AddressAlign: 0x100049  - Name: .rodata50    Type: SHT_PROGBITS51    Size: 452    Offset: 0x200053    AddressAlign: 0x100054  - Name: .data55    Type: SHT_PROGBITS56    Offset: 0x200457    Size: 458  - Name: .nobits159    Type: SHT_NOBITS60    Offset: 0x200861    Size: 162  - Name: .nobits263    Type: SHT_NOBITS64    # Intentionally set to 0x2009 though the previous section is SHT_NOBITS.65    Offset: 0x200966    Size: 167ProgramHeaders:68  # Program header with no sections.69  - Type:     0x6abcdef0 # arbitrary type70    Offset:   0x123471    FileSize: 111172    MemSize:  999973  # Program header with only file size set.74  - Type:     0x6abcdef075    FileSize: 676    FirstSec: .rodata77    LastSec:  .rodata78  # Program header with only mem size set.79  - Type:     0x6abcdef080    MemSize:  681    FirstSec: .rodata82    LastSec:  .rodata83  # Program header with only offset set.84  - Type:     0x6abcdef085    Offset:   0x1fff86    FirstSec: .rodata87    LastSec:  .rodata88  # Program header with sections, valid properties.89  - Type:     0x6abcdef090    Offset:   0xffe91    FileSize: 792    MemSize:  993    FirstSec: .text94    LastSec:  .text95  # Program header with invalid properties.96  - Type:     0x6abcdef097    Offset:   0x300098    FileSize: 399    MemSize:  2100  # Program header with 2 SHT_NOBITS sections.101  - Type:     0x6abcdef0102    Offset:   0x2004103    FirstSec: .data104    LastSec:  .nobits2105 106## Test the "Offset" property.107 108## Check that by default the p_offset field of a segment is set to the109## offset of the section with the minimum offset.110# RUN: yaml2obj --docnum=2 %s -o %t2111# RUN: llvm-readelf %t2 --sections --program-headers | \112# RUN:   FileCheck %s --check-prefixes=DEFAULT-OFFSET113 114# DEFAULT-OFFSET:      [Nr] Name Type     Address          Off115# DEFAULT-OFFSET:      [ 1] .foo PROGBITS 0000000000001000 0000b0116# DEFAULT-OFFSET-NEXT: [ 2] .bar PROGBITS 0000000000001001 0000b1117 118# DEFAULT-OFFSET:       Type Offset119# DEFAULT-OFFSET-NEXT:  LOAD 0x0000b0120# DEFAULT-OFFSET-NEXT:  LOAD 0x0000b1121 122--- !ELF123FileHeader:124  Class: ELFCLASS64125  Data:  ELFDATA2LSB126  Type:  ET_EXEC127Sections:128  - Name:    .foo129    Type:    SHT_PROGBITS130    Flags:   [ SHF_ALLOC ]131    Size:    0x1132    Address: 0x1000133  - Name:  .bar134    Type:  SHT_PROGBITS135    Flags: [ SHF_ALLOC ]136    Size:  0x1137ProgramHeaders:138  - Type:     PT_LOAD139    FirstSec: .foo140    LastSec:  .bar141  - Type:     PT_LOAD142    FirstSec: .bar143    LastSec:  .bar144 145## Check we can set the "Offset" value explicitly to be less than or equal to146## the offset of a section in the segment.147# RUN: yaml2obj --docnum=3 -DOFFSET=0x77 %s -o %t3148# RUN: llvm-readelf %t3 --sections --program-headers | \149# RUN:   FileCheck %s --check-prefixes=VALID-OFFSET,VALID-OFFSET-LESS150# RUN: yaml2obj --docnum=3 -DOFFSET=0x78 %s -o %t4151# RUN: llvm-readelf %t4 --sections --program-headers | \152# RUN:   FileCheck %s --check-prefixes=VALID-OFFSET,VALID-OFFSET-EQ153 154# VALID-OFFSET: [Nr] Name Type     Address          Off155# VALID-OFFSET: [ 1] .foo PROGBITS 0000000000000000 000078156 157# VALID-OFFSET:      Type Offset158# VALID-OFFSET-EQ:   LOAD 0x000078159# VALID-OFFSET-LESS: LOAD 0x000077160 161--- !ELF162FileHeader:163  Class: ELFCLASS64164  Data:  ELFDATA2LSB165  Type:  ET_EXEC166Sections:167  - Name:  .foo168    Type:  SHT_PROGBITS169    Flags: [ SHF_ALLOC ]170    Size:  0x1171ProgramHeaders:172  - Type:    PT_LOAD173    Offset:  [[OFFSET]]174    FirstSec: .foo175    LastSec:  .foo176 177## Check we report an error when the "Offset" value is larger than the offset of a section in the segment.178# RUN: not yaml2obj --docnum=3 -DOFFSET=0x79 %s -o /dev/null 2>&1 | \179# RUN:   FileCheck %s --check-prefix=INVALID-OFFSET180 181# 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)182 183## Check "Offset" is used before the section offset is overriden using "ShOffset".184# RUN: yaml2obj --docnum=4 %s -o %t5185# RUN: llvm-readelf %t5 --sections --program-headers | FileCheck %s --check-prefix=SHOFFSET186 187# SHOFFSET: [Nr] Name Type     Address          Off188# SHOFFSET: [ 1] .foo PROGBITS 0000000000000000 ffffffff189 190# SHOFFSET:      Type Offset191# SHOFFSET-NEXT: LOAD 0x000078192 193--- !ELF194FileHeader:195  Class: ELFCLASS64196  Data:  ELFDATA2LSB197  Type:  ET_EXEC198Sections:199  - Name:     .foo200    Type:     SHT_PROGBITS201    Flags:    [ SHF_ALLOC ]202    Size:     0x1203    ShOffset: 0xFFFFFFFF204ProgramHeaders:205  - Type:     PT_LOAD206    Offset:   0x78207    FirstSec: .foo208    LastSec:  .foo209