[llvm-commits] [llvm] r53154 - /llvm/trunk/lib/Linker/LinkModules.cpp
Anton Korobeynikov
asl at math.spbu.ru
Sat Jul 5 16:03:21 PDT 2008
Author: asl
Date: Sat Jul 5 18:03:21 2008
New Revision: 53154
URL: http://llvm.org/viewvc/llvm-project?rev=53154&view=rev
Log:
Properly link alias and function decls. This fixes PR2146
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=53154&r1=53153&r2=53154&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Sat Jul 5 18:03:21 2008
@@ -899,21 +899,30 @@
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Function *SF = I; // SrcFunction
- Function *DF = 0;
+ GlobalValue *DGV = 0;
Value *MappedDF;
// If this function is internal or has no name, it doesn't participate in
// linkage.
if (SF->hasName() && !SF->hasInternalLinkage()) {
// Check to see if may have to link the function.
- DF = Dest->getFunction(SF->getName());
- if (DF && DF->hasInternalLinkage())
- DF = 0;
+ DGV = Dest->getFunction(SF->getName());
}
-
+
+ // Check to see if may have to link the function with the alias
+ if (!DGV && SF->hasName() && !SF->hasInternalLinkage()) {
+ DGV = Dest->getNamedAlias(SF->getName());
+ if (DGV && DGV->getType() != SF->getType())
+ // If types don't agree due to opaque types, try to resolve them.
+ RecursiveResolveTypes(SF->getType(), DGV->getType());
+ }
+
+ if (DGV && DGV->hasInternalLinkage())
+ DGV = 0;
+
// If there is no linkage to be performed, just bring over SF without
// modifying it.
- if (DF == 0) {
+ if (DGV == 0) {
// Function does not already exist, simply insert an function signature
// identical to SF into the dest module.
Function *NewDF = Function::Create(SF->getFunctionType(),
@@ -930,9 +939,19 @@
// ... and remember this mapping...
ValueMap[SF] = NewDF;
continue;
+ } else if (GlobalAlias *DGA = dyn_cast<GlobalAlias>(DGV)) {
+ // SF is global, but DF is alias. The only valid mapping is when SF is
+ // external declaration, which is effectively a no-op.
+ if (!SF->isDeclaration())
+ return Error(Err, "Function-Alias Collision on '" + SF->getName() +
+ "': symbol multiple defined");
+
+ // Make sure to remember this mapping...
+ ValueMap[SF] = DGA;
+ continue;
}
-
-
+
+ Function* DF = cast<Function>(DGV);
// If types don't agree because of opaque, try to resolve them.
if (SF->getType() != DF->getType())
RecursiveResolveTypes(SF->getType(), DF->getType());
More information about the llvm-commits
mailing list