Skip to content

Commit ac4fc72

Browse files
MaskRaycachemeifyoucan
authored andcommitted
MCFragment: Remove setContents/setFixups
Make the fixed-size part of MCFragment append-only to support allocating content as trailing data. Update CodeView callers to use setVarContents instead of setContents. Remove unused setFixups.
1 parent a18008e commit ac4fc72

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

llvm/include/llvm/MC/MCSection.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,16 @@ class MCFragment {
232232
/// FT_Relaxable, x86-specific
233233
bool AllowAutoPadding : 1;
234234

235+
// Track content and fixups for the fixed-size part as fragments are
236+
// appended to the section. The content remains immutable, except when
237+
// modified by applyFixup.
235238
uint32_t ContentStart = 0;
236239
uint32_t ContentEnd = 0;
237240
uint32_t FixupStart = 0;
238241
uint32_t FixupEnd = 0;
239242

243+
// Track content and fixups for the optional variable-size tail part,
244+
// typically modified during relaxation.
240245
uint32_t VarContentStart = 0;
241246
uint32_t VarContentEnd = 0;
242247
uint32_t VarFixupStart = 0;
@@ -365,7 +370,6 @@ class MCFragment {
365370
getContentsForAppending().append(Num, Elt);
366371
doneAppending();
367372
}
368-
LLVM_ABI void setContents(ArrayRef<char> Contents);
369373
MutableArrayRef<char> getContents() {
370374
return MutableArrayRef(getParent()->ContentStorage)
371375
.slice(ContentStart, ContentEnd - ContentStart);
@@ -397,7 +401,6 @@ class MCFragment {
397401
void clearFixups() { FixupEnd = FixupStart; }
398402
LLVM_ABI void addFixup(MCFixup Fixup);
399403
LLVM_ABI void appendFixups(ArrayRef<MCFixup> Fixups);
400-
LLVM_ABI void setFixups(ArrayRef<MCFixup> Fixups);
401404
MutableArrayRef<MCFixup> getFixups() {
402405
return MutableArrayRef(getParent()->FixupStorage)
403406
.slice(FixupStart, FixupEnd - FixupStart);

llvm/lib/MC/MCAssembler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -923,15 +923,15 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCFragment &F) {
923923
}
924924

925925
bool MCAssembler::relaxCVInlineLineTable(MCCVInlineLineTableFragment &F) {
926-
unsigned OldSize = F.getContents().size();
926+
unsigned OldSize = F.getVarContents().size();
927927
getContext().getCVContext().encodeInlineLineTable(*this, F);
928-
return OldSize != F.getContents().size();
928+
return OldSize != F.getVarContents().size();
929929
}
930930

931931
bool MCAssembler::relaxCVDefRange(MCCVDefRangeFragment &F) {
932-
unsigned OldSize = F.getContents().size();
932+
unsigned OldSize = F.getVarContents().size();
933933
getContext().getCVContext().encodeDefRange(*this, F);
934-
return OldSize != F.getContents().size();
934+
return OldSize != F.getVarContents().size();
935935
}
936936

937937
bool MCAssembler::relaxFill(MCFillFragment &F) {

llvm/lib/MC/MCCodeView.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ using namespace llvm;
2626
using namespace llvm::codeview;
2727

2828
void CodeViewContext::finish() {
29-
if (StrTabFragment)
30-
StrTabFragment->setContents(StrTab);
29+
if (!StrTabFragment)
30+
return;
31+
assert(StrTabFragment->getKind() == MCFragment::FT_Data);
32+
StrTabFragment->setVarContents(StrTab);
3133
}
3234

3335
/// This is a valid number for use with .cv_loc if we've already seen a .cv_file
@@ -168,6 +170,7 @@ void CodeViewContext::emitStringTable(MCObjectStreamer &OS) {
168170
if (!StrTabFragment) {
169171
OS.newFragment();
170172
StrTabFragment = OS.getCurrentFragment();
173+
OS.newFragment();
171174
}
172175

173176
OS.emitValueToAlignment(Align(4), 0);
@@ -603,7 +606,7 @@ void CodeViewContext::encodeInlineLineTable(const MCAssembler &Asm,
603606

604607
compressAnnotation(BinaryAnnotationsOpCode::ChangeCodeLength, Buffer);
605608
compressAnnotation(std::min(EndSymLength, LocAfterLength), Buffer);
606-
Frag.setContents(Buffer);
609+
Frag.setVarContents(Buffer);
607610
}
608611

609612
void CodeViewContext::encodeDefRange(const MCAssembler &Asm,
@@ -691,6 +694,6 @@ void CodeViewContext::encodeDefRange(const MCAssembler &Asm,
691694
}
692695
}
693696

694-
Frag.setContents(Contents);
695-
Frag.setFixups(Fixups);
697+
Frag.setVarContents(Contents);
698+
Frag.setVarFixups(Fixups);
696699
}

llvm/lib/MC/MCSection.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ LLVM_DUMP_METHOD void MCSection::dump(
5858
}
5959
#endif
6060

61-
void MCFragment::setContents(ArrayRef<char> Contents) {
62-
auto &S = getParent()->ContentStorage;
63-
if (ContentStart + Contents.size() > ContentEnd) {
64-
ContentStart = S.size();
65-
S.resize_for_overwrite(S.size() + Contents.size());
66-
}
67-
ContentEnd = ContentStart + Contents.size();
68-
llvm::copy(Contents, S.begin() + ContentStart);
69-
}
70-
7161
void MCFragment::setVarContents(ArrayRef<char> Contents) {
7262
auto &S = getParent()->ContentStorage;
7363
if (VarContentStart + Contents.size() > VarContentEnd) {
@@ -94,16 +84,6 @@ void MCFragment::appendFixups(ArrayRef<MCFixup> Fixups) {
9484
FixupEnd = S.size();
9585
}
9686

97-
void MCFragment::setFixups(ArrayRef<MCFixup> Fixups) {
98-
auto &S = getParent()->FixupStorage;
99-
if (FixupStart + Fixups.size() > FixupEnd) {
100-
FixupStart = S.size();
101-
S.resize_for_overwrite(S.size() + Fixups.size());
102-
}
103-
FixupEnd = FixupStart + Fixups.size();
104-
llvm::copy(Fixups, S.begin() + FixupStart);
105-
}
106-
10787
void MCFragment::setVarFixups(ArrayRef<MCFixup> Fixups) {
10888
auto &S = getParent()->FixupStorage;
10989
if (VarFixupStart + Fixups.size() > VarFixupEnd) {

0 commit comments

Comments
 (0)