Fix several fixmes and clean up code by sinking *all* section
[oota-llvm.git] / lib / Target / TargetLoweringObjectFile.cpp
index 23e549a42b08442140be4b0a328dd8c1fe2e11ec..6aca6da8afef6dad72cdccd49157b4d2e6429c40 100644 (file)
@@ -233,20 +233,9 @@ const MCSection *TargetLoweringObjectFile::
 SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang,
                  const TargetMachine &TM) const {
   // Select section name.
-  if (GV->hasSection()) {
-    // If the target has special section hacks for specifically named globals,
-    // return them now.
-    if (const MCSection *TS = getSpecialCasedSectionGlobals(GV, Mang, Kind))
-      return TS;
-    
-    // If the target has magic semantics for certain section names, make sure to
-    // pick up the flags.  This allows the user to write things with attribute
-    // section and still get the appropriate section flags printed.
-    Kind = getKindForNamedSection(GV->getSection().c_str(), Kind);
-    
-    return getOrCreateSection(GV->getSection().c_str(), false, Kind);
-  }
-
+  if (GV->hasSection())
+    return getExplicitSectionGlobal(GV, Kind, Mang, TM);
+  
   
   // Use default section depending on the 'type' of global
   return SelectSectionForGlobal(GV, Kind, Mang, TM);
@@ -381,8 +370,8 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
 }
 
 
-SectionKind TargetLoweringObjectFileELF::
-getKindForNamedSection(const char *Name, SectionKind K) const {
+static SectionKind 
+getELFKindForNamedSection(const char *Name, SectionKind K) {
   if (Name[0] != '.') return K;
   
   // Some lame default implementation based on some magic section names.
@@ -407,6 +396,17 @@ getKindForNamedSection(const char *Name, SectionKind K) const {
   return K;
 }
 
+const MCSection *TargetLoweringObjectFileELF::
+getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                         Mangler *Mang, const TargetMachine &TM) const {
+  // Infer section flags from the section name if we can.
+  Kind = getELFKindForNamedSection(GV->getSection().c_str(), Kind);
+  
+  return getOrCreateSection(GV->getSection().c_str(), false, Kind);
+}
+      
+      
+      
 void TargetLoweringObjectFileELF::
 getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str) const {
   Str.push_back(',');
@@ -688,6 +688,12 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
                        SectionKind::getMetadata());
 }
 
+const MCSection *TargetLoweringObjectFileMachO::
+getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                         Mangler *Mang, const TargetMachine &TM) const {
+  return getOrCreateSection(GV->getSection().c_str(), false, Kind);
+}
+
 const MCSection *TargetLoweringObjectFileMachO::
 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
                        Mangler *Mang, const TargetMachine &TM) const {
@@ -837,6 +843,13 @@ void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
                        true, SectionKind::getMetadata());
 }
 
+const MCSection *TargetLoweringObjectFileCOFF::
+getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
+                         Mangler *Mang, const TargetMachine &TM) const {
+  return getOrCreateSection(GV->getSection().c_str(), false, Kind);
+}
+
+
 void TargetLoweringObjectFileCOFF::
 getSectionFlagsAsString(SectionKind Kind, SmallVectorImpl<char> &Str) const {
   // FIXME: Inefficient.