[PATCH] D36745: [LLD][ELF] Always write non-immediate bits for AArch64 branch instruction.

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 08:23:43 PDT 2017


peter.smith created this revision.
Herald added subscribers: kristof.beyls, javed.absar, emaste, rengolin, aemerson.

To support errata patching on AArch64 we need to be able to overwrite an arbitrary instruction with a branch. For AArch64 it is sufficient to always write all the bits of the branch instruction and not just the immediate field. This is safe as the non-immediate bits of the branch instruction are always the same.

This is patch 2 of 3 to fix pr33463 https://bugs.llvm.org/show_bug.cgi?id=33463 although it can stand independently. The general idea for the fix will be to change an instruction in the section to be patched by adding a branch relocation (or modifying an existing relocation) at the same offset as the instruction.


https://reviews.llvm.org/D36745

Files:
  ELF/Arch/AArch64.cpp


Index: ELF/Arch/AArch64.cpp
===================================================================
--- ELF/Arch/AArch64.cpp
+++ ELF/Arch/AArch64.cpp
@@ -232,8 +232,13 @@
     checkInt<21>(Loc, Val, Type);
     write32AArch64Addr(Loc, Val);
     break;
-  case R_AARCH64_CALL26:
   case R_AARCH64_JUMP26:
+    // When patching instructions we may use a branch immediate to overwrite a
+    // potentially non-branch instruction so write the full branch instruction
+    // opcode (0 001 | 01 imm26).
+    write32le(Loc, 0x14000000);
+    // Fallthrough
+  case R_AARCH64_CALL26:
     checkInt<28>(Loc, Val, Type);
     or32le(Loc, (Val & 0x0FFFFFFC) >> 2);
     break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36745.111169.patch
Type: text/x-patch
Size: 665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170815/4e7edc27/attachment.bin>


More information about the llvm-commits mailing list