1*4566c6dbSTeresa Johnson; Test to ensure that ThinLTO sorts the modules before passing to the 2*4566c6dbSTeresa Johnson; final native link based on the linker's determination of which 3*4566c6dbSTeresa Johnson; object within a static library contains the prevailing def of a symbol. 4*4566c6dbSTeresa Johnson 5*4566c6dbSTeresa Johnson; First generate bitcode with a module summary index for each file 6*4566c6dbSTeresa Johnson; RUN: opt -module-summary %s -o %t.o 7*4566c6dbSTeresa Johnson; RUN: opt -module-summary %p/Inputs/thinlto_weak_library1.ll -o %t2.o 8*4566c6dbSTeresa Johnson; RUN: opt -module-summary %p/Inputs/thinlto_weak_library2.ll -o %t3.o 9*4566c6dbSTeresa Johnson 10*4566c6dbSTeresa Johnson; Although the objects are ordered "%t2.o %t3.o" in the library, the 11*4566c6dbSTeresa Johnson; linker selects %t3.o first since it satisfies a strong reference from 12*4566c6dbSTeresa Johnson; %t.o. It later selects %t2.o based on the strong ref from %t3.o. 13*4566c6dbSTeresa Johnson; Therefore, %t3.o's copy of @f is prevailing, and we need to link 14*4566c6dbSTeresa Johnson; %t3.o before %t2.o in the final native link. 15*4566c6dbSTeresa Johnson; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \ 16*4566c6dbSTeresa Johnson; RUN: --plugin-opt=thinlto \ 17*4566c6dbSTeresa Johnson; RUN: --plugin-opt=save-temps \ 18*4566c6dbSTeresa Johnson; RUN: -m elf_x86_64 \ 19*4566c6dbSTeresa Johnson; RUN: -o %t4 \ 20*4566c6dbSTeresa Johnson; RUN: %t.o \ 21*4566c6dbSTeresa Johnson; RUN: --start-lib %t2.o %t3.o --end-lib 22*4566c6dbSTeresa Johnson 23*4566c6dbSTeresa Johnson; Make sure we completely dropped the definition of the non-prevailing 24*4566c6dbSTeresa Johnson; copy of f() (and didn't simply convert to available_externally, which 25*4566c6dbSTeresa Johnson; would incorrectly enable inlining). 26*4566c6dbSTeresa Johnson; RUN: llvm-dis %t2.o.1.promote.bc -o - | FileCheck %s 27*4566c6dbSTeresa Johnson; CHECK: declare i32 @f() 28*4566c6dbSTeresa Johnson 29*4566c6dbSTeresa Johnson; ModuleID = 'thinlto_weak_library.c' 30*4566c6dbSTeresa Johnsonsource_filename = "thinlto_weak_library.c" 31*4566c6dbSTeresa Johnsontarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 32*4566c6dbSTeresa Johnsontarget triple = "x86_64-unknown-linux-gnu" 33*4566c6dbSTeresa Johnson 34*4566c6dbSTeresa Johnson; Function Attrs: nounwind uwtable 35*4566c6dbSTeresa Johnsondefine i32 @main() local_unnamed_addr { 36*4566c6dbSTeresa Johnsonentry: 37*4566c6dbSTeresa Johnson tail call void (...) @test2() 38*4566c6dbSTeresa Johnson ret i32 0 39*4566c6dbSTeresa Johnson} 40*4566c6dbSTeresa Johnson 41*4566c6dbSTeresa Johnsondeclare void @test2(...) local_unnamed_addr 42