Fix a crash with X86 Mach-O and a subtraction expression where both symbols are

undefined and produce an error message instead as this is a non-relocatable
expression with X86 Mach-O.

rdar://8920876


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188218 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kevin Enderby 2013-08-12 22:45:44 +00:00
parent 4f96b7e147
commit ebc573ed5b
2 changed files with 10 additions and 0 deletions

View 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) -

View File

@ -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