aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Linker
diff options
context:
space:
mode:
authorLauro Ramos Venancio <lauro.venancio@gmail.com>2007-06-28 19:02:54 +0000
committerLauro Ramos Venancio <lauro.venancio@gmail.com>2007-06-28 19:02:54 +0000
commit31ed0fb804dd86fb15093e114701932119914400 (patch)
treecd41053f841edce10d86aabcf6ae703706269529 /lib/Linker
parentef6ba18a4c6ecddb12ec50668021776a6b73a71c (diff)
downloadexternal_llvm-31ed0fb804dd86fb15093e114701932119914400.zip
external_llvm-31ed0fb804dd86fb15093e114701932119914400.tar.gz
external_llvm-31ed0fb804dd86fb15093e114701932119914400.tar.bz2
When linking two modules, we should copy the alias.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37776 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker')
-rw-r--r--lib/Linker/LinkModules.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index 88bf621..c69010a 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -561,6 +561,31 @@ static bool LinkGlobals(Module *Dest, Module *Src,
return false;
}
+// LinkAlias - Loop through the alias in the src module and link them into the
+// dest module.
+static bool LinkAlias(Module *Dest, const Module *Src, std::string *Err) {
+ // Loop over all alias in the src module
+ for (Module::const_alias_iterator I = Src->alias_begin(),
+ E = Src->alias_end(); I != E; ++I) {
+ const GlobalAlias *GA = I;
+
+ GlobalValue *NewAliased = NULL;
+ const GlobalValue *Aliased = GA->getAliasedGlobal();
+ if (isa<GlobalVariable>(*Aliased))
+ NewAliased = Dest->getGlobalVariable(Aliased->getName());
+ else if (isa<Function>(*Aliased))
+ NewAliased = Dest->getFunction(Aliased->getName());
+ // FIXME: we should handle the bitcast alias.
+ assert(NewAliased && "Can't find the aliased GV.");
+
+ GlobalAlias *NewGA = new GlobalAlias(GA->getType()->getElementType(),
+ GA->getLinkage(), GA->getName(),
+ NewAliased, Dest);
+ CopyGVAttributes(NewGA, GA);
+ }
+ return false;
+}
+
// LinkGlobalInits - Update the initializers in the Dest module now that all
// globals that may be referenced are in Dest.
@@ -1005,6 +1030,9 @@ Linker::LinkModules(Module *Dest, Module *Src, std::string *ErrorMsg) {
// If there were any appending global variables, link them together now.
if (LinkAppendingVars(Dest, AppendingVars, ErrorMsg)) return true;
+ // If there were any alias, link them now.
+ if (LinkAlias(Dest, Src, ErrorMsg)) return true;
+
// If the source library's module id is in the dependent library list of the
// destination library, remove it since that module is now linked in.
sys::Path modId;