Skip to content

Commit fadc722

Browse files
committed
[MC] switchSectionNoPrint: update CurFrag
To ensure that CurFrag->Parent and SectionStack.back() are in sync.
1 parent 567b2c6 commit fadc722

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class MCObjectStreamer : public MCStreamer {
125125
void emitSLEB128Value(const MCExpr *Value) override;
126126
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
127127
void changeSection(MCSection *Section, uint32_t Subsection = 0) override;
128+
void switchSectionNoPrint(MCSection *Section) override;
128129
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
129130

130131
/// Emit an instruction to a special fragment, because this instruction

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,8 @@ class MCStreamer {
433433
virtual void switchSection(MCSection *Section, uint32_t Subsec = 0);
434434
bool switchSection(MCSection *Section, const MCExpr *);
435435

436-
/// Set the current section where code is being emitted to \p Section.
437-
/// This is required to update CurSection. This version does not call
438-
/// changeSection.
439-
void switchSectionNoChange(MCSection *Section) {
440-
assert(Section && "Cannot switch to a null section!");
441-
MCSectionSubPair curSection = SectionStack.back().first;
442-
SectionStack.back().second = curSection;
443-
SectionStack.back().first = MCSectionSubPair(Section, 0);
444-
}
436+
/// Similar to switchSection, but does not print the section directive.
437+
virtual void switchSectionNoPrint(MCSection *Section);
445438

446439
/// Create the default sections and set the initial one.
447440
virtual void initSections(bool NoExecStack, const MCSubtargetInfo &STI);

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,7 @@ void MCAsmStreamer::emitWinEHHandlerData(SMLoc Loc) {
22092209

22102210
MCSection *TextSec = &CurFrame->Function->getSection();
22112211
MCSection *XData = getAssociatedXDataSection(TextSec);
2212-
switchSectionNoChange(XData);
2212+
switchSectionNoPrint(XData);
22132213

22142214
OS << "\t.seh_handlerdata";
22152215
EmitEOL();
@@ -2626,7 +2626,7 @@ void MCAsmStreamer::doFinalizationAtSectionEnd(MCSection *Section) {
26262626
if (MAI->usesDwarfFileAndLocDirectives())
26272627
return;
26282628

2629-
switchSectionNoChange(Section);
2629+
switchSectionNoPrint(Section);
26302630

26312631
MCSymbol *Sym = getCurrentSectionOnly()->getEndSymbol(getContext());
26322632

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
313313
return getAssembler().registerSection(*Section);
314314
}
315315

316+
void MCObjectStreamer::switchSectionNoPrint(MCSection *Section) {
317+
MCStreamer::switchSectionNoPrint(Section);
318+
changeSection(Section, 0);
319+
}
320+
316321
void MCObjectStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
317322
getAssembler().registerSymbol(*Symbol);
318323
MCStreamer::emitAssignment(Symbol, Value);

llvm/lib/MC/MCStreamer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,12 @@ bool MCStreamer::switchSection(MCSection *Section, const MCExpr *SubsecExpr) {
12901290
return false;
12911291
}
12921292

1293+
void MCStreamer::switchSectionNoPrint(MCSection *Section) {
1294+
SectionStack.back().second = SectionStack.back().first;
1295+
SectionStack.back().first = MCSectionSubPair(Section, 0);
1296+
CurFrag = &Section->getDummyFragment();
1297+
}
1298+
12931299
MCSymbol *MCStreamer::endSection(MCSection *Section) {
12941300
// TODO: keep track of the last subsection so that this symbol appears in the
12951301
// correct place.

0 commit comments

Comments
 (0)