1*68da426eSMehdi Amini; RUN: opt -module-summary %s -o %t.o
2*68da426eSMehdi Amini; RUN: opt -module-summary %p/Inputs/thinlto_linkonceresolution.ll -o %t2.o
3a17f2cd1STeresa Johnson
4a17f2cd1STeresa Johnson; Ensure the plugin ensures that for ThinLTO the prevailing copy of a
5a17f2cd1STeresa Johnson; linkonce symbol is changed to weak to ensure it is not eliminated.
6a17f2cd1STeresa Johnson; Note that gold picks the first copy of f() as the prevailing one,
7a17f2cd1STeresa Johnson; so listing %t2.o first is sufficient to ensure that this copy is
8a17f2cd1STeresa Johnson; preempted. Also, set the import-instr-limit to 0 to prevent f() from
9a17f2cd1STeresa Johnson; being imported from %t2.o which hides the problem.
105d07531dSTeresa Johnson; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
11a17f2cd1STeresa Johnson; RUN:     --plugin-opt=thinlto \
12a17f2cd1STeresa Johnson; RUN:     --plugin-opt=-import-instr-limit=0 \
13a17f2cd1STeresa Johnson; RUN:     --plugin-opt=save-temps \
14a17f2cd1STeresa Johnson; RUN:     -o %t3.o %t2.o %t.o
15a17f2cd1STeresa Johnson; RUN: llvm-nm %t3.o | FileCheck %s
16a17f2cd1STeresa Johnson; RUN: llvm-dis %t.o.opt.bc -o - | FileCheck --check-prefix=OPT %s
17a17f2cd1STeresa Johnson; RUN: llvm-dis %t2.o.opt.bc -o - | FileCheck --check-prefix=OPT2 %s
18a17f2cd1STeresa Johnson
19a17f2cd1STeresa Johnson; Ensure that f() is defined in resulting object file, and also
20a17f2cd1STeresa Johnson; confirm the weak linkage directly in the saved opt bitcode files.
21a17f2cd1STeresa Johnson; CHECK-NOT: U f
22a17f2cd1STeresa Johnson; OPT: declare extern_weak hidden void @f()
23a17f2cd1STeresa Johnson; OPT2: define weak_odr hidden void @f()
24a17f2cd1STeresa Johnson
25a17f2cd1STeresa Johnsontarget triple = "x86_64-unknown-linux-gnu"
26a17f2cd1STeresa Johnsondefine i32 @g() {
27a17f2cd1STeresa Johnson  call void @f()
28a17f2cd1STeresa Johnson  ret i32 0
29a17f2cd1STeresa Johnson}
30a17f2cd1STeresa Johnsondefine linkonce_odr hidden void @f() {
31a17f2cd1STeresa Johnson  ret void
32a17f2cd1STeresa Johnson}
33