[PATCH] D23157: [COFF][ARM] Error out if 24 bit thumb branches are out of range

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 4 23:01:19 PDT 2016


mstorsjo updated this revision to Diff 66910.
mstorsjo added a comment.

Moved the check up in the function as requested, added a test based on ELF/arm-thumb-branch-error.s.


https://reviews.llvm.org/D23157

Files:
  COFF/Chunks.cpp
  test/COFF/Inputs/far-arm-thumb-abs.s
  test/COFF/arm-thumb-branch-error.s

Index: test/COFF/arm-thumb-branch-error.s
===================================================================
--- /dev/null
+++ test/COFF/arm-thumb-branch-error.s
@@ -0,0 +1,10 @@
+// RUN: llvm-mc -filetype=obj -triple=thumbv7a-windows-gnu %s -o %t
+// RUN: llvm-mc -filetype=obj -triple=thumbv7a-windows-gnu %S/Inputs/far-arm-thumb-abs.s -o %tfar
+// RUN: not lld-link -entry:_start -subsystem:console %t %tfar -out:%t2 2>&1 | FileCheck %s
+// REQUIRES: arm
+ .syntax unified
+ .globl _start
+_start:
+ bl  too_far1
+
+// CHECK: relocation out of range
Index: test/COFF/Inputs/far-arm-thumb-abs.s
===================================================================
--- /dev/null
+++ test/COFF/Inputs/far-arm-thumb-abs.s
@@ -0,0 +1,2 @@
+.global too_far1
+too_far1 = 0x1401004
Index: COFF/Chunks.cpp
===================================================================
--- COFF/Chunks.cpp
+++ COFF/Chunks.cpp
@@ -111,6 +111,8 @@
 }
 
 static void applyBranch24T(uint8_t *Off, int32_t V) {
+  if (!isInt<25>(V))
+    fatal("relocation out of range");
   uint32_t S = V < 0 ? 1 : 0;
   uint32_t J1 = ((~V >> 23) & 1) ^ S;
   uint32_t J2 = ((~V >> 22) & 1) ^ S;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23157.66910.patch
Type: text/x-patch
Size: 1158 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160805/a4cba898/attachment.bin>


More information about the llvm-commits mailing list