xref: /llvm-project/llvm/test/tools/yaml2obj/ELF/override-shsize.yaml (revision 51f4958057d6c246e85c3fbc65353bc0d7c1049b)
1## Check we are able to set custom sh_size field
2## for different sections.
3
4# RUN: yaml2obj --docnum=1 %s -o %t1
5# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=CASE1
6
7# CASE1:      Section Headers:
8# CASE1-NEXT:  [Nr] Name           Type     Address          Off    Size
9# CASE1-NEXT:  [ 0]                NULL     0000000000000000 000000 000000
10# CASE1-NEXT:  [ 1] .dynsym        DYNSYM   0000000000000000 000040 000001
11# CASE1-NEXT:  [ 2] .symtab        SYMTAB   0000000000000000 000058 000002
12# CASE1-NEXT:  [ 3] .dynamic       DYNAMIC  0000000000000000 000070 000003
13# CASE1-NEXT:  [ 4] .rela          RELA     0000000000000000 000070 000004
14# CASE1-NEXT:  [ 5] .nobits        NOBITS   0000000000000000 000070 000005
15# CASE1-NEXT:  [ 6] .group         GROUP    0000000000000000 000070 000006
16# CASE1-NEXT:  [ 7] .gnu.version   VERSYM   0000000000000000 000070 000007
17# CASE1-NEXT:  [ 8] .gnu.version_r VERNEED  0000000000000000 000070 000008
18# CASE1-NEXT:  [ 9] .gnu.version_d VERDEF   0000000000000000 000070 000009
19# CASE1-NEXT:  [10] .regular       PROGBITS 0000000000000000 000070 00000a
20# CASE1-NEXT:  [11] .strtab        STRTAB   0000000000000000 000070 00000b
21
22--- !ELF
23FileHeader:
24  Class: ELFCLASS64
25  Data:  ELFDATA2LSB
26  Type:  ET_REL
27Sections:
28  - Name: .dynsym
29    Type: SHT_DYNSYM
30    ShSize: 0x000000001
31  - Name: .symtab
32    Type: SHT_SYMTAB
33    ShSize: 0x000000002
34  - Name: .dynamic
35    Type: SHT_DYNAMIC
36    ShSize: 0x000000003
37  - Name: .rela
38    Type: SHT_RELA
39    ShSize: 0x000000004
40  - Name: .nobits
41    Type: SHT_NOBITS
42    ShSize: 0x000000005
43  - Name: .group
44    Type: SHT_GROUP
45    ShSize: 0x000000006
46    Members:
47  - Name: .gnu.version
48    Type: SHT_GNU_versym
49    Entries: [ ]
50    ShSize: 0x000000007
51  - Name:   .gnu.version_r
52    Type:   SHT_GNU_verneed
53    ShSize: 0x000000008
54    Dependencies:
55  - Name: .gnu.version_d
56    Type: SHT_GNU_verdef
57    ShSize: 0x000000009
58    Entries:
59  - Name: .regular
60    Type: SHT_PROGBITS
61    ShSize: 0x00000000A
62  - Name: .strtab
63    Type: SHT_STRTAB
64    ShSize: 0x00000000B
65
66## Here we check that defining ShSize does not actually change
67## the content and also does not affect file size.
68
69# RUN: yaml2obj --docnum=2 %s -o %t2
70# RUN: yaml2obj --docnum=3 %s -o %t3
71# RUN: od -t x1 -v %t2 > %t.txt
72# RUN: od -t x1 -v %t3 >> %t.txt
73# RUN: FileCheck %s --input-file=%t.txt --ignore-case --check-prefix=CASE2
74
75# CASE2: [[OFFSET:.*]] fe fe fe fe fe fe fe fe
76# CASE2: [[FILESIZE:.*]]{{$}}
77# CASE2: [[OFFSET]] fe fe fe fe fe fe fe fe
78# CASE2: [[FILESIZE]]{{$}}
79
80--- !ELF
81FileHeader:
82  Class: ELFCLASS64
83  Data:  ELFDATA2LSB
84  Type:  ET_REL
85Sections:
86  - Name: .foo
87    Type: SHT_PROGBITS
88    Content: "fefefefefefefefe"
89
90--- !ELF
91FileHeader:
92  Class: ELFCLASS64
93  Data:  ELFDATA2LSB
94  Type:  ET_REL
95Sections:
96  - Name: .foo
97    Type: SHT_PROGBITS
98    ShSize: 1
99    Content: "fefefefefefefefe"
100
101## Check we can define sh_size larger than section content size
102## and thus create overlaping sections.
103
104# RUN: yaml2obj --docnum=4 %s -o %t4
105# RUN: llvm-readobj --sections --section-data %t4 | FileCheck %s --check-prefix=CASE4
106
107# CASE4:      Name: .foo
108# CASE4:      SectionData (
109# CASE4-NEXT: 0000: AAAABBBB |....|
110# CASE4:      Name: .bar
111# CASE4:      SectionData (
112# CASE4-NEXT: 0000: BBBB |..|
113
114--- !ELF
115FileHeader:
116  Class: ELFCLASS64
117  Data:  ELFDATA2LSB
118  Type:  ET_REL
119Sections:
120  - Name: .foo
121    Type: SHT_PROGBITS
122    Content: "aaaa"
123    ShSize: 4
124  - Name: .bar
125    Type: SHT_PROGBITS
126    Content: "bbbb"
127
128## Check we can set both Size and ShSize and the number of the actual
129## bytes written is equal to Size in this case.
130
131# RUN: yaml2obj --docnum=5 %s -o %t5
132# RUN: od -t x1 -v %t5 | FileCheck %s --ignore-case --check-prefix=CASE5
133
134# CASE5: aa aa 00 00 bb bb
135
136--- !ELF
137FileHeader:
138  Class: ELFCLASS64
139  Data:  ELFDATA2LSB
140  Type:  ET_REL
141Sections:
142  - Name: .foo
143    Type: SHT_PROGBITS
144    Content: "aaaa"
145  - Name: .bar
146    Type: SHT_PROGBITS
147    Size: 2
148    ShSize: 4
149  - Name: .zed
150    Type: SHT_PROGBITS
151    Content: "bbbb"
152