From b27d6ffe4e4aebde3cf032be74c3dbfcbaeea909 Mon Sep 17 00:00:00 2001 From: Vladislav Khmelevsky Date: Tue, 28 Jun 2022 19:54:59 +0300 Subject: [PATCH] [RuntimeDyld] Fix R_AARCH64_TSTBR14 relocation Wrong mask was used to get branch instruction imm value. Differential Revision: https://reviews.llvm.org/D128740 --- .../ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 2 +- .../RuntimeDyld/AArch64/ELF_ARM64_TSTBR14.s | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 llvm/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_TSTBR14.s diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index da1102fc9f07..c702584b7a33 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -479,7 +479,7 @@ void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section, *TargetPtr &= 0xfff8001fU; // Immediate:15:2 goes in bits 18:5 of TBZ, TBNZ - or32le(TargetPtr, (BranchImm & 0x0FFFFFFC) << 3); + or32le(TargetPtr, (BranchImm & 0x0000FFFC) << 3); break; } case ELF::R_AARCH64_CALL26: // fallthrough diff --git a/llvm/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_TSTBR14.s b/llvm/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_TSTBR14.s new file mode 100644 index 000000000000..2fc9b3d32e51 --- /dev/null +++ b/llvm/test/ExecutionEngine/RuntimeDyld/AArch64/ELF_ARM64_TSTBR14.s @@ -0,0 +1,14 @@ +# RUN: llvm-mc -triple=arm64-none-linux-gnu -filetype=obj -o %t %s +# RUN: llvm-rtdyld -triple=aarch64_be-none-linux-gnu -verify -check=%s %t + +.section .text.1,"ax" +.globl foo +foo: + ret + +.globl _main +_main: + tbnz x0, #1, foo + +## Branch 1 instruction back from _main +# rtdyld-check: *{4}(_main) = 0x370FFFE0