Provide section selection for X86 ELF targets
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 9 Jul 2008 13:23:08 +0000 (13:23 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 9 Jul 2008 13:23:08 +0000 (13:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53305 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 0b810c77cfcdfd1e65c6b29303cac07209e91934..6d2f6437bb0bcfd4d7ae037c361dfbebffcc0e94 100644 (file)
@@ -261,6 +261,9 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
 
   std::string Name;
 
+  // FIXME: Should we use some hashing based on section name and just check
+  // flags?
+
   // Select section name
   if (GV->hasSection()) {
     // Honour section already set, if any
index 96e452ee284cecb78b1b040d8c26c533247f2c38..5e328fb78a36ab288ca5cd71b4b583e7d9b4a63b 100644 (file)
@@ -313,6 +313,51 @@ X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
   }
 }
 
+std::string
+X86ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
+  SectionKind::Kind kind = SectionKindForGlobal(GV);
+
+  if (const Function *F = dyn_cast<Function>(GV)) {
+    switch (F->getLinkage()) {
+     default: assert(0 && "Unknown linkage type!");
+     case Function::InternalLinkage:
+     case Function::DLLExportLinkage:
+     case Function::ExternalLinkage:
+      return getTextSection();
+     case Function::WeakLinkage:
+     case Function::LinkOnceLinkage:
+      return UniqueSectionForGlobal(F, kind);
+    }
+  } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
+    if (GVar->hasCommonLinkage() ||
+        GVar->hasLinkOnceLinkage() ||
+        GVar->hasWeakLinkage())
+      return UniqueSectionForGlobal(GVar, kind);
+    else {
+      switch (kind) {
+       case SectionKind::Data:
+        return getDataSection();
+       case SectionKind::BSS:
+        // ELF targets usually have BSS sections
+        return getBSSSection();
+       case SectionKind::ROData:
+       case SectionKind::RODataMergeStr:
+       case SectionKind::RODataMergeConst:
+        // FIXME: Temporary
+        return getReadOnlySection();
+       case SectionKind::ThreadData:
+        // ELF targets usually support TLS stuff
+        return getTLSDataSection();
+       case SectionKind::ThreadBSS:
+        return getTLSBSSSection();
+       default:
+        assert(0 && "Unsuported section kind for global");
+      }
+    }
+  } else
+    assert(0 && "Unsupported global");
+}
+
 std::string X86ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
   std::string Flags = ",\"";
 
@@ -472,67 +517,3 @@ X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
   DataSectionStartSuffix = "\tsegment 'DATA'";
   SectionEndDirectiveSuffix = "\tends\n";
 }
-
-std::string X86TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
-  SectionKind::Kind kind = SectionKindForGlobal(GV);
-  unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
-  std::string Name;
-
-  // FIXME: Should we use some hashing based on section name and just check
-  // flags?
-  // FIXME: It seems, that Darwin uses much more sections.
-
-  // Select section name
-  if (GV->hasSection()) {
-    // Honour section already set, if any
-    Name = GV->getSection();
-  } else {
-    // Use default section depending on the 'type' of global
-    if (const Function *F = dyn_cast<Function>(GV)) {
-      switch (F->getLinkage()) {
-       default: assert(0 && "Unknown linkage type!");
-       case Function::InternalLinkage:
-       case Function::DLLExportLinkage:
-       case Function::ExternalLinkage:
-        Name = getTextSection();
-        break;
-       case Function::WeakLinkage:
-       case Function::LinkOnceLinkage:
-        Name = UniqueSectionForGlobal(F, kind);
-        break;
-      }
-    } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
-      if (GVar->hasCommonLinkage() ||
-          GVar->hasLinkOnceLinkage() ||
-          GVar->hasWeakLinkage())
-        Name = UniqueSectionForGlobal(GVar, kind);
-      else {
-        switch (kind) {
-         case SectionKind::Data:
-          Name = getDataSection();
-          break;
-         case SectionKind::BSS:
-          Name = (getBSSSection() ? getBSSSection() : getDataSection());
-          break;
-         case SectionKind::ROData:
-         case SectionKind::RODataMergeStr:
-         case SectionKind::RODataMergeConst:
-          // FIXME: Temporary
-          Name = getDataSection();
-          break;
-         case SectionKind::ThreadData:
-          Name = (getTLSDataSection() ? getTLSDataSection() : getDataSection());
-          break;
-         case SectionKind::ThreadBSS:
-          Name = (getTLSBSSSection() ? getTLSBSSSection() : getDataSection());
-         default:
-          assert(0 && "Unsuported section kind for global");
-        }
-      }
-    } else
-      assert(0 && "Unsupported global");
-  }
-
-  Name += PrintSectionFlags(flags);
-  return Name;
-}
index 85969920115367258e146af1ea76cd9c4dff0840..483b774d6d9d4c2b8ba42276e6052eb093d9cd1f 100644 (file)
@@ -45,6 +45,8 @@ namespace llvm {
     explicit X86ELFTargetAsmInfo(const X86TargetMachine &TM);
     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
                                            bool Global) const;
+
+    virtual std::string SelectSectionForGlobal(const GlobalValue *GV) const;
     virtual std::string PrintSectionFlags(unsigned flags) const;
   };