Skip to content

Commit 66a3e5c

Browse files
committed
boundary check for CBZ/CBNZ fixup
1 parent 1856935 commit 66a3e5c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,15 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
566566
// Offset by 4, and don't encode the low two bits.
567567
return ((Value - 4) >> 2) & 0xff;
568568
case ARM::fixup_arm_thumb_cb: {
569+
// CB instructions can only branch to offsets in [4, 126] in multiples of 2
570+
// so ensure that the raw value LSB is zero and it lies in [2, 130].
571+
// An offset of 2 will be relaxed to a NOP.
572+
if (Ctx) {
573+
if ((int64_t)Value < 2 || Value > 0x82 || Value & 1) {
574+
Ctx->reportError(Fixup.getLoc(), "out of range pc-relative fixup value");
575+
return 0;
576+
}
577+
}
569578
// Offset by 4 and don't encode the lower bit, which is always 0.
570579
// FIXME: diagnose if no Thumb2
571580
uint32_t Binary = (Value - 4) >> 1;

0 commit comments

Comments
 (0)