diff options
author | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2019-03-06 18:10:41 +0000 |
---|---|---|
committer | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2019-03-06 18:10:41 +0000 |
commit | c01140ef1ff66869d4ea9465c3cd198d82d30cab (patch) | |
tree | 0e10d2c533d1a820c6efefd925464af36780b437 | |
parent | 6795eb388442469af74245545b445d9505fdc9d8 (diff) | |
download | bcm5719-llvm-c01140ef1ff66869d4ea9465c3cd198d82d30cab.tar.gz bcm5719-llvm-c01140ef1ff66869d4ea9465c3cd198d82d30cab.zip |
[MC][MachO] Emit an error for emitting relocations of the form -SYM + cst
Emit an error for an unsupported relocation. mach-o relocations can't
encode the form -SYM + cst.
Differential Revision: https://reviews.llvm.org/D58944
llvm-svn: 355527
-rw-r--r-- | llvm/lib/MC/MachObjectWriter.cpp | 15 | ||||
-rw-r--r-- | llvm/test/MC/MachO/bad-reloc.s | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index 395273e44f6..f0ceb86b25a 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -13,6 +13,7 @@ #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCDirectives.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCFixupKindInfo.h" @@ -448,11 +449,25 @@ void MachObjectWriter::writeLinkerOptionsLoadCommand( assert(W.OS.tell() - Start == Size); } +static bool isFixupTargetValid(const MCValue &Target) { + // Target is (LHS - RHS + cst). + // We don't support the form where LHS is null: -RHS + cst + if (!Target.getSymA() && Target.getSymB()) + return false; + return true; +} + void MachObjectWriter::recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) { + if (!isFixupTargetValid(Target)) { + Asm.getContext().reportError(Fixup.getLoc(), + "unsupported relocation expression"); + return; + } + TargetObjectWriter->recordRelocation(this, Asm, Layout, Fragment, Fixup, Target, FixedValue); } diff --git a/llvm/test/MC/MachO/bad-reloc.s b/llvm/test/MC/MachO/bad-reloc.s new file mode 100644 index 00000000000..2c591c43b8f --- /dev/null +++ b/llvm/test/MC/MachO/bad-reloc.s @@ -0,0 +1,5 @@ +// RUN: not llvm-mc -triple x86_64-apple-darwin %s -filetype=obj -o - 2>&1 | FileCheck %s + +.quad (0 - undef) + +// CHECK: error: unsupported relocation expression |