mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-20 02:58:10 +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.
|
||||
class MCObjectStreamer : public MCStreamer {
|
||||
MCAssembler *Assembler;
|
||||
MCSection *CurSectionData;
|
||||
MCSection::iterator CurInsertionPoint;
|
||||
bool EmitEHFrame;
|
||||
bool EmitDebugFrame;
|
||||
@ -64,14 +63,15 @@ public:
|
||||
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);
|
||||
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
|
||||
|
@ -821,9 +821,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
|
||||
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;
|
||||
@ -882,6 +880,9 @@ bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout,
|
||||
if (!Symbol.isVariable() && Symbol.isUndefined() && !IsGlobal)
|
||||
return false;
|
||||
|
||||
if (MCELF::GetType(Data) == ELF::STT_SECTION)
|
||||
return true;
|
||||
|
||||
if (Symbol.isTemporary())
|
||||
return false;
|
||||
|
||||
|
@ -159,11 +159,14 @@ void MCELFStreamer::ChangeSection(MCSection *Section,
|
||||
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) {
|
||||
|
@ -162,9 +162,10 @@ void MCMachOStreamer::ChangeSection(MCSection *Section,
|
||||
|
||||
// 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();
|
||||
EmitLabel(Label);
|
||||
Section->setBeginSymbol(Label);
|
||||
HasSectionLabel[Section] = true;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ MCObjectStreamer::MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
|
||||
: 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();
|
||||
@ -42,8 +42,9 @@ void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) {
|
||||
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);
|
||||
@ -79,7 +80,6 @@ bool MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi,
|
||||
void MCObjectStreamer::reset() {
|
||||
if (Assembler)
|
||||
Assembler->reset();
|
||||
CurSectionData = nullptr;
|
||||
CurInsertionPoint = MCSection::iterator();
|
||||
EmitEHFrame = true;
|
||||
EmitDebugFrame = false;
|
||||
@ -212,7 +212,6 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
|
||||
flushPendingLabels(nullptr);
|
||||
|
||||
bool Created = getAssembler().registerSection(*Section);
|
||||
CurSectionData = Section;
|
||||
|
||||
int64_t IntSubsection = 0;
|
||||
if (Subsection &&
|
||||
@ -221,7 +220,7 @@ bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
|
||||
if (IntSubsection < 0 || IntSubsection > 8192)
|
||||
report_fatal_error("Subsection number out of range");
|
||||
CurInsertionPoint =
|
||||
CurSectionData->getSubsectionInsertionPoint(unsigned(IntSubsection));
|
||||
Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
|
||||
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
|
||||
// section and generate a .file directive.
|
||||
if (getContext().getGenDwarfForAssembly()) {
|
||||
MCSymbol *SectionStartSym = getContext().createTempSymbol();
|
||||
getStreamer().EmitLabel(SectionStartSym);
|
||||
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;
|
||||
Sec->setBeginSymbol(SectionStartSym);
|
||||
getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(
|
||||
0, StringRef(), getContext().getMainFileName()));
|
||||
}
|
||||
|
@ -537,9 +537,11 @@ EndStmt:
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -669,9 +669,9 @@ void MCStreamer::SwitchSection(MCSection *Section, const MCExpr *Subsection) {
|
||||
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");
|
||||
ChangeSection(Section, Subsection);
|
||||
MCSymbol *Sym = Section->getBeginSymbol();
|
||||
if (Sym && !Sym->isInSection())
|
||||
EmitLabel(Sym);
|
||||
|
Loading…
Reference in New Issue
Block a user