From c3a14af2d3b561794c85f4aeaa70e9a988e44f70 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Mon, 17 Oct 2022 18:03:15 +0200 Subject: [PATCH] Force TARGET_TB_PCREL to 1 --- accel/tcg/cpu-exec.c | 7 ++++++- accel/tcg/translate-all.c | 4 +++- include/exec/cpu-defs.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 11ae212680..0b0d78a323 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -1054,9 +1054,10 @@ int cpu_exec(CPUState *cpu) //// --- Begin LibAFL code --- +#if !TARGET_TB_PCREL if (last_tb->jmp_reset_offset[1] != TB_JMP_RESET_OFFSET_INVALID) { mmap_lock(); - TranslationBlock *edge = libafl_gen_edge(cpu, last_tb->pc, tb->pc, + TranslationBlock *edge = libafl_gen_edge(cpu, tb_pc(last_tb), tb_pc(tb), tb_exit, cs_base, flags, cflags); mmap_unlock(); @@ -1069,6 +1070,10 @@ int cpu_exec(CPUState *cpu) } else { tb_add_jump(last_tb, tb_exit, tb); } +#else + // No party if TARGET_TB_PCREL is 1 + tb_add_jump(last_tb, tb_exit, tb); +#endif //// --- End LibAFL code --- } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 828f2beaa3..d7e570f20c 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -2062,7 +2062,9 @@ TranslationBlock *libafl_gen_edge(CPUState *cpu, target_ulong src_block, gen_code_buf = tcg_ctx->code_gen_ptr; tb->tc.ptr = tcg_splitwx_to_rx(gen_code_buf); +#if !TARGET_TB_PCREL tb->pc = pc; +#endif tb->cs_base = cs_base; tb->flags = flags; tb->cflags = cflags; @@ -2102,7 +2104,7 @@ TranslationBlock *libafl_gen_edge(CPUState *cpu, target_ulong src_block, tcg_ctx->cpu = NULL; max_insns = tb->icount; - trace_translate_block(tb, tb->pc, tb->tc.ptr); + trace_translate_block(tb, pc, tb->tc.ptr); /* generate machine code */ tb->jmp_reset_offset[0] = TB_JMP_RESET_OFFSET_INVALID; diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h index 21309cf567..ff81fff592 100644 --- a/include/exec/cpu-defs.h +++ b/include/exec/cpu-defs.h @@ -33,6 +33,8 @@ #include "cpu-param.h" +#define TARGET_TB_PCREL 1 + #ifndef TARGET_LONG_BITS # error TARGET_LONG_BITS must be defined in cpu-param.h #endif