Index: lib/LTO/LTO.cpp =================================================================== --- lib/LTO/LTO.cpp +++ lib/LTO/LTO.cpp @@ -704,18 +704,17 @@ if (!Sym.getIRName().empty()) { auto GUID = GlobalValue::getGUID(GlobalValue::getGlobalIdentifier( Sym.getIRName(), GlobalValue::ExternalLinkage, "")); - if (Res.Prevailing) { + if (Res.Prevailing) ThinLTO.PrevailingModuleForGUID[GUID] = BM.getModuleIdentifier(); - // For linker redefined symbols (via --wrap or --defsym) we want to - // switch the linkage to `weak` to prevent IPOs from happening. - // Find the summary in the module for this very GV and record the new - // linkage so that we can switch it when we import the GV. - if (Res.LinkerRedefined) - if (auto S = ThinLTO.CombinedIndex.findSummaryInModule( - GUID, BM.getModuleIdentifier())) - S->setLinkage(GlobalValue::WeakAnyLinkage); - } + // For linker redefined symbols (via --wrap or --defsym) we want to + // switch the linkage to `weak` to prevent IPOs from happening. + // Find the summary in the module for this very GV and record the new + // linkage so that we can switch it when we import the GV. + if (Res.LinkerRedefined) + if (auto S = ThinLTO.CombinedIndex.findSummaryInModule( + GUID, BM.getModuleIdentifier())) + S->setLinkage(GlobalValue::WeakAnyLinkage); // If the linker resolved the symbol to a local definition then mark it // as local in the summary for the module we are adding. Index: test/LTO/Resolution/X86/linker-redef-thin.ll =================================================================== --- test/LTO/Resolution/X86/linker-redef-thin.ll +++ test/LTO/Resolution/X86/linker-redef-thin.ll @@ -8,6 +8,11 @@ ; CHECK-NEXT: Binding: Weak ; CHECK-NEXT: Type: Function +; RUN: llvm-lto2 run -o %t1.o %t.o -r %t.o,patatino,r +; RUN: llvm-readobj -t %t1.o.1 | FileCheck %s --check-prefix=NOSYM + +; NOSYM-NOT: Name: patatino + target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu"