1## Check we are able to handle SHT_GNU_verdef sections.
2
3# RUN: yaml2obj --docnum=1 %s -o %t1
4# RUN: llvm-readobj -V %t1 | FileCheck %s
5
6# CHECK:      VersionDefinitions [
7# CHECK-NEXT:   Definition {
8# CHECK-NEXT:     Version: 1
9# CHECK-NEXT:     Flags [ (0x1)
10# CHECK-NEXT:       Base (0x1)
11# CHECK-NEXT:     ]
12# CHECK-NEXT:     Index: 1
13# CHECK-NEXT:     Hash: 170240160
14# CHECK-NEXT:     Name: dso.so.0
15# CHECK-NEXT:     Predecessors: []
16# CHECK-NEXT:   }
17# CHECK-NEXT:   Definition {
18# CHECK-NEXT:     Version: 1
19# CHECK-NEXT:     Flags [ (0x2)
20# CHECK-NEXT:       Weak (0x2)
21# CHECK-NEXT:     ]
22# CHECK-NEXT:     Index: 2
23# CHECK-NEXT:     Hash: 108387921
24# CHECK-NEXT:     Name: VERSION_1
25# CHECK-NEXT:     Predecessors: []
26# CHECK-NEXT:   }
27# CHECK-NEXT:   Definition {
28# CHECK-NEXT:     Version: 1
29# CHECK-NEXT:     Flags [ (0x3)
30# CHECK-NEXT:       Base (0x1)
31# CHECK-NEXT:       Weak (0x2)
32# CHECK-NEXT:     ]
33# CHECK-NEXT:     Index: 3
34# CHECK-NEXT:     Hash: 108387922
35# CHECK-NEXT:     Name: VERSION_2
36# CHECK-NEXT:     Predecessors: [VERSION_3]
37# CHECK-NEXT:   }
38# CHECK-NEXT: ]
39
40--- !ELF
41FileHeader:
42  Class: ELFCLASS64
43  Data:  ELFDATA2LSB
44  Type:  ET_DYN
45  Entry: 0x0000000000001000
46Sections:
47  - Name:            .gnu.version_d
48    Type:            SHT_GNU_verdef
49    Flags:           [ SHF_ALLOC ]
50    Address:         0x0000000000000230
51    Link:            .dynstr
52    AddressAlign:    0x0000000000000004
53    Info:            0x0000000000000003
54    Entries:
55      - Version:         1
56        Flags:           1
57        VersionNdx:      1
58        Hash:            170240160
59        Names:
60          - dso.so.0
61      - Version:         1
62        Flags:           2
63        VersionNdx:      2
64        Hash:            108387921
65        Names:
66          - VERSION_1
67      - Version:         1
68        Flags:           3
69        VersionNdx:      3
70        Hash:            108387922
71        Names:
72          - VERSION_2
73          - VERSION_3
74DynamicSymbols:
75  - Name:    foo
76    Binding: STB_GLOBAL
77
78## Check we can use "Content" to describe the content.
79
80# RUN: yaml2obj --docnum=2 %s -o %t2
81# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=CONTENT
82
83# CONTENT:      Name: .gnu.version_d
84# CONTENT-NEXT: Type: SHT_GNU_verdef
85# CONTENT-NEXT: Flags [ (0x2)
86# CONTENT-NEXT:   SHF_ALLOC (0x2)
87# CONTENT-NEXT: ]
88# CONTENT-NEXT: Address: 0x0
89# CONTENT-NEXT: Offset: 0x40
90# CONTENT-NEXT: Size: 3
91# CONTENT-NEXT: Link: 0
92# CONTENT-NEXT: Info: 1
93# CONTENT-NEXT: AddressAlignment:
94# CONTENT-NEXT: EntrySize:
95# CONTENT-NEXT: SectionData (
96# CONTENT-NEXT:   0000: 112233
97# CONTENT-NEXT: )
98
99--- !ELF
100FileHeader:
101  Class: ELFCLASS64
102  Data:  ELFDATA2LSB
103  Type:  ET_DYN
104Sections:
105  - Name:    .gnu.version_d
106    Type:    SHT_GNU_verdef
107    Flags:   [ SHF_ALLOC ]
108    Info:    0x0000000000000001
109    Content: "112233"
110
111## Check we can omit "Content" and "Entries" fields to produce an empty SHT_GNU_verdef section.
112
113# RUN: yaml2obj --docnum=3 %s -o %t3
114# RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=NO-PROPS
115
116# NO-PROPS: [Nr] Name           Type   Address          Off    Size   ES Flg Lk Inf Al
117# NO-PROPS: [ 1] .gnu.version_d VERDEF 0000000000000000 000040 000000 00   A 0   1  0
118
119--- !ELF
120FileHeader:
121  Class: ELFCLASS64
122  Data:  ELFDATA2LSB
123  Type:  ET_DYN
124Sections:
125  - Name:  .gnu.version_d
126    Type:  SHT_GNU_verdef
127    Flags: [ SHF_ALLOC ]
128    Info:  0x0000000000000001
129
130## Check we can use the "Content" key with the "Size" key when the size is greater
131## than or equal to the content size.
132
133# RUN: not yaml2obj --docnum=4 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \
134# RUN:   FileCheck %s --check-prefix=CONTENT-SIZE-ERR
135
136# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size
137
138--- !ELF
139FileHeader:
140  Class: ELFCLASS64
141  Data:  ELFDATA2LSB
142  Type:  ET_DYN
143Sections:
144  - Name:    .gnu.version_d
145    Type:    SHT_GNU_verdef
146    Info:    0x1
147    Size:    [[SIZE=<none>]]
148    Content: [[CONTENT=<none>]]
149    Entries: [[ENTRIES=<none>]]
150
151# RUN: yaml2obj --docnum=4 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o
152# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \
153# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011"
154
155# RUN: yaml2obj --docnum=4 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o
156# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \
157# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100"
158
159# CHECK-CONTENT:      Name: .gnu.version_d
160# CHECK-CONTENT:      SectionData (
161# CHECK-CONTENT-NEXT:   0000: [[DATA]] |
162# CHECK-CONTENT-NEXT: )
163
164## Check we can use the "Size" key alone to create the section.
165
166# RUN: yaml2obj --docnum=4 -DSIZE=3 %s -o %t.size.o
167# RUN: llvm-readobj --sections --section-data %t.size.o | \
168# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000"
169
170## Check we can use the "Content" key alone to create the section.
171
172# RUN: yaml2obj --docnum=4 -DCONTENT="'112233'" %s -o %t.content.o
173# RUN: llvm-readobj --sections --section-data %t.content.o | \
174# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233"
175
176## Check we can't use the "Entries" key together with the "Content" or "Size" keys.
177
178# RUN: not yaml2obj --docnum=4 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \
179# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
180# RUN: not yaml2obj --docnum=4 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \
181# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
182
183# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size"
184