[llvm-branch-commits] [llvm-branch] r134472 - /llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp

Chris Lattner sabre at nondot.org
Tue Jul 5 23:10:35 PDT 2011


Author: lattner
Date: Wed Jul  6 01:10:35 2011
New Revision: 134472

URL: http://llvm.org/viewvc/llvm-project?rev=134472&view=rev
Log:
simplify handling of appending globals to be more local.

Modified:
    llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp

Modified: llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp?rev=134472&r1=134471&r2=134472&view=diff
==============================================================================
--- llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp (original)
+++ llvm/branches/type-system-rewrite/lib/Linker/LinkModules.cpp Wed Jul  6 01:10:35 2011
@@ -413,12 +413,6 @@
     // If Dest is external but Src is not:
     LinkFromSrc = true;
     LT = Src->getLinkage();
-  } else if (Src->hasAppendingLinkage() || Dest->hasAppendingLinkage()) {
-    if (Src->getLinkage() != Dest->getLinkage())
-      return emitError("Linking globals named '" + Src->getName() +
-            "': can only link appending global with another appending global!");
-    LinkFromSrc = true; // Special cased.
-    LT = Src->getLinkage();
   } else if (Src->isWeakForLinker()) {
     // At this point we know that Dest has LinkOnce, External*, Weak, Common,
     // or DLL* linkage.
@@ -466,6 +460,10 @@
 bool ModuleLinker::linkAppendingVars(GlobalVariable *DstGV,
                                      const GlobalVariable *SrcGV) {
  
+  if (!SrcGV->hasAppendingLinkage() || !DstGV->hasAppendingLinkage())
+    return emitError("Linking globals named '" + SrcGV->getName() +
+           "': can only link appending global with another appending global!");
+  
   ArrayType *DstTy = cast<ArrayType>(DstGV->getType()->getElementType());
   ArrayType *SrcTy = cast<ArrayType>(SrcGV->getType()->getElementType());
   // FIXME: Should map element type.
@@ -606,14 +604,15 @@
     return false;
   }
 
+  // Concatenation of appending linkage variables is magic.
+  if (DGV->hasAppendingLinkage() || SGV->hasAppendingLinkage())
+    return linkAppendingVars(cast<GlobalVariable>(DGV), SGV);
+
   GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
   bool LinkFromSrc = false;
   if (getLinkageResult(DGV, SGV, NewLinkage, LinkFromSrc))
     return true;
 
-  if (DGV->hasAppendingLinkage())
-    return linkAppendingVars(cast<GlobalVariable>(DGV), SGV);
-
   if (LinkFromSrc) {
     if (isa<GlobalAlias>(DGV))
       return emitError("Global alias collision on '" + SGV->getName() +





More information about the llvm-branch-commits mailing list