aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorAlexander Yermolovich <ayermolo@fb.com>2021-06-24 08:02:45 -0700
committerWenlei He <aktoon@gmail.com>2021-06-24 09:09:33 -0700
commita224c5199b327ed0efcdcd87b6dbf950cf4d9ee1 (patch)
treed300c79f453996ce5dda9c57bfd27dd8acbedc05 /llvm/lib/MC/ELFObjectWriter.cpp
parent929189a4995ece3162adced7a7d9be8e17dc4079 (diff)
downloadllvm-a224c5199b327ed0efcdcd87b6dbf950cf4d9ee1.zip
llvm-a224c5199b327ed0efcdcd87b6dbf950cf4d9ee1.tar.gz
llvm-a224c5199b327ed0efcdcd87b6dbf950cf4d9ee1.tar.bz2
[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
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp25
1 files changed, 5 insertions, 20 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 534c263..fec77d2 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1127,14 +1127,6 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
OWriter.TargetObjectWriter->addTargetSectionFlags(Ctx, Section);
}
- MCSectionELF *CGProfileSection = nullptr;
- if (!Asm.CGProfile.empty()) {
- CGProfileSection = Ctx.getELFSection(".llvm.call-graph-profile",
- ELF::SHT_LLVM_CALL_GRAPH_PROFILE,
- ELF::SHF_EXCLUDE, 16);
- SectionIndexMap[CGProfileSection] = addToSectionTable(CGProfileSection);
- }
-
for (MCSectionELF *Group : Groups) {
// Remember the offset into the file for this section.
const uint64_t SecStart = align(Group->getAlignment());
@@ -1186,17 +1178,6 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
}
}
- if (CGProfileSection) {
- uint64_t SecStart = W.OS.tell();
- for (const MCAssembler::CGProfileEntry &CGPE : Asm.CGProfile) {
- W.write<uint32_t>(CGPE.From->getSymbol().getIndex());
- W.write<uint32_t>(CGPE.To->getSymbol().getIndex());
- W.write<uint64_t>(CGPE.Count);
- }
- uint64_t SecEnd = W.OS.tell();
- SectionOffsets[CGProfileSection] = std::make_pair(SecStart, SecEnd);
- }
-
{
uint64_t SecStart = W.OS.tell();
StrTabBuilder.write(W.OS);
@@ -1471,7 +1452,11 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
return;
unsigned Type = TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);
- bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type);
+ const auto *Parent = cast<MCSectionELF>(Fragment->getParent());
+ // Emiting relocation with sybmol for CG Profile to help with --cg-profile.
+ bool RelocateWithSymbol =
+ shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type) ||
+ (Parent->getType() == ELF::SHT_LLVM_CALL_GRAPH_PROFILE);
uint64_t Addend = 0;
FixedValue = !RelocateWithSymbol && SymA && !SymA->isUndefined()