1 ;; Test to ensure we properly resolve weak symbols and internalize them when
4 ; RUN: opt -module-summary %s -o %t.bc
5 ; RUN: opt -module-summary %p/Inputs/weak_resolution.ll -o %t2.bc
7 ;; First try this with the legacy LTO API
8 ; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc
9 ;; Verify that prevailing weak for linker symbol is selected across modules,
10 ;; non-prevailing ODR are not kept when possible, but non-ODR non-prevailing
12 ; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=MOD1
13 ; RUN: llvm-lto -thinlto-action=internalize %t.bc -thinlto-index=%t3.bc -exported-symbol=_linkoncefunc -o - | llvm-dis -o - | FileCheck %s --check-prefix=MOD1-INT
14 ; RUN: llvm-lto -thinlto-action=promote %t2.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=MOD2
15 ; When exported, we always preserve a linkonce
16 ; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - --exported-symbol=_linkonceodrfuncInSingleModule --exported-symbol=_weakfuncInSingleModule | llvm-dis -o - | FileCheck %s --check-prefix=EXPORTED
18 ;; Now try this with the new LTO API
19 ; RUN: llvm-lto2 run %t.bc %t2.bc -o %t3.out -save-temps \
20 ; RUN: -r %t.bc,_linkonceodralias,pl \
21 ; RUN: -r %t.bc,_linkoncealias,pl \
22 ; RUN: -r %t.bc,_linkonceodrvarInSingleModule,pl \
23 ; RUN: -r %t.bc,_weakodrvarInSingleModule,pl \
24 ; RUN: -r %t.bc,_weakvarInSingleModule,pl \
25 ; RUN: -r %t.bc,_linkonceodrfuncwithalias,pl \
26 ; RUN: -r %t.bc,_linkoncefuncwithalias,pl \
27 ; RUN: -r %t.bc,_linkonceodrfunc,pl \
28 ; RUN: -r %t.bc,_linkoncefunc,pl \
29 ; RUN: -r %t.bc,_weakodrfunc,pl \
30 ; RUN: -r %t.bc,_weakfunc,pl \
31 ; RUN: -r %t.bc,_linkonceodrfuncInSingleModule,pl \
32 ; RUN: -r %t.bc,_weakfuncInSingleModule,pl \
33 ; RUN: -r %t2.bc,_linkonceodrfuncwithalias,l \
34 ; RUN: -r %t2.bc,_linkoncefuncwithalias,l \
35 ; RUN: -r %t2.bc,_linkonceodrfunc,l \
36 ; RUN: -r %t2.bc,_linkoncefunc,l \
37 ; RUN: -r %t2.bc,_weakodrfunc,l \
38 ; RUN: -r %t2.bc,_weakfunc,l \
39 ; RUN: -r %t2.bc,_linkonceodralias,l \
40 ; RUN: -r %t2.bc,_linkoncealias,l
41 ; RUN: llvm-dis %t3.out.1.2.internalize.bc -o - | FileCheck %s --check-prefix=MOD1-INT
43 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
44 target triple = "x86_64-apple-macosx10.11.0"
46 ;; Alias are resolved, but can't be turned into "available_externally"
47 ; MOD1: @linkonceodralias = weak_odr alias void (), ptr @linkonceodrfuncwithalias
48 ; MOD2: @linkonceodralias = linkonce_odr alias void (), ptr @linkonceodrfuncwithalias
49 @linkonceodralias = linkonce_odr alias void (), ptr @linkonceodrfuncwithalias
51 ;; Alias are resolved, but can't be turned into "available_externally"
52 ; MOD1: @linkoncealias = weak alias void (), ptr @linkoncefuncwithalias
53 ; MOD2: @linkoncealias = linkonce alias void (), ptr @linkoncefuncwithalias
54 @linkoncealias = linkonce alias void (), ptr @linkoncefuncwithalias
56 ;; Non-exported linkonce/weak variables can always be internalized, regardless
57 ;; of whether they are const or *unnamed_addr.
58 ; MOD1-INT: @linkonceodrvarInSingleModule = internal global
59 ; MOD1-INT: @weakodrvarInSingleModule = internal global
60 ; MOD1-INT: @weakvarInSingleModule = internal global
61 @linkonceodrvarInSingleModule = linkonce_odr dso_local global ptr null, align 8
62 @weakodrvarInSingleModule = weak_odr dso_local global ptr null, align 8
63 @weakvarInSingleModule = weak dso_local global ptr null, align 8
65 ;; Function with an alias are resolved to weak_odr in prevailing module, but
66 ;; not optimized in non-prevailing module (illegal to have an
67 ;; available_externally aliasee).
68 ; MOD1: define weak_odr void @linkonceodrfuncwithalias()
69 ; MOD2: define linkonce_odr void @linkonceodrfuncwithalias()
70 define linkonce_odr void @linkonceodrfuncwithalias() #0 {
75 ;; Function with an alias are resolved to weak in prevailing module, but
76 ;; not optimized in non-prevailing module (illegal to have an
77 ;; available_externally aliasee).
78 ; MOD1: define weak void @linkoncefuncwithalias()
79 ; MOD2: define linkonce void @linkoncefuncwithalias()
80 define linkonce void @linkoncefuncwithalias() #0 {
85 ; MOD1: define weak_odr void @linkonceodrfunc()
86 ; MOD2: define available_externally void @linkonceodrfunc()
87 define linkonce_odr void @linkonceodrfunc() #0 {
91 ; MOD1: define weak void @linkoncefunc()
92 ;; New LTO API will use dso_local
93 ; MOD1-INT: define weak{{.*}} void @linkoncefunc()
94 ; MOD2: declare void @linkoncefunc()
95 define linkonce void @linkoncefunc() #0 {
99 ; MOD1: define weak_odr void @weakodrfunc()
100 ; MOD2: define available_externally void @weakodrfunc()
101 define weak_odr void @weakodrfunc() #0 {
105 ; MOD1: define weak void @weakfunc()
106 ; MOD2: declare void @weakfunc()
107 define weak void @weakfunc() #0 {
112 ;; A linkonce_odr with a single, non-exported, def can be safely
113 ;; internalized without increasing code size or being concerned
114 ;; about affecting function pointer equality.
115 ; MOD1: define weak_odr void @linkonceodrfuncInSingleModule()
116 ; MOD1-INT: define internal void @linkonceodrfuncInSingleModule()
117 ; EXPORTED: define weak_odr void @linkonceodrfuncInSingleModule()
118 define linkonce_odr void @linkonceodrfuncInSingleModule() #0 {
123 ; MOD1: define weak void @weakfuncInSingleModule()
124 ; MOD1-INT: define internal void @weakfuncInSingleModule()
125 ; EXPORTED: define weak void @weakfuncInSingleModule()
126 define weak void @weakfuncInSingleModule() {