From: Kevin Enderby Date: Thu, 5 Sep 2013 20:25:06 +0000 (+0000) Subject: Fixed a crash in the integrated assembler for Mach-O when a symbol difference X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d8e2f1757d9ececd7937406596fec8e4ebfb7d46;p=oota-llvm.git Fixed a crash in the integrated assembler for Mach-O when a symbol difference expression uses an assembler temporary symbol from an assignment.  In this case the symbol does not have a fragment so the use of getFragment() would be NULL and caused a crash. In the case of an assembler temporary symbol we want to use the AliasedSymbol (if any) which will create a local relocation entry, but if it is not an assembler temporary symbol then let it use that symbol with an external relocation entry. rdar://9356266 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190096 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp b/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp index b6f10ba9945..eb7c0b1a996 100644 --- a/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp +++ b/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp @@ -144,10 +144,14 @@ void X86MachObjectWriter::RecordX86_64Relocation(MachObjectWriter *Writer, } } else if (Target.getSymB()) { // A - B + constant const MCSymbol *A = &Target.getSymA()->getSymbol(); + if (A->isTemporary()) + A = &A->AliasedSymbol(); MCSymbolData &A_SD = Asm.getSymbolData(*A); const MCSymbolData *A_Base = Asm.getAtom(&A_SD); const MCSymbol *B = &Target.getSymB()->getSymbol(); + if (B->isTemporary()) + B = &B->AliasedSymbol(); MCSymbolData &B_SD = Asm.getSymbolData(*B); const MCSymbolData *B_Base = Asm.getAtom(&B_SD); diff --git a/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s b/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s new file mode 100644 index 00000000000..5d548790a7a --- /dev/null +++ b/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s @@ -0,0 +1,38 @@ +// RUN: llvm-mc -triple x86_64-apple-darwin9 %s -filetype=obj -o - | macho-dump --dump-section-data | FileCheck %s + +// Test case for rdar://9356266 + +// This tests that this expression does not cause a crash and produces these +// four relocation entries: +// Relocation information (__DATA,__data) 4 entries +// address pcrel length extern type scattered symbolnum/value +// 00000004 False long False SUB False 2 (__DATA,__data) +// 00000004 False long False UNSIGND False 2 (__DATA,__data) +// 00000000 False long False SUB False 2 (__DATA,__data) +// 00000000 False long False UNSIGND False 2 (__DATA,__data) + + .data +L_var1: +L_var2: +// This was working fine + .long L_var2 - L_var1 + + .set L_var3, . + .set L_var4, . +// But this was causing a crash + .long L_var4 - L_var3 + +// CHECK: ('_relocations', [ +// CHECK: # Relocation 0 +// CHECK: (('word-0', 0x4), +// CHECK: ('word-1', 0x54000002)), +// CHECK: # Relocation 1 +// CHECK: (('word-0', 0x4), +// CHECK: ('word-1', 0x4000002)), +// CHECK: # Relocation 2 +// CHECK: (('word-0', 0x0), +// CHECK: ('word-1', 0x54000002)), +// CHECK: # Relocation 3 +// CHECK: (('word-0', 0x0), +// CHECK: ('word-1', 0x4000002)), +// CHECK: ])