diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 77cb1e4946..4391983146 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -506,6 +506,14 @@ check_feature_flags(char *error_buf, uint32 error_buf_size, } #endif +#if WASM_ENABLE_MULTI_MODULE == 0 + if (feature_flags & WASM_FEATURE_MULTI_MODULE) { + set_error_buf(error_buf, error_buf_size, + "multi-module is not enabled in this build"); + return false; + } +#endif + return true; } @@ -529,7 +537,7 @@ load_target_info_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module, char *error_buf, uint32 error_buf_size) { - AOTTargetInfo target_info; + AOTTargetInfo target_info = { 0 }; const uint8 *p = buf, *p_end = buf_end; bool is_target_little_endian, is_target_64_bit; diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 805a2c3039..9ac195f7f4 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -791,8 +791,8 @@ tables_instantiate(AOTModuleInstance *module_inst, AOTModule *module, == INIT_EXPR_TYPE_REFNULL_CONST); #else bh_assert(table_seg->offset.init_expr_type - == (tbl_inst->is_table64 ? INIT_EXPR_TYPE_I64_CONST - : INIT_EXPR_TYPE_I32_CONST) + == (table->is_table64 ? INIT_EXPR_TYPE_I64_CONST + : INIT_EXPR_TYPE_I32_CONST) || table_seg->offset.init_expr_type == INIT_EXPR_TYPE_GET_GLOBAL); #endif diff --git a/core/iwasm/aot/aot_runtime.h b/core/iwasm/aot/aot_runtime.h index dbefbda901..0ac3838a0b 100644 --- a/core/iwasm/aot/aot_runtime.h +++ b/core/iwasm/aot/aot_runtime.h @@ -35,6 +35,7 @@ extern "C" { * and not at the beginning of each function call */ #define WASM_FEATURE_FRAME_PER_FUNCTION (1 << 12) #define WASM_FEATURE_FRAME_NO_FUNC_IDX (1 << 13) +#define WASM_FEATURE_MULTI_MODULE (1 << 14) typedef enum AOTSectionType { AOT_SECTION_TYPE_TARGET_INFO = 0, diff --git a/core/iwasm/compilation/aot_emit_aot_file.c b/core/iwasm/compilation/aot_emit_aot_file.c index d2744c4ebb..53a768d092 100644 --- a/core/iwasm/compilation/aot_emit_aot_file.c +++ b/core/iwasm/compilation/aot_emit_aot_file.c @@ -4604,6 +4604,9 @@ aot_obj_data_create(AOTCompContext *comp_ctx) if (!comp_ctx->call_stack_features.func_idx) { obj_data->target_info.feature_flags |= WASM_FEATURE_FRAME_NO_FUNC_IDX; } + if (comp_ctx->enable_multi_module) { + obj_data->target_info.feature_flags |= WASM_FEATURE_MULTI_MODULE; + } bh_print_time("Begin to resolve object file info"); diff --git a/core/iwasm/compilation/aot_emit_table.c b/core/iwasm/compilation/aot_emit_table.c index 773db9361f..c5d0cf6c85 100644 --- a/core/iwasm/compilation/aot_emit_table.c +++ b/core/iwasm/compilation/aot_emit_table.c @@ -96,20 +96,20 @@ get_tbl_inst_offset(const AOTCompContext *comp_ctx, : comp_ctx->comp_data->global_data_size_32bit); uint64 i = 0; -#if WASM_ENABLE_MULTI_MODULE != 0 - AOTImportTable *imp_tbls = comp_ctx->comp_data->import_tables; -#endif while (i < tbl_idx && i < comp_ctx->comp_data->import_table_count) { offset += offsetof(AOTTableInstance, elems); - /* avoid loading from current AOTTableInstance */ -#if WASM_ENABLE_MULTI_MODULE != 0 - offset += (uint64)comp_ctx->pointer_size - * aot_get_tbl_data_slots(&(imp_tbls + i)->table_type, - comp_ctx->is_jit_mode); -#else - /* there is only one pointer for imported elem */ - offset += (uint64)comp_ctx->pointer_size; -#endif + if (comp_ctx->enable_multi_module) { + AOTImportTable *imp_tbls = comp_ctx->comp_data->import_tables; + /* avoid loading from current AOTTableInstance */ + offset += (uint64)comp_ctx->pointer_size + * aot_get_tbl_data_slots(&(imp_tbls + i)->table_type, + comp_ctx->is_jit_mode); + } + else { + /* there is only one pointer for imported elem */ + offset += (uint64)comp_ctx->pointer_size; + } + ++i; } @@ -161,7 +161,7 @@ aot_compile_get_table_elem_base(AOTCompContext *comp_ctx, * for local table, * table_elem_base = (*(uint8*)WASMModuleInstance) + offset * - * if for import table, if WASM_ENABLE_MULTI_MODULE == 0 + * if for import table, if enable_multi_module == true * table_elem_base = (*(uint8*)WASMModuleInstance) + offset * table_elem_base = *(uintptr_t*)(table_elem_base) */ @@ -173,7 +173,10 @@ aot_compile_get_table_elem_base(AOTCompContext *comp_ctx, goto fail; } -#if WASM_ENABLE_MULTI_MODULE == 0 + if (comp_ctx->enable_multi_module) { + return table_elem_base; + } + if (table_index < comp_ctx->comp_data->import_table_count) { table_elem_base = LLVMBuildIntToPtr(comp_ctx->builder, table_elem_base, @@ -199,7 +202,6 @@ aot_compile_get_table_elem_base(AOTCompContext *comp_ctx, goto fail; } } -#endif return table_elem_base; fail: diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 45e97b7425..df5a2eff5a 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -2695,6 +2695,9 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) if (option->enable_shared_heap) comp_ctx->enable_shared_heap = true; + if (option->enable_multi_module) + comp_ctx->enable_multi_module = true; + comp_ctx->opt_level = option->opt_level; comp_ctx->size_level = option->size_level; diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index 0dce988bc9..5a472ae5e0 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -472,6 +472,8 @@ typedef struct AOTCompContext { bool enable_shared_heap; + bool enable_multi_module; + uint32 opt_level; uint32 size_level; diff --git a/core/iwasm/include/aot_comp_option.h b/core/iwasm/include/aot_comp_option.h index a97275d242..ef03cae4b2 100644 --- a/core/iwasm/include/aot_comp_option.h +++ b/core/iwasm/include/aot_comp_option.h @@ -74,6 +74,7 @@ typedef struct AOTCompOption { bool enable_stack_estimation; bool quick_invoke_c_api_import; bool enable_shared_heap; + bool enable_multi_module; char *use_prof_file; uint32_t opt_level; uint32_t size_level; diff --git a/tests/wamr-test-suites/spec-test-script/runtest.py b/tests/wamr-test-suites/spec-test-script/runtest.py index 97820eaad6..72c733d750 100755 --- a/tests/wamr-test-suites/spec-test-script/runtest.py +++ b/tests/wamr-test-suites/spec-test-script/runtest.py @@ -1148,6 +1148,9 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = ' cmd.append("--format=object") elif output == 'ir': cmd.append("--format=llvmir-opt") + + if opts.multi_module: + cmd.append("--enable-multi-module") # disable llvm link time optimization as it might convert # code of tail call into code of dead loop, and stack overflow diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 70a8b687cb..fbcbfe2026 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -829,11 +829,19 @@ function build_wamrc() fi echo "Build wamrc for spec test under aot compile type" + + local EXTRA_COMPILE_FLAGS="" + EXTRA_COMPILE_FLAGS+=" -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}" + + if [[ ${ENABLE_DEBUG_VERSION} == 1 ]]; then + EXTRA_COMPILE_FLAGS+=" -DCMAKE_BUILD_TYPE=Debug" + fi + cd ${WAMR_DIR}/wamr-compiler \ && ./${BUILD_LLVM_SH} \ && if [ -d build ]; then rm -r build/*; else mkdir build; fi \ && cd build \ - && cmake .. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} \ + && cmake ${EXTRA_COMPILE_FLAGS} .. \ && make -j 4 } diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index 3efe344e6a..7af52a2212 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -207,6 +207,8 @@ print_help() #endif printf(" --mllvm=