ExecutionEngine: fix a bug in the movt/movw relocator
authorSaleem Abdulrasool <compnerd@compnerd.org>
Mon, 29 Aug 2016 20:42:03 +0000 (20:42 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Mon, 29 Aug 2016 20:42:03 +0000 (20:42 +0000)
According to the arm arm specifications, 4 bytes are needed for a shift instead
of 8, this was causing the movt instruction to write to a different register
sometimes.

Patch by Walter Erquinigo!

llvm-svn: 280005

llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
llvm/test/ExecutionEngine/RuntimeDyld/ARM/COFF_Thumb.s

index 91fdd93..570c928 100644 (file)
@@ -225,7 +225,7 @@ public:
         Bytes[0] |= ((Immediate & 0xf000) >> 12);
         Bytes[1] |= ((Immediate & 0x0800) >> 11);
         Bytes[2] |= ((Immediate & 0x00ff) >>  0);
-        Bytes[3] |= ((Immediate & 0x0700) >>  8);
+        Bytes[3] |= (((Immediate & 0x0700) >>  8) << 4);
       };
 
       EncodeImmediate(&Target[0], static_cast<uint32_t>(Result) >> 00);
index 2a12812..14e74cb 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: llvm-mc -triple thumbv7-windows-itanium -filetype obj -o %t.obj %s
-// RUN: llvm-rtdyld -triple thumbv7-windows -dummy-extern OutputDebugStringA=0x78563412 -dummy-extern ExitProcess=0x54769890 -dummy-extern unnamed_addr=0x00001024 -verify -check %s %t.obj
+// RUN: llvm-rtdyld -triple thumbv7-windows -dummy-extern OutputDebugStringW=0x01310060 -dummy-extern OutputDebugStringA=0x78563412 -dummy-extern ExitProcess=0x54769890 -dummy-extern unnamed_addr=0x00001024 -verify -check %s %t.obj
 
        .text
        .syntax unified
@@ -104,4 +104,20 @@ rel10:
 rel11:
        .secrel32 relocations                           @ IMAGE_REL_ARM_SECREL
 # rtdyld-check: *{4}rel11 = relocations - section_addr(COFF_Thumb.s.tmp.obj, .data)
+rel12:                                                 @ IMAGE_REL_ARM_MOV32T
+       movw r0, :lower16:__imp_OutputDebugStringW
+# rtdyld-check: decode_operand(rel12, 1) = (__imp_OutputDebugStringW&0x0000ffff)
+       movt r0, :upper16:__imp_OutputDebugStringW
+# TODO rtdyld-check: decode_operand(rel12, 1) = (__imp_OutputDebugStringW&0xffff0000>>16)
+       bx r0
+       trap
 
+       .data
+
+       .p2align 2
+__imp_OutputDebugStringW:
+@ rel13:
+       .long OutputDebugStringW                        @ IMAGE_REL_ARM_ADDR32
+# rtdyld-check: *{4}__imp_OutputDebugStringW = 0x01310060
+
+       .p2align 2