[PATCH] D50603: Add R_HEX_16_X relocation

Sid Manning via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 16 06:51:44 PDT 2018


sidneym updated this revision to Diff 161022.
sidneym added a comment.

This is just a rebase.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D50603

Files:
  ELF/Arch/Hexagon.cpp
  test/ELF/hexagon.s


Index: test/ELF/hexagon.s
===================================================================
--- test/ELF/hexagon.s
+++ test/ELF/hexagon.s
@@ -177,3 +177,20 @@
 r_hex_32:
 .word _start
 # CHECK: 00011000
+
+# R_HEX_16_X has 4 relocation mask variations
+# 0x48000000
+memw(##_start) = r0
+# CHECK: 4880c000   memw(##69632) = r0 }
+
+# 0x49000000
+r0 = memw(##_start)
+# CHECK: 4980c000   r0 = memw(##69632)
+
+# 0x78000000
+r0 = ##_start
+# CHECK: 7800c000   r0 = ##69632 }
+
+# 0xb0000000
+r0 = add(r1, ##_start)
+# CHECK: b001c000   r0 = add(r1,##69632) }
Index: ELF/Arch/Hexagon.cpp
===================================================================
--- ELF/Arch/Hexagon.cpp
+++ ELF/Arch/Hexagon.cpp
@@ -112,6 +112,21 @@
   return 0x00001fe0;
 }
 
+static uint32_t findMaskR16(uint32_t Insn) {
+  if ((0xff000000 & Insn) == 0x48000000)
+    return 0x061f20ff;
+  if ((0xff000000 & Insn) == 0x49000000)
+    return 0x061f3fe0;
+  if ((0xff000000 & Insn) == 0x78000000)
+    return 0x00df3fe0;
+  if ((0xff000000 & Insn) == 0xb0000000)
+    return 0x0fe03fe0;
+
+  error("unrecognized instruction for R_HEX_16_X relocation: 0x" +
+        utohexstr(Insn));
+  return 0;
+}
+
 static void or32le(uint8_t *P, int32_t V) { write32le(P, read32le(P) | V); }
 
 void Hexagon::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
@@ -128,6 +143,9 @@
   case R_HEX_12_X:
     or32le(Loc, applyMask(0x000007e0, Val));
     break;
+  case R_HEX_16_X:  // This reloc only has 6 effective bits.
+    or32le(Loc, applyMask(findMaskR16(read32le(Loc)), Val & 0x3f));
+    break;
   case R_HEX_32:
     or32le(Loc, applyMask(0xffffffff, Val));
     break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50603.161022.patch
Type: text/x-patch
Size: 1652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180816/279fc89b/attachment.bin>


More information about the llvm-commits mailing list