aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCObjectStreamer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/MC/MCObjectStreamer.cpp')
-rw-r--r--llvm/lib/MC/MCObjectStreamer.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index fcd5cbf..f046552 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -185,10 +185,10 @@ void MCObjectStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
getAssembler().registerSymbol(*Symbol);
- // If there is a current fragment, mark the symbol as pointing into it.
- // Otherwise queue the label and set its fragment pointer when we emit the
- // next fragment.
- MCFragment *F = getCurrentFragment();
+ // Set the fragment and offset. This function might be called by
+ // changeSection, when the section stack top hasn't been changed to the new
+ // section.
+ MCFragment *F = CurFrag;
Symbol->setFragment(F);
Symbol->setOffset(F->getContents().size());
@@ -247,6 +247,15 @@ void MCObjectStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
assert(Section && "Cannot switch to a null section!");
getContext().clearDwarfLocSeen();
+ // Register the section and create an initial fragment for subsection 0
+ // if `Subsection` is non-zero.
+ bool NewSec = getAssembler().registerSection(*Section);
+ MCFragment *F0 = nullptr;
+ if (NewSec && Subsection) {
+ changeSection(Section, 0);
+ F0 = CurFrag;
+ }
+
auto &Subsections = Section->Subsections;
size_t I = 0, E = Subsections.size();
while (I != E && Subsections[I].first < Subsection)
@@ -262,12 +271,13 @@ void MCObjectStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
Section->CurFragList = &Subsections[I].second;
CurFrag = Section->CurFragList->Tail;
- getAssembler().registerSection(*Section);
-}
-
-void MCObjectStreamer::switchSectionNoPrint(MCSection *Section) {
- MCStreamer::switchSectionNoPrint(Section);
- changeSection(Section, 0);
+ // Define the section symbol at subsection 0's initial fragment if required.
+ if (!NewSec)
+ return;
+ if (auto *Sym = Section->getBeginSymbol()) {
+ Sym->setFragment(Subsection ? F0 : CurFrag);
+ getAssembler().registerSymbol(*Sym);
+ }
}
void MCObjectStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {