From 18774805cc8d4eb40cb0bd0b5ca67c968f859952 Mon Sep 17 00:00:00 2001 From: Qiang <56512053+FromLiQg@users.noreply.github.com> Date: Thu, 1 Sep 2022 15:31:00 +0800 Subject: [PATCH] Add more checks for Fast JIT (#1433) Add more checks for Fast JIT to fix the issues reported by instrument test: - add check for the jit_value before pushing it into the stack - add check at the end of form_and_translate_func - add checks after each jit pass --- core/iwasm/fast-jit/jit_compiler.c | 2 +- core/iwasm/fast-jit/jit_frontend.c | 3 +++ core/iwasm/fast-jit/jit_frontend.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/iwasm/fast-jit/jit_compiler.c b/core/iwasm/fast-jit/jit_compiler.c index 6282e30467..c10a409949 100644 --- a/core/iwasm/fast-jit/jit_compiler.c +++ b/core/iwasm/fast-jit/jit_compiler.c @@ -64,7 +64,7 @@ apply_compiler_passes(JitCompContext *cc) cc->cur_pass_no = p - jit_globals.passes; bh_assert(*p < COMPILER_PASS_NUM); - if (!compiler_passes[*p].run(cc)) { + if (!compiler_passes[*p].run(cc) || jit_get_last_error(cc)) { LOG_VERBOSE("JIT: compilation failed at pass[%td] = %s\n", p - jit_globals.passes, compiler_passes[*p].name); return false; diff --git a/core/iwasm/fast-jit/jit_frontend.c b/core/iwasm/fast-jit/jit_frontend.c index 124a5f5539..44c06a7dc9 100644 --- a/core/iwasm/fast-jit/jit_frontend.c +++ b/core/iwasm/fast-jit/jit_frontend.c @@ -731,6 +731,9 @@ form_and_translate_func(JitCompContext *cc) *(jit_annl_end_bcip(cc, cc->exit_label)) = cc->cur_wasm_module->load_addr; + if (jit_get_last_error(cc)) { + return false; + } return true; } diff --git a/core/iwasm/fast-jit/jit_frontend.h b/core/iwasm/fast-jit/jit_frontend.h index a31fbc5ae0..eeecf48fbd 100644 --- a/core/iwasm/fast-jit/jit_frontend.h +++ b/core/iwasm/fast-jit/jit_frontend.h @@ -513,6 +513,8 @@ set_local_f64(JitFrame *frame, int n, JitReg val) #define PUSH(jit_value, value_type) \ do { \ + if (!jit_value) \ + goto fail; \ if (!jit_cc_push_value(cc, value_type, jit_value)) \ goto fail; \ } while (0)