Skip to content

Commit dd50e8e

Browse files
committed
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 04b4f62 commit dd50e8e

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
@@ -231,11 +231,16 @@ class MCFragment {
231231
/// FT_Relaxable, x86-specific
232232
bool AllowAutoPadding : 1;
233233

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

242+
// Track content and fixups for the optional variable-size tail part,
243+
// typically modified during relaxation.
239244
uint32_t VarContentStart = 0;
240245
uint32_t VarContentEnd = 0;
241246
uint32_t VarFixupStart = 0;
@@ -364,7 +369,6 @@ class MCFragment {
364369
getContentsForAppending().append(Num, Elt);
365370
doneAppending();
366371
}
367-
LLVM_ABI void setContents(ArrayRef<char> Contents);
368372
MutableArrayRef<char> getContents() {
369373
return MutableArrayRef(getParent()->ContentStorage)
370374
.slice(ContentStart, ContentEnd - ContentStart);
@@ -396,7 +400,6 @@ class MCFragment {
396400
void clearFixups() { FixupEnd = FixupStart; }
397401
LLVM_ABI void addFixup(MCFixup Fixup);
398402
LLVM_ABI void appendFixups(ArrayRef<MCFixup> Fixups);
399-
LLVM_ABI void setFixups(ArrayRef<MCFixup> Fixups);
400403
MutableArrayRef<MCFixup> getFixups() {
401404
return MutableArrayRef(getParent()->FixupStorage)
402405
.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)