[llvm] r220599 - Fix a Mach-O assembler segfault for a subtraction expression with an undefined symbol.
Kevin Enderby
enderby at apple.com
Fri Oct 24 15:39:40 PDT 2014
Author: enderby
Date: Fri Oct 24 17:39:40 2014
New Revision: 220599
URL: http://llvm.org/viewvc/llvm-project?rev=220599&view=rev
Log:
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
Added:
llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr1.s
llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr2.s
Modified:
llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp?rev=220599&r1=220598&r2=220599&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp Fri Oct 24 17:39:40 2014
@@ -179,11 +179,14 @@ void X86MachObjectWriter::RecordX86_64Re
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));
Added: llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr1.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr1.s?rev=220599&view=auto
==============================================================================
--- llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr1.s (added)
+++ llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr1.s Fri Oct 24 17:39:40 2014
@@ -0,0 +1,6 @@
+// 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
+
+_Z:
+.long (_Z+4)-_b
+// CHECK-ERROR: error: unsupported relocation with subtraction expression, symbol '_b' can not be undefined in a subtraction expression
Added: llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr2.s?rev=220599&view=auto
==============================================================================
--- llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr2.s (added)
+++ llvm/trunk/test/MC/MachO/bad-darwin-x86_64-reloc-expr2.s Fri Oct 24 17:39:40 2014
@@ -0,0 +1,6 @@
+// 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
+
+_Z:
+.long (_a+4)-_Z
+// CHECK-ERROR: error: unsupported relocation with subtraction expression, symbol '_a' can not be undefined in a subtraction expression
More information about the llvm-commits
mailing list