1## This test checks how we handle the --elf-cg-profile option.
2
3# RUN: yaml2obj %s -o %t.o
4# RUN: llvm-readobj %t.o --cg-profile | FileCheck %s --check-prefix=LLVM
5# RUN: llvm-readelf %t.o --cg-profile | FileCheck %s --check-prefix=GNU
6# RUN: llvm-readobj %t.o --elf-cg-profile | FileCheck %s --check-prefix=LLVM
7# RUN: llvm-readelf %t.o --elf-cg-profile | FileCheck %s --check-prefix=GNU
8
9# LLVM:      CGProfile [
10# LLVM-NEXT:  CGProfileEntry {
11# LLVM-NEXT:    From: foo (1)
12# LLVM-NEXT:    To: bar (2)
13# LLVM-NEXT:    Weight: 89
14# LLVM-NEXT:  }
15# LLVM-NEXT:  CGProfileEntry {
16# LLVM-NEXT:    From: bar (2)
17# LLVM-NEXT:    To: foo (1)
18# LLVM-NEXT:    Weight: 98
19# LLVM-NEXT:  }
20# LLVM-NEXT: ]
21
22# GNU: GNUStyle::printCGProfile not implemented
23
24--- !ELF
25FileHeader:
26  Class: ELFCLASS64
27  Data:  ELFDATA2LSB
28  Type:  ET_DYN
29Sections:
30  - Name: .llvm.call-graph-profile
31    Type: SHT_LLVM_CALL_GRAPH_PROFILE
32    Entries:
33      - From:   foo
34        To:     bar
35        Weight: 89
36      - From:   bar
37        To:     foo
38        Weight: 98
39    EntSize: [[ENTSIZE=<none>]]
40Symbols:
41  - Name: foo
42  - Name: bar
43
44## Check we report a warning when unable to get the content of the SHT_LLVM_CALL_GRAPH_PROFILE section.
45# RUN: yaml2obj %s -DENTSIZE=0xF -o %t2.o
46# RUN: llvm-readobj %t2.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t2.o --check-prefix=LLVM-ERR
47# RUN: llvm-readelf %t2.o --cg-profile | FileCheck %s --check-prefix=GNU
48
49# LLVM-ERR:      CGProfile [
50# LLVM-ERR-NEXT: warning: '[[FILE]]': unable to dump the SHT_LLVM_CALL_GRAPH_PROFILE section: section [index 1] has an invalid sh_entsize: 15
51# LLVM-ERR-NEXT: ]
52
53## Check we report a warning when unable to dump a name of a symbol.
54# RUN: yaml2obj %s --docnum=2 -o %t3.o
55# RUN: llvm-readobj %t3.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t3.o --check-prefix=LLVM-BROKEN-SYM
56# RUN: llvm-readelf %t3.o --cg-profile | FileCheck %s --check-prefix=GNU
57
58# LLVM-BROKEN-SYM:      CGProfile [
59# LLVM-BROKEN-SYM-NEXT:   CGProfileEntry {
60# LLVM-BROKEN-SYM-NEXT:     From: A (1)
61# 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
62# LLVM-BROKEN-SYM-NEXT:     To: <?> (2)
63# LLVM-BROKEN-SYM-NEXT:     Weight: 10
64# LLVM-BROKEN-SYM-NEXT:   }
65# LLVM-BROKEN-SYM-NEXT:   CGProfileEntry {
66# LLVM-BROKEN-SYM-NEXT:     From: <?> (2)
67# LLVM-BROKEN-SYM-NEXT:     To: B (3)
68# LLVM-BROKEN-SYM-NEXT:     Weight: 20
69# LLVM-BROKEN-SYM-NEXT:   }
70# LLVM-BROKEN-SYM-NEXT:   CGProfileEntry {
71# LLVM-BROKEN-SYM-NEXT:     From: (0)
72# LLVM-BROKEN-SYM-NEXT: warning: '[[FILE]]': unable to read the name of symbol with index 4: unable to get symbol from section [index 3]: invalid symbol index (4)
73# LLVM-BROKEN-SYM-NEXT:     To: <?> (4)
74# LLVM-BROKEN-SYM-NEXT:     Weight: 20
75# LLVM-BROKEN-SYM-NEXT:   }
76# LLVM-BROKEN-SYM-NEXT: ]
77
78--- !ELF
79FileHeader:
80  Class: ELFCLASS64
81  Data:  ELFDATA2LSB
82  Type:  ET_DYN
83Sections:
84  - Name: .llvm.call-graph-profile
85    Type: SHT_LLVM_CALL_GRAPH_PROFILE
86    Entries:
87      - From:   1
88        To:     2
89        Weight: 10
90      - From:   2
91        To:     3
92        Weight: 20
93      - From:   0x0 ## Null symbol.
94        To:     0x4 ## This index goes past the end of the symbol table.
95        Weight: 20
96  - Name:    .strtab
97    Type:    SHT_STRTAB
98    Content: "0041004200" ## '\0', 'A', '\0', 'B', '\0'
99Symbols:
100  - StName: 1    ## 'A'
101  - StName: 0xFF ## An arbitrary currupted index in the string table.
102  - StName: 3    ## 'B'
103