xref: /llvm-project/llvm/test/tools/yaml2obj/ELF/call-graph-profile-section.yaml (revision a224c5199b327ed0efcdcd87b6dbf950cf4d9ee1)
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: 16
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: 8
27# BASIC-NEXT:   SectionData (
28# BASIC-LE-NEXT:  0000: 59000000 00000000 62000000 00000000
29# BASIC-BE-NEXT:  0000: 00000000 00000059 00000000 00000062
30# BASIC-NEXT:   )
31# BASIC-NEXT: }
32# BASIC-NEXT: Section {
33# BASIC-NEXT:  Index: [[SYMTABNDX]]
34# BASIC-NEXT:  Name: .symtab
35
36# BASIC:      CGProfile [
37# BASIC-NEXT:   CGProfileEntry {
38# BASIC-NEXT:     Weight: 89
39# BASIC-NEXT:   }
40# BASIC-NEXT:   CGProfileEntry {
41# BASIC-NEXT:     Weight: 98
42# BASIC-NEXT:   }
43# BASIC-NEXT: ]
44
45--- !ELF
46FileHeader:
47  Class: ELFCLASS[[BITS]]
48  Data:  ELFDATA2[[ENCODE]]
49  Type:  ET_DYN
50Sections:
51  - Name: .llvm.call-graph-profile
52    Type: SHT_LLVM_CALL_GRAPH_PROFILE
53    Entries:
54      - Weight: 89
55      - Weight: 98
56Symbols:
57  - Name: foo
58  - Name: bar
59
60## Check we can set arbitrary sh_link and sh_entsize values.
61## Check we can specify none of "Content", "Entries", and "Size" tags.
62# RUN: yaml2obj --docnum=2 %s -o %t.link
63# RUN: llvm-readelf --sections %t.link | FileCheck %s --check-prefix=LINK
64
65# LINK: [Nr] Name      Type                    Address          Off    Size   ES Flg Lk
66# LINK: [ 1] .llvm.foo LLVM_CALL_GRAPH_PROFILE 0000000000000000 000040 000000 00     0
67# LINK: [ 2] .llvm.bar LLVM_CALL_GRAPH_PROFILE 0000000000000000 000040 000000 ff     255
68
69--- !ELF
70FileHeader:
71  Class: ELFCLASS64
72  Data:  ELFDATA2LSB
73  Type:  ET_DYN
74Sections:
75  - Name:    .llvm.foo
76    Type:    SHT_LLVM_CALL_GRAPH_PROFILE
77    Link:    0x0
78    EntSize: 0
79  - Name:    .llvm.bar
80    Type:    SHT_LLVM_CALL_GRAPH_PROFILE
81    Link:    0xFF
82    EntSize: 0xFF
83
84## Check we can describe SHT_LLVM_CALL_GRAPH_PROFILE sections using the "Content" tag.
85# RUN: yaml2obj --docnum=3 %s -o %t.content
86# RUN: llvm-readobj --sections --section-data %t.content | FileCheck %s --check-prefix=CONTENT
87
88# CONTENT:      Name: .llvm.call-graph-profile
89# CONTENT:      SectionData (
90# CONTENT-NEXT:   0000: 11223344 |
91# CONTENT-NEXT: )
92
93--- !ELF
94FileHeader:
95  Class: ELFCLASS64
96  Data:  ELFDATA2LSB
97  Type:  ET_DYN
98Sections:
99  - Name:    .llvm.call-graph-profile
100    Type:    SHT_LLVM_CALL_GRAPH_PROFILE
101    Content: "11223344"
102
103## Check we can use the "Content" key with the "Size" key when the size is greater
104## than or equal to the content size.
105
106# RUN: not yaml2obj --docnum=4 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \
107# RUN:   FileCheck %s --check-prefix=CONTENT-SIZE-ERR
108
109# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size
110
111--- !ELF
112FileHeader:
113  Class: ELFCLASS64
114  Data:  ELFDATA2LSB
115  Type:  ET_DYN
116Sections:
117  - Name:    .llvm.foo
118    Type:    SHT_LLVM_CALL_GRAPH_PROFILE
119    Link:    0x1
120    EntSize: 0x2
121    Size:    [[SIZE=<none>]]
122    Content: [[CONTENT=<none>]]
123    Entries: [[ENTRIES=<none>]]
124
125# RUN: yaml2obj --docnum=4 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o
126# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \
127# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011"
128
129# RUN: yaml2obj --docnum=4 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o
130# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \
131# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100"
132
133# CHECK-CONTENT:      Name: .llvm.foo
134# CHECK-CONTENT-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
135# CHECK-CONTENT-NEXT: Flags [
136# CHECK-CONTENT-NEXT: ]
137# CHECK-CONTENT-NEXT: Address:
138# CHECK-CONTENT-NEXT: Offset:
139# CHECK-CONTENT-NEXT: Size:
140# CHECK-CONTENT-NEXT: Link: 1
141# CHECK-CONTENT-NEXT: Info:
142# CHECK-CONTENT-NEXT: AddressAlignment:
143# CHECK-CONTENT-NEXT: EntrySize: 2
144# CHECK-CONTENT-NEXT: SectionData (
145# CHECK-CONTENT-NEXT:   0000: [[DATA]] |
146# CHECK-CONTENT-NEXT: )
147
148## Check we can use the "Size" key alone to create the section.
149
150# RUN: yaml2obj --docnum=4 -DSIZE=3 %s -o %t.size.o
151# RUN: llvm-readobj --sections --section-data %t.size.o | \
152# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000"
153
154## Check we can use the "Content" key alone to create the section.
155
156# RUN: yaml2obj --docnum=4 -DCONTENT="'112233'" %s -o %t.content.o
157# RUN: llvm-readobj --sections --section-data %t.content.o | \
158# RUN:   FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233"
159
160## Check we can't use the "Entries" key together with the "Content" or "Size" keys.
161
162# RUN: not yaml2obj --docnum=4 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \
163# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
164# RUN: not yaml2obj --docnum=4 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \
165# RUN:   FileCheck %s --check-prefix=ENTRIES-ERR
166
167# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size"
168