[PATCH] D80169: [lld-macho] Error on encountering undefined symbols
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 18 16:17:31 PDT 2020
int3 created this revision.
int3 added reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
... instead of silently emitting a reference to the zero address.
Depends on D80049 <https://reviews.llvm.org/D80049>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D80169
Files:
lld/MachO/InputSection.cpp
lld/test/MachO/invalid/undefined-symbol.s
Index: lld/test/MachO/invalid/undefined-symbol.s
===================================================================
--- /dev/null
+++ 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
Index: lld/MachO/InputSection.cpp
===================================================================
--- lld/MachO/InputSection.cpp
+++ 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<Symbol *>()) {
- if (auto *dylibSymbol = dyn_cast<DylibSymbol>(s)) {
+ if (isa<Undefined>(s)) {
+ error("undefined symbol " + s->getName() + ", referenced from " +
+ sys::path::filename(file->getName()));
+ } else if (auto *dylibSymbol = dyn_cast<DylibSymbol>(s)) {
va = target->getDylibSymbolVA(*dylibSymbol, r.type);
} else {
va = s->getVA();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80169.264741.patch
Type: text/x-patch
Size: 1656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200518/e88c6f40/attachment.bin>
More information about the llvm-commits
mailing list