summaryrefslogtreecommitdiffstats
path: root/llvm/test/LTO/Resolution
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2017-06-30 14:03:24 +0000
committerTeresa Johnson <tejohnson@google.com>2017-06-30 14:03:24 +0000
commitb247ffbaed52c4518b8bd688a9716ba21f5513ca (patch)
tree477988f624fd143b6586ef2fffecc69dceec05f0 /llvm/test/LTO/Resolution
parent7b6097ce737a17d69e14ec9203b2b6eb0db3e57c (diff)
downloadbcm5719-llvm-b247ffbaed52c4518b8bd688a9716ba21f5513ca.tar.gz
bcm5719-llvm-b247ffbaed52c4518b8bd688a9716ba21f5513ca.zip
[LTO] Remove values from non-prevailing comdats
Summary: When linking a regular LTO module, if it has any non-prevailing values (dropped to available_externally) in comdats, we need to do more than just remove those values from their comdat. We also remove all values from that comdat, so as to avoid leaving an incomplete comdat. This is necessary in case we are compiling in mixed regular and ThinLTO mode, since the resulting regularLTO native object is always linked into the final binary first. We need to prevent the linker from selecting an incomplete comdat that was not the prevailing copy. Fixes PR32980. Reviewers: pcc, rafael Subscribers: mehdi_amini, david2050, llvm-commits, inglorion Differential Revision: https://reviews.llvm.org/D34803 llvm-svn: 306826
Diffstat (limited to 'llvm/test/LTO/Resolution')
-rw-r--r--llvm/test/LTO/Resolution/X86/Inputs/comdat-mixed-lto.ll23
-rw-r--r--llvm/test/LTO/Resolution/X86/comdat-mixed-lto.ll42
2 files changed, 65 insertions, 0 deletions
diff --git a/llvm/test/LTO/Resolution/X86/Inputs/comdat-mixed-lto.ll b/llvm/test/LTO/Resolution/X86/Inputs/comdat-mixed-lto.ll
new file mode 100644
index 00000000000..0112b89f98d
--- /dev/null
+++ b/llvm/test/LTO/Resolution/X86/Inputs/comdat-mixed-lto.ll
@@ -0,0 +1,23 @@
+; ModuleID = 'comdat-mixed-lto1.o'
+source_filename = "comdat-mixed-lto1.cpp"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%"class.Test::ptr" = type { i32 }
+
+$C = comdat any
+
+@C = linkonce_odr global %"class.Test::ptr" zeroinitializer, comdat, align 4
+@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init, i8* bitcast (%"class.Test::ptr"* @C to i8*) }]
+
+define void @testglobfunc() #1 section ".text.startup" comdat($C) {
+entry:
+ ret void
+}
+
+; Function Attrs: noinline uwtable
+define internal void @__cxx_global_var_init() #1 section ".text.startup" comdat($C) {
+entry:
+ store i32 0, i32* getelementptr inbounds (%"class.Test::ptr", %"class.Test::ptr"* @C, i32 0, i32 0), align 4
+ ret void
+}
diff --git a/llvm/test/LTO/Resolution/X86/comdat-mixed-lto.ll b/llvm/test/LTO/Resolution/X86/comdat-mixed-lto.ll
new file mode 100644
index 00000000000..f6ee22e4161
--- /dev/null
+++ b/llvm/test/LTO/Resolution/X86/comdat-mixed-lto.ll
@@ -0,0 +1,42 @@
+; Test of comdat handling with mixed thinlto and regular lto compilation.
+
+; This module is compiled with ThinLTO
+; RUN: opt -module-summary -o %t1.o %s
+; Input module compiled for regular LTO
+; RUN: opt -o %t2.o %p/Inputs/comdat-mixed-lto.ll
+
+; The copy of C from this module is prevailing. The copy of C from the
+; regular LTO module is not prevailing, and will be dropped to
+; available_externally.
+; RUN: llvm-lto2 run -r=%t1.o,C,pl -r=%t2.o,C,l -r=%t2.o,testglobfunc,lxp -r=%t1.o,testglobfunc,lx -o %t3 %t1.o %t2.o -save-temps
+
+; The Input module (regular LTO) is %t3.0. Check to make sure that we removed
+; __cxx_global_var_init and testglobfunc from comdat. Also check to ensure
+; that testglobfunc was dropped to available_externally. Otherwise we would
+; have linker multiply defined errors as it is no longer in a comdat and
+; would clash with the copy from this module.
+; RUN: llvm-dis %t3.0.0.preopt.bc -o - | FileCheck %s
+; CHECK: define internal void @__cxx_global_var_init() section ".text.startup" {
+; CHECK: define available_externally void @testglobfunc() section ".text.startup" {
+
+; ModuleID = 'comdat-mixed-lto.o'
+source_filename = "comdat-mixed-lto.cpp"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%"class.Test::ptr" = type { i32 }
+
+$C = comdat any
+
+@C = linkonce_odr global %"class.Test::ptr" zeroinitializer, comdat, align 4
+@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init, i8* bitcast (%"class.Test::ptr"* @C to i8*) }]
+define void @testglobfunc() #1 section ".text.startup" comdat($C) {
+entry:
+ ret void
+}
+
+; Function Attrs: noinline uwtable
+define internal void @__cxx_global_var_init() #1 section ".text.startup" comdat($C) {
+entry:
+ ret void
+}
OpenPOWER on IntegriCloud