mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 00:24:26 +00:00
Refactor how passes get a symbol at the end of a section.
There is now a canonical symbol at the end of a section that different passes can request. This also allows us to assert that we don't switch back to a section whose end symbol has already been printed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233026 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MCAsmInfo;
|
class MCAsmInfo;
|
||||||
|
class MCContext;
|
||||||
class MCExpr;
|
class MCExpr;
|
||||||
class MCSymbol;
|
class MCSymbol;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
@ -35,10 +36,11 @@ private:
|
|||||||
void operator=(const MCSection &) = delete;
|
void operator=(const MCSection &) = delete;
|
||||||
|
|
||||||
MCSymbol *Begin;
|
MCSymbol *Begin;
|
||||||
|
mutable MCSymbol *End;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
|
MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
|
||||||
: Begin(Begin), Variant(V), Kind(K) {}
|
: Begin(Begin), End(nullptr), Variant(V), Kind(K) {}
|
||||||
SectionVariant Variant;
|
SectionVariant Variant;
|
||||||
SectionKind Kind;
|
SectionKind Kind;
|
||||||
|
|
||||||
@ -50,6 +52,8 @@ public:
|
|||||||
SectionVariant getVariant() const { return Variant; }
|
SectionVariant getVariant() const { return Variant; }
|
||||||
|
|
||||||
MCSymbol *getBeginSymbol() const { return Begin; }
|
MCSymbol *getBeginSymbol() const { return Begin; }
|
||||||
|
MCSymbol *getEndSymbol(MCContext &Ctx) const;
|
||||||
|
bool hasEnded() const;
|
||||||
|
|
||||||
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
|
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
|
||||||
const MCExpr *Subsection) const = 0;
|
const MCExpr *Subsection) const = 0;
|
||||||
|
@ -366,6 +366,8 @@ public:
|
|||||||
/// Create the default sections and set the initial one.
|
/// Create the default sections and set the initial one.
|
||||||
virtual void InitSections(bool NoExecStack);
|
virtual void InitSections(bool NoExecStack);
|
||||||
|
|
||||||
|
MCSymbol *endSection(const MCSection *Section);
|
||||||
|
|
||||||
/// AssignSection - Sets the symbol's section.
|
/// AssignSection - Sets the symbol's section.
|
||||||
///
|
///
|
||||||
/// Each emitted symbol will be tracked in the ordering table,
|
/// Each emitted symbol will be tracked in the ordering table,
|
||||||
|
@ -1664,15 +1664,8 @@ void DwarfDebug::emitDebugARanges() {
|
|||||||
const MCSection *Section = I.first;
|
const MCSection *Section = I.first;
|
||||||
MCSymbol *Sym = nullptr;
|
MCSymbol *Sym = nullptr;
|
||||||
|
|
||||||
if (Section) {
|
if (Section)
|
||||||
// We can't call MCSection::getLabelEndName, as it's only safe to do so
|
Sym = Asm->OutStreamer.endSection(Section);
|
||||||
// if we know the section name up-front. For user-created sections, the
|
|
||||||
// resulting label may not be valid to use as a label. (section names can
|
|
||||||
// use a greater set of characters on some systems)
|
|
||||||
Sym = Asm->createTempSymbol("debug_end");
|
|
||||||
Asm->OutStreamer.SwitchSection(Section);
|
|
||||||
Asm->OutStreamer.EmitLabel(Sym);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert a final terminator.
|
// Insert a final terminator.
|
||||||
SectionMap[Section].push_back(SymbolCU(nullptr, Sym));
|
SectionMap[Section].push_back(SymbolCU(nullptr, Sym));
|
||||||
|
@ -179,23 +179,14 @@ EmitDwarfLineTable(MCObjectStreamer *MCOS, const MCSection *Section,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Emit a DW_LNE_end_sequence for the end of the section.
|
// Emit a DW_LNE_end_sequence for the end of the section.
|
||||||
// Using the pointer Section create a temporary label at the end of the
|
// Use the section end label to compute the address delta and use INT64_MAX
|
||||||
// section and use that and the LastLabel to compute the address delta
|
// as the line delta which is the signal that this is actually a
|
||||||
// and use INT64_MAX as the line delta which is the signal that this is
|
// DW_LNE_end_sequence.
|
||||||
// actually a DW_LNE_end_sequence.
|
MCSymbol *SectionEnd = MCOS->endSection(Section);
|
||||||
|
|
||||||
// Switch to the section to be able to create a symbol at its end.
|
|
||||||
// TODO: keep track of the last subsection so that this symbol appears in the
|
|
||||||
// correct place.
|
|
||||||
MCOS->SwitchSection(Section);
|
|
||||||
|
|
||||||
|
// Switch back the dwarf line section, in case endSection had to switch the
|
||||||
|
// section.
|
||||||
MCContext &Ctx = MCOS->getContext();
|
MCContext &Ctx = MCOS->getContext();
|
||||||
// Create a symbol at the end of the section.
|
|
||||||
MCSymbol *SectionEnd = Ctx.CreateTempSymbol();
|
|
||||||
// Set the value of the symbol, as we are at the end of the section.
|
|
||||||
MCOS->EmitLabel(SectionEnd);
|
|
||||||
|
|
||||||
// Switch back the dwarf line section.
|
|
||||||
MCOS->SwitchSection(Ctx.getObjectFileInfo()->getDwarfLineSection());
|
MCOS->SwitchSection(Ctx.getObjectFileInfo()->getDwarfLineSection());
|
||||||
|
|
||||||
const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
|
const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "llvm/MC/MCSection.h"
|
#include "llvm/MC/MCSection.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
|
#include "llvm/MC/MCSymbol.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@ -17,6 +18,14 @@ using namespace llvm;
|
|||||||
// MCSection
|
// MCSection
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) const {
|
||||||
|
if (!End)
|
||||||
|
End = Ctx.createTempSymbol("sec_end", true);
|
||||||
|
return End;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MCSection::hasEnded() const { return End && End->isInSection(); }
|
||||||
|
|
||||||
MCSection::~MCSection() {
|
MCSection::~MCSection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,9 +670,22 @@ void MCStreamer::SwitchSection(const MCSection *Section,
|
|||||||
SectionStack.back().second = curSection;
|
SectionStack.back().second = curSection;
|
||||||
if (MCSectionSubPair(Section, Subsection) != curSection) {
|
if (MCSectionSubPair(Section, Subsection) != curSection) {
|
||||||
SectionStack.back().first = MCSectionSubPair(Section, Subsection);
|
SectionStack.back().first = MCSectionSubPair(Section, Subsection);
|
||||||
|
assert(!Section->hasEnded() && "Section already ended");
|
||||||
ChangeSection(Section, Subsection);
|
ChangeSection(Section, Subsection);
|
||||||
MCSymbol *Sym = Section->getBeginSymbol();
|
MCSymbol *Sym = Section->getBeginSymbol();
|
||||||
if (Sym && !Sym->isInSection())
|
if (Sym && !Sym->isInSection())
|
||||||
EmitLabel(Sym);
|
EmitLabel(Sym);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MCSymbol *MCStreamer::endSection(const MCSection *Section) {
|
||||||
|
// TODO: keep track of the last subsection so that this symbol appears in the
|
||||||
|
// correct place.
|
||||||
|
MCSymbol *Sym = Section->getEndSymbol(Context);
|
||||||
|
if (Sym->isInSection())
|
||||||
|
return Sym;
|
||||||
|
|
||||||
|
SwitchSection(Section);
|
||||||
|
EmitLabel(Sym);
|
||||||
|
return Sym;
|
||||||
|
}
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
; <data section> - it should have made one span covering all vars in this CU.
|
; <data section> - it should have made one span covering all vars in this CU.
|
||||||
; CHECK-NEXT: .quad some_data
|
; CHECK-NEXT: .quad some_data
|
||||||
; CHECK-NEXT: .quad .Ldebug_end0-some_data
|
; CHECK-NEXT: .quad .Lsec_end0-some_data
|
||||||
|
|
||||||
; <other sections> - it should have made one span covering all vars in this CU.
|
; <other sections> - it should have made one span covering all vars in this CU.
|
||||||
; CHECK-NEXT: .quad some_other
|
; CHECK-NEXT: .quad some_other
|
||||||
; CHECK-NEXT: .quad .Ldebug_end1-some_other
|
; CHECK-NEXT: .quad .Lsec_end1-some_other
|
||||||
|
|
||||||
; <common symbols> - it should have made one span for each symbol.
|
; <common symbols> - it should have made one span for each symbol.
|
||||||
; CHECK-NEXT: .quad some_bss
|
; CHECK-NEXT: .quad some_bss
|
||||||
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
; <text section> - it should have made one span covering all functions in this CU.
|
; <text section> - it should have made one span covering all functions in this CU.
|
||||||
; CHECK-NEXT: .quad .Lfunc_begin0
|
; CHECK-NEXT: .quad .Lfunc_begin0
|
||||||
; CHECK-NEXT: .quad .Ldebug_end2-.Lfunc_begin0
|
; CHECK-NEXT: .quad .Lsec_end2-.Lfunc_begin0
|
||||||
|
|
||||||
; -- finish --
|
; -- finish --
|
||||||
; CHECK-NEXT: # ARange terminator
|
; CHECK-NEXT: # ARange terminator
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
; RUN: llc -generate-arange-section < %s | FileCheck %s
|
; RUN: llc -generate-arange-section < %s | FileCheck %s
|
||||||
|
|
||||||
; CHECK: .Ldebug_end0:
|
; CHECK: .section .debug_aranges,"",@progbits
|
||||||
; CHECK-NEXT: .section .debug_aranges,"",@progbits
|
|
||||||
|
|
||||||
; First CU
|
; First CU
|
||||||
; CHECK-NEXT: .long 44 # Length of ARange Set
|
; CHECK-NEXT: .long 44 # Length of ARange Set
|
||||||
@ -23,7 +22,7 @@
|
|||||||
; CHECK-NEXT: .byte 0 # Segment Size (in bytes)
|
; CHECK-NEXT: .byte 0 # Segment Size (in bytes)
|
||||||
; CHECK-NEXT: .zero 4,255
|
; CHECK-NEXT: .zero 4,255
|
||||||
; CHECK-NEXT: .quad rainbows
|
; CHECK-NEXT: .quad rainbows
|
||||||
; CHECK-NEXT: .quad .Ldebug_end0-rainbows
|
; CHECK-NEXT: .quad .Lsec_end0-rainbows
|
||||||
; CHECK-NEXT: .quad 0 # ARange terminator
|
; CHECK-NEXT: .quad 0 # ARange terminator
|
||||||
; CHECK-NEXT: .quad 0
|
; CHECK-NEXT: .quad 0
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user