[llvm] r355527 - [MC][MachO] Emit an error for emitting relocations of the form -SYM + cst
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 6 10:10:41 PST 2019
Author: thegameg
Date: Wed Mar 6 10:10:41 2019
New Revision: 355527
URL: http://llvm.org/viewvc/llvm-project?rev=355527&view=rev
Log:
[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
Added:
llvm/trunk/test/MC/MachO/bad-reloc.s
Modified:
llvm/trunk/lib/MC/MachObjectWriter.cpp
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=355527&r1=355526&r2=355527&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Wed Mar 6 10:10:41 2019
@@ -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::writeLinkerOption
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);
}
Added: llvm/trunk/test/MC/MachO/bad-reloc.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/bad-reloc.s?rev=355527&view=auto
==============================================================================
--- llvm/trunk/test/MC/MachO/bad-reloc.s (added)
+++ llvm/trunk/test/MC/MachO/bad-reloc.s Wed Mar 6 10:10:41 2019
@@ -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
More information about the llvm-commits
mailing list