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