summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Linker/IRMover.cpp11
-rw-r--r--llvm/test/Linker/alias-3.ll13
2 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 9a2cedfc59e..d357bbfeb17 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -557,6 +557,17 @@ void IRLinker::materializeInitFor(GlobalValue *New, GlobalValue *Old,
return;
}
+ // When linking a global for an alias, it will always be linked. However we
+ // need to check if it was not already scheduled to satify a reference from a
+ // regular global value initializer. We know if it has been schedule if the
+ // "New" GlobalValue that is mapped here for the alias is the same as the one
+ // already mapped. If there is an entry in the ValueMap but the value is
+ // different, it means that the value already had a definition in the
+ // destination module (linkonce for instance), but we need a new definition
+ // for the alias ("New" will be different.
+ if (ForAlias && ValueMap.lookup(Old) == New)
+ return;
+
if (ForAlias || shouldLink(New, *Old))
linkGlobalValueBody(*New, *Old);
}
diff --git a/llvm/test/Linker/alias-3.ll b/llvm/test/Linker/alias-3.ll
new file mode 100644
index 00000000000..4fb88a65c19
--- /dev/null
+++ b/llvm/test/Linker/alias-3.ll
@@ -0,0 +1,13 @@
+; RUN: llvm-link %s -S -o - | FileCheck %s
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.9"
+
+; CHECK-DAG: @A = internal constant i8 1
+; CHECK-DAG: @B = alias i8, i8* @A
+; CHECK-DAG: @C = global [2 x i8*] [i8* @A, i8* @B]
+
+@A = internal constant i8 1
+@B = alias i8, i8* @A
+@C = global [2 x i8*] [i8* @A, i8* @B]
+
+
OpenPOWER on IntegriCloud