1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00
llvm-mirror/test/tools/obj2yaml/ELF/call-graph-profile-section.yaml
Alexander Yermolovich d12ae1eaf8 [LLD][LLVM] CG Graph profile using relocations
Currently when .llvm.call-graph-profile is created by llvm it explicitly encodes the symbol indices. This section is basically a black box for post processing tools. For example, if we run strip -s on the object files the symbol table changes, but indices in that section do not. In non-visible behavior indices point to wrong symbols. The visible behavior indices point outside of Symbol table: "invalid symbol index".

This patch changes the format by using R_*_NONE relocations to indicate the from/to symbols. The Frequency (Weight) will still be in the .llvm.call-graph-profile, but symbol information will be in relocation section. In LLD information from both sections is used to reconstruct call graph profile. Relocations themselves will never be applied.

With this approach post processing tools that handle relocations correctly work for this section also. Tools can add/remove symbols and as long as they handle relocation sections with this approach information stays correct.

Doing a quick experiment with clang-13.
The size went up from 107KB to 322KB, aggregate of all the input sections. Size of clang-13 binary is ~118MB. For users of -fprofile-use/-fprofile-sample-use the size of object files will go up slightly, it will not impact final binary size.

Reviewed By: jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D104080
2021-06-24 09:09:33 -07:00

150 lines
4.9 KiB
YAML

## Test how we dump SHT_LLVM_CALL_GRAPH_PROFILE sections for 32 and 64-bit targets.
## Test we use the "Entries" property when it is possible to dump values correctly.
# RUN: yaml2obj -D BITS=64 -D ENCODE=LSB %s -o %t.le64
# RUN: obj2yaml %t.le64 | FileCheck %s --check-prefix=BASIC
# RUN: yaml2obj -D BITS=64 -D ENCODE=MSB %s -o %t.be64
# RUN: obj2yaml %t.be64 | FileCheck %s --check-prefix=BASIC
# RUN: yaml2obj -D BITS=32 -D ENCODE=LSB %s -o %t.le32
# RUN: obj2yaml %t.le32 | FileCheck %s --check-prefix=BASIC
# RUN: yaml2obj -D BITS=32 -D ENCODE=MSB %s -o %t.be32
# RUN: obj2yaml %t.be32 | FileCheck %s --check-prefix=BASIC
# BASIC: Sections:
# BASIC-NEXT: - Name: .llvm.call-graph-profile
# BASIC-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# BASIC-NEXT: Link: .symtab
# BASIC-NEXT: Entries:
# BASIC-NEXT: - Weight: 89
# BASIC-NEXT: - Weight: 98
# BASIC-NEXT: Symbols:
--- !ELF
FileHeader:
Class: ELFCLASS[[BITS]]
Data: ELFDATA2[[ENCODE]]
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 how we handle broken cases.
# RUN: yaml2obj --docnum=2 %s -o %t.invalid
# RUN: obj2yaml %t.invalid | FileCheck %s --check-prefix=INVALID
# INVALID: --- !ELF
# INVALID-NEXT: FileHeader:
# INVALID-NEXT: Class: ELFCLASS32
# INVALID-NEXT: Data: ELFDATA2MSB
# INVALID-NEXT: Type: ET_DYN
# INVALID-NEXT: Sections:
# INVALID-NEXT: - Name: .empty
# INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT: Link: .symtab
# INVALID-NEXT: - Name: .multiple.8.valid
# INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT: Link: .symtab
# INVALID-NEXT: Entries:
# INVALID-NEXT: Weight: 3
# INVALID-NEXT: - Name: .non.multiple.8
# INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT: Link: .symtab
# INVALID-NEXT: Content: '000000000000000300'
# INVALID-NEXT: - Name: .multiple.8.invalid
# INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT: Link: .symtab
# INVALID-NEXT: Content: 008899AABBCCDDEEFF
# INVALID-NEXT: - Name: .link.to.symtable
# INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT: Link: .symtab
# INVALID-NEXT: Entries:
# INVALID-NEXT: - Weight: 0
# INVALID-NEXT: - Name: .link.to.non.symtable.1
# INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT: Entries:
# INVALID-NEXT: - Weight: 0
# INVALID-NEXT: - Name: .link.to.non.symtable.2
# INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT: Link: .empty
# INVALID-NEXT: Entries:
# INVALID-NEXT: - Weight: 0
# INVALID-NEXT: - Name: .zero.entry.size
# INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT: Link: .symtab
# INVALID-NEXT: EntSize: 0x0
# INVALID-NEXT: Entries:
# INVALID-NEXT: - Weight: 0
# INVALID-NEXT: - Name: .invalid.entry.size
# INVALID-NEXT: Type: SHT_LLVM_CALL_GRAPH_PROFILE
# INVALID-NEXT: Link: .symtab
# INVALID-NEXT: EntSize: 0x1
# INVALID-NEXT: Entries:
# INVALID-NEXT: - Weight: 0
# INVALID-NEXT: Symbols:
# INVALID-NEXT: - Name: foo
# INVALID-NEXT: - Name: bar
--- !ELF
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2MSB
Type: ET_DYN
Sections:
## Case 1: Content is empty.
- Name: .empty
Type: SHT_LLVM_CALL_GRAPH_PROFILE
## Case 2: Check that we use the "Entries" property to dump the data when it
## has a size that is a multiple of 16 and is valid (it is possible to match
## symbol indexes to symbols), but fallback to dumping the whole section
## using the "Content" property otherwise.
## TODO: Teach yaml2obj to accept 'Size' key for SHT_LLVM_CALL_GRAPH_PROFILE
## sections and use Entries for cases below.
- Name: .multiple.8.valid
Type: SHT_LLVM_CALL_GRAPH_PROFILE
Content: "0000000000000003"
- Name: .non.multiple.8
Type: SHT_LLVM_CALL_GRAPH_PROFILE
Content: "000000000000000300"
- Name: .multiple.8.invalid
Type: SHT_LLVM_CALL_GRAPH_PROFILE
Content: "008899AABBCCDDEEFF"
## Case 4: Check we use the "Content" property when a linked section
## is not a symbol table.
- Name: .link.to.symtable
Type: SHT_LLVM_CALL_GRAPH_PROFILE
Entries:
- Weight: 0
- Name: .link.to.non.symtable.1
Type: SHT_LLVM_CALL_GRAPH_PROFILE
Link: 0
Entries:
- Weight: 0
- Name: .link.to.non.symtable.2
Type: SHT_LLVM_CALL_GRAPH_PROFILE
Link: 1
Entries:
- Weight: 0
## Case 5: Check we can dump a section that has a sh_entsize that is not a multiple of 16.
## Check that in these cases we print the "EntSize" key.
- Name: .zero.entry.size
Type: SHT_LLVM_CALL_GRAPH_PROFILE
EntSize: 0
Entries:
- Weight: 0
- Name: .invalid.entry.size
Type: SHT_LLVM_CALL_GRAPH_PROFILE
EntSize: 1
Entries:
- Weight: 0
Symbols:
- Name: foo
- Name: bar