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.4.opt.bc -o - | FileCheck --check-prefix=OPT %s
27
28target triple = "x86_64-unknown-linux-gnu"
29
30
31define i32 @main() #0 {
32entry:
33  call void @linkonceodralias()
34  call void @linkoncealias()
35  call void @linkonceodrfuncwithalias()
36  call void @linkoncefuncwithalias()
37  call void @linkonceodrfunc()
38  call void @linkoncefunc()
39  call void @weakodrfunc()
40  call void @weakfunc()
41  call void @linkonceodrfuncInSingleModule()
42  ret i32 0
43}
44
45; Alias are resolved
46; OPT: @linkonceodralias = weak_odr alias void (), void ()* @linkonceodrfuncwithalias
47@linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
48
49; Alias are resolved
50; OPT: @linkoncealias = weak alias void (), void ()* @linkoncefuncwithalias
51@linkoncealias = linkonce alias void (), void ()* @linkoncefuncwithalias
52
53; Function with an alias are not optimized
54; OPT: define linkonce_odr void @linkonceodrfuncwithalias()
55define linkonce_odr void @linkonceodrfuncwithalias() #0 {
56entry:
57  ret void
58}
59
60; Function with an alias are not optimized
61; OPT: define linkonce void @linkoncefuncwithalias()
62define linkonce void @linkoncefuncwithalias() #0 {
63entry:
64  ret void
65}
66
67; OPT: define weak_odr void @linkonceodrfunc()
68define linkonce_odr void @linkonceodrfunc() #0 {
69entry:
70  ret void
71}
72; OPT: define weak void @linkoncefunc()
73define linkonce void @linkoncefunc() #0 {
74entry:
75  ret void
76}
77; OPT: define weak_odr void @weakodrfunc()
78define weak_odr void @weakodrfunc() #0 {
79entry:
80  ret void
81}
82; OPT: define weak void @weakfunc()
83define weak void @weakfunc() #0 {
84entry:
85  ret void
86}
87
88; OPT: weak_odr void @linkonceodrfuncInSingleModule()
89define linkonce_odr void @linkonceodrfuncInSingleModule() #0 {
90entry:
91  ret void
92}
93