aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MachObjectWriter.cpp
diff options
context:
space:
mode:
authorLeonard Grey <lgrey@chromium.org>2022-01-12 09:12:53 -0500
committerNico Weber <thakis@chromium.org>2022-01-12 09:22:26 -0500
commit0f853930042f11f5ee489bd56b48a227d057c37e (patch)
tree8c57e4e20fe58a233d37c3186beb3ead4aa899bf /llvm/lib/MC/MachObjectWriter.cpp
parent732ad8ea62edc403727af57537b5d83dcfa937aa (diff)
downloadllvm-0f853930042f11f5ee489bd56b48a227d057c37e.zip
llvm-0f853930042f11f5ee489bd56b48a227d057c37e.tar.gz
llvm-0f853930042f11f5ee489bd56b48a227d057c37e.tar.bz2
[MachO] Port call graph profile section and directive
This ports the `.cg_profile` assembly directive and call graph profile section generation to MachO from COFF/ELF. Due to MachO section naming rules, the section is called `__LLVM,__cg_profile` rather than `.llvm.call-graph-profile` as in COFF/ELF. Support for llvm-readobj is included to facilitate testing. Corresponding LLD change is D112164 Differential Revision: https://reviews.llvm.org/D112160
Diffstat (limited to 'llvm/lib/MC/MachObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/MachObjectWriter.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 16941b1..5105c5d 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -759,6 +759,23 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm,
computeSymbolTable(Asm, LocalSymbolData, ExternalSymbolData,
UndefinedSymbolData);
+ if (!Asm.CGProfile.empty()) {
+ MCSection *CGProfileSection = Asm.getContext().getMachOSection(
+ "__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
+ MCDataFragment *Frag = dyn_cast_or_null<MCDataFragment>(
+ &*CGProfileSection->getFragmentList().begin());
+ assert(Frag && "call graph profile section not reserved");
+ Frag->getContents().set_size(0);
+ raw_svector_ostream OS(Frag->getContents());
+ for (const MCAssembler::CGProfileEntry &CGPE : Asm.CGProfile) {
+ uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
+ uint32_t ToIndex = CGPE.To->getSymbol().getIndex();
+ support::endian::write(OS, FromIndex, W.Endian);
+ support::endian::write(OS, ToIndex, W.Endian);
+ support::endian::write(OS, CGPE.Count, W.Endian);
+ }
+ }
+
unsigned NumSections = Asm.size();
const MCAssembler::VersionInfoType &VersionInfo =
Layout.getAssembler().getVersionInfo();