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%shlibext \
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; The preempted functions should have been eliminated (the plugin will
17; set linkage of odr functions to available_externally, and convert
18; linkonce and weak to declarations).
19; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck --check-prefix=OPT2 %s
20; OPT2-NOT: @
21
22; RUN: llvm-dis %t.o.3.import.bc -o - | FileCheck --check-prefix=IMPORT %s
23; RUN: llvm-dis %t2.o.3.import.bc -o - | FileCheck --check-prefix=IMPORT2 %s
24
25target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
26target triple = "x86_64-unknown-linux-gnu"
27
28
29define i32 @main() #0 {
30entry:
31  call void @linkonceodralias()
32  call void @linkoncealias()
33  call void @linkonceodrfuncwithalias()
34  call void @linkoncefuncwithalias()
35  call void @linkonceodrfunc()
36  call void @linkoncefunc()
37  call void @weakodrfunc()
38  call void @weakfunc()
39  call void @linkonceodrfuncInSingleModule()
40  ret i32 0
41}
42
43; Alias are resolved to weak_odr in prevailing module, but left as linkonce_odr
44; in non-prevailing module (illegal to have an available_externally alias).
45; IMPORT: @linkonceodralias = weak_odr alias void (), void ()* @linkonceodrfuncwithalias
46; IMPORT2: @linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
47@linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
48
49; Alias are resolved in prevailing module, but not optimized in
50; non-prevailing module (illegal to have an available_externally alias).
51; IMPORT: @linkoncealias = weak alias void (), void ()* @linkoncefuncwithalias
52; IMPORT2: @linkoncealias = linkonce alias void (), void ()* @linkoncefuncwithalias
53@linkoncealias = linkonce alias void (), void ()* @linkoncefuncwithalias
54
55; Function with an alias are resolved in prevailing module, but
56; not optimized in non-prevailing module (illegal to have an
57; available_externally aliasee).
58; IMPORT: define weak_odr void @linkonceodrfuncwithalias()
59; IMPORT2: define linkonce_odr void @linkonceodrfuncwithalias()
60define linkonce_odr void @linkonceodrfuncwithalias() #0 {
61entry:
62  ret void
63}
64
65; Function with an alias are resolved to weak in prevailing module, but
66; not optimized in non-prevailing module (illegal to have an
67; available_externally aliasee).
68; IMPORT: define weak void @linkoncefuncwithalias()
69; IMPORT2: define linkonce void @linkoncefuncwithalias()
70define linkonce void @linkoncefuncwithalias() #0 {
71entry:
72  ret void
73}
74
75; IMPORT: define weak_odr void @linkonceodrfunc()
76; IMPORT2: define available_externally void @linkonceodrfunc()
77define linkonce_odr void @linkonceodrfunc() #0 {
78entry:
79  ret void
80}
81; IMPORT: define weak void @linkoncefunc()
82; IMPORT2: declare void @linkoncefunc()
83define linkonce void @linkoncefunc() #0 {
84entry:
85  ret void
86}
87; IMPORT: define weak_odr void @weakodrfunc()
88; IMPORT2: define available_externally void @weakodrfunc()
89define weak_odr void @weakodrfunc() #0 {
90entry:
91  ret void
92}
93; IMPORT: define weak void @weakfunc()
94; IMPORT2: declare void @weakfunc()
95define weak void @weakfunc() #0 {
96entry:
97  ret void
98}
99
100; IMPORT: weak_odr void @linkonceodrfuncInSingleModule()
101define linkonce_odr void @linkonceodrfuncInSingleModule() #0 {
102entry:
103  ret void
104}
105