[PATCH] D80169: [lld-macho] Error on encountering undefined symbols
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 19 16:34:48 PDT 2020
int3 updated this revision to Diff 265079.
int3 added a comment.
move to scanRelocations
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D80169/new/
https://reviews.llvm.org/D80169
Files:
lld/MachO/InputSection.cpp
lld/MachO/Writer.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/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -249,11 +249,17 @@
} // 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() {
Index: lld/MachO/InputSection.cpp
===================================================================
--- lld/MachO/InputSection.cpp
+++ lld/MachO/InputSection.cpp
@@ -13,6 +13,7 @@
#include "lld/Common/Memory.h"
#include "llvm/Support/Endian.h"
+using namespace llvm;
using namespace llvm::MachO;
using namespace llvm::support;
using namespace lld;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80169.265079.patch
Type: text/x-patch
Size: 1783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200519/066e2c00/attachment.bin>
More information about the llvm-commits
mailing list