diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-08-12 01:51:29 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-08-12 01:51:29 +0000 |
commit | 0d46ccfc5c2f5d0894e340907f6e58067cce5b03 (patch) | |
tree | b1bf201e0d02b5e37328cb6a376ed9be61806177 | |
parent | b43b09eef54ebb99079c6541f1b14ae1a2ef7017 (diff) | |
download | llvm-0d46ccfc5c2f5d0894e340907f6e58067cce5b03.tar.gz llvm-0d46ccfc5c2f5d0894e340907f6e58067cce5b03.tar.bz2 llvm-0d46ccfc5c2f5d0894e340907f6e58067cce5b03.tar.xz |
MachOWriter: Don't crash on fixups with arithmetic, emit a relocation instead. This matches what as does.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137414 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/MC/MachObjectWriter.cpp | 8 | ||||
-rw-r--r-- | test/MC/MachO/x86_64-reloc-arithmetic.s | 21 |
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/MC/MachObjectWriter.cpp b/lib/MC/MachObjectWriter.cpp index 6f64bdf40b..7011916770 100644 --- a/lib/MC/MachObjectWriter.cpp +++ b/lib/MC/MachObjectWriter.cpp @@ -595,9 +595,13 @@ IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, return false; } - const MCFragment &FA = *Asm.getSymbolData(SA).getFragment(); + const MCFragment *FA = Asm.getSymbolData(SA).getFragment(); - A_Base = FA.getAtom(); + // Bail if the symbol has no fragment. + if (!FA) + return false; + + A_Base = FA->getAtom(); if (!A_Base) return false; diff --git a/test/MC/MachO/x86_64-reloc-arithmetic.s b/test/MC/MachO/x86_64-reloc-arithmetic.s new file mode 100644 index 0000000000..e82f69b6d4 --- /dev/null +++ b/test/MC/MachO/x86_64-reloc-arithmetic.s @@ -0,0 +1,21 @@ +// RUN: llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o - | macho-dump | FileCheck %s + +// rdar://9906375 +.org 0x100 +_foo: +_bar = _foo + 2 +_baz: + leaq _bar(%rip), %rcx + +// CHECK: ('_relocations', [ +// CHECK-NEXT: # Relocation 0 +// CHECK-NEXT: (('word-0', 0x103), +// CHECK-NEXT: ('word-1', 0x1d000001)) + +// CHECK: # Symbol 1 +// CHECK-NEXT: (('n_strx', 6) +// CHECK-NEXT: ('n_type', 0xe) +// CHECK-NEXT: ('n_sect', 1) +// CHECK-NEXT: ('n_desc', 0) +// CHECK-NEXT: ('n_value', 258) +// CHECK-NEXT: ('_string', '_bar') |