[llvm] r221304 - Don't produce relocations for a difference in a section with no symbols.

Rafael Espindola rafael.espindola at gmail.com
Tue Nov 4 14:10:33 PST 2014


Author: rafael
Date: Tue Nov  4 16:10:33 2014
New Revision: 221304

URL: http://llvm.org/viewvc/llvm-project?rev=221304&view=rev
Log:
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.

Added:
    llvm/trunk/test/MC/X86/reloc-macho.s
Modified:
    llvm/trunk/lib/MC/MachObjectWriter.cpp
    llvm/trunk/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s

Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=221304&r1=221303&r2=221304&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Tue Nov  4 16:10:33 2014
@@ -726,6 +726,10 @@ IsSymbolRefDifferenceFullyResolvedImpl(c
       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(c
     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)

Modified: llvm/trunk/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s?rev=221304&r1=221303&r2=221304&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s (original)
+++ llvm/trunk/test/MC/MachO/darwin-x86_64-diff-reloc-assign-2.s Tue Nov  4 16:10:33 2014
@@ -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: ]

Added: llvm/trunk/test/MC/X86/reloc-macho.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/X86/reloc-macho.s?rev=221304&view=auto
==============================================================================
--- llvm/trunk/test/MC/X86/reloc-macho.s (added)
+++ llvm/trunk/test/MC/X86/reloc-macho.s Tue Nov  4 16:10:33 2014
@@ -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





More information about the llvm-commits mailing list