Fix aot issue in 32-bit platform (#297)

fix aot 32-bit boundary check issue
This commit is contained in:
wenyongh 2020-07-01 12:22:13 +08:00 committed by GitHub
parent 847dccaa34
commit ee3d448eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 13 deletions

View File

@ -215,13 +215,11 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
module_inst->mem_cur_page_count = module->mem_init_page_count; module_inst->mem_cur_page_count = module->mem_init_page_count;
module_inst->mem_max_page_count = module->mem_max_page_count; module_inst->mem_max_page_count = module->mem_max_page_count;
module_inst->mem_bound_check_heap_base = module_inst->heap_base_offset; module_inst->mem_bound_check_heap_base = (int64)module_inst->heap_base_offset;
if (module_inst->memory_data_size > 0) { module_inst->mem_bound_check_1byte = (int64)module_inst->memory_data_size - 1;
module_inst->mem_bound_check_1byte = module_inst->memory_data_size - 1; module_inst->mem_bound_check_2bytes = (int64)module_inst->memory_data_size - 2;
module_inst->mem_bound_check_2bytes = module_inst->memory_data_size - 2; module_inst->mem_bound_check_4bytes = (int64)module_inst->memory_data_size - 4;
module_inst->mem_bound_check_4bytes = module_inst->memory_data_size - 4; module_inst->mem_bound_check_8bytes = (int64)module_inst->memory_data_size - 8;
module_inst->mem_bound_check_8bytes = module_inst->memory_data_size - 8;
}
for (i = 0; i < module->mem_init_data_count; i++) { for (i = 0; i < module->mem_init_data_count; i++) {
data_seg = module->mem_init_data_list[i]; data_seg = module->mem_init_data_list[i];

View File

@ -211,7 +211,7 @@ typedef struct AOTModuleInstance {
uint32 default_wasm_stack_size; uint32 default_wasm_stack_size;
/* reserved */ /* reserved */
uint32 reserved[12]; uint32 reserved[11];
union { union {
uint64 _make_it_8_byte_aligned_; uint64 _make_it_8_byte_aligned_;

View File

@ -144,11 +144,24 @@ handle_next_reachable_block(AOTCompContext *comp_ctx,
block_prev = block->prev; block_prev = block->prev;
block = aot_block_stack_pop(&func_ctx->block_stack); block = aot_block_stack_pop(&func_ctx->block_stack);
if (block->block_type == BLOCK_TYPE_IF if (block->block_type == BLOCK_TYPE_IF) {
&& block->llvm_end_block) { if (block->llvm_else_block
&& !block->skip_wasm_code_else
&& *p_frame_ip <= block->wasm_code_else) {
/* Clear value stack and start to translate else branch */
aot_value_stack_destroy(&block->value_stack);
SET_BUILDER_POS(block->llvm_else_block);
*p_frame_ip = block->wasm_code_else + 1;
/* Push back the block */
aot_block_stack_push(&func_ctx->block_stack, block);
return true;
}
else if (block->llvm_end_block) {
/* Remove unreachable basic block */
LLVMDeleteBasicBlock(block->llvm_end_block); LLVMDeleteBasicBlock(block->llvm_end_block);
block->llvm_end_block = NULL; block->llvm_end_block = NULL;
} }
}
frame_ip = block->wasm_code_end; frame_ip = block->wasm_code_end;
aot_block_destroy(block); aot_block_destroy(block);

View File

@ -111,7 +111,7 @@ check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
&& mem_offset <= mem_data_size - bytes) { && mem_offset <= mem_data_size - bytes) {
/* inside memory space */ /* inside memory space */
offset1 = I32_CONST((uint32)mem_offset); offset1 = I32_CONST((uint32)mem_offset);
CHECK_LLVM_CONST(offset_const); CHECK_LLVM_CONST(offset1);
if (!(maddr = LLVMBuildInBoundsGEP(comp_ctx->builder, mem_base_addr, if (!(maddr = LLVMBuildInBoundsGEP(comp_ctx->builder, mem_base_addr,
&offset1, 1, "maddr"))) { &offset1, 1, "maddr"))) {
aot_set_last_error("llvm build add failed."); aot_set_last_error("llvm build add failed.");