Add data.rel stuff
authorAnton Korobeynikov <asl@math.spbu.ru>
Mon, 30 Mar 2009 15:27:03 +0000 (15:27 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Mon, 30 Mar 2009 15:27:03 +0000 (15:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68031 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2eeff85d66ec16c99626d31f86b154219277d845..51cc72f62144aaaf157fe04da0899c7368e1ec37 100644 (file)
@@ -32,6 +32,11 @@ namespace llvm {
     const Section* MergeableStringSection(const GlobalVariable *GV) const;
     virtual const Section*
     SelectSectionForMachineConst(const Type *Ty) const;
+
+    const Section* DataRelSection;
+    const Section* DataRelLocalSection;
+    const Section* DataRelROSection;
+    const Section* DataRelROLocalSection;
   };
 }
 
index 73f4374af2247f24fb4803f8ec2ad2340b675d45..b871009dda8ddef8c191a76fd30700db9f9f122c 100644 (file)
@@ -36,8 +36,12 @@ namespace llvm {
       Unknown = 0,      ///< Custom section
       Text,             ///< Text section
       Data,             ///< Data section
+      DataRel,          ///< Contains data that has relocations
+      DataRelLocal,     ///< Contains data that has only local relocations
       BSS,              ///< BSS section
       ROData,           ///< Readonly data section
+      DataRelRO,        ///< Contains data that is otherwise readonly
+      DataRelROLocal,   ///< Contains r/o data with only local relocations
       RODataMergeStr,   ///< Readonly data section (mergeable strings)
       RODataMergeConst, ///< Readonly data section (mergeable constants)
       SmallData,        ///< Small data section
index 927fdd295361943308f8a90596fad777780d68b8..b33155c345736767cfda1b6b4b148be35a042387 100644 (file)
@@ -85,6 +85,9 @@ DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
     else
       return TextSection;
    case SectionKind::Data:
+   case SectionKind::DataRel:
+   case SectionKind::DataRelRO:
+   case SectionKind::DataRelROLocal:
    case SectionKind::ThreadData:
    case SectionKind::BSS:
    case SectionKind::ThreadBSS:
index 3a2a00c6582cfa0ee754fb197e2f0c5e20aafc70..8608d36747ab91bae1c0eab4d9e8493547ba33b0 100644 (file)
@@ -35,6 +35,13 @@ ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
   TLSBSSSection = getNamedSection("\t.tbss",
                 SectionFlags::Writeable | SectionFlags::TLS | SectionFlags::BSS);
 
+  DataRelSection = getNamedSection("\t.data.rel", SectionFlags::Writeable);
+  DataRelLocalSection = getNamedSection("\t.data.rel.local",
+                                        SectionFlags::Writeable);
+  DataRelROSection = getNamedSection("\t.data.rel.ro",
+                                     SectionFlags::Writeable);
+  DataRelROLocalSection = getNamedSection("\t.data.rel.ro.local",
+                                          SectionFlags::Writeable);
 }
 
 const Section*
@@ -67,6 +74,14 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
        case SectionKind::Data:
        case SectionKind::SmallData:
         return DataSection;
+       case SectionKind::DataRel:
+        return DataRelSection;
+       case SectionKind::DataRelLocal:
+        return DataRelLocalSection;
+       case SectionKind::DataRelRO:
+        return DataRelROSection;
+       case SectionKind::DataRelROLocal:
+        return DataRelROLocalSection;
        case SectionKind::BSS:
        case SectionKind::SmallBSS:
         // ELF targets usually have BSS sections
index 80f80003fe85b474d5bace266c7828b951288e94..0573a96e538e3bd9e8cf2bf922c2c437ccad52e1 100644 (file)
@@ -124,7 +124,7 @@ void TargetAsmInfo::fillDefaultValues() {
   DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
 }
 
-TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) 
+TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
   : TM(tm) {
   fillDefaultValues();
 }
@@ -220,14 +220,18 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
       unsigned Reloc = RelocBehaviour();
 
       // We already did a query for 'all' relocs, thus - early exits.
-      if (Reloc == Reloc::LocalOrGlobal)
-        return SectionKind::Data;
-      else if (Reloc == Reloc::None)
+      if (Reloc == Reloc::LocalOrGlobal) {
+        return (C->ContainsRelocations(Reloc::Local) ?
+                SectionKind::DataRelROLocal : SectionKind::DataRelRO);
+      } else if (Reloc == Reloc::None)
         return SectionKind::ROData;
       else {
         // Ok, target wants something funny. Honour it.
-        return (C->ContainsRelocations(Reloc) ?
-                SectionKind::Data : SectionKind::ROData);
+        if (C->ContainsRelocations(Reloc)) {
+          return (Reloc == Reloc::Local ?
+                  SectionKind::DataRelROLocal : SectionKind::DataRelRO);
+        } else
+          return SectionKind::ROData;
       }
     } else {
       // Check, if initializer is a null-terminated string
@@ -238,8 +242,19 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
     }
   }
 
-  // Variable is not constant or thread-local - emit to generic data section.
-  return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
+  // Variable either is not constant or thread-local - output to data section.
+  if (isThreadLocal)
+    return SectionKind::ThreadData;
+
+  if (GVar->hasInitializer()) {
+    Constant *C = GVar->getInitializer();
+    unsigned Reloc = RelocBehaviour();
+    if (Reloc != Reloc::None && C->ContainsRelocations(Reloc))
+      return (C->ContainsRelocations(Reloc::Local) ?
+              SectionKind::DataRelLocal : SectionKind::DataRel);
+  }
+
+  return SectionKind::Data;
 }
 
 unsigned
@@ -259,6 +274,10 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
       Flags |= SectionFlags::TLS;
       // FALLS THROUGH
      case SectionKind::Data:
+     case SectionKind::DataRel:
+     case SectionKind::DataRelLocal:
+     case SectionKind::DataRelRO:
+     case SectionKind::DataRelROLocal:
      case SectionKind::BSS:
       Flags |= SectionFlags::Writeable;
       break;
@@ -360,6 +379,14 @@ TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
     return ".gnu.linkonce.t." + GV->getName();
    case SectionKind::Data:
     return ".gnu.linkonce.d." + GV->getName();
+   case SectionKind::DataRel:
+    return ".gnu.linkonce.d.rel" + GV->getName();
+   case SectionKind::DataRelLocal:
+    return ".gnu.linkonce.d.rel.local" + GV->getName();
+   case SectionKind::DataRelRO:
+    return ".gnu.linkonce.d.rel.ro" + GV->getName();
+   case SectionKind::DataRelROLocal:
+    return ".gnu.linkonce.d.rel.ro.local" + GV->getName();
    case SectionKind::SmallData:
     return ".gnu.linkonce.s." + GV->getName();
    case SectionKind::BSS:
index f1d97a3893226dd3d8b0ae1bab1eab6496045864..641719a6bd261fb41d7ef477c05ad2de78ac7c03 100644 (file)
@@ -305,17 +305,12 @@ X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
   switch (kind) {
    case SectionKind::Text:
     return ".text$linkonce" + GV->getName();
-   case SectionKind::Data:
-   case SectionKind::BSS:
-   case SectionKind::ThreadData:
-   case SectionKind::ThreadBSS:
-    return ".data$linkonce" + GV->getName();
    case SectionKind::ROData:
    case SectionKind::RODataMergeConst:
    case SectionKind::RODataMergeStr:
     return ".rdata$linkonce" + GV->getName();
    default:
-    assert(0 && "Unknown section kind");
+    return ".data$linkonce" + GV->getName();
   }
   return NULL;
 }