mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238357 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8cc212a07e
commit
41cea417fa
@ -35,7 +35,6 @@ class raw_pwrite_stream;
|
|||||||
/// implementation.
|
/// implementation.
|
||||||
class MCObjectStreamer : public MCStreamer {
|
class MCObjectStreamer : public MCStreamer {
|
||||||
MCAssembler *Assembler;
|
MCAssembler *Assembler;
|
||||||
MCSection *CurSectionData;
|
|
||||||
MCSection::iterator CurInsertionPoint;
|
MCSection::iterator CurInsertionPoint;
|
||||||
bool EmitEHFrame;
|
bool EmitEHFrame;
|
||||||
bool EmitDebugFrame;
|
bool EmitDebugFrame;
|
||||||
@ -64,14 +63,15 @@ public:
|
|||||||
void EmitCFISections(bool EH, bool Debug) override;
|
void EmitCFISections(bool EH, bool Debug) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MCSection *getCurrentSectionData() const { return CurSectionData; }
|
MCSection *getCurrentSectionData() const { return getCurrentSection().first; }
|
||||||
|
|
||||||
MCFragment *getCurrentFragment() const;
|
MCFragment *getCurrentFragment() const;
|
||||||
|
|
||||||
void insert(MCFragment *F) {
|
void insert(MCFragment *F) {
|
||||||
flushPendingLabels(F);
|
flushPendingLabels(F);
|
||||||
CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
|
MCSection *CurSection = getCurrentSectionData();
|
||||||
F->setParent(CurSectionData);
|
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
|
||||||
|
@ -821,9 +821,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
|
|||||||
const MCSection *SecA =
|
const MCSection *SecA =
|
||||||
(SymA && !SymA->isUndefined()) ? &SymA->getSection() : nullptr;
|
(SymA && !SymA->isUndefined()) ? &SymA->getSection() : nullptr;
|
||||||
auto *ELFSec = cast_or_null<MCSectionELF>(SecA);
|
auto *ELFSec = cast_or_null<MCSectionELF>(SecA);
|
||||||
MCSymbol *SectionSymbol =
|
const MCSymbol *SectionSymbol = ELFSec ? ELFSec->getBeginSymbol() : nullptr;
|
||||||
ELFSec ? Asm.getContext().getOrCreateSectionSymbol(*ELFSec)
|
|
||||||
: nullptr;
|
|
||||||
ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend);
|
ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend);
|
||||||
Relocations[&FixupSection].push_back(Rec);
|
Relocations[&FixupSection].push_back(Rec);
|
||||||
return;
|
return;
|
||||||
@ -882,6 +880,9 @@ bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout,
|
|||||||
if (!Symbol.isVariable() && Symbol.isUndefined() && !IsGlobal)
|
if (!Symbol.isVariable() && Symbol.isUndefined() && !IsGlobal)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (MCELF::GetType(Data) == ELF::STT_SECTION)
|
||||||
|
return true;
|
||||||
|
|
||||||
if (Symbol.isTemporary())
|
if (Symbol.isTemporary())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -159,11 +159,14 @@ void MCELFStreamer::ChangeSection(MCSection *Section,
|
|||||||
Asm.getOrCreateSymbolData(*Grp);
|
Asm.getOrCreateSymbolData(*Grp);
|
||||||
|
|
||||||
this->MCObjectStreamer::ChangeSection(Section, Subsection);
|
this->MCObjectStreamer::ChangeSection(Section, Subsection);
|
||||||
MCSymbol *SectionSymbol = getContext().getOrCreateSectionSymbol(*SectionELF);
|
MCContext &Ctx = getContext();
|
||||||
if (SectionSymbol->isUndefined()) {
|
MCSymbol *Begin = Section->getBeginSymbol();
|
||||||
EmitLabel(SectionSymbol);
|
if (!Begin) {
|
||||||
MCELF::SetType(Asm.getSymbolData(*SectionSymbol), ELF::STT_SECTION);
|
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) {
|
||||||
|
@ -162,9 +162,10 @@ void MCMachOStreamer::ChangeSection(MCSection *Section,
|
|||||||
|
|
||||||
// Output a linker-local symbol so we don't need section-relative local
|
// Output a linker-local symbol so we don't need section-relative local
|
||||||
// relocations. The linker hates us when we do that.
|
// 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();
|
||||||
EmitLabel(Label);
|
Section->setBeginSymbol(Label);
|
||||||
HasSectionLabel[Section] = true;
|
HasSectionLabel[Section] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ MCObjectStreamer::MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
|
|||||||
: MCStreamer(Context),
|
: MCStreamer(Context),
|
||||||
Assembler(new MCAssembler(Context, TAB, *Emitter_,
|
Assembler(new MCAssembler(Context, TAB, *Emitter_,
|
||||||
*TAB.createObjectWriter(OS), OS)),
|
*TAB.createObjectWriter(OS), OS)),
|
||||||
CurSectionData(nullptr), EmitEHFrame(true), EmitDebugFrame(false) {}
|
EmitEHFrame(true), EmitDebugFrame(false) {}
|
||||||
|
|
||||||
MCObjectStreamer::~MCObjectStreamer() {
|
MCObjectStreamer::~MCObjectStreamer() {
|
||||||
delete &Assembler->getBackend();
|
delete &Assembler->getBackend();
|
||||||
@ -42,8 +42,9 @@ void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) {
|
|||||||
if (PendingLabels.size()) {
|
if (PendingLabels.size()) {
|
||||||
if (!F) {
|
if (!F) {
|
||||||
F = new MCDataFragment();
|
F = new MCDataFragment();
|
||||||
CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
|
MCSection *CurSection = getCurrentSectionData();
|
||||||
F->setParent(CurSectionData);
|
CurSection->getFragmentList().insert(CurInsertionPoint, F);
|
||||||
|
F->setParent(CurSection);
|
||||||
}
|
}
|
||||||
for (MCSymbolData *SD : PendingLabels) {
|
for (MCSymbolData *SD : PendingLabels) {
|
||||||
SD->setFragment(F);
|
SD->setFragment(F);
|
||||||
@ -79,7 +80,6 @@ bool MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi,
|
|||||||
void MCObjectStreamer::reset() {
|
void MCObjectStreamer::reset() {
|
||||||
if (Assembler)
|
if (Assembler)
|
||||||
Assembler->reset();
|
Assembler->reset();
|
||||||
CurSectionData = nullptr;
|
|
||||||
CurInsertionPoint = MCSection::iterator();
|
CurInsertionPoint = MCSection::iterator();
|
||||||
EmitEHFrame = true;
|
EmitEHFrame = true;
|
||||||
EmitDebugFrame = false;
|
EmitDebugFrame = false;
|
||||||
@ -212,7 +212,6 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
|
|||||||
flushPendingLabels(nullptr);
|
flushPendingLabels(nullptr);
|
||||||
|
|
||||||
bool Created = getAssembler().registerSection(*Section);
|
bool Created = getAssembler().registerSection(*Section);
|
||||||
CurSectionData = Section;
|
|
||||||
|
|
||||||
int64_t IntSubsection = 0;
|
int64_t IntSubsection = 0;
|
||||||
if (Subsection &&
|
if (Subsection &&
|
||||||
@ -221,7 +220,7 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
|
|||||||
if (IntSubsection < 0 || IntSubsection > 8192)
|
if (IntSubsection < 0 || IntSubsection > 8192)
|
||||||
report_fatal_error("Subsection number out of range");
|
report_fatal_error("Subsection number out of range");
|
||||||
CurInsertionPoint =
|
CurInsertionPoint =
|
||||||
CurSectionData->getSubsectionInsertionPoint(unsigned(IntSubsection));
|
Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
|
||||||
return Created;
|
return Created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,13 +630,15 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
|
|||||||
// If we are generating dwarf for assembly source files save the initial text
|
// If we are generating dwarf for assembly source files save the initial text
|
||||||
// section and generate a .file directive.
|
// section and generate a .file directive.
|
||||||
if (getContext().getGenDwarfForAssembly()) {
|
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);
|
bool InsertResult = getContext().addGenDwarfSection(Sec);
|
||||||
assert(InsertResult && ".text section should not have debug info yet");
|
assert(InsertResult && ".text section should not have debug info yet");
|
||||||
(void)InsertResult;
|
(void)InsertResult;
|
||||||
Sec->setBeginSymbol(SectionStartSym);
|
|
||||||
getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
|
getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
|
||||||
0, StringRef(), getContext().getMainFileName()));
|
0, StringRef(), getContext().getMainFileName()));
|
||||||
}
|
}
|
||||||
|
@ -537,9 +537,11 @@ EndStmt:
|
|||||||
if (getContext().getDwarfVersion() <= 2)
|
if (getContext().getDwarfVersion() <= 2)
|
||||||
Warning(loc, "DWARF2 only supports one section per compilation unit");
|
Warning(loc, "DWARF2 only supports one section per compilation unit");
|
||||||
|
|
||||||
MCSymbol *SectionStartSymbol = getContext().createTempSymbol();
|
if (!ELFSection->getBeginSymbol()) {
|
||||||
getStreamer().EmitLabel(SectionStartSymbol);
|
MCSymbol *SectionStartSymbol = getContext().createTempSymbol();
|
||||||
ELFSection->setBeginSymbol(SectionStartSymbol);
|
getStreamer().EmitLabel(SectionStartSymbol);
|
||||||
|
ELFSection->setBeginSymbol(SectionStartSymbol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,9 +669,9 @@ void MCStreamer::SwitchSection(MCSection *Section, const MCExpr *Subsection) {
|
|||||||
MCSectionSubPair curSection = SectionStack.back().first;
|
MCSectionSubPair curSection = SectionStack.back().first;
|
||||||
SectionStack.back().second = curSection;
|
SectionStack.back().second = curSection;
|
||||||
if (MCSectionSubPair(Section, Subsection) != curSection) {
|
if (MCSectionSubPair(Section, Subsection) != curSection) {
|
||||||
|
ChangeSection(Section, Subsection);
|
||||||
SectionStack.back().first = MCSectionSubPair(Section, Subsection);
|
SectionStack.back().first = MCSectionSubPair(Section, Subsection);
|
||||||
assert(!Section->hasEnded() && "Section already ended");
|
assert(!Section->hasEnded() && "Section already ended");
|
||||||
ChangeSection(Section, Subsection);
|
|
||||||
MCSymbol *Sym = Section->getBeginSymbol();
|
MCSymbol *Sym = Section->getBeginSymbol();
|
||||||
if (Sym && !Sym->isInSection())
|
if (Sym && !Sym->isInSection())
|
||||||
EmitLabel(Sym);
|
EmitLabel(Sym);
|
||||||
|
Loading…
Reference in New Issue
Block a user