[llvm-commits] [llvm] r77140 - in /llvm/trunk: include/llvm/Target/TargetAsmInfo.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/CodeGen/ELFWriter.cpp lib/Target/TargetAsmInfo.cpp

Chris Lattner sabre at nondot.org
Sun Jul 26 00:01:26 PDT 2009


Author: lattner
Date: Sun Jul 26 02:00:12 2009
New Revision: 77140

URL: http://llvm.org/viewvc/llvm-project?rev=77140&view=rev
Log:
make SectionKind know whether a symbol is weak or not in addition
to its classification.

Modified:
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/ELFWriter.cpp
    llvm/trunk/lib/Target/TargetAsmInfo.cpp

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

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Sun Jul 26 02:00:12 2009
@@ -125,13 +125,16 @@
     };
     
   private:
-    Kind K : 8;
+    Kind K : 7;
     
+    /// Weak - This is true if the referenced symbol is weak (i.e. linkonce,
+    /// weak, weak_odr, etc).  This is orthogonal from the categorization.
+    bool Weak : 1;
   public:
     
-    bool isText() const {
-      return K == Text;
-    }
+    bool isWeak() const { return Weak; }
+    
+    bool isText() const { return K == Text; }
     
     bool isReadOnly() const {
       return K == ReadOnly || K == MergeableCString || isMergeableConst();
@@ -182,9 +185,10 @@
       return K == ReadOnlyWithRelLocal;
     }
     
-    static SectionKind get(Kind K) {
+    static SectionKind get(Kind K, bool isWeak) {
       SectionKind Res;
       Res.K = K;
+      Res.Weak = isWeak;
       return Res;
     }
   };

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=77140&r1=77139&r2=77140&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sun Jul 26 02:00:12 2009
@@ -311,15 +311,17 @@
     SectionKind Kind;
     switch (CPE.getRelocationInfo()) {
     default: llvm_unreachable("Unknown section kind");
-    case 2: Kind = SectionKind::get(SectionKind::ReadOnlyWithRel); break;
-    case 1: Kind = SectionKind::get(SectionKind::ReadOnlyWithRelLocal); break;
+    case 2: Kind = SectionKind::get(SectionKind::ReadOnlyWithRel, false); break;
+    case 1:
+      Kind = SectionKind::get(SectionKind::ReadOnlyWithRelLocal,false);
+      break;
     case 0:
-      switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
-      case 4:   Kind = SectionKind::get(SectionKind::MergeableConst4); break;
-      case 8:   Kind = SectionKind::get(SectionKind::MergeableConst8); break;
-      case 16:  Kind = SectionKind::get(SectionKind::MergeableConst16); break;
-      default:  Kind = SectionKind::get(SectionKind::MergeableConst); break;
-      }
+    switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
+    case 4:  Kind = SectionKind::get(SectionKind::MergeableConst4,false); break;
+    case 8:  Kind = SectionKind::get(SectionKind::MergeableConst8,false); break;
+    case 16: Kind = SectionKind::get(SectionKind::MergeableConst16,false);break;
+    default: Kind = SectionKind::get(SectionKind::MergeableConst,false); break;
+    }
     }
 
     const Section *S = TAI->getSectionForMergeableConstant(Kind);

Modified: llvm/trunk/lib/CodeGen/ELFWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ELFWriter.cpp?rev=77140&r1=77139&r2=77140&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Sun Jul 26 02:00:12 2009
@@ -157,14 +157,16 @@
   SectionKind Kind;
   switch (CPE.getRelocationInfo()) {
   default: llvm_unreachable("Unknown section kind");
-  case 2: Kind = SectionKind::get(SectionKind::ReadOnlyWithRel); break;
-  case 1: Kind = SectionKind::get(SectionKind::ReadOnlyWithRelLocal); break;
+  case 2: Kind = SectionKind::get(SectionKind::ReadOnlyWithRel,false); break;
+  case 1:
+    Kind = SectionKind::get(SectionKind::ReadOnlyWithRelLocal,false);
+    break;
   case 0:
     switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
-    case 4:   Kind = SectionKind::get(SectionKind::MergeableConst4); break;
-    case 8:   Kind = SectionKind::get(SectionKind::MergeableConst8); break;
-    case 16:  Kind = SectionKind::get(SectionKind::MergeableConst16); break;
-    default:  Kind = SectionKind::get(SectionKind::MergeableConst); break;
+    case 4:  Kind = SectionKind::get(SectionKind::MergeableConst4,false); break;
+    case 8:  Kind = SectionKind::get(SectionKind::MergeableConst8,false); break;
+    case 16: Kind = SectionKind::get(SectionKind::MergeableConst16,false);break;
+    default: Kind = SectionKind::get(SectionKind::MergeableConst,false); break;
     }
   }
   

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

==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Sun Jul 26 02:00:12 2009
@@ -220,23 +220,24 @@
 static SectionKind SectionKindForGlobal(const GlobalValue *GV,
                                         const TargetMachine &TM) {
   Reloc::Model ReloModel = TM.getRelocationModel();
+  bool isWeak = GV->isWeakForLinker();
   
   // Early exit - functions should be always in text sections.
   const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
   if (GVar == 0)
-    return SectionKind::get(SectionKind::Text);
+    return SectionKind::get(SectionKind::Text, isWeak);
 
   
   // Handle thread-local data first.
   if (GVar->isThreadLocal()) {
     if (isSuitableForBSS(GVar))
-      return SectionKind::get(SectionKind::ThreadBSS);
-    return SectionKind::get(SectionKind::ThreadData);;
+      return SectionKind::get(SectionKind::ThreadBSS, isWeak);
+    return SectionKind::get(SectionKind::ThreadData, isWeak);
   }
 
   // Variable can be easily put to BSS section.
   if (isSuitableForBSS(GVar))
-    return SectionKind::get(SectionKind::BSS);
+    return SectionKind::get(SectionKind::BSS, isWeak);
 
   Constant *C = GVar->getInitializer();
   
@@ -252,16 +253,16 @@
       // If initializer is a null-terminated string, put it in a "cstring"
       // section if the target has it.
       if (isConstantString(C))
-        return SectionKind::get(SectionKind::MergeableCString);
+        return SectionKind::get(SectionKind::MergeableCString, isWeak);
       
       // Otherwise, just drop it into a mergable constant section.  If we have
       // a section for this size, use it, otherwise use the arbitrary sized
       // mergable section.
       switch (TM.getTargetData()->getTypeAllocSize(C->getType())) {
-      case 4:  return SectionKind::get(SectionKind::MergeableConst4);
-      case 8:  return SectionKind::get(SectionKind::MergeableConst8);
-      case 16: return SectionKind::get(SectionKind::MergeableConst16);
-      default: return SectionKind::get(SectionKind::MergeableConst);
+      case 4:  return SectionKind::get(SectionKind::MergeableConst4, isWeak);
+      case 8:  return SectionKind::get(SectionKind::MergeableConst8, isWeak);
+      case 16: return SectionKind::get(SectionKind::MergeableConst16, isWeak);
+      default: return SectionKind::get(SectionKind::MergeableConst, isWeak);
       }
       
     case Constant::LocalRelocation:
@@ -269,22 +270,22 @@
       // the relocation entries will actually be constants by the time the app
       // starts up.
       if (ReloModel == Reloc::Static)
-        return SectionKind::get(SectionKind::ReadOnly);
+        return SectionKind::get(SectionKind::ReadOnly, isWeak);
               
       // Otherwise, the dynamic linker needs to fix it up, put it in the
       // writable data.rel.local section.
-      return SectionKind::get(SectionKind::ReadOnlyWithRelLocal);
+      return SectionKind::get(SectionKind::ReadOnlyWithRelLocal, isWeak);
               
     case Constant::GlobalRelocations:
       // In static relocation model, the linker will resolve all addresses, so
       // the relocation entries will actually be constants by the time the app
       // starts up.
       if (ReloModel == Reloc::Static)
-        return SectionKind::get(SectionKind::ReadOnly);
+        return SectionKind::get(SectionKind::ReadOnly, isWeak);
       
       // Otherwise, the dynamic linker needs to fix it up, put it in the
       // writable data.rel section.
-      return SectionKind::get(SectionKind::ReadOnlyWithRel);
+      return SectionKind::get(SectionKind::ReadOnlyWithRel, isWeak);
     }
   }
 
@@ -294,16 +295,16 @@
   // globals together onto fewer pages, improving the locality of the dynamic
   // linker.
   if (ReloModel == Reloc::Static)
-    return SectionKind::get(SectionKind::DataNoRel);
+    return SectionKind::get(SectionKind::DataNoRel, isWeak);
 
   switch (C->getRelocationInfo()) {
   default: llvm_unreachable("unknown relocation info kind");
   case Constant::NoRelocation:
-    return SectionKind::get(SectionKind::DataNoRel);
+    return SectionKind::get(SectionKind::DataNoRel, isWeak);
   case Constant::LocalRelocation:
-    return SectionKind::get(SectionKind::DataRelLocal);
+    return SectionKind::get(SectionKind::DataRelLocal, isWeak);
   case Constant::GlobalRelocations:
-    return SectionKind::get(SectionKind::DataRel);
+    return SectionKind::get(SectionKind::DataRel, isWeak);
   }
 }
 





More information about the llvm-commits mailing list