#include "lld/Common/Memory.h"
#include "llvm/Support/Endian.h"
+using namespace llvm;
using namespace llvm::MachO;
using namespace llvm::support;
using namespace lld;
} // namespace
void Writer::scanRelocations() {
- for (InputSection *sect : inputSections)
- for (Reloc &r : sect->relocs)
- if (auto *s = r.target.dyn_cast<Symbol *>())
- if (auto *dylibSymbol = dyn_cast<DylibSymbol>(s))
+ for (InputSection *isec : inputSections) {
+ for (Reloc &r : isec->relocs) {
+ if (auto *s = r.target.dyn_cast<Symbol *>()) {
+ if (isa<Undefined>(s))
+ error("undefined symbol " + s->getName() + ", referenced from " +
+ sys::path::filename(isec->file->getName()));
+ else if (auto *dylibSymbol = dyn_cast<DylibSymbol>(s))
target->prepareDylibSymbolRelocation(*dylibSymbol, r.type);
+ }
+ }
+ }
}
void Writer::createLoadCommands() {
--- /dev/null
+# 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