mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-03-12 00:45:28 +00:00
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:
parent
619c2b383c
commit
16e6f41b3a
|
@ -894,15 +894,12 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end,
|
||||||
|
|
||||||
module_name = import_funcs[i].module_name;
|
module_name = import_funcs[i].module_name;
|
||||||
field_name = import_funcs[i].func_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,
|
wasm_native_resolve_symbol(module_name, field_name,
|
||||||
import_funcs[i].func_type,
|
import_funcs[i].func_type,
|
||||||
&import_funcs[i].signature,
|
&import_funcs[i].signature,
|
||||||
&import_funcs[i].attachment,
|
&import_funcs[i].attachment,
|
||||||
&import_funcs[i].call_conv_raw))) {
|
&import_funcs[i].call_conv_raw);
|
||||||
LOG_WARNING("warning: fail to link import function (%s, %s)\n",
|
|
||||||
module_name, field_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if WASM_ENABLE_LIBC_WASI != 0
|
#if WASM_ENABLE_LIBC_WASI != 0
|
||||||
if (!strcmp(import_funcs[i].module_name, "wasi_unstable")
|
if (!strcmp(import_funcs[i].module_name, "wasi_unstable")
|
||||||
|
|
|
@ -551,8 +551,15 @@ init_func_ptrs(AOTModuleInstance *module_inst, AOTModule *module,
|
||||||
|
|
||||||
/* Set import function pointers */
|
/* Set import function pointers */
|
||||||
func_ptrs = (void**)module_inst->func_ptrs.ptr;
|
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;
|
*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 */
|
/* Set defined function pointers */
|
||||||
memcpy(func_ptrs, module->func_ptrs, module->func_count * sizeof(void*));
|
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");
|
aot_set_exception(module_inst, "uninitialized element");
|
||||||
break;
|
break;
|
||||||
case EXCE_CALL_UNLINKED_IMPORT_FUNC:
|
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;
|
break;
|
||||||
case EXCE_NATIVE_STACK_OVERFLOW:
|
case EXCE_NATIVE_STACK_OVERFLOW:
|
||||||
aot_set_exception(module_inst, "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;
|
import_func = aot_module->import_funcs + func_idx;
|
||||||
if (!func_ptr) {
|
if (!func_ptr) {
|
||||||
snprintf(buf, sizeof(buf),
|
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);
|
import_func->module_name, import_func->func_name);
|
||||||
aot_set_exception(module_inst, buf);
|
aot_set_exception(module_inst, buf);
|
||||||
return false;
|
return false;
|
||||||
|
@ -1851,7 +1858,7 @@ aot_call_indirect(WASMExecEnv *exec_env,
|
||||||
bh_assert(func_idx < aot_module->import_func_count);
|
bh_assert(func_idx < aot_module->import_func_count);
|
||||||
import_func = aot_module->import_funcs + func_idx;
|
import_func = aot_module->import_funcs + func_idx;
|
||||||
snprintf(buf, sizeof(buf),
|
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);
|
import_func->module_name, import_func->func_name);
|
||||||
aot_set_exception(module_inst, buf);
|
aot_set_exception(module_inst, buf);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1036,8 +1036,8 @@ build_atomic_rmw:
|
||||||
case WASM_OP_SIMD_PREFIX:
|
case WASM_OP_SIMD_PREFIX:
|
||||||
{
|
{
|
||||||
if (!comp_ctx->enable_simd) {
|
if (!comp_ctx->enable_simd) {
|
||||||
aot_set_last_error(
|
aot_set_last_error("SIMD instruction was found, "
|
||||||
"current building does not support SIMD instructions");
|
"try adding --enable-simd option?");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,8 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder);
|
LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder);
|
||||||
LLVMBasicBlockRef check_succ;
|
LLVMBasicBlockRef check_succ;
|
||||||
AOTValue *aot_value;
|
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
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||||
bool is_shared_memory =
|
bool is_shared_memory =
|
||||||
comp_ctx->comp_data->memories[0].memory_flags & 0x02;
|
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;
|
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);
|
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");
|
BUILD_OP(Add, offset_const, addr, offset1, "offset1");
|
||||||
|
|
||||||
if (comp_ctx->enable_bound_check
|
if (comp_ctx->enable_bound_check
|
||||||
&& !(aot_value->is_local
|
&& !(is_local_of_aot_value
|
||||||
&& aot_checked_addr_list_find(func_ctx, aot_value->local_idx,
|
&& aot_checked_addr_list_find(func_ctx, local_idx_of_aot_value,
|
||||||
offset, bytes))) {
|
offset, bytes))) {
|
||||||
uint32 init_page_count =
|
uint32 init_page_count =
|
||||||
comp_ctx->comp_data->memories[0].mem_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);
|
SET_BUILD_POS(check_succ);
|
||||||
|
|
||||||
if (aot_value->is_local) {
|
if (is_local_of_aot_value) {
|
||||||
if (!aot_checked_addr_list_add(func_ctx, aot_value->local_idx,
|
if (!aot_checked_addr_list_add(func_ctx, local_idx_of_aot_value,
|
||||||
offset, bytes))
|
offset, bytes))
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::SmallVector<std::string, 1> targetAttributes;
|
||||||
llvm::Triple targetTriple(arch_c_str, "", "");
|
llvm::Triple targetTriple(arch_c_str, "", "");
|
||||||
llvm::TargetMachine *targetMachine = llvm::EngineBuilder().selectTarget(
|
auto targetMachine =
|
||||||
targetTriple, "", std::string(cpu_c_str), targetAttributes);
|
std::unique_ptr<llvm::TargetMachine>(llvm::EngineBuilder().selectTarget(
|
||||||
if (targetMachine == nullptr) {
|
targetTriple, "", std::string(cpu_c_str), targetAttributes));
|
||||||
|
if (!targetMachine) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -941,7 +941,7 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||||
|
|
||||||
if (!func_import->func_ptr_linked) {
|
if (!func_import->func_ptr_linked) {
|
||||||
snprintf(buf, sizeof(buf),
|
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);
|
func_import->module_name, func_import->field_name);
|
||||||
wasm_set_exception(module_inst, buf);
|
wasm_set_exception(module_inst, buf);
|
||||||
return;
|
return;
|
||||||
|
@ -998,7 +998,7 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
|
||||||
|
|
||||||
if (!sub_func_inst) {
|
if (!sub_func_inst) {
|
||||||
snprintf(buf, sizeof(buf),
|
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);
|
func_import->module_name, func_import->field_name);
|
||||||
wasm_set_exception(module_inst, buf);
|
wasm_set_exception(module_inst, buf);
|
||||||
return;
|
return;
|
||||||
|
@ -1865,7 +1865,7 @@ label_pop_csp_n:
|
||||||
delta = (uint32)POP_I32();
|
delta = (uint32)POP_I32();
|
||||||
|
|
||||||
if (!wasm_enlarge_memory(module, delta)) {
|
if (!wasm_enlarge_memory(module, delta)) {
|
||||||
/* fail to memory.grow, return -1 */
|
/* failed to memory.grow, return -1 */
|
||||||
PUSH_I32(-1);
|
PUSH_I32(-1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -987,8 +987,8 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||||
|
|
||||||
if (!func_import->func_ptr_linked) {
|
if (!func_import->func_ptr_linked) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
snprintf(buf,
|
snprintf(buf, sizeof(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);
|
func_import->module_name, func_import->field_name);
|
||||||
wasm_set_exception((WASMModuleInstance*)module_inst, buf);
|
wasm_set_exception((WASMModuleInstance*)module_inst, buf);
|
||||||
return;
|
return;
|
||||||
|
@ -1043,7 +1043,7 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
|
||||||
|
|
||||||
if (!sub_func_inst) {
|
if (!sub_func_inst) {
|
||||||
snprintf(buf, sizeof(buf),
|
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);
|
func_import->module_name, func_import->field_name);
|
||||||
wasm_set_exception(module_inst, buf);
|
wasm_set_exception(module_inst, buf);
|
||||||
return;
|
return;
|
||||||
|
@ -1796,7 +1796,7 @@ recover_br_info:
|
||||||
delta = (uint32)frame_lp[addr1];
|
delta = (uint32)frame_lp[addr1];
|
||||||
|
|
||||||
if (!wasm_enlarge_memory(module, delta)) {
|
if (!wasm_enlarge_memory(module, delta)) {
|
||||||
/* fail to memory.grow, return -1 */
|
/* failed to memory.grow, return -1 */
|
||||||
frame_lp[addr_ret] = -1;
|
frame_lp[addr_ret] = -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1841,8 +1841,12 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
if (type == VALUE_TYPE_V128)
|
||||||
"invalid local type");
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
for (k = 0; k < sub_local_count; k++) {
|
for (k = 0; k < sub_local_count; k++) {
|
||||||
|
|
|
@ -388,19 +388,6 @@ load_function_import(const WASMModule *parent_module, WASMModule *sub_module,
|
||||||
&linked_call_conv_raw);
|
&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->module_name = sub_module_name;
|
||||||
function->field_name = function_name;
|
function->field_name = function_name;
|
||||||
function->func_type = declare_func_type;
|
function->func_type = declare_func_type;
|
||||||
|
|
|
@ -1097,7 +1097,7 @@ check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf,
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
#if WASM_ENABLE_WAMR_COMPILER == 0
|
#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);
|
func->module_name, func->field_name);
|
||||||
#else
|
#else
|
||||||
/* do nothing to avoid confused message */
|
/* do nothing to avoid confused message */
|
||||||
|
@ -1115,7 +1115,7 @@ check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf,
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
#if WASM_ENABLE_WAMR_COMPILER == 0
|
#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);
|
global->module_name, global->field_name);
|
||||||
#else
|
#else
|
||||||
/* do nothing to avoid confused message */
|
/* do nothing to avoid confused message */
|
||||||
|
|
|
@ -159,6 +159,13 @@ static void hal_init(void)
|
||||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
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*/
|
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);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user