The plugin check accepts the .quad exlaunch writes for a backward b.cond, cbz or tbz: its relocation drops the offset's sign. Challenge Mode's two backward b.eq hooks were refused for it (#578)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-22 16:03:48 +03:00
1 parent 1c2a0e5a33
commit b61b2b0922
2 files changed
+15 -1

No files matched your search

+9
View File
@@ -292,6 +292,15 @@ class Check(unittest.TestCase):
self.assertEqual(reasons, [])
self.assertEqual(hooks[0]['relocated'], '0x37000040 +5 words')
def test_trampoline_backward_unsigned(self): # Challenge: b.eq back 0x2ec; exlaunch's .quad lacks the sign
site, t = MAIN + SITE_OFF, PLUGIN + TRAMP_OFF
form = [0x54000040, 0x14000005, xp.LDR_X17_8, xp.BR_X17]
for target in (site + 0x1FFD14, site - 0x2EC):
words = [*form, *quad(target), b(t + 24, site + 4)]
self.assertEqual(self.reasons(self.long_form(0x54FFE8A0, TRAMP_OFF, words)), [], hex(target))
self.refused(self.long_form(0x54FFE8A0, TRAMP_OFF, [*form, *quad(site + 0x1FFD18), b(t + 24, site + 4)]),
'not the original')
def test_trampoline_long_nop(self): # the .quad 8-byte aligned by one nop before the form
site, t = MAIN + SITE_OFF, PLUGIN + TRAMP_OFF + 4
form = [0x37000040, 0x14000005, xp.LDR_X17_8, xp.BR_X17, *quad(site + 0x14)]
+6 -1
View File
@@ -214,7 +214,12 @@ def relocation_end(word, orig, site, at):
return literal_end(word, orig, at)
p = at + 4 if w0 == NOP else at
w = [word(p + 4 * i) for i in range(4)]
targets = {target}
if kind in ('b.cond', 'cbz', 'tbz'):
# exlaunch's __fix_cond_comp_test_branch takes the offset field without its sign: a backward target lands
# 2^21 (b.cond, cbz) or 2^16 (tbz) bytes too far. Challenge Mode's trampolines hold such .quads; the generated
# code runs main's own branch instead, to its real target.
targets.add(site + ((orig >> 5 & (0x3FFF if kind == 'tbz' else 0x7FFFF)) << 2))
form, data = pc_relative(w[0], p) == (rel[0], p + 8) and w[1:] == [0x14000005, LDR_X17_8, BR_X17], p + 16
elif kind == 'b' and orig >> 31:
form, data = w[:3] == [LDR_X17_12, ADR_X30_16, BR_X17], p + 12
@@ -222,7 +227,7 @@ def relocation_end(word, orig, site, at):
form, data = w[:2] == [LDR_X17_8, BR_X17], p + 8
else: # adr, adrp
form, data = w[:2] == [0x58000040 | orig & 0x1F, 0x14000003], p + 8
return data + 8 if form and data % 8 == 0 and quad(word, data) == target else None
return data + 8 if form and data % 8 == 0 and quad(word, data) in targets else None
def returns_to(word, at, back):