[llvm-commits] [llvm] r47974 - /llvm/trunk/lib/Linker/LinkModules.cpp

Anton Korobeynikov asl at math.spbu.ru
Wed Mar 5 15:08:16 PST 2008


Author: asl
Date: Wed Mar  5 17:08:16 2008
New Revision: 47974

URL: http://llvm.org/viewvc/llvm-project?rev=47974&view=rev
Log:
Handle functions as targets during linking of aliases as well

Modified:
    llvm/trunk/lib/Linker/LinkModules.cpp

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

==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Wed Mar  5 17:08:16 2008
@@ -623,6 +623,7 @@
     } else if (GlobalVariable *DGV = Dest->getGlobalVariable(SGA->getName())) {
       RecursiveResolveTypes(SGA->getType(), DGV->getType(),
                             &Dest->getTypeSymbolTable(), "");
+
       // The only allowed way is to link alias with external declaration.
       if (DGV->isDeclaration()) {
         NewGA = new GlobalAlias(SGA->getType(), SGA->getLinkage(),
@@ -649,7 +650,30 @@
     } else if (Function *DF = Dest->getFunction(SGA->getName())) {
       RecursiveResolveTypes(SGA->getType(), DF->getType(),
                             &Dest->getTypeSymbolTable(), "");
-      assert(0 && "FIXME");
+
+      // The only allowed way is to link alias with external declaration.
+      if (DF->isDeclaration()) {
+        NewGA = new GlobalAlias(SGA->getType(), SGA->getLinkage(),
+                                SGA->getName(), DAliasee, Dest);
+        CopyGVAttributes(NewGA, SGA);
+
+        // Any uses of DF need to change to NewGA, with cast, if needed.
+        if (SGA->getType() != DF->getType())
+          DF->replaceAllUsesWith(ConstantExpr::getBitCast(NewGA,
+                                                          DF->getType()));
+        else
+          DF->replaceAllUsesWith(NewGA);
+
+        // DF will conflict with NewGA because they both had the same
+        // name. We must erase this now so ForceRenaming doesn't assert
+        // because DF might not have internal linkage.
+        DF->eraseFromParent();
+
+        // Proceed to 'common' steps
+      } else
+        return Error(Err, "Alias Collision on '" +
+                     ToStr(SGA->getType(), Src) +"':%"+SGA->getName()+
+                     " - symbol multiple defined");
     } else {
       // Nothing similar found, just copy alias into destination module.
 





More information about the llvm-commits mailing list