aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/tools/llvm-readobj/ELF/call-graph-profile.test
blob: 5ca5a6682f5495e9ff92c209190e95938dbd751b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
## This test checks how we handle the --elf-cg-profile option.

# RUN: yaml2obj %s -o %t.o
# RUN: llvm-readobj %t.o --cg-profile | FileCheck %s --check-prefix=LLVM
# RUN: llvm-readelf %t.o --cg-profile | FileCheck %s --check-prefix=GNU
# RUN: llvm-readobj %t.o --elf-cg-profile | FileCheck %s --check-prefix=LLVM
# RUN: llvm-readelf %t.o --elf-cg-profile | FileCheck %s --check-prefix=GNU

# LLVM:      CGProfile [
# LLVM-NEXT:  CGProfileEntry {
# LLVM-NEXT:    From: foo (1)
# LLVM-NEXT:    To: bar (2)
# LLVM-NEXT:    Weight: 89
# LLVM-NEXT:  }
# LLVM-NEXT:  CGProfileEntry {
# LLVM-NEXT:    From: bar (2)
# LLVM-NEXT:    To: foo (1)
# LLVM-NEXT:    Weight: 98
# LLVM-NEXT:  }
# LLVM-NEXT: ]

# GNU: GNUStyle::printCGProfile not implemented

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
  Machine: EM_X86_64
Sections:
  - Name: .llvm.call-graph-profile
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Entries:
      - Weight: 89
      - Weight: 98
    EntSize: [[ENTSIZE=<none>]]
  - Name: .rel.llvm.call-graph-profile
    Type: SHT_REL
    Info: .llvm.call-graph-profile
    Relocations:
      - Symbol: foo
        Type:   R_X86_64_NONE
      - Offset: 0x0
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: foo
        Type:   R_X86_64_NONE
Symbols:
  - Name: foo
  - Name: bar

## Check we report a warning when unable to get the content of the SHT_LLVM_CALL_GRAPH_PROFILE section.
# RUN: yaml2obj %s -DENTSIZE=0xF -o %t2.o
# RUN: llvm-readobj %t2.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t2.o --check-prefix=LLVM-ERR
# RUN: llvm-readelf %t2.o --cg-profile | FileCheck %s --check-prefix=GNU

# LLVM-ERR: warning: '[[FILE]]': unable to load the SHT_LLVM_CALL_GRAPH_PROFILE section: section [index 1] has invalid sh_entsize: expected 8, but got 15

## Check we report a warning when unable to dump a name of a symbol.
# RUN: yaml2obj %s --docnum=2 -o %t3.o
# RUN: llvm-readobj %t3.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t3.o --check-prefix=LLVM-BROKEN-SYM
# RUN: llvm-readelf %t3.o --cg-profile | FileCheck %s --check-prefix=GNU

# LLVM-BROKEN-SYM:      CGProfile [
# LLVM-BROKEN-SYM-NEXT:   CGProfileEntry {
# LLVM-BROKEN-SYM-NEXT:     From: A (1)
# LLVM-BROKEN-SYM-NEXT: warning: '[[FILE]]': unable to read the name of symbol with index 2: st_name (0xff) is past the end of the string table of size 0x5
# LLVM-BROKEN-SYM-NEXT:     To: <?> (2)
# LLVM-BROKEN-SYM-NEXT:     Weight: 10
# LLVM-BROKEN-SYM-NEXT:   }
# LLVM-BROKEN-SYM-NEXT:   CGProfileEntry {
# LLVM-BROKEN-SYM-NEXT:     From: <?> (2)
# LLVM-BROKEN-SYM-NEXT:     To: B (3)
# LLVM-BROKEN-SYM-NEXT:     Weight: 20
# LLVM-BROKEN-SYM-NEXT:   }
# LLVM-BROKEN-SYM-NEXT:   CGProfileEntry {
# LLVM-BROKEN-SYM-NEXT:     From: (0)
# LLVM-BROKEN-SYM-NEXT: warning: '[[FILE]]': unable to read the name of symbol with index 4: unable to get symbol from section [index 4]: invalid symbol index (4)
# LLVM-BROKEN-SYM-NEXT:     To: <?> (4)
# LLVM-BROKEN-SYM-NEXT:     Weight: 20
# LLVM-BROKEN-SYM-NEXT:   }
# LLVM-BROKEN-SYM-NEXT: ]

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
  Machine: EM_X86_64
Sections:
  - Name: .llvm.call-graph-profile
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Entries:
      - Weight: 10
      - Weight: 20
      - Weight: 20
  - Name: .rel.llvm.call-graph-profile
    Type: SHT_REL
    Info: .llvm.call-graph-profile
    Relocations:
      - Symbol: 1
        Type:   R_X86_64_NONE
      - Offset: 0x0
        Symbol: 2
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: 2
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: 3
        Type:   R_X86_64_NONE
      - Offset: 0x10
        Symbol: 0x0 ## Null symbol.
        Type:   R_X86_64_NONE
      - Offset: 0x10
        Symbol: 0x4 ## This index goes past the end of the symbol table.
        Type:   R_X86_64_NONE
  - Name:    .strtab
    Type:    SHT_STRTAB
    Content: "0041004200" ## '\0', 'A', '\0', 'B', '\0'
Symbols:
  - StName: 1    ## 'A'
  - StName: 0xFF ## An arbitrary currupted index in the string table.
  - StName: 3    ## 'B'

## Check we report a warning when a relocation section is not present.
# RUN: yaml2obj %s --docnum=3 -o %t4.o
# RUN: llvm-readobj %t4.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t4.o --check-prefix=LLVM-NO-RELOC
# RUN: llvm-readobj %t4.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t4.o --check-prefix=LLVM-NO-RELOC

# LLVM-NO-RELOC:      warning: '[[FILE]]': relocation section for a call graph section doesn't exist
# LLVM-NO-RELOC-NEXT: CGProfile [
# LLVM-NO-RELOC-NEXT:  CGProfileEntry {
# LLVM-NO-RELOC-NEXT:    Weight: 89
# LLVM-NO-RELOC-NEXT:  }
# LLVM-NO-RELOC-NEXT:  CGProfileEntry {
# LLVM-NO-RELOC-NEXT:    Weight: 98
# LLVM-NO-RELOC-NEXT:  }
# LLVM-NO-RELOC-NEXT: ]

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
Sections:
  - Name: .llvm.call-graph-profile
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Entries:
      - Weight: 89
      - Weight: 98
Symbols:
  - Name: foo
  - Name: bar

## Check we report a warning when the number of relocation section entries does not match the number of call graph entries.
# RUN: yaml2obj %s --docnum=4 -o %t5.o
# RUN: llvm-readobj %t5.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t5.o --check-prefix=LLVM-RELOC-GRAPH-NOT-MATCH
# RUN: llvm-readobj %t5.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t5.o --check-prefix=LLVM-RELOC-GRAPH-NOT-MATCH

# LLVM-RELOC-GRAPH-NOT-MATCH:      warning: '[[FILE]]': number of from/to pairs does not match number of frequencies
# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: CGProfile [
# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT:  CGProfileEntry {
# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT:    Weight: 89
# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT:  }
# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT:  CGProfileEntry {
# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT:    Weight: 98
# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT:  }
# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: ]

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
  Machine: EM_X86_64
Sections:
  - Name: .llvm.call-graph-profile
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Entries:
      - Weight: 89
      - Weight: 98
  - Name: .rel.llvm.call-graph-profile
    Type: SHT_REL
    Info: .llvm.call-graph-profile
    Relocations:
      - Symbol: foo
        Type:   R_X86_64_NONE
      - Offset: 0x0
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: foo
        Type:   R_X86_64_NONE
      - Offset: 0x10
        Symbol: foo
        Type:   R_X86_64_NONE
Symbols:
  - Name: foo
  - Name: bar

## Check we report a warning when a REL relocation section can't be loaded.
# RUN: yaml2obj %s --docnum=5 -o %t6.o
# RUN: llvm-readobj %t6.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t6.o --check-prefix=LLVM-RELOC-WRONG-SIZE
# RUN: llvm-readobj %t6.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t6.o --check-prefix=LLVM-RELOC-WRONG-SIZE

# LLVM-RELOC-WRONG-SIZE:      warning: '[[FILE]]': unable to load relocations for SHT_LLVM_CALL_GRAPH_PROFILE section: section [index 2] has invalid sh_entsize: expected 16, but got 24
# LLVM-RELOC-WRONG-SIZE-NEXT: CGProfile [
# LLVM-RELOC-WRONG-SIZE-NEXT:  CGProfileEntry {
# LLVM-RELOC-WRONG-SIZE-NEXT:    Weight: 89
# LLVM-RELOC-WRONG-SIZE-NEXT:  }
# LLVM-RELOC-WRONG-SIZE-NEXT:  CGProfileEntry {
# LLVM-RELOC-WRONG-SIZE-NEXT:    Weight: 98
# LLVM-RELOC-WRONG-SIZE-NEXT:  }
# LLVM-RELOC-WRONG-SIZE-NEXT: ]

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
  Machine: EM_X86_64
Sections:
  - Name: .llvm.call-graph-profile
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Entries:
      - Weight: 89
      - Weight: 98
  - Name: .rel.llvm.call-graph-profile
    Type: SHT_REL
    Info: .llvm.call-graph-profile
    Relocations:
      - Symbol: foo
        Type:   R_X86_64_NONE
      - Offset: 0x0
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: foo
        Type:   R_X86_64_NONE
    EntSize: 24
Symbols:
  - Name: foo
  - Name: bar

## GNU strip may convert SHT_REL to SHT_RELA. Test we can handle SHT_RELA.
# RUN: yaml2obj %s --docnum=6 -o %t7.o
# RUN: llvm-readobj %t7.o --cg-profile | FileCheck %s --check-prefix=LLVM-RELA
# RUN: llvm-readelf %t7.o --cg-profile | FileCheck %s --check-prefix=GNU-RELA

# LLVM-RELA:      CGProfile [
# LLVM-RELA-NEXT:  CGProfileEntry {
# LLVM-RELA-NEXT:    From: foo (1)
# LLVM-RELA-NEXT:    To: bar (2)
# LLVM-RELA-NEXT:    Weight: 89
# LLVM-RELA-NEXT:  }
# LLVM-RELA-NEXT:  CGProfileEntry {
# LLVM-RELA-NEXT:    From: bar (2)
# LLVM-RELA-NEXT:    To: foo (1)
# LLVM-RELA-NEXT:    Weight: 98
# LLVM-RELA-NEXT:  }
# LLVM-RELA-NEXT: ]

# GNU-RELA: GNUStyle::printCGProfile not implemented

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
  Machine: EM_X86_64
Sections:
  - Name: .llvm.call-graph-profile
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Entries:
      - Weight: 89
      - Weight: 98
  - Name: .rela.llvm.call-graph-profile
    Type: SHT_RELA
    Info: .llvm.call-graph-profile
    Relocations:
      - Symbol: foo
        Type:   R_X86_64_NONE
      - Offset: 0x0
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: foo
        Type:   R_X86_64_NONE
Symbols:
  - Name: foo
  - Name: bar

## Check we report a warning when a RELA relocation section can't be loaded.
# RUN: yaml2obj %s --docnum=7 -o %t8.o
# RUN: llvm-readobj %t8.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t8.o --check-prefix=LLVM-RELOC-WRONG-SIZE-RELA
# RUN: llvm-readobj %t8.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t8.o --check-prefix=LLVM-RELOC-WRONG-SIZE-RELA

# LLVM-RELOC-WRONG-SIZE-RELA:      warning: '[[FILE]]': unable to load relocations for SHT_LLVM_CALL_GRAPH_PROFILE section: section [index 2] has invalid sh_entsize: expected 24, but got 16
# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: CGProfile [
# LLVM-RELOC-WRONG-SIZE-RELA-NEXT:  CGProfileEntry {
# LLVM-RELOC-WRONG-SIZE-RELA-NEXT:    Weight: 89
# LLVM-RELOC-WRONG-SIZE-RELA-NEXT:  }
# LLVM-RELOC-WRONG-SIZE-RELA-NEXT:  CGProfileEntry {
# LLVM-RELOC-WRONG-SIZE-RELA-NEXT:    Weight: 98
# LLVM-RELOC-WRONG-SIZE-RELA-NEXT:  }
# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: ]

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
  Machine: EM_X86_64
Sections:
  - Name: .llvm.call-graph-profile
    Type: SHT_LLVM_CALL_GRAPH_PROFILE
    Entries:
      - Weight: 89
      - Weight: 98
  - Name: .rela.llvm.call-graph-profile
    Type: SHT_RELA
    Info: .llvm.call-graph-profile
    Relocations:
      - Symbol: foo
        Type:   R_X86_64_NONE
      - Offset: 0x0
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: bar
        Type:   R_X86_64_NONE
      - Offset: 0x8
        Symbol: foo
        Type:   R_X86_64_NONE
    EntSize: 16
Symbols:
  - Name: foo
  - Name: bar

## Check that we report a warning when we fail to get a section associated with
## a relocation section.

# RUN: yaml2obj %s --docnum=8 -o %t9.o
# RUN: llvm-readobj %t9.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t9.o --check-prefix=LLVM-RELOC-NO-SECTIONS
# RUN: llvm-readobj %t9.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t9.o --check-prefix=LLVM-RELOC-NO-SECTIONS

# LLVM-RELOC-NO-SECTIONS: warning: '[[FILE]]': unable to get CG Profile section(s): SHT_RELA section with index 1: failed to get a relocated section: invalid section index: 255

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_DYN
  Machine: EM_X86_64
Sections:
  - Name: .rela.llvm.call-graph-profile
    Type: SHT_RELA
    Info: 0xFF