[PATCH] D68875: [lld] Check for branch range overflows.

Sid Manning via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 11 11:01:18 PDT 2019


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

Update test case.


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68875/new/

https://reviews.llvm.org/D68875

Files:
  lld/ELF/Arch/Hexagon.cpp
  lld/test/ELF/hexagon-verify.s


Index: lld/test/ELF/hexagon-verify.s
===================================================================
--- /dev/null
+++ lld/test/ELF/hexagon-verify.s
@@ -0,0 +1,37 @@
+# REQUIRES: hexagon
+# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o
+# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck --implicit-check-not "out of range" %s
+
+#CHECK: relocation R_HEX_B9_PCREL out of range: 1028 is not in [-1024, 1023]
+#CHECK-NEXT: relocation R_HEX_B13_PCREL out of range: 16388 is not in [-16384, 16383]
+#CHECK-NEXT: relocation R_HEX_B15_PCREL out of range: 65540 is not in [-65536, 65535]
+#CHECK-NEXT: relocation R_HEX_B22_PCREL out of range: 8388612 is not in [-2097152, 2097151]
+
+
+	.globl	_start
+	.type	_start, @function
+_start:
+
+.section _pc9, "ax"
+{r0 = #0; jump #pc9}
+.space (1<<10)
+.section b9, "ax"
+pc9:
+
+.section _pc13, "ax"
+if (r0==#0) jump:t #pc13
+.space (1<<14)
+.section b13, "ax"
+pc13:
+
+.section _pc15, "ax"
+if (p0) jump #pc15
+.space (1<<16)
+.section b15, "ax"
+pc15:
+
+.section _pc22, "ax"
+jump #pc22
+.space (1<<23)
+.section b22, "ax"
+pc22:
Index: lld/ELF/Arch/Hexagon.cpp
===================================================================
--- lld/ELF/Arch/Hexagon.cpp
+++ lld/ELF/Arch/Hexagon.cpp
@@ -242,15 +242,18 @@
     or32le(loc, applyMask(0x0fff3fff, val >> 6));
     break;
   case R_HEX_B9_PCREL:
+    checkInt(loc, val, 11, type);
     or32le(loc, applyMask(0x003000fe, val >> 2));
     break;
   case R_HEX_B9_PCREL_X:
     or32le(loc, applyMask(0x003000fe, val & 0x3f));
     break;
   case R_HEX_B13_PCREL:
+    checkInt(loc, val, 15, type);
     or32le(loc, applyMask(0x00202ffe, val >> 2));
     break;
   case R_HEX_B15_PCREL:
+    checkInt(loc, val, 17, type);
     or32le(loc, applyMask(0x00df20fe, val >> 2));
     break;
   case R_HEX_B15_PCREL_X:
@@ -258,6 +261,7 @@
     break;
   case R_HEX_B22_PCREL:
   case R_HEX_PLT_B22_PCREL:
+    checkInt(loc, val, 22, type);
     or32le(loc, applyMask(0x1ff3ffe, val >> 2));
     break;
   case R_HEX_B22_PCREL_X:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68875.224637.patch
Type: text/x-patch
Size: 2032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191011/1fbd5588/attachment.bin>


More information about the llvm-commits mailing list