From 28f104036c66361e03b5473aaa98a396ee42319e Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Thu, 22 Jul 2021 19:39:53 +0800 Subject: [PATCH] Fix some compile warnings and update document (#670) And implement clock_gettime wrapper for libc-built. --- core/app-mgr/app-manager/module_wasm_app.c | 2 +- .../libc-builtin/libc_builtin_wrapper.c | 23 +++++++++++++++++++ doc/build_wamr.md | 5 ++-- product-mini/platforms/linux/CMakeLists.txt | 10 ++++---- .../src/platform/zephyr/iwasm_main.c | 6 +++-- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/core/app-mgr/app-manager/module_wasm_app.c b/core/app-mgr/app-manager/module_wasm_app.c index bbd5ad49bd..72e1f5e6f4 100644 --- a/core/app-mgr/app-manager/module_wasm_app.c +++ b/core/app-mgr/app-manager/module_wasm_app.c @@ -1674,7 +1674,7 @@ wasm_set_wasi_root_dir(const char *root_dir) if (!(path = realpath(root_dir, resolved_path))) return false; - strncpy(wasi_root_dir, path, sizeof(wasi_root_dir)); + snprintf(wasi_root_dir, sizeof(wasi_root_dir), "%s", path); return true; } diff --git a/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c b/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c index cb21bac771..6013199917 100644 --- a/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c +++ b/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c @@ -1068,6 +1068,28 @@ __cxa_throw_wrapper(wasm_exec_env_t exec_env, wasm_runtime_set_exception(module_inst, buf); } +struct timespec_app { + int64 tv_sec; + int32 tv_nsec; +}; + +static uint32 +clock_gettime_wrapper(wasm_exec_env_t exec_env, + uint32 clk_id, struct timespec_app *ts_app) +{ + wasm_module_inst_t module_inst = get_module_inst(exec_env); + uint64 time; + + if (!validate_native_addr(ts_app, sizeof(struct timespec_app))) + return (uint32)-1; + + time = os_time_get_boot_microsecond(); + ts_app->tv_sec = time / 1000000; + ts_app->tv_nsec = (time % 1000000) * 1000; + + return (uint32)0; +} + #if WASM_ENABLE_SPEC_TEST != 0 static void print_wrapper(wasm_exec_env_t exec_env) @@ -1167,6 +1189,7 @@ static NativeSymbol native_symbols_libc_builtin[] = { REG_NATIVE_FUNC(__cxa_allocate_exception, "(i)i"), REG_NATIVE_FUNC(__cxa_begin_catch, "(*)"), REG_NATIVE_FUNC(__cxa_throw, "(**i)"), + REG_NATIVE_FUNC(clock_gettime, "(i*)i"), }; #if WASM_ENABLE_SPEC_TEST != 0 diff --git a/doc/build_wamr.md b/doc/build_wamr.md index 72eb1f16a9..b0d418a67a 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -20,7 +20,8 @@ The script `runtime_lib.cmake` defines a number of variables for configuring the - **WAMR_BUILD_PLATFORM**: set the target platform. It can be set to any platform name (folder name) under folder [core/shared/platform](../core/shared/platform). - **WAMR_BUILD_TARGET**: set the target CPU architecture. Current supported targets are: X86_64, X86_32, AARCH64, ARM, THUMB, XTENSA, RISCV64 and MIPS. - - For ARM and THUMB, the format is \\[\]\[_VFP], where \ is the ARM sub-architecture and the "_VFP" suffix means using VFP coprocessor registers s0-s15 (d0-d7) for passing arguments or returning results in standard procedure-call. For AARCH64, the format is\[\], VFP is enabled by default. Both \ and "_VFP" are optional, e.g. AARCH64, AARCH64V8, AARCHV8.1, ARMV7, ARMV7_VFP, THUMBV7, THUMBV7_VFP and so on. + - For ARM and THUMB, the format is \\[\]\[_VFP], where \ is the ARM sub-architecture and the "_VFP" suffix means using VFP coprocessor registers s0-s15 (d0-d7) for passing arguments or returning results in standard procedure-call. Both \ and "_VFP" are optional, e.g. ARMV7, ARMV7_VFP, THUMBV7, THUMBV7_VFP and so on. + - For AARCH64, the format is\[\], VFP is enabled by default. \ is optional, e.g. AARCH64, AARCH64V8, AARCH64V8.1 and so on. - For RISCV64, the format is \[_abi], where "_abi" is optional, currently the supported formats are RISCV64, RISCV64_LP64D and RISCV64_LP64: RISCV64 and RISCV64_LP64D are identical, using [LP64D](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (LP64 with hardware floating-point calling convention for FLEN=64). And RISCV64_LP64 uses [LP64](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (Integer calling-convention only, and hardware floating-point calling convention is not used). - For RISCV32, the format is \[_abi], where "_abi" is optional, currently the supported formats are RISCV32, RISCV32_ILP32D and RISCV32_ILP32: RISCV32 and RISCV32_ILP32D are identical, using [ILP32D](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (ILP32 with hardware floating-point calling convention for FLEN=64). And RISCV32_ILP32 uses [ILP32](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (Integer calling-convention only, and hardware floating-point calling convention is not used). @@ -465,4 +466,4 @@ $ ls ../build_out/ *build_wamr.sh* will generate *linux* compatible libraries ( libiwasm.so and libvmlib.a ) and an executable binary (*iwasm*) and copy *iwasm* to *build_out*. All original generated files are still under -*product-mini/platforms/linux/build*. \ No newline at end of file +*product-mini/platforms/linux/build*. diff --git a/product-mini/platforms/linux/CMakeLists.txt b/product-mini/platforms/linux/CMakeLists.txt index 7471b41c1d..b6d088b895 100644 --- a/product-mini/platforms/linux/CMakeLists.txt +++ b/product-mini/platforms/linux/CMakeLists.txt @@ -94,12 +94,6 @@ if (COLLECT_CODE_COVERAGE EQUAL 1) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") endif () -# UNDEFINED BEHAVIOR -# refer to https://en.cppreference.com/w/cpp/language/ub -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover") -endif() - set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) @@ -114,6 +108,10 @@ if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") endif () + # UNDEFINED BEHAVIOR, refer to https://en.cppreference.com/w/cpp/language/ub + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover") + endif() endif () # The following flags are to enhance security, but it may impact performance, diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c index 391e48e047..e2f4a5c9eb 100644 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c +++ b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c @@ -27,7 +27,8 @@ extern int aee_host_msg_callback(void *msg, uint32_t msg_len); int uart_char_cnt = 0; -static void uart_irq_callback(struct device *dev) +static void uart_irq_callback(const struct device *dev, + void *user_data) { unsigned char ch; @@ -35,9 +36,10 @@ static void uart_irq_callback(struct device *dev) uart_char_cnt++; aee_host_msg_callback(&ch, 1); } + (void)user_data; } -struct device *uart_dev = NULL; +const struct device *uart_dev = NULL; static bool host_init() {