Skip to content

Commit

Permalink
boundary check for CBZ/CBNZ fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
covanam committed Feb 17, 2023
1 parent 1856935 commit 862943a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
// Offset by 4, and don't encode the low two bits.
return ((Value - 4) >> 2) & 0xff;
case ARM::fixup_arm_thumb_cb: {
// CB instructions can only branch to offsets in [4, 126] in multiples of 2
// so ensure that the raw value LSB is zero and it lies in [2, 130].
// An offset of 2 will be relaxed to a NOP.
if ((int64_t)Value < 2 || Value > 0x82 || Value & 1) {
Ctx->reportError(Fixup.getLoc(), "out of range pc-relative fixup value");
return 0;
}
// Offset by 4 and don't encode the lower bit, which is always 0.
// FIXME: diagnose if no Thumb2
uint32_t Binary = (Value - 4) >> 1;
Expand Down

0 comments on commit 862943a

Please sign in to comment.