Add a variable to track whether or not we've used a unique section,

e.g. linkonce, to TargetMachine and set it when we've done so
for ELF targets currently. This involved making TargetMachine
non-const in a TLOF use and propagating that change around - I'm
open to other ideas.

This will be used in a future commit to handle emitting debug
information with ranges.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199871 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher 2014-01-23 06:47:25 +00:00
parent fa6e5cb511
commit 80664e50cd
14 changed files with 38 additions and 33 deletions

View File

@ -53,7 +53,7 @@ public:
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
Mangler *Mang, TargetMachine &TM) const;
/// getTTypeGlobalReference - Return an MCExpr to use for a reference to the
/// specified type info global variable from exception handling information.
@ -92,7 +92,7 @@ public:
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
Mangler *Mang, TargetMachine &TM) const;
virtual const MCSection *
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
@ -131,7 +131,7 @@ public:
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
Mangler *Mang, TargetMachine &TM) const;
/// getDepLibFromLinkerOpt - Extract the dependent library name from a linker
/// option string. Returns StringRef() if the option does not specify a library.

View File

@ -38,7 +38,7 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
const DataLayout *DL;
TargetLoweringObjectFile(
const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
const TargetLoweringObjectFile &) LLVM_DELETED_FUNCTION;
void operator=(const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
public:
@ -91,14 +91,14 @@ public:
/// be passed external (or available externally) globals.
const MCSection *SectionForGlobal(const GlobalValue *GV,
SectionKind Kind, Mangler *Mang,
const TargetMachine &TM) const;
TargetMachine &TM) const;
/// SectionForGlobal - This method computes the appropriate section to emit
/// the specified global variable or function definition. This should not
/// be passed external (or available externally) globals.
const MCSection *SectionForGlobal(const GlobalValue *GV,
Mangler *Mang,
const TargetMachine &TM) const {
TargetMachine &TM) const {
return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
}
@ -167,7 +167,7 @@ public:
protected:
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
Mangler *Mang, TargetMachine &TM) const;
};
} // end namespace llvm

View File

@ -88,6 +88,7 @@ protected: // Can only create subclasses.
unsigned MCUseLoc : 1;
unsigned MCUseCFI : 1;
unsigned MCUseDwarfDirectory : 1;
unsigned DebugUseUniqueSections : 1;
unsigned RequireStructuredCFG : 1;
public:
@ -160,6 +161,9 @@ public:
bool requiresStructuredCFG() const { return RequireStructuredCFG; }
void setRequiresStructuredCFG(bool Value) { RequireStructuredCFG = Value; }
bool debugUseUniqueSections() const { return DebugUseUniqueSections; }
void setDebugUseUniqueSections(bool Value) { DebugUseUniqueSections = Value; }
/// hasMCRelaxAll - Check whether all machine code instructions should be
/// relaxed.
bool hasMCRelaxAll() const { return MCRelaxAll; }

View File

@ -232,7 +232,7 @@ static const char *getSectionPrefixForGlobal(SectionKind Kind) {
const MCSection *TargetLoweringObjectFileELF::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
Mangler *Mang, TargetMachine &TM) const {
// If we have -ffunction-section or -fdata-section then we should emit the
// global value to a uniqued section specifically for it.
bool EmitUniquedSection;
@ -258,6 +258,8 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Flags |= ELF::SHF_GROUP;
}
// Set that we've used a unique section name in the target machine.
TM.setDebugUseUniqueSections(true);
return getContext().getELFSection(Name.str(),
getELFSectionType(Name.str(), Kind),
Flags, Kind, 0, Group);
@ -529,7 +531,7 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
const MCSection *TargetLoweringObjectFileMachO::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
Mangler *Mang, TargetMachine &TM) const {
// Handle thread local data.
if (Kind.isThreadBSS()) return TLSBSSSection;
@ -754,7 +756,7 @@ static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) {
const MCSection *TargetLoweringObjectFileCOFF::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
Mangler *Mang, TargetMachine &TM) const {
// If this global is linkonce/weak and the target handles this by emitting it
// into a 'uniqued' section name, create and return the section now.

View File

@ -87,7 +87,7 @@ IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM,
const MCSection *HexagonTargetObjectFile::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
Mangler *Mang, TargetMachine &TM) const {
// Handle Small Section classification here.
if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind))

View File

@ -30,10 +30,9 @@ namespace llvm {
const TargetMachine &TM) const;
bool IsSmallDataEnabled () const;
const MCSection* SelectSectionForGlobal(const GlobalValue *GV,
SectionKind Kind,
Mangler *Mang,
const TargetMachine &TM) const;
const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
SectionKind Kind, Mangler *Mang,
TargetMachine &TM) const;
};
} // namespace llvm

View File

@ -103,7 +103,7 @@ IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM,
const MCSection *MipsTargetObjectFile::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
Mangler *Mang, TargetMachine &TM) const {
// TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*"
// sections?

View File

@ -31,9 +31,8 @@ namespace llvm {
const TargetMachine &TM) const;
const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
SectionKind Kind,
Mangler *Mang,
const TargetMachine &TM) const;
SectionKind Kind, Mangler *Mang,
TargetMachine &TM) const;
// TODO: Classify globals as mips wishes.
const MCSection *getReginfoSection() const { return ReginfoSection; }

View File

@ -24,7 +24,7 @@ Initialize(MCContext &Ctx, const TargetMachine &TM) {
const MCSection * PPC64LinuxTargetObjectFile::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
Mangler *Mang, TargetMachine &TM) const {
const MCSection *DefaultSection =
TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);

View File

@ -22,9 +22,10 @@ namespace llvm {
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
SectionKind Kind,
Mangler *Mang,
TargetMachine &TM) const;
/// \brief Describe a TLS variable address within debug info.
virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;

View File

@ -265,7 +265,7 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
/// be passed external (or available externally) globals.
const MCSection *TargetLoweringObjectFile::
SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang,
const TargetMachine &TM) const {
TargetMachine &TM) const {
// Select section name.
if (GV->hasSection())
return getExplicitSectionGlobal(GV, Kind, Mang, TM);
@ -277,11 +277,9 @@ SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang,
// Lame default implementation. Calculate the section name for global.
const MCSection *
TargetLoweringObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
SectionKind Kind,
Mangler *Mang,
const TargetMachine &TM) const{
const MCSection *TargetLoweringObjectFile::SelectSectionForGlobal(
const GlobalValue *GV, SectionKind Kind, Mangler *Mang,
TargetMachine &TM) const {
assert(!Kind.isThreadLocal() && "Doesn't support TLS");
if (Kind.isText())

View File

@ -55,6 +55,7 @@ TargetMachine::TargetMachine(const Target &T,
MCUseLoc(true),
MCUseCFI(true),
MCUseDwarfDirectory(false),
DebugUseUniqueSections(false),
RequireStructuredCFG(false),
Options(Options) {
}

View File

@ -130,7 +130,7 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
const MCSection *XCoreTargetObjectFile::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang,
const TargetMachine &TM) const{
TargetMachine &TM) const{
if (Kind.isText()) return TextSection;
if (Kind.isMergeable1ByteCString()) return CStringSection;
if (Kind.isMergeableConst4()) return MergeableConst4Section;

View File

@ -27,9 +27,10 @@ static const unsigned CodeModelLargeSize = 256;
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
SectionKind Kind,
Mangler *Mang,
TargetMachine &TM) const;
virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
};