diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index c2586b7a27..416e480223 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -3710,8 +3710,8 @@ aot_array_init_with_data(AOTModuleInstance *module_inst, uint32 seg_index, uint64 total_size = (int64)elem_size * array_len; aot_module = (AOTModule *)module_inst->module; - seg_len = aot_module->array_init_data_list[seg_index]->byte_count; - data = aot_module->array_init_data_list[seg_index]->bytes; + seg_len = aot_module->mem_init_data_list[seg_index]->byte_count; + data = aot_module->mem_init_data_list[seg_index]->bytes; if (data_seg_offset >= seg_len || total_size > seg_len - data_seg_offset) { aot_set_exception(module_inst, "out of bounds memory access"); diff --git a/core/iwasm/aot/aot_runtime.h b/core/iwasm/aot/aot_runtime.h index 6b0c3ec6ad..ddf37213d9 100644 --- a/core/iwasm/aot/aot_runtime.h +++ b/core/iwasm/aot/aot_runtime.h @@ -262,10 +262,6 @@ typedef struct AOTModule { HashMap *ref_type_set; struct WASMRttType **rtt_types; korp_mutex rtt_type_lock; - - /* array init data info */ - uint32 array_init_data_count; - AOTArrayInitData **array_init_data_list; #endif #if WASM_ENABLE_DEBUG_AOT != 0 diff --git a/core/iwasm/compilation/aot.h b/core/iwasm/compilation/aot.h index 13b3e26716..d54508e6dc 100644 --- a/core/iwasm/compilation/aot.h +++ b/core/iwasm/compilation/aot.h @@ -116,20 +116,6 @@ typedef struct AOTMemInitData { uint8 bytes[1]; } AOTMemInitData; -/* TODO: reuse mem init data or this new data structure? */ - -/** - * A segment of array init data - */ -typedef struct AOTArrayInitData { - /* Start address of init data */ - AOTInitExpr offset; - /* Byte count */ - uint32 byte_count; - /* Byte array */ - uint8 bytes[1]; -} AOTArrayInitData; - /** * Import table */ diff --git a/core/iwasm/compilation/aot_emit_gc.c b/core/iwasm/compilation/aot_emit_gc.c index 4f3d4e9a2f..cf3181ee54 100644 --- a/core/iwasm/compilation/aot_emit_gc.c +++ b/core/iwasm/compilation/aot_emit_gc.c @@ -334,19 +334,6 @@ aot_struct_obj_set_field(AOTCompContext *comp_ctx, LLVMValueRef struct_obj, goto fail; } - /* Ensure correct alignment for some platforms when field_size == 8 */ -#if !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64) \ - && !defined(BUILD_TARGET_X86_32) - if (field_size == 8) { - if (!(field_data_ptr = - LLVMBuildBitCast(comp_ctx->builder, field_data_ptr, - INT32_PTR_TYPE, "field_value_ptr_align"))) { - aot_set_last_error("llvm build bitcast failed."); - goto fail; - } - } -#endif - /* Cast to the field data type ptr */ if (!(field_data_ptr = LLVMBuildBitCast(comp_ctx->builder, field_data_ptr, LLVMPointerType(field_data_type, 0), @@ -401,19 +388,6 @@ aot_struct_obj_get_field(AOTCompContext *comp_ctx, LLVMValueRef struct_obj, break; } - /* Ensure correct alignment for some platforms when field_size == 8 */ -#if !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64) \ - && !defined(BUILD_TARGET_X86_32) - if (field_size == 8) { - if (!(field_data_ptr = - LLVMBuildBitCast(comp_ctx->builder, field_data_ptr, - INT32_PTR_TYPE, "field_value_ptr_align"))) { - aot_set_last_error("llvm build bitcast failed."); - goto fail; - } - } -#endif - if (!(field_data_ptr = LLVMBuildBitCast(comp_ctx->builder, field_data_ptr, LLVMPointerType(field_data_type, 0), "field_value_ptr"))) { @@ -862,7 +836,10 @@ aot_call_aot_array_init_with_data( param_types[5] = I32_TYPE; ret_type = INT8_TYPE; - GET_AOT_FUNCTION(aot_array_init_with_data, 6); + if (comp_ctx->is_jit_mode) + GET_AOT_FUNCTION(llvm_array_init_with_data, 6); + else + GET_AOT_FUNCTION(aot_array_init_with_data, 6); /* Call function aot_array_init_with_data() */ param_values[0] = func_ctx->aot_inst; diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 49019da46f..ee61517e76 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -3706,6 +3706,31 @@ llvm_jit_rtt_type_new(WASMModuleInstance *module_inst, uint32 type_index) rtt_type_count, rtt_type_lock); } +bool +llvm_array_init_with_data(WASMModuleInstance *module_inst, uint32 seg_index, + uint32 data_seg_offset, WASMArrayObjectRef array_obj, + uint32 elem_size, uint32 array_len) +{ + WASMModule *wasm_module = module_inst->module; + WASMDataSeg *data_seg; + uint8 *array_elem_base; + uint64 total_size; + + data_seg = wasm_module->data_segments[seg_index]; + total_size = (int64)elem_size * array_len; + + if (data_seg_offset >= data_seg->data_length + || total_size > data_seg->data_length - data_seg_offset) { + wasm_set_exception(module_inst, "out of bounds memory access"); + return false; + } + + array_elem_base = (uint8 *)wasm_array_obj_first_elem_addr(array_obj); + bh_memcpy_s(array_elem_base, (uint32)total_size, + data_seg->data + data_seg_offset, (uint32)total_size); + + return true; +} #endif /* end of WASM_ENABLE_GC != 0 */ #endif /* end of WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 */ diff --git a/core/iwasm/interpreter/wasm_runtime.h b/core/iwasm/interpreter/wasm_runtime.h index d78419ba34..d60af7b213 100644 --- a/core/iwasm/interpreter/wasm_runtime.h +++ b/core/iwasm/interpreter/wasm_runtime.h @@ -718,6 +718,11 @@ llvm_jit_obj_is_instance_of(WASMModuleInstance *module_inst, WASMRttTypeRef llvm_jit_rtt_type_new(WASMModuleInstance *module_inst, uint32 type_index); + +bool +llvm_array_init_with_data(WASMModuleInstance *module_inst, uint32 seg_index, + uint32 data_seg_offset, WASMArrayObjectRef array_obj, + uint32 elem_size, uint32 array_len); #endif #endif /* end of WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 */