]> granicus.if.org Git - llvm/commitdiff
[LTO] Fix linking with an alias defined using another alias.
authorEli Friedman <efriedma@codeaurora.org>
Fri, 13 Jul 2018 21:58:55 +0000 (21:58 +0000)
committerEli Friedman <efriedma@codeaurora.org>
Fri, 13 Jul 2018 21:58:55 +0000 (21:58 +0000)
When we're linking an alias which will be defined later, we neeed to
build a GlobalAlias, or else we'll crash later in
IRLinker::linkGlobalValueBody.

clang sometimes constructs aliases like this for C++ destructors.

Differential Revision: https://reviews.llvm.org/D49316

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337053 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Linker/IRMover.cpp
test/LTO/Resolution/X86/Inputs/alias-alias-1.ll [new file with mode: 0644]
test/LTO/Resolution/X86/alias-alias.ll [new file with mode: 0644]

index 0416ddd5601380aa0415ff139e945a828656fcd1..12f0a1e67c1d10af2444137b86f7c2d8833fc014 100644 (file)
@@ -948,7 +948,7 @@ Expected<Constant *> IRLinker::linkGlobalValueProto(GlobalValue *SGV,
     if (DoneLinkingBodies)
       return nullptr;
 
-    NewGV = copyGlobalValueProto(SGV, ShouldLink);
+    NewGV = copyGlobalValueProto(SGV, ShouldLink || ForAlias);
     if (ShouldLink || !ForAlias)
       forceRenaming(NewGV, SGV->getName());
   }
diff --git a/test/LTO/Resolution/X86/Inputs/alias-alias-1.ll b/test/LTO/Resolution/X86/Inputs/alias-alias-1.ll
new file mode 100644 (file)
index 0000000..956deab
--- /dev/null
@@ -0,0 +1,5 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@a = external global i32
+@d = global i32* @a
diff --git a/test/LTO/Resolution/X86/alias-alias.ll b/test/LTO/Resolution/X86/alias-alias.ll
new file mode 100644 (file)
index 0000000..eaf2615
--- /dev/null
@@ -0,0 +1,27 @@
+; RUN: llvm-as %s -o %t1.o
+; RUN: llvm-as %p/Inputs/alias-alias-1.ll -o %t2.o
+; RUN: llvm-lto2 run -o %t3.o %t1.o %t2.o -r %t2.o,a, -r %t2.o,d,px -r %t1.o,a,p -r %t1.o,c,p -r %t1.o,b -save-temps
+; RUN: llvm-dis < %t3.o.0.0.preopt.bc -o - | FileCheck %s
+; RUN: FileCheck --check-prefix=RES %s < %t3.o.resolution.txt
+
+; CHECK-NOT: alias
+; CHECK: @c = global i32 1
+; CHECK-NEXT: @d = global i32* @a
+; CHECK-EMPTY:
+; CHECK-NEXT: @a = weak alias i32, i32* @b
+; CHECK-NEXT: @b = internal alias i32, i32* @c
+
+; RES: 1.o{{$}}
+; RES-NEXT: {{^}}-r={{.*}}1.o,c,p{{$}}
+; RES-NEXT: {{^}}-r={{.*}}1.o,a,p{{$}}
+; RES-NEXT: {{^}}-r={{.*}}1.o,b,{{$}}
+; RES-NEXT: 2.o{{$}}
+; RES-NEXT: {{^}}-r={{.*}}2.o,a,{{$}}
+; RES-NEXT: {{^}}-r={{.*}}2.o,d,px{{$}}
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@a = weak alias i32, i32* @b
+@b = alias i32, i32* @c
+@c = global i32 1