brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.3 KiB · 73f08f9 Raw
222 lines · yaml
1## In this test we check that can redefine the null section in the YAML.2 3## Test the default output first.4 5# RUN: yaml2obj --docnum=1 %s -o %t16# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=DEFAULT7 8# DEFAULT:      Section Headers:9# DEFAULT-NEXT:  [Nr] Name      Type   Address          Off    Size   ES Flg Lk Inf Al10# DEFAULT-NEXT:  [ 0]           NULL   0000000000000000 000000 000000 00 0   0  011# DEFAULT-NEXT:  [ 1] .strtab   STRTAB 0000000000000000 000040 000001 00 0   0  112# DEFAULT-NEXT:  [ 2] .shstrtab STRTAB 0000000000000000 000041 000013 00 0   0  113 14--- !ELF15FileHeader:16  Class: ELFCLASS6417  Data:  ELFDATA2LSB18  Type:  ET_REL19 20## Now define a SHT_NULL section with fields all zeroed.21## In this case it is equal to the section created by default.22 23# RUN: yaml2obj --docnum=2 %s -o %t224# RUN: llvm-readelf --sections %t2 | FileCheck %s --check-prefix=DEFAULT25 26--- !ELF27FileHeader:28  Class: ELFCLASS6429  Data:  ELFDATA2LSB30  Type:  ET_REL31Sections:32  - Type:         SHT_NULL33    Name:         ''34    Flags:        [ ]35    AddressAlign: 0x036    Size:         0x037    EntSize:      0x038    Link:         039    Info:         040    Address:      0x041 42## Check we can redefine fields of the first SHT_NULL section.43 44# RUN: yaml2obj --docnum=3 %s -o %t345# RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=REDEF46 47# REDEF:      Section Headers:48# REDEF-NEXT:  [Nr] Name Type Address          Off    Size   ES Flg Lk Inf Al49# REDEF-NEXT:  [ 0] .foo NULL 0000000000000006 000000 000002 03   A 4   5  150 51--- !ELF52FileHeader:53  Class: ELFCLASS6454  Data:  ELFDATA2LSB55  Type:  ET_REL56Sections:57  - Type:         SHT_NULL58    Name:         .foo59    Flags:        [ SHF_ALLOC ]60    AddressAlign: 0x161    Size:         0x262    EntSize:      0x363    Link:         464    Info:         565    Address:      0x666 67## Check that file size does not change if we redefine the Size68## of the first SHT_NULL section.69 70# RUN: yaml2obj --docnum=4 %s -o %t471# RUN: wc -c < %t3 > %t.txt72# RUN: wc -c < %t4 >> %t.txt73# RUN: FileCheck %s --input-file=%t.txt --check-prefix=SIZE74 75# SIZE: [[FILESIZE:.*]]76# SIZE: [[FILESIZE]]77 78--- !ELF79FileHeader:80  Class: ELFCLASS6481  Data:  ELFDATA2LSB82  Type:  ET_REL83Sections:84  - Type:         SHT_NULL85    Name:         .foo86    Flags:        [ SHF_ALLOC ]87    AddressAlign: 0x188    Size:         0xFFFF89    EntSize:      0x390    Link:         491    Info:         592    Address:      0x693 94## Check we are still able to describe other sections too.95 96# RUN: yaml2obj --docnum=5 %s -o %t597# RUN: llvm-readelf --sections %t5 | FileCheck %s --check-prefix=OTHER-SECTION98 99# OTHER-SECTION:      Section Headers:100# OTHER-SECTION-NEXT:   [Nr] Name      Type     Address          Off    Size   ES Flg Lk Inf Al101# OTHER-SECTION-NEXT:   [ 0]           NULL     0000000000000000 000000 000000 00 0   0  0102# OTHER-SECTION-NEXT:   [ 1] foo       PROGBITS 0000000000000000 000040 000000 00 0   0  0103# OTHER-SECTION-NEXT:   [ 2] .strtab   STRTAB   0000000000000000 000040 000001 00 0   0  1104# OTHER-SECTION-NEXT:   [ 3] .shstrtab STRTAB   0000000000000000 000041 000017 00 0   0  1105 106--- !ELF107FileHeader:108  Class: ELFCLASS64109  Data:  ELFDATA2LSB110  Type:  ET_REL111Sections:112  - Type:         SHT_NULL113    Name:         ''114    Flags:        [ ]115    AddressAlign: 0x0116    Size:         0x0117    EntSize:      0x0118    Link:         0119  - Type: SHT_PROGBITS120    Name: 'foo'121 122## Check we report an error if null section sh_link field refers to an unknown section.123 124# RUN: not yaml2obj --docnum=6 %s -o %t6 2>&1 | FileCheck %s --check-prefix=CASE4125 126# CASE4:      error: unknown section referenced: '.foo' by YAML section '(index 0)'127# CASE4-NEXT: error: unknown section referenced: '.bar' by YAML section '(index 1)'128 129--- !ELF130FileHeader:131  Class: ELFCLASS64132  Data:  ELFDATA2LSB133  Type:  ET_REL134Sections:135  - Type: SHT_NULL136    Link: .foo137  - Type: SHT_NULL138    Link: .bar139 140## Check that null section fields are set to zero, if they are unspecified.141 142# RUN: yaml2obj --docnum=7 %s -o %t7143# RUN: llvm-readelf --sections %t7 | FileCheck %s --check-prefix=DEFAULT144 145--- !ELF146FileHeader:147  Class: ELFCLASS64148  Data:  ELFDATA2LSB149  Type:  ET_REL150Sections:151  - Type: SHT_NULL152 153## Check we do not crash if we have more than one SHT_NULL section.154 155# RUN: yaml2obj --docnum=8 %s -o %t8156# RUN: llvm-readelf --sections %t8 | FileCheck %s --check-prefix=MULTIPLE157 158# MULTIPLE:      Section Headers:159# MULTIPLE-NEXT:  [Nr] Name Type Address          Off    Size   ES Flg Lk Inf Al160# MULTIPLE-NEXT:  [ 0]      NULL 0000000000000000 000000 000000 00 0   0  0161# MULTIPLE-NEXT:  [ 1] .foo NULL 0000000000000123 000040 000020 10 A   1  2   0162 163--- !ELF164FileHeader:165  Class: ELFCLASS64166  Data:  ELFDATA2LSB167  Type:  ET_REL168Sections:169  - Type: SHT_NULL170  - Type:    SHT_NULL171    Name:    .foo172    Flags:   [ SHF_ALLOC ]173    Size:    0x20174    EntSize: 0x10175    Link:    1176    Info:    2177    Address: 0x123178 179## Check we can override the sh_offset/sh_size fields of the first SHT_NULL section if requested.180 181# RUN: yaml2obj --docnum=9 %s -o %t9182# RUN: llvm-readelf --sections %t9 | FileCheck %s --check-prefix=OVERRIDE183 184# OVERRIDE:      Section Headers:185# OVERRIDE-NEXT:  [Nr] Name Type Address          Off    Size   ES Flg Lk Inf Al186# OVERRIDE-NEXT:  [ 0]      NULL 0000000000000000 000007 000008 00   0 0  0187 188--- !ELF189FileHeader:190  Class: ELFCLASS64191  Data:  ELFDATA2LSB192  Type:  ET_REL193Sections:194  - Type:     SHT_NULL195    Size:     0x2196    ShOffset: 0x7197    ShSize:   0x8198 199## Check that we can set an offset for the SHT_NULL section explicitly using the "Offset" key.200## Check it affects the section header table offset.201# RUN: yaml2obj --docnum=10 %s -DOFFSET=0x100 -o %t10202# RUN: llvm-readelf --headers --sections %t10 | FileCheck %s --check-prefix=EXPLICIT-OFFSET-A203# RUN: yaml2obj --docnum=10 %s -DOFFSET=0x200 -o %t11204# RUN: llvm-readelf --headers --sections %t11 | FileCheck %s --check-prefix=EXPLICIT-OFFSET-B205 206# EXPLICIT-OFFSET-A:      Start of section headers: 280 (bytes into file)207# EXPLICIT-OFFSET-A:      [Nr] Name  Type Address          Off208# EXPLICIT-OFFSET-A-NEXT: [ 0]       NULL 0000000000000000 000100209 210# EXPLICIT-OFFSET-B:      Start of section headers: 536 (bytes into file)211# EXPLICIT-OFFSET-B:      [Nr] Name  Type Address          Off212# EXPLICIT-OFFSET-B-NEXT: [ 0]       NULL 0000000000000000 000200213 214--- !ELF215FileHeader:216  Class: ELFCLASS64217  Data:  ELFDATA2LSB218  Type:  ET_REL219Sections:220  - Type:   SHT_NULL221    Offset: [[OFFSET]]222