[llvm-commits] [llvm] r53311 - in /llvm/trunk: include/llvm/Target/TargetAsmInfo.h lib/Target/TargetAsmInfo.cpp lib/Target/X86/X86TargetAsmInfo.cpp lib/Target/X86/X86TargetAsmInfo.h

Anton Korobeynikov asl at math.spbu.ru
Wed Jul 9 06:25:26 PDT 2008


Author: asl
Date: Wed Jul  9 08:25:26 2008
New Revision: 53311

URL: http://llvm.org/viewvc/llvm-project?rev=53311&view=rev
Log:
Add hacky way to distinguish named and named sections. This will be generalized in the future.

Modified:
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/lib/Target/TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
    llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h

Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=53311&r1=53310&r2=53311&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Wed Jul  9 08:25:26 2008
@@ -53,6 +53,7 @@
       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
     };

Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=53311&r1=53310&r2=53311&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Wed Jul  9 08:25:26 2008
@@ -193,36 +193,36 @@
 
 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 @@
     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 @@
     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 @@
 
 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:

Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp?rev=53311&r1=53310&r2=53311&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp Wed Jul  9 08:25:26 2008
@@ -335,11 +335,11 @@
   X86TargetAsmInfo(TM) {
   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
 
-  ReadOnlySection = "\t.section\t.rodata";
-  FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\", at progbits,4";
-  EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\", at progbits,8";
-  SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\", at progbits,16";
-  CStringSection = "\t.section\t.rodata.str1.1,\"aMS\", at 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 = ",\"";
 

Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h?rev=53311&r1=53310&r2=53311&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h Wed Jul  9 08:25:26 2008
@@ -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;





More information about the llvm-commits mailing list