Fix some compile warnings and typos (#3854)

- Clear some compile warnings
- Fix some typos
- Fix llvm LICENSE link error
- Remove unused aot file and binarydump bin
- Add checks when loading AOT exports
This commit is contained in:
Wenyong Huang
2024-10-15 16:04:58 +08:00
committed by GitHub
parent b038f2721b
commit 327374cfee
17 changed files with 94 additions and 29 deletions

View File

@ -60,7 +60,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
### llvm ### llvm
[LICENSE](./LICENCE.txt) [LICENSE](./LICENSE)
### wasm-c-api ### wasm-c-api

View File

@ -2760,7 +2760,7 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
const uint8 *buf = *p_buf; const uint8 *buf = *p_buf;
AOTExport *exports; AOTExport *exports;
uint64 size; uint64 size;
uint32 i; uint32 i, j;
/* Allocate memory */ /* Allocate memory */
size = sizeof(AOTExport) * (uint64)module->export_count; 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_uint32(buf, buf_end, exports[i].index);
read_uint8(buf, buf_end, exports[i].kind); read_uint8(buf, buf_end, exports[i].kind);
read_string(buf, buf_end, exports[i].name); read_string(buf, buf_end, exports[i].name);
#if 0 /* TODO: check kind and index */
if (export_funcs[i].index >= for (j = 0; j < i; j++) {
module->func_count + module->import_func_count) { if (!strcmp(exports[i].name, exports[j].name)) {
set_error_buf(error_buf, error_buf_size, set_error_buf(error_buf, error_buf_size,
"function index is out of range"); "duplicate export name");
return false; 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 #endif
default:
set_error_buf(error_buf, error_buf_size, "invalid export kind");
return false;
}
} }
*p_buf = buf; *p_buf = buf;

View File

@ -137,6 +137,7 @@ is_frame_per_function(WASMExecEnv *exec_env)
return module->feature_flags & WASM_FEATURE_FRAME_PER_FUNCTION; return module->feature_flags & WASM_FEATURE_FRAME_PER_FUNCTION;
} }
#if WASM_ENABLE_DUMP_CALL_STACK != 0
static bool static bool
is_frame_func_idx_disabled(WASMExecEnv *exec_env) is_frame_func_idx_disabled(WASMExecEnv *exec_env)
{ {
@ -145,6 +146,7 @@ is_frame_func_idx_disabled(WASMExecEnv *exec_env)
return module->feature_flags & WASM_FEATURE_FRAME_NO_FUNC_IDX; return module->feature_flags & WASM_FEATURE_FRAME_NO_FUNC_IDX;
} }
#endif
static void * static void *
get_top_frame(WASMExecEnv *exec_env) get_top_frame(WASMExecEnv *exec_env)
@ -1478,9 +1480,7 @@ create_exports(AOTModuleInstance *module_inst, AOTModule *module,
} }
} }
#if WASM_ENABLE_MULTI_MEMORY == 0 #if WASM_ENABLE_MULTI_MEMORY != 0
bh_assert(module_inst->export_memory_count <= 1);
#else
if (module_inst->export_memory_count) { if (module_inst->export_memory_count) {
module_inst->export_memories = export_memories_instantiate( module_inst->export_memories = export_memories_instantiate(
module, module_inst, module_inst->export_memory_count, error_buf, module, module_inst, module_inst->export_memory_count, error_buf,

View File

@ -3610,7 +3610,8 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
char mapping_copy_buf[256]; char mapping_copy_buf[256];
char *mapping_copy = mapping_copy_buf; char *mapping_copy = mapping_copy_buf;
char *map_mapped = NULL, *map_host = NULL; 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 */ /* Allocation limit for runtime environments with reduced stack size */
if (max_len > 256) { if (max_len > 256) {

View File

@ -912,7 +912,7 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
aot_set_last_error("llvm build LOAD failed"); aot_set_last_error("llvm build LOAD failed");
return false; 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 */ will always be loaded from memory rather than register */
LLVMSetVolatile(terminate_flags, true); LLVMSetVolatile(terminate_flags, true);

View File

@ -2090,7 +2090,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef *param_values = NULL, *value_rets = NULL; LLVMValueRef *param_values = NULL, *value_rets = NULL;
LLVMValueRef *result_phis = NULL, value_ret, import_func_count; LLVMValueRef *result_phis = NULL, value_ret, import_func_count;
#if WASM_ENABLE_MEMORY64 != 0 #if WASM_ENABLE_MEMORY64 != 0
LLVMValueRef u32_max, u32_cmp_result; LLVMValueRef u32_max, u32_cmp_result = NULL;
#endif #endif
LLVMTypeRef *param_types = NULL, ret_type; LLVMTypeRef *param_types = NULL, ret_type;
LLVMTypeRef llvm_func_type, llvm_func_ptr_type; LLVMTypeRef llvm_func_type, llvm_func_ptr_type;

View File

@ -10,6 +10,8 @@
#include "aot_emit_gc.h" #include "aot_emit_gc.h"
#endif #endif
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
#if WASM_ENABLE_MEMORY64 != 0
static bool static bool
zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name) 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; return true;
} }
#endif
/* check whether a table64 elem idx is greater than UINT32_MAX, if so, throw /* check whether a table64 elem idx is greater than UINT32_MAX, if so, throw
* exception, otherwise trunc it to uint32 */ * exception, otherwise trunc it to uint32 */
@ -30,10 +33,10 @@ static bool
check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef *elem_idx, uint32 tbl_idx) LLVMValueRef *elem_idx, uint32 tbl_idx)
{ {
#if WASM_ENABLE_MEMORY64 != 0
LLVMValueRef u32_max, u32_cmp_result; LLVMValueRef u32_max, u32_cmp_result;
LLVMBasicBlockRef check_elem_idx_succ; LLVMBasicBlockRef check_elem_idx_succ;
#if WASM_ENABLE_MEMORY64 != 0
if (!IS_TABLE64(tbl_idx)) { if (!IS_TABLE64(tbl_idx)) {
return true; 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, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS, true,
u32_cmp_result, check_elem_idx_succ))) u32_cmp_result, check_elem_idx_succ)))
goto fail; goto fail;
#endif
return true; return true;
fail: fail:
return false; return false;
#else
return true;
#endif
} }
#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */
uint64 uint64
get_tbl_inst_offset(const AOTCompContext *comp_ctx, get_tbl_inst_offset(const AOTCompContext *comp_ctx,

View File

@ -1166,8 +1166,8 @@ wasm_application_execute_main(wasm_module_inst_t module_inst, int32_t argc,
char *argv[]); char *argv[]);
/** /**
* Find the specified function in argv[0] from a WASM module instance * Find the specified function from a WASM module instance and execute
* and execute that function. * that function.
* *
* @param module_inst the WASM module instance * @param module_inst the WASM module instance
* @param name the name of the function to execute. * @param name the name of the function to execute.

View File

@ -1022,8 +1022,8 @@ execute_interruptible_poll_oneoff(
uint32 i; uint32 i;
const __wasi_timestamp_t timeout = get_timeout_for_poll_oneoff( const __wasi_timestamp_t timeout = get_timeout_for_poll_oneoff(
in, nsubscriptions), in, (uint32)nsubscriptions),
time_quant = 1e9; time_quant = (__wasi_timestamp_t)1e9;
const uint64 size_to_copy = const uint64 size_to_copy =
nsubscriptions * (uint64)sizeof(wasi_subscription_t); nsubscriptions * (uint64)sizeof(wasi_subscription_t);
__wasi_subscription_t *in_copy = NULL; __wasi_subscription_t *in_copy = NULL;
@ -1034,12 +1034,13 @@ execute_interruptible_poll_oneoff(
return __WASI_ENOMEM; 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) { while (timeout == (__wasi_timestamp_t)-1 || elapsed <= timeout) {
/* update timeout for clock subscription events */ /* update timeout for clock subscription events */
update_clock_subscription_data( 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, err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out,
nsubscriptions, nevents); nsubscriptions, nevents);
elapsed += time_quant; elapsed += time_quant;

View File

@ -3130,7 +3130,7 @@ compare_address(const struct addr_pool *addr_pool_entry,
} }
addr_size = 16; 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 */ /* IPv4 0.0.0.0 or IPv6 :: means any address */
if (basebuf[0] == 0 && !memcmp(basebuf, basebuf + 1, addr_size - 1)) { if (basebuf[0] == 0 && !memcmp(basebuf, basebuf + 1, addr_size - 1)) {

View File

@ -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_PROCESS_CPUTIME_ID:
case __WASI_CLOCK_THREAD_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 maximum_time;
ULONG minimum_time; ULONG minimum_time;
ULONG current_time; ULONG current_time;

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved. # Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 3.14)
project(wasm-apps) project(wasm-apps)
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved. # Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 3.14)
project(wasm-apps) project(wasm-apps)
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)

View File

@ -1,6 +1,17 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved. # Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # 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 ## build app1
/opt/wasi-sdk/bin/clang -O3 \ /opt/wasi-sdk/bin/clang -O3 \
-z stack-size=4096 -Wl,--initial-memory=65536 \ -z stack-size=4096 -Wl,--initial-memory=65536 \