[PATCH] D41163: [LLD] [COFF] Error out if 20 bit thumb branches are out of range

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 02:25:39 PST 2017


mstorsjo created this revision.
mstorsjo added reviewers: ruiu, compnerd.
Herald added a subscriber: javed.absar.

This is similar to what was added in SVN r277838 for 24 bit branch instructions.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D41163

Files:
  COFF/Chunks.cpp
  test/COFF/Inputs/far-arm-thumb-abs20.s
  test/COFF/arm-thumb-branch20-error.s


Index: test/COFF/arm-thumb-branch20-error.s
===================================================================
--- /dev/null
+++ test/COFF/arm-thumb-branch20-error.s
@@ -0,0 +1,10 @@
+// REQUIRES: arm
+// RUN: llvm-mc -filetype=obj -triple=thumbv7a-windows-gnu %s -o %t.obj
+// RUN: llvm-mc -filetype=obj -triple=thumbv7a-windows-gnu %S/Inputs/far-arm-thumb-abs20.s -o %t.far.obj
+// RUN: not lld-link -entry:_start -subsystem:console %t.obj %t.far.obj -out:%t.exe 2>&1 | FileCheck %s
+ .syntax unified
+ .globl _start
+_start:
+ bne too_far20
+
+// CHECK: relocation out of range
Index: test/COFF/Inputs/far-arm-thumb-abs20.s
===================================================================
--- /dev/null
+++ test/COFF/Inputs/far-arm-thumb-abs20.s
@@ -0,0 +1,2 @@
+.global too_far20
+too_far20 = 0x501004
Index: COFF/Chunks.cpp
===================================================================
--- COFF/Chunks.cpp
+++ COFF/Chunks.cpp
@@ -129,6 +129,8 @@
 }
 
 static void applyBranch20T(uint8_t *Off, int32_t V) {
+  if (!isInt<21>(V))
+    fatal("relocation out of range");
   uint32_t S = V < 0 ? 1 : 0;
   uint32_t J1 = (V >> 19) & 1;
   uint32_t J2 = (V >> 18) & 1;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41163.126699.patch
Type: text/x-patch
Size: 1177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171213/3c8cb83a/attachment.bin>


More information about the llvm-commits mailing list