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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238357
91177308-0d34-0410-b5e6-
96231b3b80d8
/// implementation.
class MCObjectStreamer : public MCStreamer {
MCAssembler *Assembler;
/// implementation.
class MCObjectStreamer : public MCStreamer {
MCAssembler *Assembler;
- MCSection *CurSectionData;
MCSection::iterator CurInsertionPoint;
bool EmitEHFrame;
bool EmitDebugFrame;
MCSection::iterator CurInsertionPoint;
bool EmitEHFrame;
bool EmitDebugFrame;
void EmitCFISections(bool EH, bool Debug) override;
protected:
void EmitCFISections(bool EH, bool Debug) override;
protected:
- MCSection *getCurrentSectionData() const { return CurSectionData; }
+ MCSection *getCurrentSectionData() const { return getCurrentSection().first; }
MCFragment *getCurrentFragment() const;
void insert(MCFragment *F) {
flushPendingLabels(F);
MCFragment *getCurrentFragment() const;
void insert(MCFragment *F) {
flushPendingLabels(F);
- CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
- F->setParent(CurSectionData);
+ MCSection *CurSection = getCurrentSectionData();
+ CurSection->getFragmentList().insert(CurInsertionPoint, F);
+ F->setParent(CurSection);
}
/// Get a data fragment to write into, creating a new one if the current
}
/// Get a data fragment to write into, creating a new one if the current
const MCSection *SecA =
(SymA && !SymA->isUndefined()) ? &SymA->getSection() : nullptr;
auto *ELFSec = cast_or_null<MCSectionELF>(SecA);
const MCSection *SecA =
(SymA && !SymA->isUndefined()) ? &SymA->getSection() : nullptr;
auto *ELFSec = cast_or_null<MCSectionELF>(SecA);
- MCSymbol *SectionSymbol =
- ELFSec ? Asm.getContext().getOrCreateSectionSymbol(*ELFSec)
- : nullptr;
+ const MCSymbol *SectionSymbol = ELFSec ? ELFSec->getBeginSymbol() : nullptr;
ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend);
Relocations[&FixupSection].push_back(Rec);
return;
ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend);
Relocations[&FixupSection].push_back(Rec);
return;
if (!Symbol.isVariable() && Symbol.isUndefined() && !IsGlobal)
return false;
if (!Symbol.isVariable() && Symbol.isUndefined() && !IsGlobal)
return false;
+ if (MCELF::GetType(Data) == ELF::STT_SECTION)
+ return true;
+
if (Symbol.isTemporary())
return false;
if (Symbol.isTemporary())
return false;
Asm.getOrCreateSymbolData(*Grp);
this->MCObjectStreamer::ChangeSection(Section, Subsection);
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) {
}
void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
// Output a linker-local symbol so we don't need section-relative local
// relocations. The linker hates us when we do that.
// Output a linker-local symbol so we don't need section-relative local
// relocations. The linker hates us when we do that.
- if (LabelSections && !HasSectionLabel[Section]) {
+ if (LabelSections && !HasSectionLabel[Section] &&
+ !Section->getBeginSymbol()) {
MCSymbol *Label = getContext().createLinkerPrivateTempSymbol();
MCSymbol *Label = getContext().createLinkerPrivateTempSymbol();
+ Section->setBeginSymbol(Label);
HasSectionLabel[Section] = true;
}
}
HasSectionLabel[Section] = true;
}
}
: MCStreamer(Context),
Assembler(new MCAssembler(Context, TAB, *Emitter_,
*TAB.createObjectWriter(OS), OS)),
: MCStreamer(Context),
Assembler(new MCAssembler(Context, TAB, *Emitter_,
*TAB.createObjectWriter(OS), OS)),
- CurSectionData(nullptr), EmitEHFrame(true), EmitDebugFrame(false) {}
+ EmitEHFrame(true), EmitDebugFrame(false) {}
MCObjectStreamer::~MCObjectStreamer() {
delete &Assembler->getBackend();
MCObjectStreamer::~MCObjectStreamer() {
delete &Assembler->getBackend();
if (PendingLabels.size()) {
if (!F) {
F = new MCDataFragment();
if (PendingLabels.size()) {
if (!F) {
F = new MCDataFragment();
- CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
- F->setParent(CurSectionData);
+ MCSection *CurSection = getCurrentSectionData();
+ CurSection->getFragmentList().insert(CurInsertionPoint, F);
+ F->setParent(CurSection);
}
for (MCSymbolData *SD : PendingLabels) {
SD->setFragment(F);
}
for (MCSymbolData *SD : PendingLabels) {
SD->setFragment(F);
void MCObjectStreamer::reset() {
if (Assembler)
Assembler->reset();
void MCObjectStreamer::reset() {
if (Assembler)
Assembler->reset();
- CurSectionData = nullptr;
CurInsertionPoint = MCSection::iterator();
EmitEHFrame = true;
EmitDebugFrame = false;
CurInsertionPoint = MCSection::iterator();
EmitEHFrame = true;
EmitDebugFrame = false;
flushPendingLabels(nullptr);
bool Created = getAssembler().registerSection(*Section);
flushPendingLabels(nullptr);
bool Created = getAssembler().registerSection(*Section);
- CurSectionData = Section;
int64_t IntSubsection = 0;
if (Subsection &&
int64_t IntSubsection = 0;
if (Subsection &&
if (IntSubsection < 0 || IntSubsection > 8192)
report_fatal_error("Subsection number out of range");
CurInsertionPoint =
if (IntSubsection < 0 || IntSubsection > 8192)
report_fatal_error("Subsection number out of range");
CurInsertionPoint =
- CurSectionData->getSubsectionInsertionPoint(unsigned(IntSubsection));
+ Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
// If we are generating dwarf for assembly source files save the initial text
// section and generate a .file directive.
if (getContext().getGenDwarfForAssembly()) {
// If we are generating dwarf for assembly source files save the initial text
// section and generate a .file directive.
if (getContext().getGenDwarfForAssembly()) {
- MCSymbol *SectionStartSym = getContext().createTempSymbol();
- getStreamer().EmitLabel(SectionStartSym);
MCSection *Sec = getStreamer().getCurrentSection().first;
MCSection *Sec = getStreamer().getCurrentSection().first;
+ if (!Sec->getBeginSymbol()) {
+ MCSymbol *SectionStartSym = getContext().createTempSymbol();
+ getStreamer().EmitLabel(SectionStartSym);
+ Sec->setBeginSymbol(SectionStartSym);
+ }
bool InsertResult = getContext().addGenDwarfSection(Sec);
assert(InsertResult && ".text section should not have debug info yet");
(void)InsertResult;
bool InsertResult = getContext().addGenDwarfSection(Sec);
assert(InsertResult && ".text section should not have debug info yet");
(void)InsertResult;
- Sec->setBeginSymbol(SectionStartSym);
getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
0, StringRef(), getContext().getMainFileName()));
}
getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
0, StringRef(), getContext().getMainFileName()));
}
if (getContext().getDwarfVersion() <= 2)
Warning(loc, "DWARF2 only supports one section per compilation unit");
if (getContext().getDwarfVersion() <= 2)
Warning(loc, "DWARF2 only supports one section per compilation unit");
- MCSymbol *SectionStartSymbol = getContext().createTempSymbol();
- getStreamer().EmitLabel(SectionStartSymbol);
- ELFSection->setBeginSymbol(SectionStartSymbol);
+ if (!ELFSection->getBeginSymbol()) {
+ MCSymbol *SectionStartSymbol = getContext().createTempSymbol();
+ getStreamer().EmitLabel(SectionStartSymbol);
+ ELFSection->setBeginSymbol(SectionStartSymbol);
+ }
MCSectionSubPair curSection = SectionStack.back().first;
SectionStack.back().second = curSection;
if (MCSectionSubPair(Section, Subsection) != curSection) {
MCSectionSubPair curSection = SectionStack.back().first;
SectionStack.back().second = curSection;
if (MCSectionSubPair(Section, Subsection) != curSection) {
+ ChangeSection(Section, Subsection);
SectionStack.back().first = MCSectionSubPair(Section, Subsection);
assert(!Section->hasEnded() && "Section already ended");
SectionStack.back().first = MCSectionSubPair(Section, Subsection);
assert(!Section->hasEnded() && "Section already ended");
- ChangeSection(Section, Subsection);
MCSymbol *Sym = Section->getBeginSymbol();
if (Sym && !Sym->isInSection())
EmitLabel(Sym);
MCSymbol *Sym = Section->getBeginSymbol();
if (Sym && !Sym->isInSection())
EmitLabel(Sym);