1; RUN: opt -module-summary %s -o %t.o
2; RUN: opt -module-summary %p/Inputs/thinlto_weak_resolution.ll -o %t2.o
3
4; Verify that prevailing weak for linker symbol is kept.
5; Note that gold picks the first copy of a function as the prevailing one,
6; so listing %t.o first is sufficient to ensure that its copies are prevailing.
7; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
8; RUN:     --plugin-opt=thinlto \
9; RUN:     --plugin-opt=save-temps \
10; RUN:     -shared \
11; RUN:     -o %t3.o %t.o %t2.o
12
13; RUN: llvm-nm %t3.o | FileCheck %s
14; CHECK: weakfunc
15
16; Most of the preempted functions should have been eliminated (the plugin will
17; set linkage of odr functions to available_externally and linkonce functions
18; are removed by globaldce). FIXME: Need to introduce combined index linkage
19; that means "drop this function" so we can avoid importing linkonce functions
20; and drop weak functions.
21; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck --check-prefix=OPT2 %s
22; OPT2-NOT: @
23; OPT2: @weakfunc
24; OPT2-NOT: @
25
26; RUN: llvm-dis %t.o.3.import.bc -o - | FileCheck --check-prefix=IMPORT %s
27; RUN llvm-dis %t2.o.3.import.bc -o - | FileCheck --check-prefix=IMPORT2 %s
28
29target triple = "x86_64-unknown-linux-gnu"
30
31
32define i32 @main() #0 {
33entry:
34  call void @linkonceodralias()
35  call void @linkoncealias()
36  call void @linkonceodrfuncwithalias()
37  call void @linkoncefuncwithalias()
38  call void @linkonceodrfunc()
39  call void @linkoncefunc()
40  call void @weakodrfunc()
41  call void @weakfunc()
42  call void @linkonceodrfuncInSingleModule()
43  ret i32 0
44}
45
46; Alias are resolved to weak_odr in prevailing module, but left as linkonce_odr
47; in non-prevailing module (illegal to have an available_externally alias).
48; IMPORT: @linkonceodralias = weak_odr alias void (), void ()* @linkonceodrfuncwithalias
49; IMPORT2: @linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
50@linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
51
52; Alias are resolved in prevailing module, but not optimized in
53; non-prevailing module (illegal to have an available_externally alias).
54; IMPORT: @linkoncealias = weak alias void (), void ()* @linkoncefuncwithalias
55; IMPORT2: @linkoncealias = linkonce alias void (), void ()* @linkoncefuncwithalias
56@linkoncealias = linkonce alias void (), void ()* @linkoncefuncwithalias
57
58; Function with an alias are resolved in prevailing module, but
59; not optimized in non-prevailing module (illegal to have an
60; available_externally aliasee).
61; IMPORT: define weak_odr void @linkonceodrfuncwithalias()
62; IMPORT2: define linkonce_odr void @linkonceodrfuncwithalias()
63define linkonce_odr void @linkonceodrfuncwithalias() #0 {
64entry:
65  ret void
66}
67
68; Function with an alias are resolved to weak in prevailing module, but
69; not optimized in non-prevailing module (illegal to have an
70; available_externally aliasee).
71; IMPORT: define weak void @linkoncefuncwithalias()
72; IMPORT2: define linkonce void @linkoncefuncwithalias()
73define linkonce void @linkoncefuncwithalias() #0 {
74entry:
75  ret void
76}
77
78; IMPORT: define weak_odr void @linkonceodrfunc()
79; IMPORT2: define available_externally void @linkonceodrfunc()
80define linkonce_odr void @linkonceodrfunc() #0 {
81entry:
82  ret void
83}
84; IMPORT: define weak void @linkoncefunc()
85; IMPORT2: define linkonce void @linkoncefunc()
86define linkonce void @linkoncefunc() #0 {
87entry:
88  ret void
89}
90; IMPORT: define weak_odr void @weakodrfunc()
91; IMPORT2: define available_externally void @weakodrfunc()
92define weak_odr void @weakodrfunc() #0 {
93entry:
94  ret void
95}
96; IMPORT: define weak void @weakfunc()
97; IMPORT2: define weak void @weakfunc()
98define weak void @weakfunc() #0 {
99entry:
100  ret void
101}
102
103; IMPORT: weak_odr void @linkonceodrfuncInSingleModule()
104define linkonce_odr void @linkonceodrfuncInSingleModule() #0 {
105entry:
106  ret void
107}
108