Replace UniqueSectionForGlobal with getSectionPrefixForUniqueGlobal.
authorChris Lattner <sabre@nondot.org>
Fri, 24 Jul 2009 04:49:34 +0000 (04:49 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 24 Jul 2009 04:49:34 +0000 (04:49 +0000)
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
include/llvm/Target/TargetAsmInfo.h
lib/Target/DarwinTargetAsmInfo.cpp
lib/Target/ELFTargetAsmInfo.cpp
lib/Target/TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.h

index a6f48e1ea3c7a496461a8957eb6664cac2eef71f..48f9133923e6b9bdfdc7adcdddb9c597392ddabc 100644 (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;
 
index 112f1051fbbd5338cde4c9808a7603eaea77de18..63afe9bd6a19305132afb10a56caa89e0485aa5e 100644 (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 ""; }
 
index bc2189e1ef0f511865c485be292c6b040b3d0555..0ea9bd16661364297c572a9b0d6251512b856fb4 100644 (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 "";
-}
index 9f1aec3a82eafa7cb01fc41e2ed50f4dbaa7d6eb..735adce5f2cc064e20778862220226de7fb40b87 100644 (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 {
index bf543cc4ec3d879cfee1ee84c9f32514c655b0f9..d13a3226cfac2d8c19ebc836b9763d8f41ba7bd9 100644 (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;
 }
index 18bcbdca45c713cc5b7d39c22cc255b58782692c..99615dbd8ba68c68b22bbc66cef069247450b998 100644 (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;
 }
index d3da33e4f374c040a69713dc19be4053d072106b..94bae7ee831c73385ed3a20aa42ae877493d3340 100644 (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;
   };