Replace UniqueSectionForGlobal with getSectionPrefixForUniqueGlobal.

The later doesn't depend on any crazy LLVM IR stuff, and this
pulls the concatenation of prefix with GV name (the root problem behind
PR4584) out one level.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76948 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-07-24 04:49:34 +00:00
parent 837f332372
commit 55acc6807f
7 changed files with 49 additions and 67 deletions

View File

@ -35,8 +35,6 @@ namespace llvm {
explicit DarwinTargetAsmInfo(const TargetMachine &TM);
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind kind) const;
virtual bool emitUsedDirectiveFor(const GlobalValue *GV,
Mangler *Mang) const;

View File

@ -579,6 +579,16 @@ namespace llvm {
getSectionForMergableConstant(uint64_t Size, unsigned ReloInfo) const;
/// getSectionPrefixForUniqueGlobal - Return a string that we should prepend
/// onto a global's name in order to get the unique section name for the
/// global. This is important for globals that need to be merged across
/// translation units.
virtual const char *
getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const;
/// SectionKindForGlobal - This hook allows the target to select proper
/// section kind used for global emission.
// FIXME: Eliminate this.
@ -597,11 +607,6 @@ namespace llvm {
// FIXME: Eliminate this.
virtual const Section* SectionForGlobal(const GlobalValue *GV) const;
// Helper methods for SectionForGlobal
// FIXME: Eliminate this.
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind kind) const;
const std::string &getSectionFlags(unsigned Flags) const;
virtual std::string printSectionFlags(unsigned flags) const { return ""; }

View File

@ -204,9 +204,3 @@ DarwinTargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
return ReadOnlySection; // .const
}
std::string
DarwinTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind kind) const {
llvm_unreachable("Darwin does not use unique sections");
return "";
}

View File

@ -90,13 +90,15 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
case Function::WeakODRLinkage:
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
std::string Name = UniqueSectionForGlobal(GV, Kind);
// FIXME: Use mangler interface (PR4584).
std::string Name = getSectionPrefixForUniqueGlobal(Kind)+GV->getName();
unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
return getNamedSection(Name.c_str(), Flags);
}
} else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
if (GVar->isWeakForLinker()) {
std::string Name = UniqueSectionForGlobal(GVar, Kind);
// FIXME: Use mangler interface (PR4584).
std::string Name = getSectionPrefixForUniqueGlobal(Kind)+GV->getName();
unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str());
return getNamedSection(Name.c_str(), Flags);
} else {

View File

@ -305,7 +305,8 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
SectionKind::Kind Kind = SectionKindForGlobal(GV);
if (GV->isWeakForLinker()) {
std::string Name = UniqueSectionForGlobal(GV, Kind);
// FIXME: Use mangler interface (PR4584).
std::string Name = getSectionPrefixForUniqueGlobal(Kind)+GV->getName();
unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
return getNamedSection(Name.c_str(), Flags);
} else {
@ -334,34 +335,22 @@ TargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
std::string
TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind Kind) const {
const char *
TargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const {
switch (Kind) {
case SectionKind::Text:
return ".gnu.linkonce.t." + GV->getNameStr();
case SectionKind::Data:
return ".gnu.linkonce.d." + GV->getNameStr();
case SectionKind::DataRel:
return ".gnu.linkonce.d.rel" + GV->getNameStr();
case SectionKind::DataRelLocal:
return ".gnu.linkonce.d.rel.local" + GV->getNameStr();
case SectionKind::DataRelRO:
return ".gnu.linkonce.d.rel.ro" + GV->getNameStr();
case SectionKind::DataRelROLocal:
return ".gnu.linkonce.d.rel.ro.local" + GV->getNameStr();
case SectionKind::BSS:
return ".gnu.linkonce.b." + GV->getNameStr();
default: llvm_unreachable("Unknown section kind");
case SectionKind::Text: return ".gnu.linkonce.t.";
case SectionKind::Data: return ".gnu.linkonce.d.";
case SectionKind::DataRel: return ".gnu.linkonce.d.rel.";
case SectionKind::DataRelLocal: return ".gnu.linkonce.d.rel.local.";
case SectionKind::DataRelRO: return ".gnu.linkonce.d.rel.ro.";
case SectionKind::DataRelROLocal: return ".gnu.linkonce.d.rel.ro.local.";
case SectionKind::BSS: return ".gnu.linkonce.b.";
case SectionKind::ROData:
case SectionKind::RODataMergeConst:
case SectionKind::RODataMergeStr:
return ".gnu.linkonce.r." + GV->getNameStr();
case SectionKind::ThreadData:
return ".gnu.linkonce.td." + GV->getNameStr();
case SectionKind::ThreadBSS:
return ".gnu.linkonce.tb." + GV->getNameStr();
default:
llvm_unreachable("Unknown section kind");
case SectionKind::RODataMergeStr: return ".gnu.linkonce.r.";
case SectionKind::ThreadData: return ".gnu.linkonce.td.";
case SectionKind::ThreadBSS: return ".gnu.linkonce.tb.";
}
return NULL;
}

View File

@ -256,33 +256,27 @@ X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Format |= DW_EH_PE_indirect;
return (Format | DW_EH_PE_pcrel);
} else {
if (is64Bit &&
(CM == CodeModel::Small ||
(CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
return DW_EH_PE_udata4;
else
return DW_EH_PE_absptr;
}
if (is64Bit &&
(CM == CodeModel::Small ||
(CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
return DW_EH_PE_udata4;
return DW_EH_PE_absptr;
}
std::string
X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind kind) const {
switch (kind) {
case SectionKind::Text:
return ".text$linkonce" + GV->getName();
case SectionKind::Data:
case SectionKind::BSS:
case SectionKind::ThreadData:
case SectionKind::ThreadBSS:
return ".data$linkonce" + GV->getName();
case SectionKind::ROData:
case SectionKind::RODataMergeConst:
case SectionKind::RODataMergeStr:
return ".rdata$linkonce" + GV->getName();
default:
llvm_unreachable("Unknown section kind");
const char *X86COFFTargetAsmInfo::
getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const {
switch (Kind) {
default: llvm_unreachable("Unknown section kind");
case SectionKind::Text: return ".text$linkonce";
case SectionKind::Data:
case SectionKind::BSS:
case SectionKind::ThreadData:
case SectionKind::ThreadBSS: return ".data$linkonce";
case SectionKind::ROData:
case SectionKind::RODataMergeConst:
case SectionKind::RODataMergeStr: return ".rdata$linkonce";
}
return NULL;
}

View File

@ -53,8 +53,8 @@ namespace llvm {
explicit X86COFFTargetAsmInfo(const X86TargetMachine &TM);
virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
bool Global) const;
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind kind) const;
virtual const char *
getSectionPrefixForUniqueGlobal(SectionKind::Kind kind) const;
virtual std::string printSectionFlags(unsigned flags) const;
};