summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSid Manning <sidneym@quicinc.com>2019-10-15 14:12:54 +0000
committerSid Manning <sidneym@quicinc.com>2019-10-15 14:12:54 +0000
commitab5025654448ad0c93af18727f9b0698f451bd94 (patch)
treeb667534092a6fd5245a05c14aa575708b1279327
parentbae629b96622962245aad7b7dfcbce915d9c02a2 (diff)
downloadbcm5719-llvm-ab5025654448ad0c93af18727f9b0698f451bd94.tar.gz
bcm5719-llvm-ab5025654448ad0c93af18727f9b0698f451bd94.zip
[lld] Check for branch range overflows.
Differential Revision: https://reviews.llvm.org/D68875 llvm-svn: 374891
-rw-r--r--lld/ELF/Arch/Hexagon.cpp4
-rw-r--r--lld/test/ELF/hexagon-jump-error.s31
2 files changed, 35 insertions, 0 deletions
diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index e716040d253..67264a2272d 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -242,15 +242,18 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
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 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
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:
diff --git a/lld/test/ELF/hexagon-jump-error.s b/lld/test/ELF/hexagon-jump-error.s
new file mode 100644
index 00000000000..2aef0d778c3
--- /dev/null
+++ b/lld/test/ELF/hexagon-jump-error.s
@@ -0,0 +1,31 @@
+# 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
+
+ .globl _start
+ .type _start, @function
+_start:
+
+# CHECK: relocation R_HEX_B9_PCREL out of range: 1028 is not in [-1024, 1023]
+{r0 = #0; jump #1f}
+.space (1<<10)
+.section b9, "ax"
+1:
+
+# CHECK-NEXT: relocation R_HEX_B13_PCREL out of range: 16388 is not in [-16384, 16383]
+if (r0==#0) jump:t #1f
+.space (1<<14)
+.section b13, "ax"
+1:
+
+# CHECK-NEXT: relocation R_HEX_B15_PCREL out of range: 65540 is not in [-65536, 65535]
+if (p0) jump #1f
+.space (1<<16)
+.section b15, "ax"
+1:
+
+# CHECK-NEXT: relocation R_HEX_B22_PCREL out of range: 8388612 is not in [-2097152, 2097151]
+jump #1f
+.space (1<<23)
+.section b22, "ax"
+1:
OpenPOWER on IntegriCloud