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; 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: 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