Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -859,9 +859,14 @@ // symbols here means that we report undefined symbols only when // they have relocations pointing to them. We don't care about // undefined symbols that are in dead-stripped sections. - if (!Body.isLocal() && Body.isUndefined() && !Body.symbol()->isWeak()) + if (!Body.isLocal() && Body.isUndefined() && !Body.symbol()->isWeak()) { reportUndefined(Body, Sec, Rel.r_offset); + // If we report an undefined, and we have an error, go on. + if (ErrorCount) + continue; + } + RelExpr Expr = Target->getRelExpr(Type, Body, *Sec.File, Sec.Data.begin() + Rel.r_offset); Index: test/ELF/Inputs/undefined-error.s =================================================================== --- /dev/null +++ test/ELF/Inputs/undefined-error.s @@ -0,0 +1 @@ +callq fmod@PLT Index: test/ELF/pr34872.s =================================================================== --- /dev/null +++ test/ELF/pr34872.s @@ -0,0 +1,13 @@ +# RUN: llvm-mc %s -filetype=obj -triple=x86_64-pc-linux -o %t.o +# RUN: llvm-mc %p/Inputs/undefined-error.s -filetype=obj \ +# RUN: -triple=x86_64-pc-linux -o %t2.o +# RUN: ld.lld -shared %t2.o -o %t2.so +# RUN: not ld.lld %t2.so %t.o 2>&1 | FileCheck %s + +# CHECK: undefined symbol: fmod +# CHECK-NOT: 'fmod' defined in {{.*}} has no type + +.global main + +main: + callq fmod