[llvm-commits] [llvm] r121280 - /llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp

Jim Grosbach grosbach at apple.com
Wed Dec 8 12:32:07 PST 2010


Author: grosbach
Date: Wed Dec  8 14:32:07 2010
New Revision: 121280

URL: http://llvm.org/viewvc/llvm-project?rev=121280&view=rev
Log:
Tweak ARM fixup value adjustments for Thumb to better handle the half-word
ordering of thumb mode.

Modified:
    llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp

Modified: llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp?rev=121280&r1=121279&r2=121280&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp Wed Dec  8 14:32:07 2010
@@ -134,17 +134,24 @@
     // xxxxxSIIIIIIIIII xxxxxIIIIIIIIIII
     // Note that the halfwords are stored high first, low second; so we need
     // to transpose the fixup value here to map properly.
+    // FIXME: Something isn't quite right with this. Some, but not all, BLX
+    // instructions are getting the encoded value off by one.
     uint32_t Binary = 0x3fffff & ((Value - 4) >> 1);
     Binary = ((Binary & 0x7ff) << 16) | (Binary >> 11);
     return Binary;
   }
   case ARM::fixup_arm_thumb_cp:
-    // Offset by 4, and don't encode the low two bits.
-    return ((Value - 4) >> 2) & 0xff;
-  case ARM::fixup_t2_pcrel_10:
-  case ARM::fixup_arm_pcrel_10: {
-    // Offset by 8 just as above.
-    Value = Value - 8;
+    // Offset by 4, and don't encode the low two bits. Two bytes of that
+    // 'off by 4' is implicitly handled by the half-word ordering of the
+    // Thumb encoding, so we only need to adjust by 2 here.
+    return ((Value - 2) >> 2) & 0xff;
+  case ARM::fixup_arm_pcrel_10:
+    Value = Value - 6; // ARM fixups offset by an additional word and don't
+                       // need to adjust for the half-word ordering.
+    // Fall through.
+  case ARM::fixup_t2_pcrel_10: {
+    // Offset by 4, adjusted by two due to the half-word ordering of thumb.
+    Value = Value - 2;
     bool isAdd = true;
     if ((int64_t)Value < 0) {
       Value = -Value;
@@ -154,7 +161,7 @@
     Value >>= 2;
     assert ((Value < 256) && "Out of range pc-relative fixup value!");
     Value |= isAdd << 23;
-    
+
     // Same addressing mode as fixup_arm_pcrel_10,
     // but with 16-bit halfwords swapped.
     if (Kind == ARM::fixup_t2_pcrel_10) {
@@ -162,7 +169,7 @@
       swapped |= (Value & 0x0000FFFF) << 16;
       return swapped;
     }
-    
+
     return Value;
   }
   }





More information about the llvm-commits mailing list