From 294618592b6570175fd48a89f84b92b5aa3ea329 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 29 Aug 2016 20:42:03 +0000 Subject: [PATCH] ExecutionEngine: fix a bug in the movt/movw relocator 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! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280005 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h | 2 +- test/ExecutionEngine/RuntimeDyld/ARM/COFF_Thumb.s | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h index 91fdd936d7d..570c928cbce 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h @@ -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(Result) >> 00); diff --git a/test/ExecutionEngine/RuntimeDyld/ARM/COFF_Thumb.s b/test/ExecutionEngine/RuntimeDyld/ARM/COFF_Thumb.s index 2a128124d0d..14e74cb39ac 100644 --- a/test/ExecutionEngine/RuntimeDyld/ARM/COFF_Thumb.s +++ b/test/ExecutionEngine/RuntimeDyld/ARM/COFF_Thumb.s @@ -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 -- 2.11.0