From 55acc6807f3349228afac27fa1a11cecd11c51b5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 24 Jul 2009 04:49:34 +0000 Subject: [PATCH] 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 --- include/llvm/Target/DarwinTargetAsmInfo.h | 2 -- include/llvm/Target/TargetAsmInfo.h | 15 +++++--- lib/Target/DarwinTargetAsmInfo.cpp | 6 ---- lib/Target/ELFTargetAsmInfo.cpp | 6 ++-- lib/Target/TargetAsmInfo.cpp | 41 ++++++++-------------- lib/Target/X86/X86TargetAsmInfo.cpp | 42 ++++++++++------------- lib/Target/X86/X86TargetAsmInfo.h | 4 +-- 7 files changed, 49 insertions(+), 67 deletions(-) diff --git a/include/llvm/Target/DarwinTargetAsmInfo.h b/include/llvm/Target/DarwinTargetAsmInfo.h index a6f48e1ea3c..48f9133923e 100644 --- a/include/llvm/Target/DarwinTargetAsmInfo.h +++ b/include/llvm/Target/DarwinTargetAsmInfo.h @@ -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; diff --git a/include/llvm/Target/TargetAsmInfo.h b/include/llvm/Target/TargetAsmInfo.h index 112f1051fbb..63afe9bd6a1 100644 --- a/include/llvm/Target/TargetAsmInfo.h +++ b/include/llvm/Target/TargetAsmInfo.h @@ -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 ""; } diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp index bc2189e1ef0..0ea9bd16661 100644 --- a/lib/Target/DarwinTargetAsmInfo.cpp +++ b/lib/Target/DarwinTargetAsmInfo.cpp @@ -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 ""; -} diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp index 9f1aec3a82e..735adce5f2c 100644 --- a/lib/Target/ELFTargetAsmInfo.cpp +++ b/lib/Target/ELFTargetAsmInfo.cpp @@ -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(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 { diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index bf543cc4ec3..d13a3226cfa 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -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; } diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp index 18bcbdca45c..99615dbd8ba 100644 --- a/lib/Target/X86/X86TargetAsmInfo.cpp +++ b/lib/Target/X86/X86TargetAsmInfo.cpp @@ -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; } diff --git a/lib/Target/X86/X86TargetAsmInfo.h b/lib/Target/X86/X86TargetAsmInfo.h index d3da33e4f37..94bae7ee831 100644 --- a/lib/Target/X86/X86TargetAsmInfo.h +++ b/lib/Target/X86/X86TargetAsmInfo.h @@ -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; }; -- 2.34.1