1## Check we are able to produce a valid SHT_LLVM_LINKER_OPTIONS
2## section from its description.
3
4## Check we can use "Options", "Size" and "Content" alone to describe the data.
5
6# RUN: yaml2obj --docnum=1 %s -o %t1
7# RUN: llvm-readobj --string-dump .linker-options1 --sections --section-data %t1 \
8# RUN:   | FileCheck %s --check-prefix=OPTIONS
9
10# OPTIONS:        Name: .linker-options1
11# OPTIONS-NEXT:   Type: SHT_LLVM_LINKER_OPTIONS
12# OPTIONS-NEXT:   Flags [
13# OPTIONS-NEXT:   ]
14# OPTIONS-NEXT:   Address: 0x0
15# OPTIONS-NEXT:   Offset: 0x40
16# OPTIONS-NEXT:   Size: 34
17# OPTIONS-NEXT:   Link: 0
18# OPTIONS-NEXT:   Info: 0
19# OPTIONS-NEXT:   AddressAlignment: 0
20# OPTIONS-NEXT:   EntrySize: 0
21
22# OPTIONS:      Name: .linker-options2
23# OPTIONS-NEXT: Type: SHT_LLVM_LINKER_OPTIONS
24# OPTIONS:      SectionData (
25# OPTIONS-NEXT:   0000: 00112233 |
26# OPTIONS-NEXT: )
27
28# OPTIONS:      Name: .linker-options3
29# OPTIONS-NEXT: Type: SHT_LLVM_LINKER_OPTIONS
30# OPTIONS:      SectionData (
31# OPTIONS-NEXT:   0000: 00000000 |
32# OPTIONS-NEXT: )
33
34# OPTIONS:      String dump of section '.linker-options1':
35# OPTIONS-NEXT: [     0] option 0
36# OPTIONS-NEXT: [     9] value 0
37# OPTIONS-NEXT: [    11] option 1
38# OPTIONS-NEXT: [    1a] value 1
39
40--- !ELF
41FileHeader:
42  Class: ELFCLASS64
43  Data:  ELFDATA2LSB
44  Type:  ET_REL
45Sections:
46  - Name: .linker-options1
47    Type: SHT_LLVM_LINKER_OPTIONS
48    Options:
49      - Name:  option 0
50        Value: value 0
51      - Name:  option 1
52        Value: value 1
53  - Name: .linker-options2
54    Type: SHT_LLVM_LINKER_OPTIONS
55    Content: "00112233"
56  - Name: .linker-options3
57    Type: SHT_LLVM_LINKER_OPTIONS
58    Size: 4
59
60## Check that "Value" and "Name" fields are mandatory when using "Options" key.
61
62# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=NOVALUE
63# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --check-prefix=NONAME
64
65# NOVALUE: error: missing required key 'Value'
66# NONAME: error: missing required key 'Name'
67
68--- !ELF
69FileHeader:
70  Class: ELFCLASS64
71  Data:  ELFDATA2LSB
72  Type:  ET_REL
73Sections:
74  - Name: .linker-options
75    Type: SHT_LLVM_LINKER_OPTIONS
76    Options:
77      - Name: name
78
79--- !ELF
80FileHeader:
81  Class: ELFCLASS64
82  Data:  ELFDATA2LSB
83  Type:  ET_REL
84Sections:
85  - Name: .linker-options
86    Type: SHT_LLVM_LINKER_OPTIONS
87    Options:
88      - Value: value
89
90## Check we can't use "Options" or "Size" keys together with the "Content" key.
91
92# RUN: not yaml2obj %s -DOPTIONS="[]" -DCONTENT="''" --docnum=4 2>&1 | \
93# RUN:   FileCheck %s --check-prefix=TOGETHER
94
95# RUN: not yaml2obj %s -DOPTIONS="[]" -DSIZE="0" --docnum=4 2>&1 | \
96# RUN:   FileCheck %s --check-prefix=TOGETHER
97
98# TOGETHER: error: "Options" cannot be used with "Content" or "Size"
99
100--- !ELF
101FileHeader:
102  Class: ELFCLASS64
103  Data:  ELFDATA2LSB
104  Type:  ET_REL
105Sections:
106  - Name:    .linker-options
107    Type:    SHT_LLVM_LINKER_OPTIONS
108    Options: [[OPTIONS=<none>]]
109    Content: [[CONTENT=<none>]]
110    Size:    [[SIZE=<none>]]
111
112## Check we can omit "Options", "Content" and "Size" keys. This produces an empty section.
113
114# RUN: yaml2obj %s --docnum=4 2>&1 -o %t5
115# RUN: llvm-readelf --sections %t5 | FileCheck %s --check-prefix=NONE
116
117# NONE: [Nr] Name            Type                Address          Off    Size
118# NONE: [ 1] .linker-options LLVM_LINKER_OPTIONS 0000000000000000 000040 000000
119
120## Check we can use the "Content" key with the "Size" key when the size is greater
121## than or equal to the content size.
122
123# RUN: not yaml2obj --docnum=4 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \
124# RUN:   FileCheck %s --check-prefix=CONTENT-SIZE-ERR
125
126# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size
127
128# RUN: yaml2obj --docnum=4 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o
129# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \
130# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011"
131
132# CHECK-CONTENT:      Name: .linker-options (1)
133# CHECK-CONTENT:      SectionData (
134# CHECK-CONTENT-NEXT:   0000: [[DATA]] |
135# CHECK-CONTENT-NEXT: )
136
137# RUN: yaml2obj --docnum=4 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o
138# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \
139# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100"
140