1## Test how we create SHT_LLVM_CALL_GRAPH_PROFILE sections.
2
3## Test that the content of SHT_LLVM_CALL_GRAPH_PROFILE sections
4## for 32/64-bit little/big endian targets is correct.
5# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=LSB %s -o %t.le64
6# RUN: llvm-readobj --cg-profile --sections --section-data %t.le64 | FileCheck %s --check-prefixes=BASIC,BASIC-LE
7# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=MSB %s -o %t.be64
8# RUN: llvm-readobj --cg-profile --sections --section-data %t.be64 | FileCheck %s --check-prefixes=BASIC,BASIC-BE
9# RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=LSB %s -o %t.le32
10# RUN: llvm-readobj --cg-profile --sections --section-data %t.le32 | FileCheck %s --check-prefixes=BASIC,BASIC-LE
11# RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=MSB %s -o %t.be32
12# RUN: llvm-readobj --cg-profile --sections --section-data %t.be32 | FileCheck %s --check-prefixes=BASIC,BASIC-BE
13
14# BASIC:        Name: .llvm.call-graph-profile
15# BASIC-NEXT:   Type: SHT_LLVM_CALL_GRAPH_PROFILE
16# BASIC-NEXT:   Flags [
17# BASIC-NEXT:   ]
18# BASIC-NEXT:   Address: 0x0
19# BASIC-NEXT:   Offset:
20# BASIC-NEXT:   Size: 32
21## Check that we link SHT_LLVM_CALL_GRAPH_PROFILE section with .symtab by default.
22# BASIC-NEXT:   Link: [[SYMTABNDX:.*]]
23# BASIC-NEXT:   Info: 0
24# BASIC-NEXT:   AddressAlignment: 0
25## Check that the entry size is set to 16 by default.
26# BASIC-NEXT:   EntrySize: 16
27# BASIC-NEXT:   SectionData (
28# BASIC-LE-NEXT:  0000: 01000000 02000000 59000000 00000000
29# BASIC-LE-NEXT:  0010: 02000000 01000000 62000000 00000000
30# BASIC-BE-NEXT:  0000: 00000001 00000002 00000000 00000059
31# BASIC-BE-NEXT:  0010: 00000002 00000001 00000000 00000062
32# BASIC-NEXT:   )
33# BASIC-NEXT: }
34# BASIC-NEXT: Section {
35# BASIC-NEXT:   Index: [[SYMTABNDX]]
36# BASIC-NEXT:   Name: .symtab
37
38# BASIC:      CGProfile [
39# BASIC-NEXT:   CGProfileEntry {
40# BASIC-NEXT:     From: foo (1)
41# BASIC-NEXT:     To: bar (2)
42# BASIC-NEXT:     Weight: 89
43# BASIC-NEXT:   }
44# BASIC-NEXT:   CGProfileEntry {
45# BASIC-NEXT:     From: bar (2)
46# BASIC-NEXT:     To: foo (1)
47# BASIC-NEXT:     Weight: 98
48# BASIC-NEXT:   }
49# BASIC-NEXT: ]
50
51--- !ELF
52FileHeader:
53  Class: ELFCLASS[[BITS]]
54  Data:  ELFDATA2[[ENCODE]]
55  Type:  ET_DYN
56Sections:
57  - Name: .llvm.call-graph-profile
58    Type: SHT_LLVM_CALL_GRAPH_PROFILE
59    Entries:
60      - From:   1
61        To:     2
62        Weight: 89
63      - From:   2
64        To:     1
65        Weight: 98
66Symbols:
67  - Name: foo
68  - Name: bar
69
70## Check we can set arbitrary sh_link and sh_entsize values.
71## Check we can specify none of "Content", "Entries", and "Size" tags.
72# RUN: yaml2obj --docnum=2 %s -o %t.link
73# RUN: llvm-readelf --sections %t.link | FileCheck %s --check-prefix=LINK
74
75# LINK: [Nr] Name      Type                    Address          Off    Size   ES Flg Lk
76# LINK: [ 1] .llvm.foo LLVM_CALL_GRAPH_PROFILE 0000000000000000 000040 000000 00     0
77# LINK: [ 2] .llvm.bar LLVM_CALL_GRAPH_PROFILE 0000000000000000 000040 000000 ff     255
78
79--- !ELF
80FileHeader:
81  Class: ELFCLASS64
82  Data:  ELFDATA2LSB
83  Type:  ET_DYN
84Sections:
85  - Name:    .llvm.foo
86    Type:    SHT_LLVM_CALL_GRAPH_PROFILE
87    Link:    0x0
88    EntSize: 0
89  - Name:    .llvm.bar
90    Type:    SHT_LLVM_CALL_GRAPH_PROFILE
91    Link:    0xFF
92    EntSize: 0xFF
93
94## Check we can refer to symbols by name.
95# RUN: yaml2obj --docnum=3 %s -o %t.sym
96# RUN: llvm-readobj --cg-profile %t.sym | FileCheck %s --check-prefix=SYMBOL-NAMES
97
98# SYMBOL-NAMES:      CGProfile [
99# SYMBOL-NAMES-NEXT:   CGProfileEntry {
100# SYMBOL-NAMES-NEXT:     From: foo (1)
101# SYMBOL-NAMES-NEXT:     To: bar (2)
102# SYMBOL-NAMES-NEXT:     Weight: 10
103# SYMBOL-NAMES-NEXT:   }
104# SYMBOL-NAMES-NEXT:   CGProfileEntry {
105# SYMBOL-NAMES-NEXT:     From: foo (1)
106# SYMBOL-NAMES-NEXT:     To: foo (3)
107# SYMBOL-NAMES-NEXT:     Weight: 30
108# SYMBOL-NAMES-NEXT:   }
109# SYMBOL-NAMES-NEXT: ]
110
111--- !ELF
112FileHeader:
113  Class:  ELFCLASS64
114  Data:   ELFDATA2LSB
115  Type:   ET_DYN
116Sections:
117  - Name: .llvm.call-graph-profile
118    Type: SHT_LLVM_CALL_GRAPH_PROFILE
119    Entries:
120## Case 1: Test we can use symbol names to describe an entry.
121      - From:   foo
122        To:     bar
123        Weight: 10
124## Case 2: Test we can refer to symbols with suffixes.
125      - From:   foo
126        To:     'foo (1)'
127        Weight: 30
128Symbols:
129  - Name: foo
130  - Name: bar
131  - Name: 'foo (1)'
132
133## Check we can describe SHT_LLVM_CALL_GRAPH_PROFILE sections using the "Content" tag.
134# RUN: yaml2obj --docnum=4 %s -o %t.content
135# RUN: llvm-readobj --sections --section-data %t.content | FileCheck %s --check-prefix=CONTENT
136
137# CONTENT:      Name: .llvm.call-graph-profile
138# CONTENT:      SectionData (
139# CONTENT-NEXT:   0000: 11223344 |
140# CONTENT-NEXT: )
141
142--- !ELF
143FileHeader:
144  Class: ELFCLASS64
145  Data:  ELFDATA2LSB
146  Type:  ET_DYN
147Sections:
148  - Name:    .llvm.call-graph-profile
149    Type:    SHT_LLVM_CALL_GRAPH_PROFILE
150    Content: "11223344"
151
152## Check we can't reference unknown symbols by name.
153# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=UNKNOWN-NAME
154# RUN: not yaml2obj --docnum=6 %s 2>&1 | FileCheck %s --check-prefix=UNKNOWN-NAME
155# UNKNOWN-NAME: error: unknown symbol referenced: 'bar' by YAML section '.llvm.call-graph-profile'
156
157--- !ELF
158FileHeader:
159  Class: ELFCLASS64
160  Data:  ELFDATA2LSB
161  Type:  ET_DYN
162Sections:
163  - Name: .llvm.call-graph-profile
164    Type: SHT_LLVM_CALL_GRAPH_PROFILE
165## The first symbol is valid, but the second is unknown.
166    Entries:
167      - From:   foo
168        To:     bar
169        Weight: 10
170Symbols:
171  - Name: foo
172
173--- !ELF
174FileHeader:
175  Class: ELFCLASS64
176  Data:  ELFDATA2LSB
177  Type:  ET_DYN
178Sections:
179  - Name: .llvm.call-graph-profile
180    Type: SHT_LLVM_CALL_GRAPH_PROFILE
181## The first symbol is unknown, but the second is valid.
182    Entries:
183      - From:   bar
184        To:     foo
185        Weight: 10
186Symbols:
187  - Name: foo
188
189## Check we can specify arbitrary symbol indexes for an SHT_LLVM_CALL_GRAPH_PROFILE section entry.
190# RUN: yaml2obj --docnum=7 %s -o %t.unk
191# RUN: llvm-readobj --sections --section-data %t.unk | FileCheck %s --check-prefix=UNKNOWN-INDEX
192
193# UNKNOWN-INDEX:      Name: .llvm.call-graph-profile
194# UNKNOWN-INDEX:      SectionData (
195# UNKNOWN-INDEX-NEXT:   0000: 01000000 02000000 03000000 00000000 |
196# UNKNOWN-INDEX-NEXT: )
197
198--- !ELF
199FileHeader:
200  Class: ELFCLASS64
201  Data:  ELFDATA2LSB
202  Type:  ET_DYN
203Sections:
204  - Name: .llvm.call-graph-profile
205    Type: SHT_LLVM_CALL_GRAPH_PROFILE
206    Entries:
207      - From:   1
208        To:     2
209        Weight: 3
210
211## Check we can use the "Content" key with the "Size" key when the size is greater
212## than or equal to the content size.
213
214# RUN: not yaml2obj --docnum=8 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \
215# RUN:   FileCheck %s --check-prefix=CONTENT-SIZE-ERR
216
217# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size
218
219--- !ELF
220FileHeader:
221  Class: ELFCLASS64
222  Data:  ELFDATA2LSB
223  Type:  ET_DYN
224Sections:
225  - Name:    .llvm.foo
226    Type:    SHT_LLVM_CALL_GRAPH_PROFILE
227    Link:    0x1
228    EntSize: 0x2
229    Size:    [[SIZE=<none>]]
230    Content: [[CONTENT=<none>]]
231    Entries: [[ENTRIES=<none>]]
232
233# RUN: yaml2obj --docnum=8 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o
234# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \
235# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011"
236
237# RUN: yaml2obj --docnum=8 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o
238# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \
239# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100"
240
241# CHECK-CONTENT:      Name: .llvm.foo
242# CHECK-CONTENT-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
243# CHECK-CONTENT-NEXT: Flags [
244# CHECK-CONTENT-NEXT: ]
245# CHECK-CONTENT-NEXT: Address:
246# CHECK-CONTENT-NEXT: Offset:
247# CHECK-CONTENT-NEXT: Size:
248# CHECK-CONTENT-NEXT: Link: 1
249# CHECK-CONTENT-NEXT: Info:
250# CHECK-CONTENT-NEXT: AddressAlignment:
251# CHECK-CONTENT-NEXT: EntrySize: 2
252# CHECK-CONTENT-NEXT: SectionData (
253# CHECK-CONTENT-NEXT:   0000: [[DATA]] |
254# CHECK-CONTENT-NEXT: )
255
256## Check we can use the "Size" key alone to create the section.
257
258# RUN: yaml2obj --docnum=8 -DSIZE=3 %s -o %t.size.o
259# RUN: llvm-readobj --sections --section-data %t.size.o | \
260# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000"
261
262## Check we can use the "Content" key alone to create the section.
263
264# RUN: yaml2obj --docnum=8 -DCONTENT="'112233'" %s -o %t.content.o
265# RUN: llvm-readobj --sections --section-data %t.content.o | \
266# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233"
267
268## Check we can't use the "Entries" key together with the "Content" or "Size" keys.
269
270# RUN: not yaml2obj --docnum=8 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \
271# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
272# RUN: not yaml2obj --docnum=8 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \
273# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
274
275# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size"
276