brintos

brintos / llvm-project-archived public Read only

0
0
Text · 22.4 KiB · ef66b35 Raw
707 lines · yaml
1## Show that obj2yaml is able to dump program headers.2 3## Part I. Base check. All simple cases that look OK as a part of a single large test live here.4 5# RUN: yaml2obj %s -o %t16 7## Show the layout of the object before we dump it using obj2yaml.8## The check is here to make it clear what the layout should look like.9# RUN: llvm-readelf --segments %t1 | FileCheck %s --check-prefix=SEGMENT-MAPPING10 11# SEGMENT-MAPPING:      Program Headers:12# SEGMENT-MAPPING-NEXT:   Type      Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align13# SEGMENT-MAPPING-NEXT:   LOAD      0x000000 0x0000000000000000 0x0000000000000000 0x000281 0x000281 R   0x100014# SEGMENT-MAPPING-NEXT:   LOAD      0x000281 0x0000000000001000 0x0000000000001000 0x000010 0x000010 R E 0x100015# SEGMENT-MAPPING-NEXT:   LOAD      0x000291 0x0000000000002000 0x0000000000002000 0x000009 0x000009 R   0x100016# SEGMENT-MAPPING-NEXT:   LOAD      0x00029a 0x0000000000003ef0 0x0000000000003ef0 0x000011 0x000011 RW  0x100017# SEGMENT-MAPPING-NEXT:   DYNAMIC   0x00029a 0x0000000000003ef0 0x0000000000003ef0 0x000010 0x000010 RW  0x818# SEGMENT-MAPPING-NEXT:   GNU_RELRO 0x00029a 0x0000000000003ef0 0x0000000000003ef0 0x000010 0x000010 R   0x119# SEGMENT-MAPPING-NEXT:   LOAD      0x000000 0x0000000000004000 0x0000000000004000 0x000000 0x000000 R   0x120# SEGMENT-MAPPING-NEXT:   LOAD      0x000248 0x00000000000001a0 0x00000000000001a0 0x000020 0x000020 R   0x121# SEGMENT-MAPPING-NEXT:   LOAD      0x000248 0x00000000000001a0 0x00000000000001a0 0x000020 0x000020 R   0x122# SEGMENT-MAPPING:      Section to Segment mapping:23# SEGMENT-MAPPING-NEXT:  Segment Sections...24# SEGMENT-MAPPING-NEXT:   00     .hash .gnu.hash .dynsym .dynstr {{$}}25# SEGMENT-MAPPING-NEXT:   01     .foo .zed {{$}}26# SEGMENT-MAPPING-NEXT:   02     .foo .baz {{$}}27# SEGMENT-MAPPING-NEXT:   03     .dynamic .dynamic.tail {{$}}28# SEGMENT-MAPPING-NEXT:   04     .dynamic {{$}}29# SEGMENT-MAPPING-NEXT:   05     .dynamic {{$}}30# SEGMENT-MAPPING-NEXT:   06{{ *$}}31# SEGMENT-MAPPING-NEXT:   07     .gnu.hash {{$}}32# SEGMENT-MAPPING-NEXT:   08     .gnu.hash {{$}}33# SEGMENT-MAPPING-NEXT:   None   .symtab .strtab .shstrtab {{$}}34 35## Check that obj2yaml produced a correct program headers description.36 37# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=YAML38 39# YAML:      ProgramHeaders:40# YAML-NEXT:  - Type:     PT_LOAD41# YAML-NEXT:    Flags:    [ PF_R ]42# YAML-NEXT:    FirstSec: .hash43# YAML-NEXT:    LastSec:  .dynstr44# YAML-NEXT:    Align:    0x100045# YAML-NEXT:    Offset:   0x046# YAML-NEXT:  - Type:     PT_LOAD47# YAML-NEXT:    Flags:    [ PF_X, PF_R ]48# YAML-NEXT:    FirstSec: .foo49# YAML-NEXT:    LastSec:  .zed50# YAML-NEXT:    VAddr:    0x100051# YAML-NEXT:    Align:    0x100052# YAML-NEXT:    Offset:   0x28153# YAML-NEXT:  - Type:     PT_LOAD54# YAML-NEXT:    Flags:    [ PF_R ]55# YAML-NEXT:    FirstSec: '.foo (1)'56# YAML-NEXT:    LastSec:  .baz57# YAML-NEXT:    VAddr:    0x200058# YAML-NEXT:    Align:    0x100059# YAML-NEXT:    Offset:   0x29160# YAML-NEXT:  - Type:     PT_LOAD61# YAML-NEXT:    Flags:    [ PF_W, PF_R ]62# YAML-NEXT:    FirstSec: .dynamic63# YAML-NEXT:    LastSec:  .dynamic.tail64# YAML-NEXT:    VAddr:    0x3EF065# YAML-NEXT:    Align:    0x100066# YAML-NEXT:    Offset:   0x29A67# YAML-NEXT:  - Type:     PT_DYNAMIC68# YAML-NEXT:    Flags:    [ PF_W, PF_R ]69# YAML-NEXT:    FirstSec: .dynamic70# YAML-NEXT:    LastSec:  .dynamic71# YAML-NEXT:    VAddr:    0x3EF072# YAML-NEXT:    Align:    0x873# YAML-NEXT:    Offset:   0x29A74# YAML-NEXT:  - Type:     PT_GNU_RELRO75# YAML-NEXT:    Flags:    [ PF_R ]76# YAML-NEXT:    FirstSec: .dynamic77# YAML-NEXT:    LastSec:  .dynamic78# YAML-NEXT:    VAddr:    0x3EF079# YAML-NEXT:    Offset:   0x29A80# YAML-NEXT:  - Type:  PT_LOAD81# YAML-NEXT:    Flags: [ PF_R ]82# YAML-NEXT:    VAddr: 0x400083# YAML-NEXT:    Offset:   0x084# YAML-NEXT:  - Type:     PT_LOAD85# YAML-NEXT:    Flags:    [ PF_R ]86# YAML-NEXT:    FirstSec: .gnu.hash87# YAML-NEXT:    LastSec:  .gnu.hash88# YAML-NEXT:    VAddr:    0x1A089# YAML-NEXT:    Offset:   0x24890# YAML-NEXT:  - Type:     PT_LOAD91# YAML-NEXT:    Flags:    [ PF_R ]92# YAML-NEXT:    FirstSec: .gnu.hash93# YAML-NEXT:    LastSec:  .gnu.hash94# YAML-NEXT:    VAddr:    0x1A095# YAML-NEXT:    Offset:   0x24896# YAML-NEXT: Sections:97 98--- !ELF99FileHeader:100  Class: ELFCLASS64101  Data:  ELFDATA2LSB102  Type:  ET_DYN103ProgramHeaders:104## Check we can create a PT_LOAD with arbitrary (we used .hash, .gnu.hash)105## and implicit sections (we use .dynsym, .dynstr). It also checks that the106## SHT_NULL section at index 0 is not included in the segment.107  - Type:     PT_LOAD108    Flags:    [ PF_R ]109    FirstSec: .hash110    LastSec:  .dynstr111    Align:  0x1000112    Offset: 0x0113## Check we can create a PT_LOAD with a different set of properties and sections.114  - Type:     PT_LOAD115    Flags:    [ PF_X, PF_R ]116    FirstSec: .foo117    LastSec:  .zed118    VAddr:    0x1000119    Align:    0x1000120## Create a PT_LOAD to demonstate we are able to refer to output sections with the same name.121  - Type:     PT_LOAD122    Flags:    [ PF_R ]123    FirstSec: '.foo (1)'124    LastSec:  .baz125    VAddr:    0x2000126    Align:    0x1000127## Show we can create a writeable PT_LOAD segment and put an arbitrary section into it.128## Here we test both regular (SHT_PROGBITS) and a special section (SHT_DYNAMIC).129  - Type:     PT_LOAD130    Flags:    [ PF_W, PF_R ]131    FirstSec: .dynamic132    LastSec:  .dynamic.tail133    VAddr:    0x3EF0134    Align:    0x1000135## Show we can create a nested dynamic segment and put a section into it.136  - Type:     PT_DYNAMIC137    Flags:    [ PF_W, PF_R ]138    FirstSec: .dynamic139    LastSec:  .dynamic140    VAddr:    0x3EF0141    Align:    0x8142## Show we can create a relro segment and put a section into it.143## We used .dynamic here and in tests above to demonstrate that144## we can place a section in any number of segments.145## Also, we explicitly set the "Align" property to 1 to demonstate146## that we do not dump it, because it is the default alignment147## value set by yaml2obj.148  - Type:     PT_GNU_RELRO149    Flags:    [ PF_R ]150    FirstSec: .dynamic151    LastSec:  .dynamic152    VAddr:    0x3EF0153    Align:    0x1154## Show we can dump a standalone empty segment.155  - Type:  PT_LOAD156    Flags: [ PF_R ]157    VAddr: 0x4000158    Align: 0x1159## ELF specification says that loadable segment entries in the160## program header are sorted by virtual address.161## Show we can dump an out of order segment.162  - Type:     PT_LOAD163    Flags:    [ PF_R ]164    FirstSec: .gnu.hash165    LastSec:  .gnu.hash166    VAddr:    0x1A0167    Align:    0x1168## Test we are able to dump duplicated segments.169## We use a segment that is the same as the previous one for this.170  - Type:     PT_LOAD171    Flags:    [ PF_R ]172    FirstSec: .gnu.hash173    LastSec:  .gnu.hash174    VAddr:    0x1A0175    Align:    0x1176Sections:177  - Name:    .hash178    Type:    SHT_PROGBITS179    Flags:   [ SHF_ALLOC ]180    Address: 0x190181    Size:    0x10182  - Name:    .gnu.hash183    Type:    SHT_PROGBITS184    Flags:   [ SHF_ALLOC ]185    Address: 0x1A0186    Size:    0x20187  - Name:    .dynsym188    Type:    SHT_DYNSYM189    Flags:   [ SHF_ALLOC ]190    Address: 0x1C0191    Link:    .dynstr192    EntSize: 0x18193  - Name:    .dynstr194    Type:    SHT_STRTAB195    Flags:   [ SHF_ALLOC ]196    Address: 0x1D8197  - Name:    .foo198    Type:    SHT_PROGBITS199    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]200    Address: 0x1000201    Size:    0x8202  - Name:    .zed203    Type:    SHT_PROGBITS204    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]205    Address: 0x1008206    Size:    0x8207  - Name:    '.foo (1)'208    Type:    SHT_PROGBITS209    Flags:   [ SHF_ALLOC ]210    Address: 0x2000211    Size:    0x8212  - Name:    .baz213    Type:    SHT_PROGBITS214    Flags:   [ SHF_ALLOC ]215    Address: 0x2008216    Size:    0x1217  - Name:    .dynamic218    Type:    SHT_DYNAMIC219    Flags:   [ SHF_WRITE, SHF_ALLOC ]220    Address: 0x0000000000003EF0221    Link:    .dynstr222    Entries:223      - Tag:   DT_NULL224        Value: 0x0225  - Name:    .dynamic.tail226    Type:    SHT_PROGBITS227    Flags:   [ SHF_WRITE, SHF_ALLOC ]228    Content: "FE"229Symbols: []230DynamicSymbols: []231 232## Part II. More specific tests.233 234## Check we are able to dump segments that are empty or235## contain empty sections.236# RUN: yaml2obj --docnum=2 %s -o %t2237# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=EMPTY238 239# EMPTY:      - Type:     PT_LOAD240# EMPTY-NEXT:   Flags:    [ PF_W, PF_R ]241# EMPTY-NEXT:   FirstSec: .empty.tls.start242# EMPTY-NEXT:   LastSec:  .empty.tls.end243# EMPTY-NEXT:   VAddr:    0x1000244# EMPTY-NEXT:   Align:    0x1000245# EMPTY-NEXT:   Offset:   0x120246# EMPTY-NEXT: - Type:     PT_TLS247# EMPTY-NEXT:   Flags:    [ PF_W, PF_R ]248# EMPTY-NEXT:   FirstSec: .empty.tls.start249# EMPTY-NEXT:   LastSec:  .empty.tls.start250# EMPTY-NEXT:   VAddr:    0x1000251# EMPTY-NEXT:   Offset:   0x120252# EMPTY-NEXT: - Type:     PT_TLS253# EMPTY-NEXT:   Flags:    [ PF_W, PF_R ]254# EMPTY-NEXT:   FirstSec: .empty.tls.middle255# EMPTY-NEXT:   LastSec:  .empty.tls.middle256# EMPTY-NEXT:   VAddr:    0x1100257# EMPTY-NEXT:   Offset:   0x220258# EMPTY-NEXT: - Type:     PT_TLS259# EMPTY-NEXT:   Flags:    [ PF_W, PF_R ]260# EMPTY-NEXT:   FirstSec: .empty.tls.end261# EMPTY-NEXT:   LastSec:  .empty.tls.end262# EMPTY-NEXT:   VAddr:    0x1200263# EMPTY-NEXT:   Offset:   0x320264# EMPTY-NEXT: Sections:265 266--- !ELF267FileHeader:268  Class: ELFCLASS64269  Data:  ELFDATA2LSB270  Type:  ET_DYN271ProgramHeaders:272  - Type:     PT_LOAD273    Flags:    [ PF_W, PF_R ]274    FirstSec: .empty.tls.start275    LastSec:  .empty.tls.end276    VAddr:    0x1000277    Align:    0x1000278  - Type:     PT_TLS279    Flags:    [ PF_W, PF_R ]280    FirstSec: .empty.tls.start281    LastSec:  .empty.tls.start282    VAddr:    0x1000283    Align:    0x1284  - Type:     PT_TLS285    Flags:    [ PF_W, PF_R ]286    FirstSec: .empty.tls.middle287    LastSec:  .empty.tls.middle288    VAddr:    0x1100289    Align:    0x1290  - Type:     PT_TLS291    Flags:    [ PF_W, PF_R ]292    FirstSec: .empty.tls.end293    LastSec:  .empty.tls.end294    VAddr:    0x1200295    Align:    0x1296Sections:297  - Name:    .empty.tls.start298    Type:    SHT_PROGBITS299    Flags:   [ SHF_ALLOC, SHF_TLS ]300    Size:    0x0301    Address: 0x1000302  - Name:  .section.1303    Type:  SHT_PROGBITS304    Flags: [ SHF_ALLOC ]305    Size:  0x100306  - Name:  .empty.tls.middle307    Type:  SHT_PROGBITS308    Flags: [ SHF_ALLOC, SHF_TLS ]309    Size:  0x0310  - Name:  .section.2311    Type:  SHT_PROGBITS312    Flags: [ SHF_ALLOC ]313    Size:  0x100314  - Name:  .empty.tls.end315    Type:  SHT_PROGBITS316    Flags: [ SHF_ALLOC, SHF_TLS ]317    Size:  0x0318 319## Document we are able to dump misaligned segments.320## I.e. segments where (p_offset % p_align) != (p_vaddr % p_align).321# RUN: yaml2obj --docnum=3 %s -o %t3322# RUN: llvm-readelf --segments --sections %t3 | FileCheck %s --check-prefix=MISALIGNED-READELF323# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=MISALIGNED-YAML324 325## As a misaligned p_offset value we use (`.foo` section offset - 1).326# MISALIGNED-READELF:      [Nr] Name Type     Address          Off327# MISALIGNED-READELF:      [ 1] .foo PROGBITS 0000000000001000 000078328# MISALIGNED-READELF:      Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align329# MISALIGNED-READELF-NEXT: LOAD 0x000077 0x0000000000001000 0x0000000000001000 0x000078 0x000078 R   0x1000330 331# MISALIGNED-YAML:      ProgramHeaders:332# MISALIGNED-YAML-NEXT:  - Type:     PT_LOAD333# MISALIGNED-YAML-NEXT:    Flags:    [ PF_R ]334# MISALIGNED-YAML-NEXT:    FirstSec: .foo335# MISALIGNED-YAML-NEXT:    LastSec:  .foo336# MISALIGNED-YAML-NEXT:    VAddr:    0x1000337# MISALIGNED-YAML-NEXT:    Align:    0x1000338# MISALIGNED-YAML-NEXT:    Offset:   0x77339# MISALIGNED-YAML-NEXT: Sections:340 341--- !ELF342FileHeader:343  Class: ELFCLASS64344  Data:  ELFDATA2LSB345  Type:  ET_DYN346ProgramHeaders:347  - Type:     PT_LOAD348    Flags:    [ PF_R ]349    FirstSec: .foo350    LastSec:  .foo351    VAddr:    0x1000352    Align:    0x1000353    Offset:   0x000077354Sections:355  - Name:    .foo356    Type:    SHT_PROGBITS357    Flags:   [ SHF_ALLOC ]358    Size:    0x77359    Address: 0x1000360 361## Test we include non-allocatable sections in segments.362## We also document that SHT_NULL sections are not considered to be inside a segment.363# RUN: yaml2obj --docnum=4 %s -o %t4364# RUN: obj2yaml %t4 | FileCheck %s --check-prefix=NON-ALLOC365 366# NON-ALLOC:      ProgramHeaders:367# NON-ALLOC-NEXT: - Type:     PT_LOAD368# NON-ALLOC-NEXT:   Flags:    [ PF_R ]369# NON-ALLOC-NEXT:   FirstSec: .alloc.1370# NON-ALLOC-NEXT:   LastSec:  .non-alloc.1371# NON-ALLOC-NEXT:   Offset:   0x120372# NON-ALLOC-NEXT: - Type:     PT_LOAD373# NON-ALLOC-NEXT:   Flags:    [ PF_R ]374# NON-ALLOC-NEXT:   FirstSec: .alloc.1375# NON-ALLOC-NEXT:   LastSec:  .non-alloc.1376# NON-ALLOC-NEXT:   Offset:   0x120377# NON-ALLOC-NEXT: - Type:     PT_LOAD378# NON-ALLOC-NEXT:   Flags:    [ PF_R ]379# NON-ALLOC-NEXT:   FirstSec: .alloc.2380# NON-ALLOC-NEXT:   LastSec:  .alloc.2381# NON-ALLOC-NEXT:   Offset:   0x230382# NON-ALLOC-NEXT: - Type:     PT_LOAD383# NON-ALLOC-NEXT:   Flags:    [ PF_R ]384# NON-ALLOC-NEXT:   FirstSec: .alloc.1385# NON-ALLOC-NEXT:   LastSec:  .alloc.2386# NON-ALLOC-NEXT:   Offset:   0x120387# NON-ALLOC-NEXT: Sections:388 389--- !ELF390FileHeader:391  Class: ELFCLASS64392  Data:  ELFDATA2LSB393  Type:  ET_DYN394ProgramHeaders:395  - Type:     PT_LOAD396    Flags:    [ PF_R ]397    FirstSec: .alloc.1398    LastSec:  .non-alloc.1399  - Type:     PT_LOAD400    Flags:    [ PF_R ]401    FirstSec: .alloc.1402    LastSec:  .non-alloc.2403  - Type:     PT_LOAD404    Flags:    [ PF_R ]405    FirstSec: .non-alloc.2406    LastSec:  .alloc.2407  - Type:     PT_LOAD408    Flags:    [ PF_R ]409    FirstSec: .alloc.1410    LastSec:  .alloc.2411Sections:412  - Name:    .alloc.1413    Type:    SHT_PROGBITS414    Flags:   [ SHF_ALLOC ]415    Size:    0x100416    Address: 0x1000417  - Name:    .non-alloc.1418    Type:    SHT_PROGBITS419    Flags:   [ ]420    Size:    0x10421  - Name:    .non-alloc.2422    Type:    SHT_NULL423    Flags:   [ ]424    Size:    0x10425  - Name:    .alloc.2426    Type:    SHT_PROGBITS427    Flags:   [ SHF_ALLOC ]428    Size:    0x1429 430## Check how we dump segments which contain SHT_NOBITS sections.431# RUN: yaml2obj --docnum=5 %s -o %t5432# RUN: obj2yaml %t5 | FileCheck %s --check-prefix=NOBITS433 434# NOBITS:      ProgramHeaders:435# NOBITS-NEXT:   - Type:     PT_LOAD436# NOBITS-NEXT:     Flags:    [ PF_W, PF_R ]437# NOBITS-NEXT:     FirstSec: .bss438# NOBITS-NEXT:     LastSec:  .bss439# NOBITS-NEXT:     VAddr:    0x1001440# NOBITS-NEXT:     Offset:   0x191441# NOBITS-NEXT:   - Type:     PT_LOAD442# NOBITS-NEXT:     Flags:    [ PF_W, PF_R ]443# NOBITS-NEXT:     FirstSec: .data.1444# NOBITS-NEXT:     LastSec:  .bss445# NOBITS-NEXT:     VAddr:    0x1000446# NOBITS-NEXT:     Offset:   0x190447# NOBITS-NEXT:   - Type:     PT_LOAD448# NOBITS-NEXT:     Flags:    [ PF_W, PF_R ]449# NOBITS-NEXT:     FirstSec: .data.1450# NOBITS-NEXT:     LastSec:  .data.2451# NOBITS-NEXT:     VAddr:    0x1000452# NOBITS-NEXT:     Offset:   0x190453# NOBITS-NEXT:   - Type:     PT_LOAD454# NOBITS-NEXT:     Flags:    [ PF_W, PF_R ]455# NOBITS-NEXT:     FirstSec: .bss456# NOBITS-NEXT:     LastSec:  .data.2457# NOBITS-NEXT:     VAddr:    0x1001458# NOBITS-NEXT:     Offset:   0x191459# NOBITS-NEXT:   - Type:     PT_LOAD460# NOBITS-NEXT:     Flags:    [ PF_W, PF_R ]461# NOBITS-NEXT:     FirstSec: .foo.bss462# NOBITS-NEXT:     LastSec:  .bar.bss463# NOBITS-NEXT:     VAddr:    0x200000000464# NOBITS-NEXT:     Offset:   0x193465# NOBITS-NEXT:   - Type:     PT_LOAD466# NOBITS-NEXT:     Flags:    [ PF_W, PF_R ]467# NOBITS-NEXT:     FirstSec: .data.3468# NOBITS-NEXT:     LastSec:  .bss.large469# NOBITS-NEXT:     VAddr:    0x200000030470# NOBITS-NEXT:     Offset:   0x193471# NOBITS-NEXT: Sections:472 473--- !ELF474FileHeader:475  Class: ELFCLASS64476  Data:  ELFDATA2LSB477  Type:  ET_EXEC478ProgramHeaders:479## Case 1: the segment contains a single SHT_NOBITS section.480  - Type:     PT_LOAD481    Flags:    [ PF_W, PF_R ]482    FirstSec: .bss483    LastSec:  .bss484    VAddr:    0x1001485## Case 2: the SHT_NOBITS section is the last section in the segment.486  - Type:     PT_LOAD487    Flags:    [ PF_W, PF_R ]488    FirstSec: .data.1489    LastSec:  .bss490    VAddr:    0x1000491## Case 3: the SHT_NOBITS section is in the middle of the segment.492  - Type:     PT_LOAD493    Flags:    [ PF_W, PF_R ]494    FirstSec: .data.1495    LastSec:  .data.2496    VAddr:    0x1000497## Case 4: the SHT_NOBITS section is the first section in the segment.498  - Type:     PT_LOAD499    Flags:    [ PF_W, PF_R ]500    FirstSec: .bss501    LastSec:  .data.2502    VAddr:    0x1001503## Case 5: another two SHT_NOBITS sections in a different segment.504  - Type:     PT_LOAD505    Flags:    [ PF_W, PF_R ]506    FirstSec: .foo.bss507    LastSec:  .bar.bss508    VAddr:    0x200000000509## Case 6: a SHT_NOBITS section following a normal section, where the SHT_NOBITS size points past the end of the program header.510  - Type:     PT_LOAD511    Flags:    [ PF_W, PF_R ]512    FirstSec: .data.3513    LastSec:  .bss.large514    VAddr:    0x200000030515Sections:516  - Name:    .data.1517    Type:    SHT_PROGBITS518    Flags:   [ SHF_WRITE, SHF_ALLOC ]519## Use an arbitrary address and size.520    Address: 0x1000521    Size:    0x1522  - Name:   .bss523    Type:   SHT_NOBITS524    Flags:  [ SHF_WRITE, SHF_ALLOC ]525## Use an arbitrary non-zero size.526    Size:   0x1527  - Name:     .data.2528    Type:     SHT_PROGBITS529    Flags:    [ SHF_WRITE, SHF_ALLOC ]530## Use an arbitrary size.531    Size:     0x1532  - Name:    .foo.bss533    Type:    SHT_NOBITS534    Flags:   [ SHF_WRITE, SHF_ALLOC ]535## Set an arbitrary address and size so that this section can be used536## to start a different non-overlapping segment.537## I.e. its address is larger than addresses of previous sections.538    Size:    0x10539    Address: 0x200000000540  - Name:    .bar.bss541    Type:    SHT_NOBITS542    Flags:   [ SHF_WRITE, SHF_ALLOC ]543## Use an arbitrary size that is different to the size of544## the previous section.545    Size:    0x20546  - Name: .data.3547    Type: SHT_PROGBITS548    Flags: [ SHF_WRITE, SHF_ALLOC ]549## Use an abitrary size. Also use an address that is larger than the previous550## section, because the tools expect segment addresses to be in order.551    Size: 0x1552    Address: 0x200000030553  - Name: .bss.large554    Type: SHT_NOBITS555    Flags: [ SHF_WRITE, SHF_ALLOC ]556## Use a size that is larger than the file size.557    Size: 0x00000000FFFFFFFF558    Address: 0x200000031559 560## Check that we require sections in a program header561## declaration to be sorted by their offsets.562# RUN: not yaml2obj --docnum=6 %s -o %t6 2>&1 | \563# RUN:   FileCheck %s --check-prefix=UNSORTED --implicit-check-not="error:"564 565# UNSORTED:      error: program header with index 0: the section index of .bar is greater than the index of .foo566 567--- !ELF568FileHeader:569  Class: ELFCLASS64570  Data:  ELFDATA2LSB571  Type:  ET_DYN572ProgramHeaders:573## Case 1: the .bar section is placed after the .foo section in the file.574##         Check we report an error about the violation of the order.575  - Type:     PT_LOAD576    Flags:    [ PF_R ]577    FirstSec: .bar578    LastSec:  .foo579    VAddr:    0x1000580## There is nothing wrong with this segment. We have it to show that581## we report correct program header indices in error messages.582  - Type:     PT_LOAD583    Flags:    [ PF_R ]584    FirstSec: .foo585    LastSec:  .bar586    VAddr:    0x1000587Sections:588  - Name:    .foo589    Type:    SHT_PROGBITS590    Flags:   [ SHF_ALLOC ]591    Size:    0x1592    Address: 0x1000593  - Name:    .bar594    Type:    SHT_PROGBITS595    Flags:   [ SHF_ALLOC ]596    Size:    0x1597 598## Check how we dump segments which contain empty sections.599# RUN: yaml2obj --docnum=7 %s -o %t7600 601## Show the layout of the object before we dump it using obj2yaml.602## Notes: 1) '.empty.foo', '.empty.bar1' and '.bar' have the same file offset, but '.empty.foo'603##           has a VA that is outside of the segment, hence we should not include it in it.604##        2) '.bar1' ends at 0x79, which is the starting file offset of both '.empty.bar2'605##           and '.empty.zed'. We should only include '.empty.bar2', because the VA of the606##           '.empty.zed' section is outside the segment's virtual space.607# RUN: llvm-readelf -S %t7 | FileCheck %s --check-prefix=ZERO-SIZE-MAPPING608 609# ZERO-SIZE-MAPPING:      Section Headers:610# ZERO-SIZE-MAPPING-NEXT:   [Nr] Name        Type     Address          Off    Size611# ZERO-SIZE-MAPPING:        [ 1] .empty.foo  PROGBITS 0000000000001000 000078 000000612# ZERO-SIZE-MAPPING-NEXT:   [ 2] .empty.bar1 PROGBITS 0000000000002000 000078 000000613# ZERO-SIZE-MAPPING-NEXT:   [ 3] .bar        PROGBITS 0000000000002000 000078 000001614# ZERO-SIZE-MAPPING-NEXT:   [ 4] .empty.bar2 PROGBITS 0000000000002001 000079 000000615# ZERO-SIZE-MAPPING-NEXT:   [ 5] .empty.zed  PROGBITS 0000000000003000 000079 000000616 617# RUN: obj2yaml %t7 | FileCheck %s --check-prefix=ZERO-SIZE618 619# ZERO-SIZE:      ProgramHeaders:620# ZERO-SIZE-NEXT:   - Type:     PT_LOAD621# ZERO-SIZE-NEXT:     Flags:    [ PF_W, PF_R ]622# ZERO-SIZE-NEXT:     FirstSec: .empty.bar1623# ZERO-SIZE-NEXT:     LastSec:  .empty.bar2624# ZERO-SIZE-NEXT:     VAddr:    0x2000625# ZERO-SIZE-NEXT:     Offset:   0x78626# ZERO-SIZE-NEXT: Sections:627 628--- !ELF629FileHeader:630  Class: ELFCLASS64631  Data:  ELFDATA2LSB632  Type:  ET_EXEC633ProgramHeaders:634  - Type:     PT_LOAD635    Flags:    [ PF_W, PF_R ]636    FirstSec: .bar637    LastSec:  .bar638    VAddr:    0x2000639Sections:640  - Name:    .empty.foo641    Type:    SHT_PROGBITS642    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]643    Address: 0x1000644  - Name:    .empty.bar1645    Type:    SHT_PROGBITS646    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]647    Address: 0x2000648  - Name:    .bar649    Type:    SHT_PROGBITS650    Flags:   [ SHF_WRITE, SHF_ALLOC ]651    Address: 0x2000652    Size:    0x1653  - Name:    .empty.bar2654    Type:    SHT_PROGBITS655    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]656    Address: 0x2001657  - Name:    .empty.zed658    Type:    SHT_PROGBITS659    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]660    Address: 0x3000661 662## Check how we dump a segment when we have sections that are outside of the virtual663## address space of a segment, but inside its file space. We do not include such sections664## in a segment when they are at the edges of a segment, because this is a normal case and665## it may mean they belong to a different segment.666# RUN: yaml2obj --docnum=8 %s -o %t8667# RUN: obj2yaml %t8 | FileCheck %s --check-prefix=BROKEN-VA668 669# BROKEN-VA:      ProgramHeaders:670# BROKEN-VA-NEXT:  - Type:     PT_LOAD671# BROKEN-VA-NEXT:    Flags:    [ PF_W, PF_R ]672# BROKEN-VA-NEXT:    FirstSec: .empty_middle673# BROKEN-VA-NEXT:    LastSec:  .empty_middle674# BROKEN-VA-NEXT:    VAddr:    0x1000675 676--- !ELF677FileHeader:678  Class: ELFCLASS64679  Data:  ELFDATA2LSB680  Type:  ET_EXEC681ProgramHeaders:682  - Type:     PT_LOAD683    Flags:    [ PF_W, PF_R ]684    VAddr:    0x1000685    FirstSec: .empty_begin686    LastSec:  .empty_end687Sections:688  - Name:    .empty_begin689    Type:    SHT_PROGBITS690    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]691    Address: 0xFEFEFEFE692  - Type:    Fill693    Pattern: "00"694    Size:    1695    Name:    begin696  - Name:    .empty_middle697    Type:    SHT_PROGBITS698    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]699    Address: 0xFEFEFEFE700  - Type:    Fill701    Pattern: "00"702    Size:    1703  - Name:    .empty_end704    Type:    SHT_PROGBITS705    Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]706    Address: 0xFEFEFEFE707