1## Check we are able to produce a valid SHT_GNU_versym
2## section from its description.
3
4# RUN: yaml2obj --docnum=1 %s -o %t1
5# RUN: llvm-readobj -V %t1 | FileCheck %s
6
7# CHECK:      VersionSymbols [
8# CHECK-NEXT:   Symbol {
9# CHECK-NEXT:     Version: 0
10# CHECK-NEXT:     Name:
11# CHECK-NEXT:   }
12# CHECK-NEXT:   Symbol {
13# CHECK-NEXT:     Version: 3
14# CHECK-NEXT:     Name: f1@v1
15# CHECK-NEXT:   }
16# CHECK-NEXT:   Symbol {
17# CHECK-NEXT:     Version: 4
18# CHECK-NEXT:     Name: f2@v2
19# CHECK-NEXT:   }
20# CHECK-NEXT: ]
21# CHECK-NEXT: VersionDefinitions [
22# CHECK-NEXT: ]
23# CHECK-NEXT: VersionRequirements [
24# CHECK-NEXT:   Dependency {
25# CHECK-NEXT:     Version: 1
26# CHECK-NEXT:     Count: 2
27# CHECK-NEXT:     FileName: dso.so.0
28# CHECK-NEXT:     Entries [
29# CHECK-NEXT:       Entry {
30# CHECK-NEXT:         Hash: 1937
31# CHECK-NEXT:         Flags [ (0x0)
32# CHECK-NEXT:         ]
33# CHECK-NEXT:         Index: 3
34# CHECK-NEXT:         Name: v1
35# CHECK-NEXT:       }
36# CHECK-NEXT:       Entry {
37# CHECK-NEXT:         Hash: 1938
38# CHECK-NEXT:         Flags [ (0x0)
39# CHECK-NEXT:         ]
40# CHECK-NEXT:         Index: 4
41# CHECK-NEXT:         Name: v2
42# CHECK-NEXT:       }
43# CHECK-NEXT:     ]
44# CHECK-NEXT:   }
45# CHECK-NEXT: ]
46
47--- !ELF
48FileHeader:
49  Class: ELFCLASS64
50  Data:  ELFDATA2LSB
51  Type:  ET_EXEC
52  Entry: 0x0000000000201000
53Sections:
54  - Name:            .gnu.version
55    Type:            SHT_GNU_versym
56    Flags:           [ SHF_ALLOC ]
57    Address:         0x0000000000200210
58    Link:            .dynsym
59    AddressAlign:    0x0000000000000002
60    EntSize:         0x0000000000000002
61    Entries:         [ 0, 3, 4 ]
62  - Name:            .gnu.version_r
63    Type:            SHT_GNU_verneed
64    Flags:           [ SHF_ALLOC ]
65    Address:         0x0000000000200250
66    Link:            .dynstr
67    AddressAlign:    0x0000000000000004
68    Info:            0x0000000000000001
69    Dependencies:
70      - Version:         1
71        File:            dso.so.0
72        Entries:
73          - Name:            v1
74            Hash:            1937
75            Flags:           0
76            Other:           3
77          - Name:            v2
78            Hash:            1938
79            Flags:           0
80            Other:           4
81DynamicSymbols:
82  - Name:    f1
83    Binding: STB_GLOBAL
84  - Name:    f2
85    Binding: STB_GLOBAL
86...
87
88## Check we are able to set custom sh_entsize field for SHT_GNU_versym section.
89
90# RUN: yaml2obj --docnum=2 %s -o %t2
91# RUN: llvm-readelf -S %t2 | FileCheck %s --check-prefix=ENTSIZE
92
93# ENTSIZE: Section Headers:
94# ENTSIZE:   [Nr] Name         Type   Address          Off    Size   ES
95# ENTSIZE:   [ 1] .gnu.version VERSYM 0000000000000000 000040 000000 03
96
97--- !ELF
98FileHeader:
99  Class: ELFCLASS64
100  Data:  ELFDATA2LSB
101  OSABI: ELFOSABI_FREEBSD
102  Type:  ET_DYN
103Sections:
104  - Name:    .gnu.version
105    Type:    SHT_GNU_versym
106    EntSize: 0x0000000000000003
107    Entries: [ ]
108
109## Check we can use the "Content" key with the "Size" key when the size is greater
110## than or equal to the content size.
111
112# RUN: not yaml2obj --docnum=3 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \
113# RUN:   FileCheck %s --check-prefix=CONTENT-SIZE-ERR
114
115# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size
116
117--- !ELF
118FileHeader:
119  Class: ELFCLASS64
120  Data:  ELFDATA2LSB
121  Type:  ET_DYN
122Sections:
123  - Name:    .gnu.version
124    Type:    SHT_GNU_versym
125    Size:    [[SIZE=<none>]]
126    Content: [[CONTENT=<none>]]
127    Entries: [[ENTRIES=<none>]]
128
129# RUN: yaml2obj --docnum=3 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o
130# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \
131# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011"
132
133# RUN: yaml2obj --docnum=3 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o
134# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \
135# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100"
136
137# CHECK-CONTENT:      Name: .gnu.version
138# CHECK-CONTENT:      SectionData (
139# CHECK-CONTENT-NEXT:   0000: [[DATA]] |
140# CHECK-CONTENT-NEXT: )
141
142## Check we can use the "Size" key alone to create the section.
143
144# RUN: yaml2obj --docnum=3 -DSIZE=3 %s -o %t.size.o
145# RUN: llvm-readobj --sections --section-data %t.size.o | \
146# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000"
147
148## Check we can use the "Content" key alone to create the section.
149
150# RUN: yaml2obj --docnum=3 -DCONTENT="'112233'" %s -o %t.content.o
151# RUN: llvm-readobj --sections --section-data %t.content.o | \
152# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233"
153
154## Check we can't use the "Entries" key together with the "Content" or "Size" keys.
155
156# RUN: not yaml2obj --docnum=3 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \
157# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
158# RUN: not yaml2obj --docnum=3 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \
159# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
160
161# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size"
162