Index: lld/trunk/COFF/Chunks.cpp =================================================================== --- lld/trunk/COFF/Chunks.cpp +++ lld/trunk/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; Index: lld/trunk/test/COFF/Inputs/far-arm-thumb-abs20.s =================================================================== --- lld/trunk/test/COFF/Inputs/far-arm-thumb-abs20.s +++ lld/trunk/test/COFF/Inputs/far-arm-thumb-abs20.s @@ -0,0 +1,2 @@ +.global too_far20 +too_far20 = 0x501004 Index: lld/trunk/test/COFF/arm-thumb-branch20-error.s =================================================================== --- lld/trunk/test/COFF/arm-thumb-branch20-error.s +++ lld/trunk/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