aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MachObjectWriter.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2025-07-20 12:52:36 -0700
committerFangrui Song <i@maskray.me>2025-07-20 12:52:37 -0700
commitca006eeeedddd4e38c8f93e69a3dcb1fc554d453 (patch)
tree361ddc76ba3f6ea1e7604da28755c7e131b42002 /llvm/lib/MC/MachObjectWriter.cpp
parentef4e4a0084753ed76c61f9f0d1b510fd12715c78 (diff)
downloadllvm-ca006eeeedddd4e38c8f93e69a3dcb1fc554d453.zip
llvm-ca006eeeedddd4e38c8f93e69a3dcb1fc554d453.tar.gz
llvm-ca006eeeedddd4e38c8f93e69a3dcb1fc554d453.tar.bz2
MCFragment: Remove clearContents and uses of non-streaming doneAppending
Make the fixed-size part of MCFragment append-only to support allocating content as trailing data. The `doneAppending` API is reserved by MCStreamer API before finish and should not be used by the addrsig and call-graph-profile features.
Diffstat (limited to 'llvm/lib/MC/MachObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/MachObjectWriter.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 3298eef..48d2fc6 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -797,11 +797,8 @@ uint64_t MachObjectWriter::writeObject() {
UndefinedSymbolData);
if (!CGProfile.empty()) {
- MCSection *CGProfileSection = getContext().getMachOSection(
- "__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
- auto &Frag = *CGProfileSection->begin();
- Frag.clearContents();
- raw_svector_ostream OS(Frag.getContentsForAppending());
+ SmallString<0> Content;
+ raw_svector_ostream OS(Content);
for (const MCObjectWriter::CGProfileEntry &CGPE : CGProfile) {
uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
uint32_t ToIndex = CGPE.To->getSymbol().getIndex();
@@ -809,7 +806,9 @@ uint64_t MachObjectWriter::writeObject() {
support::endian::write(OS, ToIndex, W.Endian);
support::endian::write(OS, CGPE.Count, W.Endian);
}
- Frag.doneAppending();
+ MCSection *Sec = getContext().getMachOSection("__LLVM", "__cg_profile", 0,
+ SectionKind::getMetadata());
+ llvm::copy(OS.str(), Sec->curFragList()->Head->getContents().data());
}
unsigned NumSections = Asm.end() - Asm.begin();