373 lines · plain
1## This test checks how we handle the --elf-cg-profile option.2 3# RUN: yaml2obj %s -o %t.o4# RUN: llvm-readobj %t.o --cg-profile | FileCheck %s --check-prefix=LLVM5# RUN: llvm-readelf %t.o --cg-profile | FileCheck %s --check-prefix=GNU6# RUN: llvm-readobj %t.o --elf-cg-profile | FileCheck %s --check-prefix=LLVM7# RUN: llvm-readelf %t.o --elf-cg-profile | FileCheck %s --check-prefix=GNU8 9# LLVM: CGProfile [10# LLVM-NEXT: CGProfileEntry {11# LLVM-NEXT: From: foo (1)12# LLVM-NEXT: To: bar (2)13# LLVM-NEXT: Weight: 8914# LLVM-NEXT: }15# LLVM-NEXT: CGProfileEntry {16# LLVM-NEXT: From: bar (2)17# LLVM-NEXT: To: foo (1)18# LLVM-NEXT: Weight: 9819# LLVM-NEXT: }20# LLVM-NEXT: ]21 22# GNU: GNUStyle::printCGProfile not implemented23 24--- !ELF25FileHeader:26 Class: ELFCLASS6427 Data: ELFDATA2LSB28 Type: ET_DYN29 Machine: EM_X86_6430Sections:31 - Name: .llvm.call-graph-profile32 Type: SHT_LLVM_CALL_GRAPH_PROFILE33 Entries:34 - Weight: 8935 - Weight: 9836 EntSize: [[ENTSIZE=<none>]]37 - Name: .rel.llvm.call-graph-profile38 Type: SHT_REL39 Info: .llvm.call-graph-profile40 Relocations:41 - Symbol: foo42 Type: R_X86_64_NONE43 - Offset: 0x044 Symbol: bar45 Type: R_X86_64_NONE46 - Offset: 0x847 Symbol: bar48 Type: R_X86_64_NONE49 - Offset: 0x850 Symbol: foo51 Type: R_X86_64_NONE52Symbols:53 - Name: foo54 - Name: bar55 56## Check we report a warning when unable to get the content of the SHT_LLVM_CALL_GRAPH_PROFILE section.57# RUN: yaml2obj %s -DENTSIZE=0xF -o %t2.o58# RUN: llvm-readobj %t2.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t2.o --check-prefix=LLVM-ERR59# RUN: llvm-readelf %t2.o --cg-profile | FileCheck %s --check-prefix=GNU60 61# 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 1562 63## Check we report a warning when unable to dump a name of a symbol.64# RUN: yaml2obj %s --docnum=2 -o %t3.o65# RUN: llvm-readobj %t3.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t3.o --check-prefix=LLVM-BROKEN-SYM66# RUN: llvm-readelf %t3.o --cg-profile | FileCheck %s --check-prefix=GNU67 68# LLVM-BROKEN-SYM: CGProfile [69# LLVM-BROKEN-SYM-NEXT: CGProfileEntry {70# LLVM-BROKEN-SYM-NEXT: From: A (1)71# 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 0x572# LLVM-BROKEN-SYM-NEXT: To: <?> (2)73# LLVM-BROKEN-SYM-NEXT: Weight: 1074# LLVM-BROKEN-SYM-NEXT: }75# LLVM-BROKEN-SYM-NEXT: CGProfileEntry {76# LLVM-BROKEN-SYM-NEXT: From: <?> (2)77# LLVM-BROKEN-SYM-NEXT: To: B (3)78# LLVM-BROKEN-SYM-NEXT: Weight: 2079# LLVM-BROKEN-SYM-NEXT: }80# LLVM-BROKEN-SYM-NEXT: CGProfileEntry {81# LLVM-BROKEN-SYM-NEXT: From: (0)82# 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)83# LLVM-BROKEN-SYM-NEXT: To: <?> (4)84# LLVM-BROKEN-SYM-NEXT: Weight: 2085# LLVM-BROKEN-SYM-NEXT: }86# LLVM-BROKEN-SYM-NEXT: ]87 88--- !ELF89FileHeader:90 Class: ELFCLASS6491 Data: ELFDATA2LSB92 Type: ET_DYN93 Machine: EM_X86_6494Sections:95 - Name: .llvm.call-graph-profile96 Type: SHT_LLVM_CALL_GRAPH_PROFILE97 Entries:98 - Weight: 1099 - Weight: 20100 - Weight: 20101 - Name: .rel.llvm.call-graph-profile102 Type: SHT_REL103 Info: .llvm.call-graph-profile104 Relocations:105 - Symbol: 1106 Type: R_X86_64_NONE107 - Offset: 0x0108 Symbol: 2109 Type: R_X86_64_NONE110 - Offset: 0x8111 Symbol: 2112 Type: R_X86_64_NONE113 - Offset: 0x8114 Symbol: 3115 Type: R_X86_64_NONE116 - Offset: 0x10117 Symbol: 0x0 ## Null symbol.118 Type: R_X86_64_NONE119 - Offset: 0x10120 Symbol: 0x4 ## This index goes past the end of the symbol table.121 Type: R_X86_64_NONE122 - Name: .strtab123 Type: SHT_STRTAB124 Content: "0041004200" ## '\0', 'A', '\0', 'B', '\0'125Symbols:126 - StName: 1 ## 'A'127 - StName: 0xFF ## An arbitrary currupted index in the string table.128 - StName: 3 ## 'B'129 130## Check we report a warning when a relocation section is not present.131# RUN: yaml2obj %s --docnum=3 -o %t4.o132# RUN: llvm-readobj %t4.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t4.o --check-prefix=LLVM-NO-RELOC133# RUN: llvm-readobj %t4.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t4.o --check-prefix=LLVM-NO-RELOC134 135# LLVM-NO-RELOC: warning: '[[FILE]]': relocation section for a call graph section doesn't exist136# LLVM-NO-RELOC-NEXT: CGProfile [137# LLVM-NO-RELOC-NEXT: CGProfileEntry {138# LLVM-NO-RELOC-NEXT: Weight: 89139# LLVM-NO-RELOC-NEXT: }140# LLVM-NO-RELOC-NEXT: CGProfileEntry {141# LLVM-NO-RELOC-NEXT: Weight: 98142# LLVM-NO-RELOC-NEXT: }143# LLVM-NO-RELOC-NEXT: ]144 145--- !ELF146FileHeader:147 Class: ELFCLASS64148 Data: ELFDATA2LSB149 Type: ET_DYN150Sections:151 - Name: .llvm.call-graph-profile152 Type: SHT_LLVM_CALL_GRAPH_PROFILE153 Entries:154 - Weight: 89155 - Weight: 98156Symbols:157 - Name: foo158 - Name: bar159 160## Check we report a warning when the number of relocation section entries does not match the number of call graph entries.161# RUN: yaml2obj %s --docnum=4 -o %t5.o162# RUN: llvm-readobj %t5.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t5.o --check-prefix=LLVM-RELOC-GRAPH-NOT-MATCH163# RUN: llvm-readobj %t5.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t5.o --check-prefix=LLVM-RELOC-GRAPH-NOT-MATCH164 165# LLVM-RELOC-GRAPH-NOT-MATCH: warning: '[[FILE]]': number of from/to pairs does not match number of frequencies166# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: CGProfile [167# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: CGProfileEntry {168# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: Weight: 89169# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: }170# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: CGProfileEntry {171# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: Weight: 98172# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: }173# LLVM-RELOC-GRAPH-NOT-MATCH-NEXT: ]174 175--- !ELF176FileHeader:177 Class: ELFCLASS64178 Data: ELFDATA2LSB179 Type: ET_DYN180 Machine: EM_X86_64181Sections:182 - Name: .llvm.call-graph-profile183 Type: SHT_LLVM_CALL_GRAPH_PROFILE184 Entries:185 - Weight: 89186 - Weight: 98187 - Name: .rel.llvm.call-graph-profile188 Type: SHT_REL189 Info: .llvm.call-graph-profile190 Relocations:191 - Symbol: foo192 Type: R_X86_64_NONE193 - Offset: 0x0194 Symbol: bar195 Type: R_X86_64_NONE196 - Offset: 0x8197 Symbol: bar198 Type: R_X86_64_NONE199 - Offset: 0x8200 Symbol: foo201 Type: R_X86_64_NONE202 - Offset: 0x10203 Symbol: foo204 Type: R_X86_64_NONE205Symbols:206 - Name: foo207 - Name: bar208 209## Check we report a warning when a REL relocation section can't be loaded.210# RUN: yaml2obj %s --docnum=5 -o %t6.o211# RUN: llvm-readobj %t6.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t6.o --check-prefix=LLVM-RELOC-WRONG-SIZE212# RUN: llvm-readobj %t6.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t6.o --check-prefix=LLVM-RELOC-WRONG-SIZE213 214# 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 24215# LLVM-RELOC-WRONG-SIZE-NEXT: CGProfile [216# LLVM-RELOC-WRONG-SIZE-NEXT: CGProfileEntry {217# LLVM-RELOC-WRONG-SIZE-NEXT: Weight: 89218# LLVM-RELOC-WRONG-SIZE-NEXT: }219# LLVM-RELOC-WRONG-SIZE-NEXT: CGProfileEntry {220# LLVM-RELOC-WRONG-SIZE-NEXT: Weight: 98221# LLVM-RELOC-WRONG-SIZE-NEXT: }222# LLVM-RELOC-WRONG-SIZE-NEXT: ]223 224--- !ELF225FileHeader:226 Class: ELFCLASS64227 Data: ELFDATA2LSB228 Type: ET_DYN229 Machine: EM_X86_64230Sections:231 - Name: .llvm.call-graph-profile232 Type: SHT_LLVM_CALL_GRAPH_PROFILE233 Entries:234 - Weight: 89235 - Weight: 98236 - Name: .rel.llvm.call-graph-profile237 Type: SHT_REL238 Info: .llvm.call-graph-profile239 Relocations:240 - Symbol: foo241 Type: R_X86_64_NONE242 - Offset: 0x0243 Symbol: bar244 Type: R_X86_64_NONE245 - Offset: 0x8246 Symbol: bar247 Type: R_X86_64_NONE248 - Offset: 0x8249 Symbol: foo250 Type: R_X86_64_NONE251 EntSize: 24252Symbols:253 - Name: foo254 - Name: bar255 256## GNU strip may convert SHT_REL to SHT_RELA. Test we can handle SHT_RELA.257# RUN: yaml2obj %s --docnum=6 -o %t7.o258# RUN: llvm-readobj %t7.o --cg-profile | FileCheck %s --check-prefix=LLVM-RELA259# RUN: llvm-readelf %t7.o --cg-profile | FileCheck %s --check-prefix=GNU-RELA260 261# LLVM-RELA: CGProfile [262# LLVM-RELA-NEXT: CGProfileEntry {263# LLVM-RELA-NEXT: From: foo (1)264# LLVM-RELA-NEXT: To: bar (2)265# LLVM-RELA-NEXT: Weight: 89266# LLVM-RELA-NEXT: }267# LLVM-RELA-NEXT: CGProfileEntry {268# LLVM-RELA-NEXT: From: bar (2)269# LLVM-RELA-NEXT: To: foo (1)270# LLVM-RELA-NEXT: Weight: 98271# LLVM-RELA-NEXT: }272# LLVM-RELA-NEXT: ]273 274# GNU-RELA: GNUStyle::printCGProfile not implemented275 276--- !ELF277FileHeader:278 Class: ELFCLASS64279 Data: ELFDATA2LSB280 Type: ET_DYN281 Machine: EM_X86_64282Sections:283 - Name: .llvm.call-graph-profile284 Type: SHT_LLVM_CALL_GRAPH_PROFILE285 Entries:286 - Weight: 89287 - Weight: 98288 - Name: .rela.llvm.call-graph-profile289 Type: SHT_RELA290 Info: .llvm.call-graph-profile291 Relocations:292 - Symbol: foo293 Type: R_X86_64_NONE294 - Offset: 0x0295 Symbol: bar296 Type: R_X86_64_NONE297 - Offset: 0x8298 Symbol: bar299 Type: R_X86_64_NONE300 - Offset: 0x8301 Symbol: foo302 Type: R_X86_64_NONE303Symbols:304 - Name: foo305 - Name: bar306 307## Check we report a warning when a RELA relocation section can't be loaded.308# RUN: yaml2obj %s --docnum=7 -o %t8.o309# RUN: llvm-readobj %t8.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t8.o --check-prefix=LLVM-RELOC-WRONG-SIZE-RELA310# RUN: llvm-readobj %t8.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t8.o --check-prefix=LLVM-RELOC-WRONG-SIZE-RELA311 312# 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 16313# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: CGProfile [314# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: CGProfileEntry {315# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: Weight: 89316# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: }317# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: CGProfileEntry {318# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: Weight: 98319# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: }320# LLVM-RELOC-WRONG-SIZE-RELA-NEXT: ]321 322--- !ELF323FileHeader:324 Class: ELFCLASS64325 Data: ELFDATA2LSB326 Type: ET_DYN327 Machine: EM_X86_64328Sections:329 - Name: .llvm.call-graph-profile330 Type: SHT_LLVM_CALL_GRAPH_PROFILE331 Entries:332 - Weight: 89333 - Weight: 98334 - Name: .rela.llvm.call-graph-profile335 Type: SHT_RELA336 Info: .llvm.call-graph-profile337 Relocations:338 - Symbol: foo339 Type: R_X86_64_NONE340 - Offset: 0x0341 Symbol: bar342 Type: R_X86_64_NONE343 - Offset: 0x8344 Symbol: bar345 Type: R_X86_64_NONE346 - Offset: 0x8347 Symbol: foo348 Type: R_X86_64_NONE349 EntSize: 16350Symbols:351 - Name: foo352 - Name: bar353 354## Check that we report a warning when we fail to get a section associated with355## a relocation section.356 357# RUN: yaml2obj %s --docnum=8 -o %t9.o358# RUN: llvm-readobj %t9.o --cg-profile 2>&1 | FileCheck %s -DFILE=%t9.o --check-prefix=LLVM-RELOC-NO-SECTIONS359# RUN: llvm-readobj %t9.o --elf-cg-profile 2>&1 | FileCheck %s -DFILE=%t9.o --check-prefix=LLVM-RELOC-NO-SECTIONS360 361# 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: 255362 363--- !ELF364FileHeader:365 Class: ELFCLASS64366 Data: ELFDATA2LSB367 Type: ET_DYN368 Machine: EM_X86_64369Sections:370 - Name: .rela.llvm.call-graph-profile371 Type: SHT_RELA372 Info: 0xFF373