From d8e2f1757d9ececd7937406596fec8e4ebfb7d46 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Thu, 5 Sep 2013 20:25:06 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20a=20crash=20in=20the=20integrated=20ass?= =?UTF-8?q?embler=20for=20Mach-O=20when=20a=20symbol=20difference=20expres?= =?UTF-8?q?sion=20uses=20an=20assembler=20temporary=20symbol=20from=20an?= =?UTF-8?q?=20assignment.=20=C2=A0In=20this=20case=20the=20symbol=20does?= =?UTF-8?q?=20not=20have=20a=20fragment=20so=20the=20use=20of=20getFragmen?= =?UTF-8?q?t()=20would=20be=20NULL=20and=20caused=20a=20crash.=20In=20the?= =?UTF-8?q?=20case=20of=20an=20assembler=20temporary=20symbol=20we=20want?= =?UTF-8?q?=20to=20use=20the=20AliasedSymbol=20(if=20any)=20which=20will?= =?UTF-8?q?=20create=20a=20local=20relocation=20entry,=20but=20if=20it=20i?= =?UTF-8?q?s=20not=20an=20assembler=20temporary=20symbol=20then=20let=20it?= =?UTF-8?q?=20use=20that=20symbol=20with=20an=20external=20relocation=20en?= =?UTF-8?q?try.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rdar://9356266 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190096 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../X86/MCTargetDesc/X86MachObjectWriter.cpp | 4 ++ .../MachO/darwin-x86_64-diff-reloc-assign-2.s | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s 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: ])