[llvm-commits] CVS: llvm/lib/Linker/LinkModules.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Dec 7 19:29:05 PST 2004



Changes in directory llvm/lib/Linker:

LinkModules.cpp updated: 1.97 -> 1.98
---
Log message:

Add a disgusting hack to work around a libstdc++ issue.  This code should
be removed when PR400: http://llvm.cs.uiuc.edu/PR400  is resolved.


---
Diffs of the changes:  (+23 -0)

Index: llvm/lib/Linker/LinkModules.cpp
diff -u llvm/lib/Linker/LinkModules.cpp:1.97 llvm/lib/Linker/LinkModules.cpp:1.98
--- llvm/lib/Linker/LinkModules.cpp:1.97	Sat Dec  4 12:54:48 2004
+++ llvm/lib/Linker/LinkModules.cpp	Tue Dec  7 21:28:51 2004
@@ -425,6 +425,20 @@
   return false;
 }
 
+// Gross hack, see call sites.
+static void CoutHack(GlobalVariable *GV1, GlobalVariable *GV2) {
+  const Type *GV1Ty = GV1->getType()->getElementType();
+  const Type *GV2Ty = GV2->getType()->getElementType();
+
+  if (GV1->isExternal() && isa<StructType>(GV1Ty) &&
+      GV2->hasInitializer() && GV2->hasExternalLinkage() && 
+      GV2->getInitializer()->isNullValue() && isa<ArrayType>(GV2Ty) &&
+      cast<ArrayType>(GV2Ty)->getElementType() == Type::SByteTy) {
+    GV1->setInitializer(Constant::getNullValue(GV1Ty));
+    GV2->setInitializer(0);
+  }
+}
+
 // LinkGlobals - Loop through the global variables in the src module and merge
 // them into the dest module.
 static bool LinkGlobals(Module *Dest, Module *Src,
@@ -459,6 +473,15 @@
     assert(SGV->hasInitializer() || SGV->hasExternalLinkage() &&
            "Global must either be external or have an initializer!");
 
+    // This is a gross hack to handle cin/cout until PR400 is implemented.  If
+    // we are linking an external struct against a zero-initialized array of
+    // sbytes, move the initializer from the array to the struct so we keep the
+    // struct type.
+    if (DGV) {
+      CoutHack(DGV, SGV);
+      CoutHack(SGV, DGV);
+    }
+
     GlobalValue::LinkageTypes NewLinkage;
     bool LinkFromSrc;
     if (GetLinkageResult(DGV, SGV, NewLinkage, LinkFromSrc, Err))






More information about the llvm-commits mailing list