Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -543,7 +543,14 @@ // recorded in the index using the original name. // FIXME: This may not be needed once PR27866 is fixed. const auto &GS = DefinedGlobals.find(GlobalValue::getGUID(OrigName)); - assert(GS != DefinedGlobals.end()); + // If we don't find the original name, then conservatively return + // true, indicating that it must be preserved. One example where + // we might not find it is when the linked in local copy for an alias + // conflicts with the declaration created for the aliased preempted + // weak value, and the ValueSymbolTable appends a unique identifier + // to distinguish them. + if (GS == DefinedGlobals.end()) + return true; Linkage = GS->second->linkage(); } else { Linkage = GS->second->linkage(); Index: test/tools/gold/X86/Inputs/thinlto_alias2.ll =================================================================== --- /dev/null +++ test/tools/gold/X86/Inputs/thinlto_alias2.ll @@ -0,0 +1,8 @@ +$c2 = comdat any + +define weak_odr i32 @f1(i8*) unnamed_addr comdat($c2) { + ret i32 41 +} + +@r2 = global i32(i8*)* @f1 +@a2 = alias i32(i8*), i32(i8*)* @f1 Index: test/tools/gold/X86/thinlto_alias2.ll =================================================================== --- /dev/null +++ test/tools/gold/X86/thinlto_alias2.ll @@ -0,0 +1,22 @@ +; RUN: opt -module-summary %s -o %t.o +; RUN: opt -module-summary %p/Inputs/thinlto_alias2.ll -o %t2.o + +; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \ +; RUN: -shared \ +; RUN: --plugin-opt=thinlto \ +; RUN: --plugin-opt=-import-instr-limit=0 \ +; RUN: --plugin-opt=save-temps \ +; RUN: -o %t3.o %t.o %t2.o +; RUN: llvm-dis %t2.o.opt.bc -o - | FileCheck %s + +$c1 = comdat any + +define weak_odr i32 @f1(i8*) unnamed_addr comdat($c1) { + ret i32 42 +} + +@a1 = alias i32 (i8*), i32 (i8*)* @f1 + +; CHECK: @a2 = alias i32 (i8*), i32 (i8*)* @f1.1.llvm.0 +; CHECK: declare i32 @f1(i8*) unnamed_addr +; CHECK: define hidden i32 @f1.1.llvm.0(i8* nocapture readnone) unnamed_addr #0 comdat($c2) {