From aeeaf4b02eb044cca187759b2d1ea811919a2d32 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 12 Apr 2022 10:23:54 +0800 Subject: [PATCH] Fix fast-jit codegen lower_select issue (#1082) Directly patch the offset in condition jmp instructions as the offset generated by asmjit is always 0. --- core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp b/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp index 699b69711..1f3784e55 100644 --- a/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp +++ b/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp @@ -3545,12 +3545,9 @@ static bool cmp_r_and_jmp_relative(x86::Assembler &a, int32 reg_no, COND_OP op, int32 offset) { - Imm target; - - if (offset >= -127 && offset <= 127) - target.setValue((int8)offset); - else - target.setValue(offset); + Imm target(INT32_MAX); + char *stream = (char *)a.code()->sectionById(0)->buffer().data() + + a.code()->sectionById(0)->buffer().size(); switch (op) { case EQ: @@ -3588,6 +3585,8 @@ cmp_r_and_jmp_relative(x86::Assembler &a, int32 reg_no, COND_OP op, break; } + /* The offset written by asmjit is always 0, we patch it again */ + *(int32 *)(stream + 2) = offset; return true; }