Add hacky way to distinguish named and named sections. This will be generalized in...
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 9 Jul 2008 13:25:26 +0000 (13:25 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 9 Jul 2008 13:25:26 +0000 (13:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53311 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetAsmInfo.h
lib/Target/TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.h

index 8d2861f6a673182d56b64017c33e06fd12b74553..0c946dafa1695c83e998de2559a6ea38b6f24d02 100644 (file)
@@ -53,6 +53,7 @@ namespace llvm {
       TLS        = 1 << 5,    ///< Section contains thread-local data
       Debug      = 1 << 6,    ///< Section contains debug data
       Linkonce   = 1 << 7,    ///< Section is linkonce
+      Named      = 1 << 8,    ///< Section is named
       // Some gap for future flags
       EntitySize = 0xFF << 24 ///< Entity size for mergeable sections
     };
index 22ee3ef9fe6afa6c029eb70493b90b86cc0dfd35..6d27d1f4f044d028522aa29b1cefd9acd50533c6 100644 (file)
@@ -193,36 +193,36 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
 
 unsigned
 TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
-                                     const char* name) const {
-  unsigned flags = SectionFlags::None;
+                                     const char* Name) const {
+  unsigned Flags = SectionFlags::None;
 
   // Decode flags from global itself.
   if (GV) {
-    SectionKind::Kind kind = SectionKindForGlobal(GV);
-    switch (kind) {
+    SectionKind::Kind Kind = SectionKindForGlobal(GV);
+    switch (Kind) {
      case SectionKind::Text:
-      flags |= SectionFlags::Code;
+      Flags |= SectionFlags::Code;
       break;
      case SectionKind::ThreadData:
-      flags |= SectionFlags::TLS;
+      Flags |= SectionFlags::TLS;
       // FALLS THROUGH
      case SectionKind::Data:
-      flags |= SectionFlags::Writeable;
+      Flags |= SectionFlags::Writeable;
       break;
      case SectionKind::ThreadBSS:
-      flags |= SectionFlags::TLS;
+      Flags |= SectionFlags::TLS;
       // FALLS THROUGH
      case SectionKind::BSS:
-      flags |= SectionFlags::BSS;
+      Flags |= SectionFlags::BSS;
       break;
      case SectionKind::ROData:
       // No additional flags here
       break;
      case SectionKind::RODataMergeStr:
-      flags |= SectionFlags::Strings;
+      Flags |= SectionFlags::Strings;
       // FALLS THROUGH
      case SectionKind::RODataMergeConst:
-      flags |= SectionFlags::Mergeable;
+      Flags |= SectionFlags::Mergeable;
       break;
      default:
       assert(0 && "Unexpected section kind!");
@@ -231,35 +231,35 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
     if (GV->hasLinkOnceLinkage() ||
         GV->hasWeakLinkage() ||
         GV->hasCommonLinkage())
-      flags |= SectionFlags::Linkonce;
+      Flags |= SectionFlags::Linkonce;
   }
 
   // Add flags from sections, if any.
-  if (name) {
-    // Some lame default implementation
-    if (strcmp(name, ".bss") == 0 ||
-        strncmp(name, ".bss.", 5) == 0 ||
-        strncmp(name, ".gnu.linkonce.b.", 16) == 0 ||
-        strncmp(name, ".llvm.linkonce.b.", 17) == 0)
-      flags |= SectionFlags::BSS;
-    else if (strcmp(name, ".tdata") == 0 ||
-             strncmp(name, ".tdata.", 7) == 0 ||
-             strncmp(name, ".gnu.linkonce.td.", 17) == 0 ||
-             strncmp(name, ".llvm.linkonce.td.", 18) == 0)
-      flags |= SectionFlags::TLS;
-    else if (strcmp(name, ".tbss") == 0 ||
-             strncmp(name, ".tbss.", 6) == 0 ||
-             strncmp(name, ".gnu.linkonce.tb.", 17) == 0 ||
-             strncmp(name, ".llvm.linkonce.tb.", 18) == 0)
-      flags |= SectionFlags::BSS | SectionFlags::TLS;
+  if (Name) {
+    Flags |= SectionFlags::Named;
+
+    // Some lame default implementation based on some magic section names.
+    if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
+        strncmp(Name, ".llvm.linkonce.b.", 17) == 0)
+      Flags |= SectionFlags::BSS;
+    else if (strcmp(Name, ".tdata") == 0 ||
+             strncmp(Name, ".tdata.", 7) == 0 ||
+             strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
+             strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
+      Flags |= SectionFlags::TLS;
+    else if (strcmp(Name, ".tbss") == 0 ||
+             strncmp(Name, ".tbss.", 6) == 0 ||
+             strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
+             strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
+      Flags |= SectionFlags::BSS | SectionFlags::TLS;
   }
 
-  return flags;
+  return Flags;
 }
 
 std::string
 TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
-  unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
+  unsigned Flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
 
   std::string Name;
 
@@ -275,28 +275,33 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
     Name = SelectSectionForGlobal(GV);
   }
 
-  Name += PrintSectionFlags(flags);
+  // If section is named we need to switch into it via special '.section'
+  // directive and also append funky flags. Otherwise - section name is just
+  // some magic assembler directive.
+  if (Flags & SectionFlags::Named)
+    Name = SwitchToSectionDirective + Name + PrintSectionFlags(Flags);
+
   return Name;
 }
 
 // Lame default implementation. Calculate the section name for global.
 std::string
 TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
-  SectionKind::Kind kind = SectionKindForGlobal(GV);
+  SectionKind::Kind Kind = SectionKindForGlobal(GV);
 
   if (GV->hasLinkOnceLinkage() ||
       GV->hasWeakLinkage() ||
       GV->hasCommonLinkage())
-    return UniqueSectionForGlobal(GV, kind);
+    return UniqueSectionForGlobal(GV, Kind);
   else {
-    if (kind == SectionKind::Text)
+    if (Kind == SectionKind::Text)
       return getTextSection();
-    else if (kind == SectionKind::BSS && getBSSSection())
+    else if (Kind == SectionKind::BSS && getBSSSection())
       return getBSSSection();
     else if (getReadOnlySection() &&
-             (kind == SectionKind::ROData ||
-              kind == SectionKind::RODataMergeConst ||
-              kind == SectionKind::RODataMergeStr))
+             (Kind == SectionKind::ROData ||
+              Kind == SectionKind::RODataMergeConst ||
+              Kind == SectionKind::RODataMergeStr))
       return getReadOnlySection();
   }
 
@@ -305,8 +310,8 @@ TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
 
 std::string
 TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
-                                      SectionKind::Kind kind) const {
-  switch (kind) {
+                                      SectionKind::Kind Kind) const {
+  switch (Kind) {
    case SectionKind::Text:
     return ".gnu.linkonce.t." + GV->getName();
    case SectionKind::Data:
index e03b3a28cdcfe8966c8a55fbceef2cef70dfc121..6a3bdfa6546b0eb00aabc45e54d464dd7e60ac5f 100644 (file)
@@ -335,11 +335,11 @@ X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
   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 @@ X86ELFTargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
     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 @@ X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
   }
 }
 
+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 = ",\"";
 
index a700d64f7cb8a3ceb9f357240ffc6f9051ce5ee4..bf68bf136d5fe47fdb5464f38d12a4c1270309aa 100644 (file)
@@ -63,6 +63,8 @@ namespace llvm {
     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;