Fix a crash with X86 Mach-O and a subtraction expression where both symbols are
authorKevin Enderby <enderby@apple.com>
Mon, 12 Aug 2013 22:45:44 +0000 (22:45 +0000)
committerKevin Enderby <enderby@apple.com>
Mon, 12 Aug 2013 22:45:44 +0000 (22:45 +0000)
undefined and produce an error message instead as this is a non-relocatable
expression with X86 Mach-O.

rdar://8920876

llvm-svn: 188218

llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
llvm/test/MC/MachO/bad-darwin-x86_64-diff-relocs.s [new file with mode: 0644]

index 64f005c469bc990efbd78e6ed6048a71b4f42d84..6eff224e26143b506e26b2d19c184feb85c53b2a 100644 (file)
@@ -175,6 +175,11 @@ void X86MachObjectWriter::RecordX86_64Relocation(MachObjectWriter *Writer,
     if (A_Base == B_Base && A_Base)
       report_fatal_error("unsupported relocation with identical base");
 
+    // A subtraction expression where both symbols are undefined is a
+    // non-relocatable expression.
+    if (A->isUndefined() && B->isUndefined())
+      report_fatal_error("unsupported relocation with subtraction expression");
+
     Value += Writer->getSymbolAddress(&A_SD, Layout) -
       (A_Base == NULL ? 0 : Writer->getSymbolAddress(A_Base, Layout));
     Value -= Writer->getSymbolAddress(&B_SD, Layout) -
diff --git a/llvm/test/MC/MachO/bad-darwin-x86_64-diff-relocs.s b/llvm/test/MC/MachO/bad-darwin-x86_64-diff-relocs.s
new file mode 100644 (file)
index 0000000..1ccebc5
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: not llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o - 2> %t.err > %t
+// RUN: FileCheck --check-prefix=CHECK-ERROR < %t.err %s
+
+.quad _foo - _bar
+// CHECK-ERROR: unsupported relocation with subtraction expression