Index: lib/LTO/LTO.cpp =================================================================== --- lib/LTO/LTO.cpp +++ lib/LTO/LTO.cpp @@ -291,7 +291,7 @@ recordNewLinkage) { for (auto &S : GVSummaryList) { GlobalValue::LinkageTypes OriginalLinkage = S->linkage(); - if (!GlobalValue::isWeakForLinker(OriginalLinkage)) + if (GlobalValue::isLocalLinkage(OriginalLinkage)) continue; // We need to emit only one of these. The prevailing module will keep it, // but turned into a weak, while the others will drop it when possible. Index: lib/LTO/ThinLTOCodeGenerator.cpp =================================================================== --- lib/LTO/ThinLTOCodeGenerator.cpp +++ lib/LTO/ThinLTOCodeGenerator.cpp @@ -127,8 +127,16 @@ return GVSummaryList.size() > 1; }; + auto IsAppendingLinkage = [&](const GlobalValueSummaryList &GVSummaryList) { + return GVSummaryList.size() > 0 && + GlobalValue::isAppendingLinkage(GVSummaryList[0]->linkage()); + }; + for (auto &I : Index) { - if (HasMultipleCopies(I.second.SummaryList)) + auto &GVSummaryList = I.second.SummaryList; + if (HasMultipleCopies(GVSummaryList) && + // There are no non-prevailing copies for symbols with AppendingLinkage + !IsAppendingLinkage(GVSummaryList)) PrevailingCopy[I.first] = getFirstDefinitionForLinker(I.second.SummaryList); } Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -911,7 +911,10 @@ return; } - if (!GlobalValue::isWeakForLinker(GV.getLinkage())) + if (GlobalValue::isLocalLinkage(GV.getLinkage()) || + GlobalValue::isAppendingLinkage(GV.getLinkage()) || + // In case it was dead and already converted to declaration. + GV.isDeclaration()) return; // Check for a non-prevailing def that has interposable linkage // (e.g. non-odr weak or linkonce). In that case we can't simply Index: test/LTO/Resolution/X86/dead-strip-fulllto.ll =================================================================== --- test/LTO/Resolution/X86/dead-strip-fulllto.ll +++ test/LTO/Resolution/X86/dead-strip-fulllto.ll @@ -1,14 +1,14 @@ ; RUN: opt -module-summary -o %t %s ; RUN: opt -module-summary -o %t2 %S/Inputs/dead-strip-fulllto.ll -; RUN: llvm-lto2 run %t -r %t,main,px -r %t,live1,p -r %t,live2,p -r %t,dead2,p \ -; RUN: %t2 -r %t2,live1, -r %t2,live2, -r %t2,dead1,p -r %t2,dead2, -r %t2,odr, \ +; RUN: llvm-lto2 run %t -r %t,main,px -r %t,live1, -r %t,live2,p -r %t,dead2,p \ +; RUN: %t2 -r %t2,live1,p -r %t2,live2, -r %t2,dead1,p -r %t2,dead2, -r %t2,odr, \ ; RUN: -save-temps -o %t3 ; RUN: llvm-nm %t3.0 | FileCheck --check-prefix=FULL %s ; RUN: llvm-nm %t3.1 | FileCheck --check-prefix=THIN %s -; RUN: llvm-lto2 run %t -r %t,main,px -r %t,live1,p -r %t,live2,p -r %t,dead2,p \ -; RUN: %t2 -r %t2,live1, -r %t2,live2, -r %t2,dead1,p -r %t2,dead2, -r %t2,odr, \ +; RUN: llvm-lto2 run %t -r %t,main,px -r %t,live1, -r %t,live2,p -r %t,dead2,p \ +; RUN: %t2 -r %t2,live1,p -r %t2,live2, -r %t2,dead1,p -r %t2,dead2, -r %t2,odr, \ ; RUN: -save-temps -o %t3 -O0 ; RUN: llvm-nm %t3.0 | FileCheck --check-prefix=FULL %s ; RUN: llvm-nm %t3.1 | FileCheck --check-prefix=THIN %s Index: test/ThinLTO/X86/Inputs/strong_non_prevailing.ll =================================================================== --- /dev/null +++ test/ThinLTO/X86/Inputs/strong_non_prevailing.ll @@ -0,0 +1,6 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +$__llvm_profile_filename = comdat any + +@__llvm_profile_filename = constant [19 x i8] c"default_%m.profraw\00", comdat Index: test/ThinLTO/X86/funcimport.ll =================================================================== --- test/ThinLTO/X86/funcimport.ll +++ test/ThinLTO/X86/funcimport.ll @@ -40,7 +40,7 @@ ; CODEGEN: T _main ; Verify that all run together -; RUN: llvm-lto -thinlto-action=run %t2.bc %t.bc +; RUN: llvm-lto -thinlto-action=run %t2.bc %t.bc -exported-symbol=_main ; RUN: llvm-nm -o - < %t.bc.thinlto.o | FileCheck %s --check-prefix=ALL ; RUN: llvm-nm -o - < %t2.bc.thinlto.o | FileCheck %s --check-prefix=ALL2 ; ALL: T _callfuncptr Index: test/ThinLTO/X86/strong_non_prevailing.ll =================================================================== --- /dev/null +++ test/ThinLTO/X86/strong_non_prevailing.ll @@ -0,0 +1,16 @@ +; RUN: opt -module-summary %s -o %t.bc +; RUN: opt -module-summary %p/Inputs/strong_non_prevailing.ll -o %t2.bc + +; RUN: llvm-lto -thinlto-action=run %t.bc %t2.bc -exported-symbol=__llvm_profile_filename +; RUN: llvm-nm -o - < %t.bc.thinlto.o | FileCheck %s --check-prefix=EXPORTED +; RUN: llvm-nm -o - < %t2.bc.thinlto.o 2>&1 | FileCheck %s --check-prefix=NOT_EXPORTED + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +$__llvm_profile_filename = comdat any + +@__llvm_profile_filename = constant [19 x i8] c"default_%m.profraw\00", comdat + +; EXPORTED: N __llvm_profile_filename +; NOT_EXPORTED-NOT: N __llvm_profile_filename Index: test/Transforms/FunctionImport/funcimport_var.ll =================================================================== --- test/Transforms/FunctionImport/funcimport_var.ll +++ test/Transforms/FunctionImport/funcimport_var.ll @@ -4,7 +4,7 @@ ; RUN: opt -module-summary %p/Inputs/funcimport_var2.ll -o %t2.bc ; RUN: llvm-lto -thinlto -thinlto-action=thinlink -o %t3 %t.bc %t2.bc ; RUN: llvm-lto -thinlto -thinlto-action=import -thinlto-index=%t3 %t.bc %t2.bc -; RUN: llvm-lto -thinlto -thinlto-action=run %t.bc %t2.bc +; RUN: llvm-lto -thinlto -thinlto-action=run %t.bc %t2.bc -exported-symbol=_Z4LinkPKcS0_ ; RUN: llvm-nm %t.bc.thinlto.o | FileCheck %s ; RUN: llvm-lto2 run %t.bc %t2.bc -o %t.out \ ; RUN: -r %t.bc,_Z4LinkPKcS0_,plx \