Fix wamr compiler issues and refine some error messages (#470)

Fix potential memory leak issue when using llvm::EngineBuilder().selectTarget()
Fix issue of accessing aot_value's fields after it is freed
Fix JIT not print failed to link import warning
Change some error messages: 'fail to' to 'failed to'
Update error message when SIMD isn't enabled
Fix install littlevgl wasm app of wasi version failed

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
Wenyong Huang 2020-12-14 23:05:39 -06:00 committed by GitHub
parent 619c2b383c
commit 16e6f41b3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 54 additions and 44 deletions

View File

@ -894,15 +894,12 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end,
module_name = import_funcs[i].module_name;
field_name = import_funcs[i].func_name;
if (!(import_funcs[i].func_ptr_linked =
import_funcs[i].func_ptr_linked =
wasm_native_resolve_symbol(module_name, field_name,
import_funcs[i].func_type,
&import_funcs[i].signature,
&import_funcs[i].attachment,
&import_funcs[i].call_conv_raw))) {
LOG_WARNING("warning: fail to link import function (%s, %s)\n",
module_name, field_name);
}
&import_funcs[i].call_conv_raw);
#if WASM_ENABLE_LIBC_WASI != 0
if (!strcmp(import_funcs[i].module_name, "wasi_unstable")

View File

@ -551,8 +551,15 @@ init_func_ptrs(AOTModuleInstance *module_inst, AOTModule *module,
/* Set import function pointers */
func_ptrs = (void**)module_inst->func_ptrs.ptr;
for (i = 0; i < module->import_func_count; i++, func_ptrs++)
for (i = 0; i < module->import_func_count; i++, func_ptrs++) {
*func_ptrs = (void*)module->import_funcs[i].func_ptr_linked;
if (!*func_ptrs) {
const char *module_name = module->import_funcs[i].module_name;
const char *field_name = module->import_funcs[i].func_name;
LOG_WARNING("warning: failed to link import function (%s, %s)",
module_name, field_name);
}
}
/* Set defined function pointers */
memcpy(func_ptrs, module->func_ptrs, module->func_count * sizeof(void*));
@ -1232,7 +1239,7 @@ aot_set_exception_with_id(AOTModuleInstance *module_inst,
aot_set_exception(module_inst, "uninitialized element");
break;
case EXCE_CALL_UNLINKED_IMPORT_FUNC:
aot_set_exception(module_inst, "fail to call unlinked import function");
aot_set_exception(module_inst, "failed to call unlinked import function");
break;
case EXCE_NATIVE_STACK_OVERFLOW:
aot_set_exception(module_inst, "native stack overflow");
@ -1775,7 +1782,7 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
import_func = aot_module->import_funcs + func_idx;
if (!func_ptr) {
snprintf(buf, sizeof(buf),
"fail to call unlinked import function (%s, %s)",
"failed to call unlinked import function (%s, %s)",
import_func->module_name, import_func->func_name);
aot_set_exception(module_inst, buf);
return false;
@ -1851,7 +1858,7 @@ aot_call_indirect(WASMExecEnv *exec_env,
bh_assert(func_idx < aot_module->import_func_count);
import_func = aot_module->import_funcs + func_idx;
snprintf(buf, sizeof(buf),
"fail to call unlinked import function (%s, %s)",
"failed to call unlinked import function (%s, %s)",
import_func->module_name, import_func->func_name);
aot_set_exception(module_inst, buf);
return false;

View File

@ -1036,8 +1036,8 @@ build_atomic_rmw:
case WASM_OP_SIMD_PREFIX:
{
if (!comp_ctx->enable_simd) {
aot_set_last_error(
"current building does not support SIMD instructions");
aot_set_last_error("SIMD instruction was found, "
"try adding --enable-simd option?");
return false;
}

View File

@ -86,7 +86,8 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder);
LLVMBasicBlockRef check_succ;
AOTValue *aot_value;
bool is_target_64bit;
uint32 local_idx_of_aot_value = 0;
bool is_target_64bit, is_local_of_aot_value = false;
#if WASM_ENABLE_SHARED_MEMORY != 0
bool is_shared_memory =
comp_ctx->comp_data->memories[0].memory_flags & 0x02;
@ -116,6 +117,12 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
aot_value = func_ctx->block_stack.block_list_end->value_stack.value_list_end;
if (aot_value) {
/* aot_value is freed in the following POP_I32(addr),
so save its fields here for further use */
is_local_of_aot_value = aot_value->is_local;
local_idx_of_aot_value = aot_value->local_idx;
}
POP_I32(addr);
@ -156,8 +163,8 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
BUILD_OP(Add, offset_const, addr, offset1, "offset1");
if (comp_ctx->enable_bound_check
&& !(aot_value->is_local
&& aot_checked_addr_list_find(func_ctx, aot_value->local_idx,
&& !(is_local_of_aot_value
&& aot_checked_addr_list_find(func_ctx, local_idx_of_aot_value,
offset, bytes))) {
uint32 init_page_count =
comp_ctx->comp_data->memories[0].mem_init_page_count;
@ -207,8 +214,8 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
SET_BUILD_POS(check_succ);
if (aot_value->is_local) {
if (!aot_checked_addr_list_add(func_ctx, aot_value->local_idx,
if (is_local_of_aot_value) {
if (!aot_checked_addr_list_add(func_ctx, local_idx_of_aot_value,
offset, bytes))
goto fail;
}

View File

@ -115,9 +115,10 @@ aot_check_simd_compatibility(const char *arch_c_str, const char *cpu_c_str)
llvm::SmallVector<std::string, 1> targetAttributes;
llvm::Triple targetTriple(arch_c_str, "", "");
llvm::TargetMachine *targetMachine = llvm::EngineBuilder().selectTarget(
targetTriple, "", std::string(cpu_c_str), targetAttributes);
if (targetMachine == nullptr) {
auto targetMachine =
std::unique_ptr<llvm::TargetMachine>(llvm::EngineBuilder().selectTarget(
targetTriple, "", std::string(cpu_c_str), targetAttributes));
if (!targetMachine) {
return false;
}

View File

@ -941,7 +941,7 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
if (!func_import->func_ptr_linked) {
snprintf(buf, sizeof(buf),
"fail to call unlinked import function (%s, %s)",
"failed to call unlinked import function (%s, %s)",
func_import->module_name, func_import->field_name);
wasm_set_exception(module_inst, buf);
return;
@ -998,7 +998,7 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
if (!sub_func_inst) {
snprintf(buf, sizeof(buf),
"fail to call unlinked import function (%s, %s)",
"failed to call unlinked import function (%s, %s)",
func_import->module_name, func_import->field_name);
wasm_set_exception(module_inst, buf);
return;
@ -1865,7 +1865,7 @@ label_pop_csp_n:
delta = (uint32)POP_I32();
if (!wasm_enlarge_memory(module, delta)) {
/* fail to memory.grow, return -1 */
/* failed to memory.grow, return -1 */
PUSH_I32(-1);
}
else {

View File

@ -987,8 +987,8 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
if (!func_import->func_ptr_linked) {
char buf[128];
snprintf(buf,
sizeof(buf), "fail to call unlinked import function (%s, %s)",
snprintf(buf, sizeof(buf),
"failed to call unlinked import function (%s, %s)",
func_import->module_name, func_import->field_name);
wasm_set_exception((WASMModuleInstance*)module_inst, buf);
return;
@ -1043,7 +1043,7 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
if (!sub_func_inst) {
snprintf(buf, sizeof(buf),
"fail to call unlinked import function (%s, %s)",
"failed to call unlinked import function (%s, %s)",
func_import->module_name, func_import->field_name);
wasm_set_exception(module_inst, buf);
return;
@ -1796,7 +1796,7 @@ recover_br_info:
delta = (uint32)frame_lp[addr1];
if (!wasm_enlarge_memory(module, delta)) {
/* fail to memory.grow, return -1 */
/* failed to memory.grow, return -1 */
frame_lp[addr_ret] = -1;
}
else {

View File

@ -1841,8 +1841,12 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
#endif
#endif
) {
set_error_buf(error_buf, error_buf_size,
"invalid local type");
if (type == VALUE_TYPE_V128)
set_error_buf(error_buf, error_buf_size,
"v128 value type requires simd feature");
else
set_error_buf_v(error_buf, error_buf_size,
"invalid local type 0x%02X", type);
return false;
}
for (k = 0; k < sub_local_count; k++) {

View File

@ -388,19 +388,6 @@ load_function_import(const WASMModule *parent_module, WASMModule *sub_module,
&linked_call_conv_raw);
}
if (!linked_func) {
#if WASM_ENABLE_SPEC_TEST != 0
set_error_buf(error_buf, error_buf_size,
"unknown import or incompatible import type");
return false;
#else
#if WASM_ENABLE_WAMR_COMPILER == 0
LOG_WARNING("warning: fail to link import function (%s, %s)",
sub_module_name, function_name);
#endif
#endif
}
function->module_name = sub_module_name;
function->field_name = function_name;
function->func_type = declare_func_type;

View File

@ -1097,7 +1097,7 @@ check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf,
return false;
#else
#if WASM_ENABLE_WAMR_COMPILER == 0
LOG_WARNING("warning: fail to link import function (%s, %s)",
LOG_WARNING("warning: failed to link import function (%s, %s)",
func->module_name, func->field_name);
#else
/* do nothing to avoid confused message */
@ -1115,7 +1115,7 @@ check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf,
return false;
#else
#if WASM_ENABLE_WAMR_COMPILER == 0
LOG_DEBUG("warning: fail to link import global (%s, %s)",
LOG_DEBUG("warning: failed to link import global (%s, %s)",
global->module_name, global->field_name);
#else
/* do nothing to avoid confused message */

View File

@ -159,6 +159,13 @@ static void hal_init(void)
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read = display_input_read; /*This function will be called periodically (by the library) to get the mouse position and state*/
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv);
}
/* Implement empry main function as wasi start function calls it */
int main(int argc, char **argv)
{
(void)argc;
(void)argv;
return 0;
}