From 2813f496d98f3e6d2c9c2774601999e147af34ef Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Fri, 24 Oct 2014 22:39:40 +0000 Subject: Fix a Mach-O assembler segfault for a subtraction expression with an undefined symbol. In a Mach-O object file a relocatable expression of the form SymbolA - SymbolB + constant is allowed when both symbols are defined in a section. But when either symbol is undefined it is an error. The code was crashing when it had an undefined symbol in this case. And should have printed a error message using the location information in the relocation entry. rdar://18678402 llvm-svn: 220599 --- llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp') diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp index adf3fd8e491..5685a7fde14 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp @@ -179,11 +179,14 @@ void X86MachObjectWriter::RecordX86_64Relocation(MachObjectWriter *Writer, if (A_Base == B_Base && A_Base) report_fatal_error("unsupported relocation with identical base", false); - // A subtraction expression where both symbols are undefined is a + // A subtraction expression where either symbol is undefined is a // non-relocatable expression. - if (A->isUndefined() && B->isUndefined()) - report_fatal_error("unsupported relocation with subtraction expression", - false); + if (A->isUndefined() || B->isUndefined()) { + StringRef Name = A->isUndefined() ? A->getName() : B->getName(); + Asm.getContext().FatalError(Fixup.getLoc(), + "unsupported relocation with subtraction expression, symbol '" + + Name + "' can not be undefined in a subtraction expression"); + } Value += Writer->getSymbolAddress(&A_SD, Layout) - (!A_Base ? 0 : Writer->getSymbolAddress(A_Base, Layout)); -- cgit v1.2.3