[llvm-commits] [llvm] r51118 - in /llvm/trunk: include/llvm/ lib/AsmParser/ lib/Bitcode/Reader/ lib/Bitcode/Writer/ lib/CodeGen/ lib/ExecutionEngine/ lib/Linker/ lib/Target/Alpha/ lib/Target/CBackend/ lib/Target/CellSPU/ lib/Target/CppBackend/ lib/Target/IA64/ lib/Target/Mips/ lib/Target/PIC16/ lib/Target/PowerPC/ lib/Target/Sparc/ lib/Target/X86/ lib/VMCore/

Dale Johannesen dalej at apple.com
Wed May 14 13:12:51 PDT 2008


Author: johannes
Date: Wed May 14 15:12:51 2008
New Revision: 51118

URL: http://llvm.org/viewvc/llvm-project?rev=51118&view=rev
Log:
Add CommonLinkage; currently tentative definitions
are represented as "weak", but there are subtle differences
in some cases on Darwin, so we need both.  The intent
is that "common" will behave identically to "weak" unless
somebody changes their target to do something else.
No functional change as yet.


Modified:
    llvm/trunk/include/llvm/GlobalValue.h
    llvm/trunk/lib/AsmParser/LLLexer.cpp
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/trunk/lib/CodeGen/ELFWriter.cpp
    llvm/trunk/lib/CodeGen/MachOWriter.cpp
    llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/lib/Target/Alpha/AlphaAsmPrinter.cpp
    llvm/trunk/lib/Target/CBackend/CBackend.cpp
    llvm/trunk/lib/Target/CellSPU/SPUAsmPrinter.cpp
    llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp
    llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp
    llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
    llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp
    llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
    llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp
    llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp
    llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp
    llvm/trunk/lib/Target/X86/X86IntelAsmPrinter.cpp
    llvm/trunk/lib/Target/X86/X86Subtarget.cpp
    llvm/trunk/lib/VMCore/AsmWriter.cpp

Modified: llvm/trunk/include/llvm/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalValue.h?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/include/llvm/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/GlobalValue.h Wed May 14 15:12:51 2008
@@ -38,7 +38,8 @@
     DLLImportLinkage,   ///< Function to be imported from DLL
     DLLExportLinkage,   ///< Function to be accessible from DLL
     ExternalWeakLinkage,///< ExternalWeak linkage description
-    GhostLinkage        ///< Stand-in functions for streaming fns from BC files    
+    GhostLinkage,       ///< Stand-in functions for streaming fns from BC files
+    CommonLinkage       ///< Tentative definitions
   };
 
   /// @brief An enumeration for the kinds of visibility of global values.
@@ -100,6 +101,7 @@
   bool hasExternalLinkage()   const { return Linkage == ExternalLinkage; }
   bool hasLinkOnceLinkage()   const { return Linkage == LinkOnceLinkage; }
   bool hasWeakLinkage()       const { return Linkage == WeakLinkage; }
+  bool hasCommonLinkage()     const { return Linkage == CommonLinkage; }
   bool hasAppendingLinkage()  const { return Linkage == AppendingLinkage; }
   bool hasInternalLinkage()   const { return Linkage == InternalLinkage; }
   bool hasDLLImportLinkage()  const { return Linkage == DLLImportLinkage; }

Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLLexer.cpp Wed May 14 15:12:51 2008
@@ -451,6 +451,7 @@
   KEYWORD("appending", APPENDING);
   KEYWORD("dllimport", DLLIMPORT);
   KEYWORD("dllexport", DLLEXPORT);
+  KEYWORD("common", COMMON);
   KEYWORD("hidden", HIDDEN);
   KEYWORD("protected", PROTECTED);
   KEYWORD("extern_weak", EXTERN_WEAK);

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Wed May 14 15:12:51 2008
@@ -66,6 +66,7 @@
   case 5: return GlobalValue::DLLImportLinkage;
   case 6: return GlobalValue::DLLExportLinkage;
   case 7: return GlobalValue::ExternalWeakLinkage;
+  case 8: return GlobalValue::CommonLinkage;
   }
 }
 

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Wed May 14 15:12:51 2008
@@ -270,6 +270,7 @@
   case GlobalValue::DLLImportLinkage:    return 5;
   case GlobalValue::DLLExportLinkage:    return 6;
   case GlobalValue::ExternalWeakLinkage: return 7;
+  case GlobalValue::CommonLinkage:       return 8;
   }
 }
 

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

==============================================================================
--- llvm/trunk/lib/CodeGen/ELFWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/ELFWriter.cpp Wed May 14 15:12:51 2008
@@ -282,7 +282,8 @@
     // If this global is part of the common block, add it now.  Variables are
     // part of the common block if they are zero initialized and allowed to be
     // merged with other symbols.
-    if (GV->hasLinkOnceLinkage() || GV->hasWeakLinkage()) {
+    if (GV->hasLinkOnceLinkage() || GV->hasWeakLinkage() ||
+        GV->hasCommonLinkage()) {
       ELFSym CommonSym(GV);
       // Value for common symbols is the alignment required.
       CommonSym.Value = Align;
@@ -313,7 +314,7 @@
     BSSSym.SetType(ELFSym::STT_OBJECT);
 
     switch (GV->getLinkage()) {
-    default:  // weak/linkonce handled above
+    default:  // weak/linkonce/common handled above
       assert(0 && "Unexpected linkage type!");
     case GlobalValue::AppendingLinkage:  // FIXME: This should be improved!
     case GlobalValue::ExternalLinkage:

Modified: llvm/trunk/lib/CodeGen/MachOWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachOWriter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachOWriter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachOWriter.cpp Wed May 14 15:12:51 2008
@@ -403,7 +403,8 @@
     // If this global is part of the common block, add it now.  Variables are
     // part of the common block if they are zero initialized and allowed to be
     // merged with other symbols.
-    if (NoInit || GV->hasLinkOnceLinkage() || GV->hasWeakLinkage()) {
+    if (NoInit || GV->hasLinkOnceLinkage() || GV->hasWeakLinkage() ||
+        GV->hasCommonLinkage()) {
       MachOSym ExtOrCommonSym(GV, Mang->getValueName(GV), MachOSym::NO_SECT,TM);
       // For undefined (N_UNDF) external (N_EXT) types, n_value is the size in
       // bytes of the symbol.
@@ -951,6 +952,7 @@
     break;
   case GlobalValue::WeakLinkage:
   case GlobalValue::LinkOnceLinkage:
+  case GlobalValue::CommonLinkage:
     assert(!isa<Function>(gv) && "Unexpected linkage type for Function!");
   case GlobalValue::ExternalLinkage:
     GVName = TAI->getGlobalPrefix() + name;

Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Wed May 14 15:12:51 2008
@@ -884,7 +884,7 @@
           continue;
         
         // Otherwise, we know it's linkonce/weak, replace it if this is a strong
-        // symbol.
+        // symbol.  FIXME is this right for common?
         if (GV->hasExternalLinkage() || GVEntry->hasExternalWeakLinkage())
           GVEntry = GV;
       }

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Wed May 14 15:12:51 2008
@@ -410,10 +410,12 @@
             "': can only link appending global with another appending global!");
     LinkFromSrc = true; // Special cased.
     LT = Src->getLinkage();
-  } else if (Src->hasWeakLinkage() || Src->hasLinkOnceLinkage()) {
-    // At this point we know that Dest has LinkOnce, External*, Weak, or
-    // DLL* linkage.
-    if ((Dest->hasLinkOnceLinkage() && Src->hasWeakLinkage()) ||
+  } else if (Src->hasWeakLinkage() || Src->hasLinkOnceLinkage() ||
+             Src->hasCommonLinkage()) {
+    // At this point we know that Dest has LinkOnce, External*, Weak, Common,
+    // or DLL* linkage.
+    if ((Dest->hasLinkOnceLinkage() && 
+          (Src->hasWeakLinkage() || Src->hasCommonLinkage())) ||
         Dest->hasExternalWeakLinkage()) {
       LinkFromSrc = true;
       LT = Src->getLinkage();
@@ -421,7 +423,8 @@
       LinkFromSrc = false;
       LT = Dest->getLinkage();
     }
-  } else if (Dest->hasWeakLinkage() || Dest->hasLinkOnceLinkage()) {
+  } else if (Dest->hasWeakLinkage() || Dest->hasLinkOnceLinkage() ||
+             Dest->hasCommonLinkage()) {
     // At this point we know that Src has External* or DLL* linkage.
     if (Src->hasExternalWeakLinkage()) {
       LinkFromSrc = false;
@@ -792,10 +795,12 @@
           if (DGV->getInitializer() != SInit)
             return Error(Err, "Global Variable Collision on '" + SGV->getName() +
                          "': global variables have different initializers");
-        } else if (DGV->hasLinkOnceLinkage() || DGV->hasWeakLinkage()) {
+        } else if (DGV->hasLinkOnceLinkage() || DGV->hasWeakLinkage() ||
+                   DGV->hasCommonLinkage()) {
           // Nothing is required, mapped values will take the new global
           // automatically.
-        } else if (SGV->hasLinkOnceLinkage() || SGV->hasWeakLinkage()) {
+        } else if (SGV->hasLinkOnceLinkage() || SGV->hasWeakLinkage() ||
+                   SGV->hasCommonLinkage()) {
           // Nothing is required, mapped values will take the new global
           // automatically.
         } else if (DGV->hasAppendingLinkage()) {
@@ -916,16 +921,19 @@
       DF->setLinkage(SF->getLinkage());
       // Visibility of prototype is overridden by vis of definition.
       DF->setVisibility(SF->getVisibility());
-    } else if (SF->hasWeakLinkage() || SF->hasLinkOnceLinkage()) {
+    } else if (SF->hasWeakLinkage() || SF->hasLinkOnceLinkage() ||
+               SF->hasCommonLinkage()) {
       // At this point we know that DF has LinkOnce, Weak, or External* linkage.
       ValueMap[SF] = DF;
 
       // Linkonce+Weak = Weak
       // *+External Weak = *
-      if ((DF->hasLinkOnceLinkage() && SF->hasWeakLinkage()) ||
+      if ((DF->hasLinkOnceLinkage() && 
+              (SF->hasWeakLinkage() || SF->hasCommonLinkage())) ||
           DF->hasExternalWeakLinkage())
         DF->setLinkage(SF->getLinkage());
-    } else if (DF->hasWeakLinkage() || DF->hasLinkOnceLinkage()) {
+    } else if (DF->hasWeakLinkage() || DF->hasLinkOnceLinkage() ||
+               DF->hasCommonLinkage()) {
       // At this point we know that SF has LinkOnce or External* linkage.
       ValueMap[SF] = DF;
       if (!SF->hasLinkOnceLinkage() && !SF->hasExternalWeakLinkage())

Modified: llvm/trunk/lib/Target/Alpha/AlphaAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaAsmPrinter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Alpha/AlphaAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Alpha/AlphaAsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -225,6 +225,7 @@
     switch (I->getLinkage()) {
     case GlobalValue::LinkOnceLinkage:
     case GlobalValue::WeakLinkage:
+    case GlobalValue::CommonLinkage:
       O << TAI->getWeakRefDirective() << name << '\n';
       break;
     case GlobalValue::AppendingLinkage:

Modified: llvm/trunk/lib/Target/CBackend/CBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CBackend/CBackend.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Target/CBackend/CBackend.cpp (original)
+++ llvm/trunk/lib/Target/CBackend/CBackend.cpp Wed May 14 15:12:51 2008
@@ -1604,7 +1604,8 @@
     for (Module::global_iterator I = M.global_begin(), E = M.global_end();
          I != E; ++I) {
 
-      if (I->hasExternalLinkage() || I->hasExternalWeakLinkage())
+      if (I->hasExternalLinkage() || I->hasExternalWeakLinkage() || 
+          I->hasCommonLinkage())
         Out << "extern ";
       else if (I->hasDLLImportLinkage())
         Out << "__declspec(dllimport) ";
@@ -1678,6 +1679,8 @@
 
         if (I->hasLinkOnceLinkage())
           Out << " __attribute__((common))";
+        else if (I->hasCommonLinkage())     // FIXME is this right?
+          Out << " __ATTRIBUTE_WEAK__";
         else if (I->hasWeakLinkage())
           Out << " __ATTRIBUTE_WEAK__";
         else if (I->hasExternalWeakLinkage())
@@ -1715,6 +1718,8 @@
           Out << " __attribute__((common))";
         else if (I->hasWeakLinkage())
           Out << " __ATTRIBUTE_WEAK__";
+        else if (I->hasCommonLinkage())
+          Out << " __ATTRIBUTE_WEAK__";
 
         if (I->hasHiddenVisibility())
           Out << " __HIDDEN__";
@@ -1724,6 +1729,7 @@
         // this, however, occurs when the variable has weak linkage.  In this
         // case, the assembler will complain about the variable being both weak
         // and common, so we disable this optimization.
+        // FIXME common linkage should avoid this problem.
         if (!I->getInitializer()->isNullValue()) {
           Out << " = " ;
           writeOperand(I->getInitializer());

Modified: llvm/trunk/lib/Target/CellSPU/SPUAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CellSPU/SPUAsmPrinter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Target/CellSPU/SPUAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/CellSPU/SPUAsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -340,7 +340,7 @@
     // stubs
     if (TM.getRelocationModel() != Reloc::Static) {
       if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
-            GV->hasLinkOnceLinkage()))) {
+            GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
         GVStubs.insert(Name);
         O << "L" << Name << "$non_lazy_ptr";
         return;
@@ -510,7 +510,7 @@
 
     if (C->isNullValue() && /* FIXME: Verify correct */
         (I->hasInternalLinkage() || I->hasWeakLinkage() ||
-         I->hasLinkOnceLinkage() ||
+         I->hasLinkOnceLinkage() || I->hasCommonLinkage() ||
          (I->hasExternalLinkage() && !I->hasSection()))) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
       if (I->hasExternalLinkage()) {
@@ -537,6 +537,7 @@
       switch (I->getLinkage()) {
       case GlobalValue::LinkOnceLinkage:
       case GlobalValue::WeakLinkage:
+      case GlobalValue::CommonLinkage:
         O << "\t.global " << name << '\n'
           << "\t.weak_definition " << name << '\n';
         SwitchToDataSection(".section __DATA,__datacoal_nt,coalesced", I);

Modified: llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp (original)
+++ llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp Wed May 14 15:12:51 2008
@@ -301,6 +301,8 @@
       Out << "GlobalValue::ExternalWeakLinkage"; break;
     case GlobalValue::GhostLinkage:
       Out << "GlobalValue::GhostLinkage"; break;
+    case GlobalValue::CommonLinkage:
+      Out << "GlobalValue::CommonLinkage"; break;
     }
   }
 

Modified: llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/IA64/IA64AsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -275,6 +275,7 @@
 
       if (C->isNullValue() &&
           (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
+           I->hasCommonLinkage() ||
            I->hasWeakLinkage() /* FIXME: Verify correct */)) {
         SwitchToDataSection(".data", I);
         if (I->hasInternalLinkage()) {
@@ -289,6 +290,7 @@
       } else {
         switch (I->getLinkage()) {
           case GlobalValue::LinkOnceLinkage:
+          case GlobalValue::CommonLinkage:
           case GlobalValue::WeakLinkage:   // FIXME: Verify correct for weak.
                                            // Nonnull linkonce -> weak
             O << "\t.weak " << name << "\n";

Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -461,7 +461,8 @@
 
       // Is this correct ?
       if (C->isNullValue() && (I->hasLinkOnceLinkage() || 
-          I->hasInternalLinkage() || I->hasWeakLinkage())) 
+          I->hasInternalLinkage() || I->hasWeakLinkage() ||
+          I->hasCommonLinkage()))
       {
         if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
@@ -487,7 +488,8 @@
         switch (I->getLinkage()) 
         {
           case GlobalValue::LinkOnceLinkage:
-          case GlobalValue::WeakLinkage:   
+          case GlobalValue::CommonLinkage:
+          case GlobalValue::WeakLinkage:
             // FIXME: Verify correct for weak.
             // Nonnull linkonce -> weak
             O << "\t.weak " << name << "\n";

Modified: llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16AsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -414,7 +414,7 @@
 
       if (!I->hasSection() &&
           (I->hasInternalLinkage() || I->hasWeakLinkage() ||
-           I->hasLinkOnceLinkage())) {
+           I->hasLinkOnceLinkage() || I->hasCommonLinkage())) {
         if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
         if (!NoZerosInBSS && TAI->getBSSSection())
           SwitchToDataSection(M.getModuleIdentifier().c_str(), I);

Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -185,7 +185,7 @@
         if (MO.getType() == MachineOperand::MO_GlobalAddress) {
           GlobalValue *GV = MO.getGlobal();
           if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
-                GV->hasLinkOnceLinkage()))) {
+                GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
             // Dynamically-resolved functions need a stub for the function.
             std::string Name = Mang->getValueName(GV);
             FnStubs.insert(Name);
@@ -390,7 +390,7 @@
     // External or weakly linked global variables need non-lazily-resolved stubs
     if (TM.getRelocationModel() != Reloc::Static) {
       if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
-            GV->hasLinkOnceLinkage()))) {
+            GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
         GVStubs.insert(Name);
         O << "L" << Name << "$non_lazy_ptr";
         return;
@@ -671,8 +671,8 @@
     unsigned Align = TD->getPreferredAlignmentLog(I);
 
     if (C->isNullValue() && /* FIXME: Verify correct */
-        !I->hasSection() &&
-        (I->hasInternalLinkage() || I->hasWeakLinkage() ||
+        !I->hasSection() && (I->hasCommonLinkage() ||
+         I->hasInternalLinkage() || I->hasWeakLinkage() ||
          I->hasLinkOnceLinkage() || I->hasExternalLinkage())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
       if (I->hasExternalLinkage()) {
@@ -696,6 +696,7 @@
       switch (I->getLinkage()) {
       case GlobalValue::LinkOnceLinkage:
       case GlobalValue::WeakLinkage:
+      case GlobalValue::CommonLinkage:
         O << "\t.global " << name << '\n'
           << "\t.type " << name << ", @object\n"
           << "\t.weak " << name << '\n';
@@ -936,8 +937,8 @@
     unsigned Align = TD->getPreferredAlignmentLog(I);
 
     if (C->isNullValue() && /* FIXME: Verify correct */
-        !I->hasSection() &&
-        (I->hasInternalLinkage() || I->hasWeakLinkage() ||
+        !I->hasSection() && (I->hasCommonLinkage() ||
+         I->hasInternalLinkage() || I->hasWeakLinkage() ||
          I->hasLinkOnceLinkage() || I->hasExternalLinkage())) {
       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
       if (I->hasExternalLinkage()) {
@@ -961,6 +962,7 @@
       switch (I->getLinkage()) {
       case GlobalValue::LinkOnceLinkage:
       case GlobalValue::WeakLinkage:
+      case GlobalValue::CommonLinkage:
         O << "\t.globl " << name << '\n'
           << "\t.weak_definition " << name << '\n';
         SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", I);

Modified: llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -231,8 +231,8 @@
       unsigned Size = TD->getABITypeSize(C->getType());
       unsigned Align = TD->getPreferredAlignment(I);
 
-      if (C->isNullValue() &&
-          (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
+      if (C->isNullValue() && (I->hasCommonLinkage() ||
+           I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
            I->hasWeakLinkage() /* FIXME: Verify correct */)) {
         SwitchToDataSection(".data", I);
         if (I->hasInternalLinkage())
@@ -243,6 +243,7 @@
         O << "\n";
       } else {
         switch (I->getLinkage()) {
+        case GlobalValue::CommonLinkage:
         case GlobalValue::LinkOnceLinkage:
         case GlobalValue::WeakLinkage:   // FIXME: Verify correct for weak.
           // Nonnull linkonce -> weak

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ATTAsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -309,7 +309,8 @@
       // non-lazily-resolved stubs
       if (GV->isDeclaration() ||
           GV->hasWeakLinkage() ||
-          GV->hasLinkOnceLinkage()) {
+          GV->hasLinkOnceLinkage() ||
+          GV->hasCommonLinkage()) {
         // Dynamically-resolved functions need a stub for the function.
         if (isCallOp && isa<Function>(GV)) {
           FnStubs.insert(Name);

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -200,7 +200,7 @@
       
       if (!I->isThreadLocal() &&
           (I->hasInternalLinkage() || I->hasWeakLinkage() ||
-           I->hasLinkOnceLinkage())) {
+           I->hasLinkOnceLinkage() || I->hasCommonLinkage())) {
         if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
         if (!NoZerosInBSS && TAI->getBSSSection())
           SwitchToDataSection(TAI->getBSSSection(), I);
@@ -235,6 +235,7 @@
     }
 
     switch (I->getLinkage()) {
+    case GlobalValue::CommonLinkage:
     case GlobalValue::LinkOnceLinkage:
     case GlobalValue::WeakLinkage:
       if (Subtarget->isTargetDarwin()) {

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86IntelAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86IntelAsmPrinter.cpp Wed May 14 15:12:51 2008
@@ -373,6 +373,7 @@
     bool bCustomSegment = false;
 
     switch (I->getLinkage()) {
+    case GlobalValue::CommonLinkage:
     case GlobalValue::LinkOnceLinkage:
     case GlobalValue::WeakLinkage:
       SwitchToDataSection("");

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

==============================================================================
--- llvm/trunk/lib/Target/X86/X86Subtarget.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86Subtarget.cpp Wed May 14 15:12:51 2008
@@ -41,6 +41,7 @@
     if (isTargetDarwin()) {
       return (!isDirectCall &&
               (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
+               GV->hasCommonLinkage() ||
                (GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode())));
     } else if (isTargetELF()) {
       // Extra load is needed for all non-statics.

Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=51118&r1=51117&r2=51118&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Wed May 14 15:12:51 2008
@@ -930,6 +930,7 @@
   } else {
     switch (GV->getLinkage()) {
     case GlobalValue::InternalLinkage:     Out << "internal "; break;
+    case GlobalValue::CommonLinkage:       Out << "common "; break;
     case GlobalValue::LinkOnceLinkage:     Out << "linkonce "; break;
     case GlobalValue::WeakLinkage:         Out << "weak "; break;
     case GlobalValue::AppendingLinkage:    Out << "appending "; break;
@@ -1049,6 +1050,7 @@
   case GlobalValue::InternalLinkage:     Out << "internal "; break;
   case GlobalValue::LinkOnceLinkage:     Out << "linkonce "; break;
   case GlobalValue::WeakLinkage:         Out << "weak "; break;
+  case GlobalValue::CommonLinkage:       Out << "common "; break;
   case GlobalValue::AppendingLinkage:    Out << "appending "; break;
   case GlobalValue::DLLImportLinkage:    Out << "dllimport "; break;
   case GlobalValue::DLLExportLinkage:    Out << "dllexport "; break;





More information about the llvm-commits mailing list