Index: llvm/trunk/lib/LTO/LTO.cpp =================================================================== --- llvm/trunk/lib/LTO/LTO.cpp +++ llvm/trunk/lib/LTO/LTO.cpp @@ -416,8 +416,11 @@ auto &GlobalRes = GlobalResolutions[Sym.getName()]; GlobalRes.UnnamedAddr &= Sym.isUnnamedAddr(); - if (Res.Prevailing) + if (Res.Prevailing) { + assert((GlobalRes.IRName.empty() || !Sym.getIRName().empty()) && + "Overriding existing resolution with undefined asm symbol"); GlobalRes.IRName = Sym.getIRName(); + } // Set the partition to external if we know it is re-defined by the linker // with -defsym or -wrap options, used elsewhere, e.g. it is visible to a Index: llvm/trunk/test/LTO/X86/symver-asm.ll =================================================================== --- llvm/trunk/test/LTO/X86/symver-asm.ll +++ llvm/trunk/test/LTO/X86/symver-asm.ll @@ -1,7 +1,7 @@ ; RUN: llvm-as < %s >%t1 ; RUN: llvm-lto -exported-symbol=io_cancel_0_4 -exported-symbol=io_cancel_weak_0_4 -exported-symbol=foo -o %t2 %t1 ; RUN: llvm-nm %t2 | FileCheck %s -; RUN: llvm-lto2 run -r %t1,io_cancel_0_4,plx -r %t1,io_cancel_0_4,plx -r %t1,io_cancel_local_0_4,plx -r %t1,io_cancel_weak_0_4,plx -r %t1,io_cancel_weak_0_4,plx -r %t1,io_cancel@@LIBAIO_0.4,plx -r %t1,io_cancel_weak@@LIBAIO_0.4,plx -r %t1,io_cancel_weak@@LIBAIO_0.4.1,plx -r %t1,foo,plx -r %t1,foo,plx -r %t1,foo@@VER1,plx -o %t3 %t1 -save-temps +; RUN: llvm-lto2 run -r %t1,io_cancel_0_4,plx -r %t1,io_cancel_0_4,lx -r %t1,io_cancel_local_0_4,plx -r %t1,io_cancel_weak_0_4,plx -r %t1,io_cancel_weak_0_4,lx -r %t1,io_cancel@@LIBAIO_0.4,plx -r %t1,io_cancel_weak@@LIBAIO_0.4,plx -r %t1,io_cancel_weak@@LIBAIO_0.4.1,plx -r %t1,foo,plx -r %t1,foo,lx -r %t1,foo@@VER1,plx -o %t3 %t1 -save-temps ; RUN: llvm-nm %t3.0 | FileCheck %s ; RUN: llvm-dis %t3.0.2.internalize.bc -o - | FileCheck %s --check-prefix=INTERN Index: llvm/trunk/test/ThinLTO/X86/module_asm2.ll =================================================================== --- llvm/trunk/test/ThinLTO/X86/module_asm2.ll +++ llvm/trunk/test/ThinLTO/X86/module_asm2.ll @@ -11,9 +11,9 @@ ; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps \ ; RUN: -r=%t1.bc,foo,plx \ ; RUN: -r=%t1.bc,globalfunc,plx \ -; RUN: -r=%t1.bc,globalfunc,plx \ -; RUN: -r=%t1.bc,weakfunc,plx \ +; RUN: -r=%t1.bc,globalfunc,lx \ ; RUN: -r=%t1.bc,weakfunc,plx \ +; RUN: -r=%t1.bc,weakfunc,lx \ ; RUN: -r=%t1.bc,b,pl \ ; RUN: -r=%t1.bc,x,pl \ ; RUN: -r=%t1.bc,func1,pl \ Index: llvm/trunk/tools/gold/gold-plugin.cpp =================================================================== --- llvm/trunk/tools/gold/gold-plugin.cpp +++ llvm/trunk/tools/gold/gold-plugin.cpp @@ -619,6 +619,10 @@ [](char C) { return C == '_' || isAlnum(C); }); } +static bool isUndefined(ld_plugin_symbol &Sym) { + return Sym.def == LDPK_UNDEF || Sym.def == LDPK_WEAKUNDEF; +} + static void addModule(LTO &Lto, claimed_file &F, const void *View, StringRef Filename) { MemoryBufferRef BufferRef(StringRef((const char *)View, F.filesize), @@ -656,16 +660,16 @@ break; case LDPR_PREVAILING_DEF_IRONLY: - R.Prevailing = true; + R.Prevailing = !isUndefined(Sym); break; case LDPR_PREVAILING_DEF: - R.Prevailing = true; + R.Prevailing = !isUndefined(Sym); R.VisibleToRegularObj = true; break; case LDPR_PREVAILING_DEF_IRONLY_EXP: - R.Prevailing = true; + R.Prevailing = !isUndefined(Sym); if (!Res.CanOmitFromDynSym) R.VisibleToRegularObj = true; break;