There is only one current section.
Both MCStreamer and MCObjectStreamer were maintaining a current section
variable and they were slightly out of sync. I don't think this was observable,
but was inefficient and error prone.
Changing this requires a few cascading changes:
* SwitchSection has to call ChangeSection earlier for ChangeSection to see
the old section.
* With that change, ChangeSection cannot call EmitLabel, since during
ChangeSection we are still in the old section.
* When the object streamer requires a begin label, just reused the existing
generic support for begin labels instead of calling EmitLabel directly.
llvm-svn: 238357
diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index 653a1d2..aa818f9 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -159,11 +159,14 @@
Asm.getOrCreateSymbolData(*Grp);
this->MCObjectStreamer::ChangeSection(Section, Subsection);
- MCSymbol *SectionSymbol = getContext().getOrCreateSectionSymbol(*SectionELF);
- if (SectionSymbol->isUndefined()) {
- EmitLabel(SectionSymbol);
- MCELF::SetType(Asm.getSymbolData(*SectionSymbol), ELF::STT_SECTION);
+ MCContext &Ctx = getContext();
+ MCSymbol *Begin = Section->getBeginSymbol();
+ if (!Begin) {
+ Begin = Ctx.getOrCreateSectionSymbol(*SectionELF);
+ Section->setBeginSymbol(Begin);
}
+ if (Begin->isUndefined())
+ MCELF::SetType(Asm.getOrCreateSymbolData(*Begin), ELF::STT_SECTION);
}
void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {