diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -7,12 +7,16 @@ //===----------------------------------------------------------------------===// #include "InputSection.h" +#include "InputFiles.h" #include "OutputSegment.h" #include "Symbols.h" #include "Target.h" +#include "lld/Common/ErrorHandler.h" #include "lld/Common/Memory.h" #include "llvm/Support/Endian.h" +#include "llvm/Support/Path.h" +using namespace llvm; using namespace llvm::MachO; using namespace llvm::support; using namespace lld; @@ -33,7 +37,10 @@ for (Reloc &r : relocs) { uint64_t va = 0; if (auto *s = r.target.dyn_cast()) { - if (auto *dylibSymbol = dyn_cast(s)) { + if (isa(s)) { + error("undefined symbol " + s->getName() + ", referenced from " + + sys::path::filename(file->getName())); + } else if (auto *dylibSymbol = dyn_cast(s)) { va = target->getDylibSymbolVA(*dylibSymbol, r.type); } else { va = s->getVA(); diff --git a/lld/test/MachO/invalid/undefined-symbol.s b/lld/test/MachO/invalid/undefined-symbol.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/invalid/undefined-symbol.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o +# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 | FileCheck %s -DBASENAME=%basename_t +# CHECK: error: undefined symbol _foo, referenced from [[BASENAME]] + +.globl _main +.text +_main: + callq _foo + movq $0, %rax + retq