14566c6dbSTeresa Johnson; Test to ensure that ThinLTO sorts the modules before passing to the 24566c6dbSTeresa Johnson; final native link based on the linker's determination of which 34566c6dbSTeresa Johnson; object within a static library contains the prevailing def of a symbol. 44566c6dbSTeresa Johnson 54566c6dbSTeresa Johnson; First generate bitcode with a module summary index for each file 64566c6dbSTeresa Johnson; RUN: opt -module-summary %s -o %t.o 74566c6dbSTeresa Johnson; RUN: opt -module-summary %p/Inputs/thinlto_weak_library1.ll -o %t2.o 84566c6dbSTeresa Johnson; RUN: opt -module-summary %p/Inputs/thinlto_weak_library2.ll -o %t3.o 94566c6dbSTeresa Johnson 104566c6dbSTeresa Johnson; Although the objects are ordered "%t2.o %t3.o" in the library, the 114566c6dbSTeresa Johnson; linker selects %t3.o first since it satisfies a strong reference from 124566c6dbSTeresa Johnson; %t.o. It later selects %t2.o based on the strong ref from %t3.o. 134566c6dbSTeresa Johnson; Therefore, %t3.o's copy of @f is prevailing, and we need to link 144566c6dbSTeresa Johnson; %t3.o before %t2.o in the final native link. 153efcfaddSEugene Leviant; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \ 164566c6dbSTeresa Johnson; RUN: --plugin-opt=thinlto \ 174566c6dbSTeresa Johnson; RUN: --plugin-opt=save-temps \ 184566c6dbSTeresa Johnson; RUN: -m elf_x86_64 \ 194566c6dbSTeresa Johnson; RUN: -o %t4 \ 204566c6dbSTeresa Johnson; RUN: %t.o \ 214566c6dbSTeresa Johnson; RUN: --start-lib %t2.o %t3.o --end-lib 224566c6dbSTeresa Johnson 234566c6dbSTeresa Johnson; Make sure we completely dropped the definition of the non-prevailing 244566c6dbSTeresa Johnson; copy of f() (and didn't simply convert to available_externally, which 254566c6dbSTeresa Johnson; would incorrectly enable inlining). 264566c6dbSTeresa Johnson; RUN: llvm-dis %t2.o.1.promote.bc -o - | FileCheck %s 27*c3de1d0bSFangrui Song; CHECK: declare i32 @f() 284566c6dbSTeresa Johnson 294566c6dbSTeresa Johnson; ModuleID = 'thinlto_weak_library.c' 304566c6dbSTeresa Johnsonsource_filename = "thinlto_weak_library.c" 314566c6dbSTeresa Johnsontarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 324566c6dbSTeresa Johnsontarget triple = "x86_64-unknown-linux-gnu" 334566c6dbSTeresa Johnson 344566c6dbSTeresa Johnson; Function Attrs: nounwind uwtable 354566c6dbSTeresa Johnsondefine i32 @main() local_unnamed_addr { 364566c6dbSTeresa Johnsonentry: 374566c6dbSTeresa Johnson tail call void (...) @test2() 384566c6dbSTeresa Johnson ret i32 0 394566c6dbSTeresa Johnson} 404566c6dbSTeresa Johnson 414566c6dbSTeresa Johnsondeclare void @test2(...) local_unnamed_addr 42