Fix several bugs in named sections handling
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 9 Jul 2008 13:25:46 +0000 (13:25 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 9 Jul 2008 13:25:46 +0000 (13:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53312 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.cpp

index 6d27d1f4f044d028522aa29b1cefd9acd50533c6..483af129013f0601503e7392b693fbe9bbd0ea43 100644 (file)
@@ -235,7 +235,7 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
   }
 
   // Add flags from sections, if any.
-  if (Name) {
+  if (Name && *Name) {
     Flags |= SectionFlags::Named;
 
     // Some lame default implementation based on some magic section names.
@@ -279,7 +279,7 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
   // directive and also append funky flags. Otherwise - section name is just
   // some magic assembler directive.
   if (Flags & SectionFlags::Named)
-    Name = SwitchToSectionDirective + Name + PrintSectionFlags(Flags);
+    Name = getSwitchToSectionDirective() + Name + PrintSectionFlags(Flags);
 
   return Name;
 }
index 6a3bdfa6546b0eb00aabc45e54d464dd7e60ac5f..7a56ed55e06d91889700a242bd15a807be2ae4cf 100644 (file)
@@ -336,9 +336,9 @@ X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
 
   ReadOnlySection = ".rodata";
-  FourByteConstantSection = ".rodata.cst";
-  EightByteConstantSection = ".rodata.cst";
-  SixteenByteConstantSection = ".rodata.cst";
+  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 = ".rodata.str";
   PrivateGlobalPrefix = ".L";
   WeakRefDirective = "\t.weak\t";
@@ -466,12 +466,10 @@ X86ELFTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
   unsigned Size = SectionFlags::getEntitySize(Flags);
 
   // FIXME: string here is temporary, until stuff will fully land in.
-  if (Size == 4)
-    return FourByteConstantSection;
-  else if (Size == 8)
-    return EightByteConstantSection;
-  else if (Size == 16)
-    return SixteenByteConstantSection;
+  // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's
+  // currently directly used by asmprinter.
+  if (Size == 4 || Size == 8 || Size == 16)
+    return ".rodata.cst" + utostr(Size);
 
   return getReadOnlySection();
 }
@@ -525,8 +523,8 @@ X86ELFTargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
 
   // Mark section as named, when needed (so, we we will need .section directive
   // to switch into it).
-  if (Flags & (SectionFlags::Mergeable ||
-               SectionFlags::TLS ||
+  if (Flags & (SectionFlags::Mergeable |
+               SectionFlags::TLS |
                SectionFlags::Linkonce))
     Flags |= SectionFlags::Named;