From ac4032949aef40d003f027bc10bcd15e44facb3e Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 14 Oct 2024 10:31:39 +0800 Subject: [PATCH 1/6] Fix some warnings and typos --- ATTRIBUTIONS.md | 2 +- core/iwasm/aot/aot_runtime.c | 11 ++++++++++- core/iwasm/compilation/aot_emit_control.c | 2 +- core/iwasm/compilation/aot_emit_function.c | 2 +- core/iwasm/compilation/aot_emit_table.c | 12 +++++++++--- core/iwasm/include/wasm_export.h | 4 ++-- samples/multi-thread/wasm-apps/CMakeLists.txt | 4 ++-- samples/spawn-thread/wasm-apps/CMakeLists.txt | 2 +- tests/wamr-test-suites/test_wamr.sh | 2 +- 9 files changed, 28 insertions(+), 13 deletions(-) diff --git a/ATTRIBUTIONS.md b/ATTRIBUTIONS.md index cba0e5c4b0..ce0d4f8526 100644 --- a/ATTRIBUTIONS.md +++ b/ATTRIBUTIONS.md @@ -60,7 +60,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the ### llvm -[LICENSE](./LICENCE.txt) +[LICENSE](./LICENSE) ### wasm-c-api diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index ebef544106..3e9d2cb491 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1476,7 +1476,16 @@ create_exports(AOTModuleInstance *module_inst, AOTModule *module, } #if WASM_ENABLE_MULTI_MEMORY == 0 - bh_assert(module_inst->export_memory_count <= 1); + if (module_inst->export_memory_count) { + /* There may be multiple export memories but they must + point to the first memory */ + bh_assert(module_inst->memory_count == 1); + for (i = 0; i < module->export_count; i++) { + if (exports[i].kind == EXPORT_KIND_MEMORY) { + bh_assert(exports[i].index == 0); + } + } + } #else if (module_inst->export_memory_count) { module_inst->export_memories = export_memories_instantiate( diff --git a/core/iwasm/compilation/aot_emit_control.c b/core/iwasm/compilation/aot_emit_control.c index 945f63952b..1c50fe75f6 100644 --- a/core/iwasm/compilation/aot_emit_control.c +++ b/core/iwasm/compilation/aot_emit_control.c @@ -912,7 +912,7 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, aot_set_last_error("llvm build LOAD failed"); return false; } - /* Set terminate_flags memory accecc to volatile, so that the value + /* Set terminate_flags memory access to volatile, so that the value will always be loaded from memory rather than register */ LLVMSetVolatile(terminate_flags, true); diff --git a/core/iwasm/compilation/aot_emit_function.c b/core/iwasm/compilation/aot_emit_function.c index 167acc62f2..49b1ac1cb4 100644 --- a/core/iwasm/compilation/aot_emit_function.c +++ b/core/iwasm/compilation/aot_emit_function.c @@ -2090,7 +2090,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef *param_values = NULL, *value_rets = NULL; LLVMValueRef *result_phis = NULL, value_ret, import_func_count; #if WASM_ENABLE_MEMORY64 != 0 - LLVMValueRef u32_max, u32_cmp_result; + LLVMValueRef u32_max, u32_cmp_result = NULL; #endif LLVMTypeRef *param_types = NULL, ret_type; LLVMTypeRef llvm_func_type, llvm_func_ptr_type; diff --git a/core/iwasm/compilation/aot_emit_table.c b/core/iwasm/compilation/aot_emit_table.c index d65d2f4132..e9c3b143e1 100644 --- a/core/iwasm/compilation/aot_emit_table.c +++ b/core/iwasm/compilation/aot_emit_table.c @@ -10,6 +10,8 @@ #include "aot_emit_gc.h" #endif +#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 +#if WASM_ENABLE_MEMORY64 != 0 static bool zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name) { @@ -23,6 +25,7 @@ zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name) } return true; } +#endif /* check whether a table64 elem idx is greater than UINT32_MAX, if so, throw * exception, otherwise trunc it to uint32 */ @@ -30,10 +33,10 @@ static bool check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef *elem_idx, uint32 tbl_idx) { +#if WASM_ENABLE_MEMORY64 != 0 LLVMValueRef u32_max, u32_cmp_result; LLVMBasicBlockRef check_elem_idx_succ; -#if WASM_ENABLE_MEMORY64 != 0 if (!IS_TABLE64(tbl_idx)) { return true; } @@ -69,12 +72,15 @@ check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS, true, u32_cmp_result, check_elem_idx_succ))) goto fail; -#endif return true; fail: return false; +#else + return false; +#endif } +#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ uint64 get_tbl_inst_offset(const AOTCompContext *comp_ctx, @@ -738,4 +744,4 @@ aot_compile_op_table_fill(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } -#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ +#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index c9037b3cc1..add0b16a44 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1159,8 +1159,8 @@ wasm_application_execute_main(wasm_module_inst_t module_inst, int32_t argc, char *argv[]); /** - * Find the specified function in argv[0] from a WASM module instance - * and execute that function. + * Find the specified function from a WASM module instance and execute + * that function. * * @param module_inst the WASM module instance * @param name the name of the function to execute. diff --git a/samples/multi-thread/wasm-apps/CMakeLists.txt b/samples/multi-thread/wasm-apps/CMakeLists.txt index d7352e4274..f424143942 100644 --- a/samples/multi-thread/wasm-apps/CMakeLists.txt +++ b/samples/multi-thread/wasm-apps/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8...3.18) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) @@ -43,4 +43,4 @@ add_executable(main_thread_exception.wasm main_thread_exception.c) target_link_libraries(main_thread_exception.wasm) add_executable(main_global_atomic.wasm main_global_atomic.c) -target_link_libraries(main_global_atomic.wasm) \ No newline at end of file +target_link_libraries(main_global_atomic.wasm) diff --git a/samples/spawn-thread/wasm-apps/CMakeLists.txt b/samples/spawn-thread/wasm-apps/CMakeLists.txt index 0996d5841d..d371bd77eb 100644 --- a/samples/spawn-thread/wasm-apps/CMakeLists.txt +++ b/samples/spawn-thread/wasm-apps/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8...3.18) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 4893bb65dd..70a8b687cb 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -502,7 +502,7 @@ function spec_test() # Reset to commit: "Merge remote-tracking branch 'upstream/main' into merge2" git reset --hard 48e69f394869c55b7bbe14ac963c09f4605490b6 git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast test/core/data.wast - # Patch table64 extension + # Patch table64 extension git checkout 940398cd4823522a9b36bec4984be4b153dedb81 -- test/core/call_indirect.wast test/core/table.wast test/core/table_copy.wast test/core/table_copy_mixed.wast test/core/table_fill.wast test/core/table_get.wast test/core/table_grow.wast test/core/table_init.wast test/core/table_set.wast test/core/table_size.wast git apply ../../spec-test-script/memory64_ignore_cases.patch || exit 1 elif [[ ${ENABLE_MULTI_MEMORY} == 1 ]]; then From 69664507716ff753b69a748e16513d0748b54002 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 14 Oct 2024 11:03:24 +0800 Subject: [PATCH 2/6] fix warnings on windows --- core/iwasm/common/wasm_runtime_common.c | 3 ++- core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c | 9 +++++---- .../libc-wasi/sandboxed-system-primitives/src/posix.c | 2 +- core/shared/platform/windows/win_clock.c | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 453cf9e3c8..5a91a01f56 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3592,7 +3592,8 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, char mapping_copy_buf[256]; char *mapping_copy = mapping_copy_buf; char *map_mapped = NULL, *map_host = NULL; - const unsigned long max_len = strlen(map_dir_list[i]) * 2 + 3; + const unsigned long max_len = + (unsigned long)strlen(map_dir_list[i]) * 2 + 3; /* Allocation limit for runtime environments with reduced stack size */ if (max_len > 256) { diff --git a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c index aef8f17035..6d057a6a18 100644 --- a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c +++ b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c @@ -1022,8 +1022,8 @@ execute_interruptible_poll_oneoff( uint32 i; const __wasi_timestamp_t timeout = get_timeout_for_poll_oneoff( - in, nsubscriptions), - time_quant = 1e9; + in, (uint32)nsubscriptions), + time_quant = (__wasi_timestamp_t)1e9; const uint64 size_to_copy = nsubscriptions * (uint64)sizeof(wasi_subscription_t); __wasi_subscription_t *in_copy = NULL; @@ -1034,12 +1034,13 @@ execute_interruptible_poll_oneoff( return __WASI_ENOMEM; } - bh_memcpy_s(in_copy, size_to_copy, in, size_to_copy); + bh_memcpy_s(in_copy, (uint32)size_to_copy, in, (uint32)size_to_copy); while (timeout == (__wasi_timestamp_t)-1 || elapsed <= timeout) { /* update timeout for clock subscription events */ update_clock_subscription_data( - in_copy, nsubscriptions, min_uint64(time_quant, timeout - elapsed)); + in_copy, (uint32)nsubscriptions, + min_uint64(time_quant, timeout - elapsed)); err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out, nsubscriptions, nevents); elapsed += time_quant; diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index a313b9be54..d26c460fed 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -3130,7 +3130,7 @@ compare_address(const struct addr_pool *addr_pool_entry, } addr_size = 16; } - max_addr_mask = addr_size * 8; + max_addr_mask = (uint8)(addr_size * 8); /* IPv4 0.0.0.0 or IPv6 :: means any address */ if (basebuf[0] == 0 && !memcmp(basebuf, basebuf + 1, addr_size - 1)) { diff --git a/core/shared/platform/windows/win_clock.c b/core/shared/platform/windows/win_clock.c index 826004f7c0..ec0bc85664 100644 --- a/core/shared/platform/windows/win_clock.c +++ b/core/shared/platform/windows/win_clock.c @@ -58,7 +58,7 @@ os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution) case __WASI_CLOCK_PROCESS_CPUTIME_ID: case __WASI_CLOCK_THREAD_CPUTIME_ID: { -#if WINAPI_PARTITION_DESKTOP +#if WINAPI_PARTITION_DESKTOP && WASM_ENABLE_WAMR_COMPILER == 0 ULONG maximum_time; ULONG minimum_time; ULONG current_time; From 7b27d2c2e35c93644ef5c27f4a55ddbfdf610c14 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 14 Oct 2024 11:37:51 +0800 Subject: [PATCH 3/6] address CI error --- core/iwasm/compilation/aot_emit_table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/compilation/aot_emit_table.c b/core/iwasm/compilation/aot_emit_table.c index e9c3b143e1..e8dae410bd 100644 --- a/core/iwasm/compilation/aot_emit_table.c +++ b/core/iwasm/compilation/aot_emit_table.c @@ -77,7 +77,7 @@ check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, fail: return false; #else - return false; + return true; #endif } #endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ From cb0286ca74d54951fce8684561cade5ac0d3f7a7 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 14 Oct 2024 15:42:14 +0800 Subject: [PATCH 4/6] remove unused binarydump binary and aot file --- tests/unit/runtime-common/wasm-apps/main.aot | Bin 1164 -> 0 bytes tests/unit/wasm-vm/wasm-apps/binarydump | Bin 13448 -> 0 bytes tests/unit/wasm-vm/wasm-apps/build.sh | 11 +++++++++++ 3 files changed, 11 insertions(+) delete mode 100644 tests/unit/runtime-common/wasm-apps/main.aot delete mode 100755 tests/unit/wasm-vm/wasm-apps/binarydump diff --git a/tests/unit/runtime-common/wasm-apps/main.aot b/tests/unit/runtime-common/wasm-apps/main.aot deleted file mode 100644 index 79319145a9019df34a340da8f14f9a3f95e5175d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1164 zcmah|L2J}d5Pq%7#&+%IP_WuVSJ;E6(gi8qixAji7E%#x^`P|;H?Q4bHwnpeyDGTF z1!)LMPu~0sp1kN`DYPQqihsbH2v+Dx1%*1_OV(0WH{#)8J(|r2EK@PZl28MwaM^oE>?xPJj#~B+ZGc@0DqaytxyBVyA;*uX0rHJI@ zP>M!vK!1PsIH6L56zg<4DGWY&K*54NQUeM@4-C6?C~c4hFQDL$6OX>%=L>SeYq1;) zLf4Z^1Y?-FPl5?Ws)1k%YWniq*V72{;0{?Zt{c~k1!MlI+1(wpl2zSI{HfXG#SQ_C zC$oFKQ-m@rZwlS#aN-|UvOLopA-`7HE<9Q%$4VZI)soBS&DbjGwd83VrSW5Qcw5!- zgkZ06u2%f5hq2{%bMg022-lLF8CO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#G+7X}@#IdPJCM)_Z4o&%d z>X;NAj?#mnPJJ=Iq0TnSZiu$4!~w2SZE-fM6w-}o*bK{~Tn>@r?AM}nk97cS5fGs` z&v-e-)R1-7OCAd=Rgg!<93UM7 zNwrdU;y_y|r0e~ejEvMetVYM;96Co&>D_Wxx5dMm45qYo0?whQV@%Y9p}|tOLdj4u zZ)R-R4EKYYX^Rf28uo>abc%VgcWQY3t-(e!JSe%rMAqA%jp5{GEXusZ4TUp9%o`m` zz@J6Uv?al|9_{6oFgj#uBOWFLSxd!D<`v2EqUs$?f;Ej%Tq-p?N_9D*lxMU0i2NmUW>*htib&+?#kN%>)TJN;T zK-Ib&Dxx^^_Z(1K6RY;sy6CpF=ayOVJAl$t^m)i>jjedKep-H z>O^z++3nT(?vk`u@7>C#URD(SEr-2Y2VRsPI#j&M-pT*I!(P3=T$1)*R*7@8tNi_u z!(Oc`_s9=R>U)aPm&2-9_Gi*wjh}iy^GW*=nw+-cjQ=&rD1XXcowrx#@ae39y*S&y z3ZdOzt!HcK;5JH#gtp>r|0ZM}{8X6gyO}zd@6>nl@4&XsX0O)A8y^OU;?#HY--8Z? zsM=TSX#NT9zYklQYRX=%x7Gifp!EP1IUS4fsQGsRGJE@KUB0kIm=*OcZm~bAAOGR7 zFRtIYWpQ2^N~-J>T>x%xU#&OJbIU-*Db1I}a}NUYrTVYli!X4?LbYRYR$Ho0ln(h( z`%QKbb!D&C$4X4PR1~FYrrH()dHI`1tqPsduonj_{HVEa*PG!Mr|x5#4!iMF{ZY?9 Sxw;vk- diff --git a/tests/unit/wasm-vm/wasm-apps/build.sh b/tests/unit/wasm-vm/wasm-apps/build.sh index dbf062ae7a..28496ff2f2 100755 --- a/tests/unit/wasm-vm/wasm-apps/build.sh +++ b/tests/unit/wasm-vm/wasm-apps/build.sh @@ -1,6 +1,17 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +readonly CURR_DIR=$PWD +readonly BINARYDUMP_DIR=$PWD/../../../../test-tools/binarydump-tool + +# build binarydump +cd $BINARYDUMP_DIR +mkdir -p build && cd build +cmake .. && make -j +cp -a binarydump $CURR_DIR + +cd $CURR_DIR + ## build app1 /opt/wasi-sdk/bin/clang -O3 \ -z stack-size=4096 -Wl,--initial-memory=65536 \ From 25fae5d1d88a4b5b4b208acc30447082e5055727 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 14 Oct 2024 16:06:47 +0800 Subject: [PATCH 5/6] fix warning in aot_runtime.c --- core/iwasm/aot/aot_runtime.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 3e9d2cb491..6414425a10 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -134,6 +134,7 @@ is_frame_per_function(WASMExecEnv *exec_env) return module->feature_flags & WASM_FEATURE_FRAME_PER_FUNCTION; } +#if WASM_ENABLE_DUMP_CALL_STACK != 0 static bool is_frame_func_idx_disabled(WASMExecEnv *exec_env) { @@ -142,6 +143,7 @@ is_frame_func_idx_disabled(WASMExecEnv *exec_env) return module->feature_flags & WASM_FEATURE_FRAME_NO_FUNC_IDX; } +#endif static void * get_top_frame(WASMExecEnv *exec_env) From 1840d7a0d05e7bf29595792fa4a0c6c344fd1e21 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 15 Oct 2024 09:39:54 +0800 Subject: [PATCH 6/6] add checks for aot exports, update minimum version of cmake --- core/iwasm/aot/aot_loader.c | 60 ++++++++++++++++--- core/iwasm/aot/aot_runtime.c | 13 +--- samples/multi-thread/wasm-apps/CMakeLists.txt | 2 +- samples/spawn-thread/wasm-apps/CMakeLists.txt | 2 +- 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 1a4a6d1e10..df06e87069 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -2760,7 +2760,7 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, const uint8 *buf = *p_buf; AOTExport *exports; uint64 size; - uint32 i; + uint32 i, j; /* Allocate memory */ size = sizeof(AOTExport) * (uint64)module->export_count; @@ -2774,14 +2774,60 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, read_uint32(buf, buf_end, exports[i].index); read_uint8(buf, buf_end, exports[i].kind); read_string(buf, buf_end, exports[i].name); -#if 0 /* TODO: check kind and index */ - if (export_funcs[i].index >= - module->func_count + module->import_func_count) { - set_error_buf(error_buf, error_buf_size, - "function index is out of range"); - return false; + + for (j = 0; j < i; j++) { + if (!strcmp(exports[i].name, exports[j].name)) { + set_error_buf(error_buf, error_buf_size, + "duplicate export name"); + return false; + } } + + /* Check export kind and index */ + switch (exports[i].kind) { + case EXPORT_KIND_FUNC: + if (exports[i].index + >= module->import_func_count + module->func_count) { + set_error_buf(error_buf, error_buf_size, + "unknown function"); + return false; + } + break; + case EXPORT_KIND_TABLE: + if (exports[i].index + >= module->import_table_count + module->table_count) { + set_error_buf(error_buf, error_buf_size, "unknown table"); + return false; + } + break; + case EXPORT_KIND_MEMORY: + if (exports[i].index + >= module->import_memory_count + module->memory_count) { + set_error_buf(error_buf, error_buf_size, "unknown memory"); + return false; + } + break; + case EXPORT_KIND_GLOBAL: + if (exports[i].index + >= module->import_global_count + module->global_count) { + set_error_buf(error_buf, error_buf_size, "unknown global"); + return false; + } + break; +#if WASM_ENABLE_TAGS != 0 + /* TODO + case EXPORT_KIND_TAG: + if (index >= module->import_tag_count + module->tag_count) { + set_error_buf(error_buf, error_buf_size, "unknown tag"); + return false; + } + break; + */ #endif + default: + set_error_buf(error_buf, error_buf_size, "invalid export kind"); + return false; + } } *p_buf = buf; diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 6414425a10..17d542d0cd 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1477,18 +1477,7 @@ create_exports(AOTModuleInstance *module_inst, AOTModule *module, } } -#if WASM_ENABLE_MULTI_MEMORY == 0 - if (module_inst->export_memory_count) { - /* There may be multiple export memories but they must - point to the first memory */ - bh_assert(module_inst->memory_count == 1); - for (i = 0; i < module->export_count; i++) { - if (exports[i].kind == EXPORT_KIND_MEMORY) { - bh_assert(exports[i].index == 0); - } - } - } -#else +#if WASM_ENABLE_MULTI_MEMORY != 0 if (module_inst->export_memory_count) { module_inst->export_memories = export_memories_instantiate( module, module_inst, module_inst->export_memory_count, error_buf, diff --git a/samples/multi-thread/wasm-apps/CMakeLists.txt b/samples/multi-thread/wasm-apps/CMakeLists.txt index f424143942..5442398f94 100644 --- a/samples/multi-thread/wasm-apps/CMakeLists.txt +++ b/samples/multi-thread/wasm-apps/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 2.8...3.18) +cmake_minimum_required(VERSION 3.14) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) diff --git a/samples/spawn-thread/wasm-apps/CMakeLists.txt b/samples/spawn-thread/wasm-apps/CMakeLists.txt index d371bd77eb..df21b4485c 100644 --- a/samples/spawn-thread/wasm-apps/CMakeLists.txt +++ b/samples/spawn-thread/wasm-apps/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 2.8...3.18) +cmake_minimum_required(VERSION 3.14) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)