Skip to content

Commit 2bebbe1

Browse files
committed
MCFragment: Migrate away from appendContents
The fixed-size content of the MCFragment object will be stored as trailing data (#150846). Any post-assembler-layout adjustments must target the variable-size tail.
1 parent 217f9e5 commit 2bebbe1

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class MCObjectStreamer : public MCStreamer {
8787
// Add a new fragment to the current section without a variable-size tail.
8888
void newFragment();
8989

90+
void appendContents(ArrayRef<char> Contents);
9091
void appendContents(size_t Num, char Elt);
9192
void addFixup(const MCExpr *Value, MCFixupKind Kind);
9293

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ void MCMachOStreamer::finalizeCGProfile() {
484484
// For each entry, reserve space for 2 32-bit indices and a 64-bit count.
485485
size_t SectionBytes =
486486
W.getCGProfile().size() * (2 * sizeof(uint32_t) + sizeof(uint64_t));
487-
(*CGProfileSection->begin()).appendContents(SectionBytes, 0);
487+
(*CGProfileSection->begin())
488+
.setVarContents(std::vector<char>(SectionBytes, 0));
488489
}
489490

490491
MCStreamer *llvm::createMachOStreamer(MCContext &Context,
@@ -520,5 +521,6 @@ void MCMachOStreamer::createAddrSigSection() {
520521
// (instead of emitting a zero-sized section) so these relocations are
521522
// technically valid, even though we don't expect these relocations to
522523
// actually be applied by the linker.
523-
Frag->appendContents(8, 0);
524+
constexpr char zero[8] = {};
525+
Frag->setVarContents(zero);
524526
}

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ void MCObjectStreamer::insert(MCFragment *F) {
5757
newFragment();
5858
}
5959

60+
void MCObjectStreamer::appendContents(ArrayRef<char> Contents) {
61+
CurFrag->appendContents(Contents);
62+
}
63+
6064
void MCObjectStreamer::appendContents(size_t Num, char Elt) {
6165
CurFrag->appendContents(Num, Elt);
6266
}
@@ -538,8 +542,7 @@ void MCObjectStreamer::emitCVFileChecksumOffsetDirective(unsigned FileNo) {
538542

539543
void MCObjectStreamer::emitBytes(StringRef Data) {
540544
MCDwarfLineEntry::make(this, getCurrentSectionOnly());
541-
MCFragment *DF = getCurrentFragment();
542-
DF->appendContents(ArrayRef(Data.data(), Data.size()));
545+
appendContents(ArrayRef(Data.data(), Data.size()));
543546
}
544547

545548
void MCObjectStreamer::emitValueToAlignment(Align Alignment, int64_t Fill,

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ uint64_t MachObjectWriter::writeObject() {
806806
}
807807
MCSection *Sec = getContext().getMachOSection("__LLVM", "__cg_profile", 0,
808808
SectionKind::getMetadata());
809-
llvm::copy(OS.str(), Sec->curFragList()->Head->getContents().data());
809+
llvm::copy(OS.str(), Sec->curFragList()->Head->getVarContents().data());
810810
}
811811

812812
unsigned NumSections = Asm.end() - Asm.begin();

0 commit comments

Comments
 (0)