Skip to contentSkip to conversation

target/arm: Fix assert on BRA.

PATCH Superseded Harald van Dijk 1 participant 2 messages Nov 28, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Fix assert on BRA.

trans_BRA does

    gen_a64_set_pc(s, dst);
    set_btype_for_br(s, a->rn);

gen_a64_set_pc does

    s->pc_save = -1;

set_btype_for_br (if aa64_bti is enabled and the register is not x16 or x17) does

    gen_pc_plus_diff(s, pc, 0);

gen_pc_plus_diff does

    assert(s->pc_save != -1);

Hence, this assert is getting hit. We need to call set_btype_for_br before gen_a64_set_pc, and there is nothing in set_btype_for_br that depends on gen_a64_set_pc having already been called, so this commit simply swaps the calls.

---
 target/arm/tcg/translate-a64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/tcg/translate-a64.c +1 -1
index 08b21d7dbf..cde22a5cca 100644
@@ -1916,8 +1916,8 @@ static bool trans_BRA(DisasContext *s, arg_bra *a)
         return false;
     }
     dst = auth_branch_target(s, cpu_reg(s,a->rn), cpu_reg_sp(s, a->rm), !a->m);
-    gen_a64_set_pc(s, dst);
     set_btype_for_br(s, a->rn);
+    gen_a64_set_pc(s, dst);
     s->base.is_jmp = DISAS_JUMP;
     return true;
 }
Signature · 1 line
2.47.3
#1 lore raw
Quoted 18 lines · Harald van Dijk

trans_BRA does

    gen_a64_set_pc(s, dst);
    set_btype_for_br(s, a->rn);

gen_a64_set_pc does

    s->pc_save = -1;

set_btype_for_br (if aa64_bti is enabled and the register is not x16 or x17) does

    gen_pc_plus_diff(s, pc, 0);

gen_pc_plus_diff does

    assert(s->pc_save != -1);
Quoted 7 lines

Hence, this assert is getting hit. We need to call set_btype_for_br before gen_a64_set_pc, and there is nothing in set_btype_for_br that depends on gen_a64_set_pc having already been called, so this commit simply swaps the calls.

---
 target/arm/tcg/translate-a64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Oops, I forgot the sign-off. Will re-send, apologies for the noise.

Cheers,
Harald van Dijk