summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-11-04 22:10:33 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-11-04 22:10:33 +0000
commitbfd0f01dd75f299bb521a2a31f270b3687be2cee (patch)
tree4bd1dfdcee854ec887ea49ed5f03de3397bd5f28 /llvm
parent4f5cbc1a1ec5adb2d2f91138092b83dcd6e654a2 (diff)
downloadbcm5719-llvm-bfd0f01dd75f299bb521a2a31f270b3687be2cee.tar.gz
bcm5719-llvm-bfd0f01dd75f299bb521a2a31f270b3687be2cee.zip
Don't produce relocations for a difference in a section with no symbols.
We were producing a relocation for ---------------- .section foo,bar La: Lb: .long La-Lb -------------- but not for --------------------- .section foo,bar zed: La: Lb: .long La-Lb ---------------- This patch handles the case where both fragments are part of the first atom in a section and there is no corresponding symbol to that atom. This fixes pr21328. llvm-svn: 221304
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/MC/MachObjectWriter.cpp9
-rw-r--r--llvm/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s2
-rw-r--r--llvm/test/MC/X86/reloc-macho.s9
3 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 7f6d12ce238..577c4b75f97 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -726,6 +726,10 @@ IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
return false;
}
+ // If they are not in the same section, we can't compute the diff.
+ if (&SecA != &SecB)
+ return false;
+
const MCFragment *FA = Asm.getSymbolData(SA).getFragment();
// Bail if the symbol has no fragment.
@@ -733,12 +737,7 @@ IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
return false;
A_Base = FA->getAtom();
- if (!A_Base)
- return false;
-
B_Base = FB.getAtom();
- if (!B_Base)
- return false;
// If the atoms are the same, they are guaranteed to have the same address.
if (A_Base == B_Base)
diff --git a/llvm/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s b/llvm/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s
index 18e9966d7b7..b69cd1b1710 100644
--- a/llvm/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s
+++ b/llvm/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s
@@ -12,7 +12,5 @@ L_var2:
// CHECK-NEXT: Section __data {
// CHECK-NEXT: 0x4 0 2 0 X86_64_RELOC_SUBTRACTOR 0 0x2
// CHECK-NEXT: 0x4 0 2 0 X86_64_RELOC_UNSIGNED 0 0x2
-// CHECK-NEXT: 0x0 0 2 0 X86_64_RELOC_SUBTRACTOR 0 0x2
-// CHECK-NEXT: 0x0 0 2 0 X86_64_RELOC_UNSIGNED 0 0x2
// CHECK-NEXT: }
// CHECK-NEXT: ]
diff --git a/llvm/test/MC/X86/reloc-macho.s b/llvm/test/MC/X86/reloc-macho.s
new file mode 100644
index 00000000000..9297b1ba8b3
--- /dev/null
+++ b/llvm/test/MC/X86/reloc-macho.s
@@ -0,0 +1,9 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-apple-darwin %s -o - | llvm-readobj -r | FileCheck %s
+
+// CHECK: Relocations [
+// CHECK-NEXT: ]
+
+ .section foo,bar
+La:
+Lb:
+ .long La-Lb
OpenPOWER on IntegriCloud