mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-09 13:16:26 +00:00
Report error in instantiation when meeting unlinked import globals (#1859)
This commit is contained in:
parent
0c4402293d
commit
7401718311
|
@ -1226,7 +1226,10 @@ load_import_globals(const uint8 **p_buf, const uint8 *buf_end,
|
||||||
}
|
}
|
||||||
import_globals[i].global_data_linked =
|
import_globals[i].global_data_linked =
|
||||||
tmp_global.global_data_linked;
|
tmp_global.global_data_linked;
|
||||||
|
import_globals[i].is_linked = true;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
import_globals[i].is_linked = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import_globals[i].size = wasm_value_type_size(import_globals[i].type);
|
import_globals[i].size = wasm_value_type_size(import_globals[i].type);
|
||||||
|
|
|
@ -976,6 +976,26 @@ execute_memory_init_function(AOTModuleInstance *module_inst)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool
|
||||||
|
check_linked_symbol(AOTModule *module, char *error_buf, uint32 error_buf_size)
|
||||||
|
{
|
||||||
|
uint32 i;
|
||||||
|
|
||||||
|
/* init_func_ptrs() will go through import functions */
|
||||||
|
|
||||||
|
for (i = 0; i < module->import_global_count; i++) {
|
||||||
|
AOTImportGlobal *global = module->import_globals + i;
|
||||||
|
if (!global->is_linked) {
|
||||||
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
|
"warning: failed to link import global (%s, %s)",
|
||||||
|
global->module_name, global->global_name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
AOTModuleInstance *
|
AOTModuleInstance *
|
||||||
aot_instantiate(AOTModule *module, bool is_sub_inst, uint32 stack_size,
|
aot_instantiate(AOTModule *module, bool is_sub_inst, uint32 stack_size,
|
||||||
uint32 heap_size, char *error_buf, uint32 error_buf_size)
|
uint32 heap_size, char *error_buf, uint32 error_buf_size)
|
||||||
|
@ -1059,6 +1079,9 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, uint32 stack_size,
|
||||||
if (!init_func_type_indexes(module_inst, module, error_buf, error_buf_size))
|
if (!init_func_type_indexes(module_inst, module, error_buf, error_buf_size))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
if (!check_linked_symbol(module, error_buf, error_buf_size))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
if (!create_exports(module_inst, module, error_buf, error_buf_size))
|
if (!create_exports(module_inst, module, error_buf, error_buf_size))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
|
|
@ -4555,6 +4555,7 @@ aot_link_global(const AOTModule *module_aot, uint16 global_idx_rt,
|
||||||
}
|
}
|
||||||
|
|
||||||
import->global_idx_rt = global_idx_rt;
|
import->global_idx_rt = global_idx_rt;
|
||||||
|
import_aot_global->is_linked = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
|
|
|
@ -149,6 +149,7 @@ typedef struct AOTImportGlobal {
|
||||||
uint32 data_offset;
|
uint32 data_offset;
|
||||||
/* global data after linked */
|
/* global data after linked */
|
||||||
WASMValue global_data_linked;
|
WASMValue global_data_linked;
|
||||||
|
bool is_linked;
|
||||||
} AOTImportGlobal;
|
} AOTImportGlobal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1235,6 +1235,7 @@ check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf,
|
||||||
#if WASM_ENABLE_WAMR_COMPILER == 0
|
#if WASM_ENABLE_WAMR_COMPILER == 0
|
||||||
LOG_WARNING("warning: failed 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);
|
||||||
|
/* will throw exception only if calling */
|
||||||
#else
|
#else
|
||||||
/* do nothing to avoid confused message */
|
/* do nothing to avoid confused message */
|
||||||
#endif /* WASM_ENABLE_WAMR_COMPILER == 0 */
|
#endif /* WASM_ENABLE_WAMR_COMPILER == 0 */
|
||||||
|
@ -1250,8 +1251,10 @@ 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: failed to link import global (%s, %s)",
|
set_error_buf_v(error_buf, error_buf_size,
|
||||||
|
"warning: failed to link import global (%s, %s)",
|
||||||
global->module_name, global->field_name);
|
global->module_name, global->field_name);
|
||||||
|
return false;
|
||||||
#else
|
#else
|
||||||
/* do nothing to avoid confused message */
|
/* do nothing to avoid confused message */
|
||||||
#endif /* WASM_ENABLE_WAMR_COMPILER == 0 */
|
#endif /* WASM_ENABLE_WAMR_COMPILER == 0 */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user