summaryrefslogtreecommitdiff
path: root/lib/Linker
diff options
context:
space:
mode:
authorDavid Chisnall <csdavec@swan.ac.uk>2010-01-09 16:27:31 +0000
committerDavid Chisnall <csdavec@swan.ac.uk>2010-01-09 16:27:31 +0000
commit3472246edee4e120e3eb1ec4ad443ba884bc7ac7 (patch)
treeda88c8e978c537f97e831d9e26d213409bda7d57 /lib/Linker
parent1fa8b00b30e3e9ea3ea86ccb819bb9eb11117e6d (diff)
downloadllvm-3472246edee4e120e3eb1ec4ad443ba884bc7ac7.tar.gz
llvm-3472246edee4e120e3eb1ec4ad443ba884bc7ac7.tar.bz2
llvm-3472246edee4e120e3eb1ec4ad443ba884bc7ac7.tar.xz
Fixed linking of modules containing aliases to constant bitcasts. Existing behaviour first tried to replace the aliases with the global that they aliased (rather than the bitcast), causing a crash on an assert because the types didn't match. When this was fixed, it then did the same thing creating the new alias (creating an alias with a different type to its aliasee).
Linking modules containing aliases to GEPs is still not quite right. GEPs that are equivalent to bitcasts will be replaced by bitcasts, GEPs that are not will just break. Aliases to GEPs that are not equivalent to bitcasts are horribly broken anyway (it might be worth adding an assert when creating the alias to prevent these being created; they just cause problems later). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93052 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker')
-rw-r--r--lib/Linker/LinkModules.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index d69395cf9b..dcd696c70d 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -855,9 +855,14 @@ static bool LinkAlias(Module *Dest, const Module *Src,
} else {
// No linking to be performed, simply create an identical version of the
// alias over in the dest module...
-
+ Constant *Aliasee = DAliasee;
+ // Fixup aliases to bitcasts. Note that aliases to GEPs are still broken
+ // by this, but aliases to GEPs are broken to a lot of other things, so
+ // it's less important.
+ if (SGA->getType() != DAliasee->getType())
+ Aliasee = ConstantExpr::getBitCast(DAliasee, SGA->getType());
NewGA = new GlobalAlias(SGA->getType(), SGA->getLinkage(),
- SGA->getName(), DAliasee, Dest);
+ SGA->getName(), Aliasee, Dest);
CopyGVAttributes(NewGA, SGA);
// Proceed to 'common' steps
@@ -1223,9 +1228,15 @@ static bool LinkAppendingVars(Module *M,
static bool ResolveAliases(Module *Dest) {
for (Module::alias_iterator I = Dest->alias_begin(), E = Dest->alias_end();
I != E; ++I)
- if (const GlobalValue *GV = I->resolveAliasedGlobal())
- if (GV != I && !GV->isDeclaration())
- I->replaceAllUsesWith(const_cast<GlobalValue*>(GV));
+ // We can't sue resolveGlobalAlias here because we need to preserve
+ // bitcasts and GEPs.
+ if (const Constant *C = I->getAliasee()) {
+ while (dyn_cast<GlobalAlias>(C))
+ C = cast<GlobalAlias>(C)->getAliasee();
+ const GlobalValue *GV = dyn_cast<GlobalValue>(C);
+ if (C != I && !(GV && GV->isDeclaration()))
+ I->replaceAllUsesWith(const_cast<Constant*>(C));
+ }
return false;
}