Add hacky way to distinguish named and named sections. This will be generalized in the future.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53311 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp
index e03b3a2..6a3bdfa 100644
--- a/lib/Target/X86/X86TargetAsmInfo.cpp
+++ b/lib/Target/X86/X86TargetAsmInfo.cpp
@@ -335,11 +335,11 @@
   X86TargetAsmInfo(TM) {
   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
 
-  ReadOnlySection = "\t.section\t.rodata";
-  FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
-  EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
-  SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
-  CStringSection = "\t.section\t.rodata.str1.1,\"aMS\",@progbits,1";
+  ReadOnlySection = ".rodata";
+  FourByteConstantSection = ".rodata.cst";
+  EightByteConstantSection = ".rodata.cst";
+  SixteenByteConstantSection = ".rodata.cst";
+  CStringSection = ".rodata.str";
   PrivateGlobalPrefix = ".L";
   WeakRefDirective = "\t.weak\t";
   SetDirective = "\t.set\t";
@@ -520,6 +520,16 @@
     Flags = SectionFlags::setEntitySize(Flags, Size);
   }
 
+  // FIXME: This is hacky and will be removed when switching from std::string
+  // sections into 'general' ones
+
+  // Mark section as named, when needed (so, we we will need .section directive
+  // to switch into it).
+  if (Flags & (SectionFlags::Mergeable ||
+               SectionFlags::TLS ||
+               SectionFlags::Linkonce))
+    Flags |= SectionFlags::Named;
+
   return Flags;
 }
 
@@ -645,6 +655,23 @@
   }
 }
 
+unsigned
+X86COFFTargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
+                                            const char* name) const {
+  unsigned Flags =
+    TargetAsmInfo::SectionFlagsForGlobal(GV,
+                                         GV->getSection().c_str());
+
+  // Mark section as named, when needed (so, we we will need .section directive
+  // to switch into it).
+  if (Flags & (SectionFlags::Mergeable ||
+               SectionFlags::TLS ||
+               SectionFlags::Linkonce))
+    Flags |= SectionFlags::Named;
+
+  return Flags;
+}
+
 std::string X86COFFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
   std::string Flags = ",\"";
 
diff --git a/lib/Target/X86/X86TargetAsmInfo.h b/lib/Target/X86/X86TargetAsmInfo.h
index a700d64..bf68bf1 100644
--- a/lib/Target/X86/X86TargetAsmInfo.h
+++ b/lib/Target/X86/X86TargetAsmInfo.h
@@ -63,6 +63,8 @@
     explicit X86COFFTargetAsmInfo(const X86TargetMachine &TM);
     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
                                            bool Global) const;
+    virtual unsigned SectionFlagsForGlobal(const GlobalValue *GV,
+                                           const char* name) const;
     virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
                                                SectionKind::Kind kind) const;
     virtual std::string PrintSectionFlags(unsigned flags) const;