Skip to contentSkip to conversation

target/sh4: add missing tcg_temp_free()

PATCH In review Philippe Mathieu-Daudé 3 participants 6 messages Dec 5, 2017 – Dec 6, 2017

lore
Share & tools
lore
#0 lore raw

cover target/sh4: add missing tcg_temp_free()

Hi,

After reading Alex commenting on IRC "java --version failing on sh4" I remember this series staged for 2.12.

This might help for:

  root@6e10336e48ac:/etc/apt# java --version
  qemu-sh4: /home/alex/lsrc/qemu/qemu.git/tcg/tcg.h:703: temp_idx: Assertion `n >= 0 && n < tcg_ctx->nb_temps' failed.
  qemu: uncaught target signal 11 (Segmentation fault) - core dumped

Regards,

Philippe.

Philippe Mathieu-Daudé (2):
target/sh4: add missing tcg_temp_free() in gen_conditional_jump() target/sh4: add missing tcg_temp_free() in _decode_opc()

 target/sh4/translate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.15.1
#1 lore raw

PATCH 1/2 target/sh4: add missing tcg_temp_free() in gen_conditional_jump()

missed in c55497ecb8c.

---
 target/sh4/translate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target/sh4/translate.c +4 -1
index 703020fe87..5aeaabdd8d 100644
@@ -322,13 +322,16 @@ static void gen_delayed_conditional_jump(DisasContext * ctx)
         gen_jump(ctx);
 
         gen_set_label(l1);
-        return;
+        goto done;
     }
 
     tcg_gen_brcondi_i32(TCG_COND_NE, ds, 0, l1);
     gen_goto_tb(ctx, 1, ctx->pc + 2);
     gen_set_label(l1);
     gen_jump(ctx);
+
+done:
+    tcg_temp_free(ds);
 }
 
 static inline void gen_load_fpr64(DisasContext *ctx, TCGv_i64 t, int reg)
Signature · 1 line
2.15.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] target/sh4: add missing tcg_temp_free() in gen_conditional_jump()

Quoted 19 lines · Philippe Mathieu-Daudé

missed in c55497ecb8c.

---
 target/sh4/translate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target/sh4/translate.c +1 -1
index 703020fe87..5aeaabdd8d 100644
@@ -322,13 +322,16 @@ static void gen_delayed_conditional_jump(DisasContext * ctx)
         gen_jump(ctx);
 
         gen_set_label(l1);
-        return;
+        goto done;
     }
 

target/sh4/translate.c static void gen_delayed_conditional_jump(DisasContext * ctx) · line 337

Quoted 10 lines
target/sh4/translate.c +3 -0
     tcg_gen_brcondi_i32(TCG_COND_NE, ds, 0, l1);
     gen_goto_tb(ctx, 1, ctx->pc + 2);
     gen_set_label(l1);
     gen_jump(ctx);
+
+done:
+    tcg_temp_free(ds);
 }
 
 static inline void gen_load_fpr64(DisasContext *ctx, TCGv_i64 t, int reg)

AFAIR, temps are not preserved across a branch (contrary to local temps), so I am not sure they need to be freed.

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net
#3 lore raw

PATCH 2/2 target/sh4: add missing tcg_temp_free() in _decode_opc()

In reply to Philippe Mathieu-Daudé

missed in c55497ecb8c and 852d481faf7.

---
 target/sh4/translate.c | 2 ++
 1 file changed, 2 insertions(+)
target/sh4/translate.c +2 -0
index 5aeaabdd8d..62d01227fc 100644
@@ -604,6 +604,7 @@ static void _decode_opc(DisasContext * ctx)
 	    tcg_gen_subi_i32(addr, REG(B11_8), 4);
             tcg_gen_qemu_st_i32(REG(B7_4), addr, ctx->memidx, MO_TEUL);
 	    tcg_gen_mov_i32(REG(B11_8), addr);
+        tcg_temp_free(addr);
 	}
 	return;
     case 0x6004:		/* mov.b @Rm+,Rn */
@@ -1527,6 +1528,7 @@ static void _decode_opc(DisasContext * ctx)
             tcg_gen_qemu_ld_i32(val, REG(B11_8), ctx->memidx, MO_TEUL);
             gen_helper_movcal(cpu_env, REG(B11_8), val);
             tcg_gen_qemu_st_i32(REG(0), REG(B11_8), ctx->memidx, MO_TEUL);
+            tcg_temp_free(val);
         }
         ctx->has_movcal = 1;
 	return;
Signature · 1 line
2.15.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] target/sh4: add missing tcg_temp_free() in _decode_opc()

Quoted 20 lines · Philippe Mathieu-Daudé

missed in c55497ecb8c and 852d481faf7.

---
 target/sh4/translate.c | 2 ++
 1 file changed, 2 insertions(+)
target/sh4/translate.c +1 -0
index 5aeaabdd8d..62d01227fc 100644
@@ -604,6 +604,7 @@ static void _decode_opc(DisasContext * ctx)
 	    tcg_gen_subi_i32(addr, REG(B11_8), 4);
             tcg_gen_qemu_st_i32(REG(B7_4), addr, ctx->memidx, MO_TEUL);
 	    tcg_gen_mov_i32(REG(B11_8), addr);
+        tcg_temp_free(addr);
 	}
 	return;
     case 0x6004:		/* mov.b @Rm+,Rn */

target/sh4/translate.c static void _decode_opc(DisasContext * ctx) · line 1534

Quoted 7 lines
target/sh4/translate.c +1 -0
@@ -1527,6 +1528,7 @@ static void _decode_opc(DisasContext * ctx)
             tcg_gen_qemu_ld_i32(val, REG(B11_8), ctx->memidx, MO_TEUL);
             gen_helper_movcal(cpu_env, REG(B11_8), val);
             tcg_gen_qemu_st_i32(REG(0), REG(B11_8), ctx->memidx, MO_TEUL);
+            tcg_temp_free(val);
         }
         ctx->has_movcal = 1;
 	return;

Good catch!

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net
#5 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Hi,

After reading Alex commenting on IRC "java --version failing on sh4" I remember this series staged for 2.12.

This might help for:

  root@6e10336e48ac:/etc/apt# java --version
  qemu-sh4: /home/alex/lsrc/qemu/qemu.git/tcg/tcg.h:703: temp_idx: Assertion `n >= 0 && n < tcg_ctx->nb_temps' failed.
  qemu: uncaught target signal 11 (Segmentation fault) - core dumped

Sadly it's decode_gusa which trips for me:

  #0  0x00007ffff6941428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
  #1  0x00007ffff694302a in __GI_abort () at abort.c:89
  #2  0x00007ffff6939bd7 in __assert_fail_base (fmt=<optimised out>, assertion=assertion@entry=0x555555678fc8 "n >= 0 && n < tcg_ctx->nb_temps", file=file@entry=0x555555678fa0 "/home/alex/lsrc/qemu/qemu.git/tcg/tcg.h", line=line@entry=703, function=function@entry=0x55555567aa38 <__PRETTY_FUNCTION__.23740> "temp_idx") at assert.c:92
  #3  0x00007ffff6939c82 in __GI___assert_fail (assertion=0x555555678fc8 "n >= 0 && n < tcg_ctx->nb_temps", file=0x555555678fa0 "/home/alex/lsrc/qemu/qemu.git/tcg/tcg.h", line=703, function=0x55555567aa38 <__PRETTY_FUNCTION__.23740> "temp_idx") at assert.c:101
  #4  0x0000555555585e03 in temp_idx (ts=0x555555902f20 <tcg_init_ctx>) at /home/alex/lsrc/qemu/qemu.git/tcg/tcg.h:703
  #5  0x0000555555585e5b in tcgv_i32_temp (v=0x0) at /home/alex/lsrc/qemu/qemu.git/tcg/tcg.h:724
  #6  0x000055555558bc2f in tcg_temp_free_i32 (arg=0x0) at /home/alex/lsrc/qemu/qemu.git/tcg/tcg.c:1053
  #7  0x00005555555ff077 in decode_gusa (ctx=0x7ffff7f67c00, env=0x5555579adf60, pmax_insns=0x7ffff7f67bec) at /home/alex/lsrc/qemu/qemu.git/target/sh4/translate.c:2193
  #8  0x00005555555ff303 in gen_intermediate_code (cs=0x5555579a5cc0, tb=0x55555593c6c0 <static_code_gen_buffer+78976>) at /home/alex/lsrc/qemu/qemu.git/target/sh4/translate.c:2268
  #9  0x00005555555bc656 in tb_gen_code (cpu=0x5555579a5cc0, pc=2134168040, cs_base=2134168044, flags=528320, cflags=524288) at /home/alex/lsrc/qemu/qemu.git/accel/tcg/translate-all.c:1292

#10 0x00005555555b9ff9 in tb_find (cpu=0x5555579a5cc0, last_tb=0x0, tb_exit=0, cf_mask=524288) at /home/alex/lsrc/qemu/qemu.git/accel/tcg/cpu-exec.c:402 #11 0x00005555555ba77d in cpu_exec (cpu=0x5555579a5cc0) at /home/alex/lsrc/qemu/qemu.git/accel/tcg/cpu-exec.c:735
#12 0x00005555555c0ed2 in cpu_loop (env=0x5555579adf60) at /home/alex/lsrc/qemu/qemu.git/linux-user/main.c:2684
#13 0x00005555555d001c in clone_func (arg=0x7fffffffc990) at /home/alex/lsrc/qemu/qemu.git/linux-user/syscall.c:6264
#14 0x00007ffff6cdd6ba in start_thread (arg=0x7ffff7f68700) at pthread_create.c:333
#15 0x00007ffff6a133dd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
#7 0x00005555555ff077 in decode_gusa (ctx=0x7ffff7f67c00, env=0x5555579adf60, pmax_insns=0x7ffff7f67bec) at /home/alex/lsrc/qemu/qemu.git/target/sh4/translate.c:2193
2193 tcg_temp_free_i32(op_arg);

The line:

    /* If op_src is not a valid register, then op_arg was a constant.  */
    if (op_src < 0) {
        tcg_temp_free_i32(op_arg);
    }

Looks pretty sketchy to me, why not check is op_arg is allocated directly? Constants still need to be freed over a block. I think TCG still keeps them around if it re-uses them.

Quoted 11 lines

Regards,

Philippe.

Philippe Mathieu-Daudé (2):
target/sh4: add missing tcg_temp_free() in gen_conditional_jump() target/sh4: add missing tcg_temp_free() in _decode_opc()

 target/sh4/translate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

--
Alex Bennée