diff --git a/.github/workflows/build_wamr_vscode_ext.yml b/.github/workflows/build_wamr_vscode_ext.yml index 5b72612ba..02a6ac7a3 100644 --- a/.github/workflows/build_wamr_vscode_ext.yml +++ b/.github/workflows/build_wamr_vscode_ext.yml @@ -27,7 +27,7 @@ jobs: - uses: actions/checkout@v5 - name: Use Node.js 18.x - uses: actions/setup-node@v4 + uses: actions/setup-node@v5 with: node-version: 18.x diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index fcd011740..a2548f1d9 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -53,7 +53,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v3.29.11 + uses: github/codeql-action/init@v3.30.1 with: languages: ${{ matrix.language }} @@ -70,7 +70,7 @@ jobs: - run: | ./.github/scripts/codeql_buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3.29.11 + uses: github/codeql-action/analyze@v3.30.1 with: category: "/language:${{matrix.language}}" upload: false @@ -99,7 +99,7 @@ jobs: output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif - name: Upload CodeQL results to code scanning - uses: github/codeql-action/upload-sarif@v3.29.11 + uses: github/codeql-action/upload-sarif@v3.30.1 with: sarif_file: ${{ steps.step1.outputs.sarif-output }} category: "/language:${{matrix.language}}" diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 032560db1..8a4a6aefe 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -124,7 +124,7 @@ jobs: - name: Build wamrc run: | mkdir build && cd build - cmake .. + cmake .. -DCMAKE_C_FLAGS="-Werror" cmake --build . --config Release --parallel 4 working-directory: wamr-compiler @@ -293,7 +293,7 @@ jobs: if: matrix.platform == 'linux' run: | mkdir build && cd build - cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} + cmake .. -DCMAKE_C_FLAGS="-Werror" ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} cmake --build . --config Release --parallel 4 working-directory: product-mini/platforms/${{ matrix.platform }} @@ -301,7 +301,7 @@ jobs: if: matrix.platform == 'android' run: | mkdir build && cd build - cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} \ + cmake .. -DCMAKE_C_FLAGS="-Werror" ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} \ -DWAMR_BUILD_TARGET=X86_64 cmake --build . --config Release --parallel 4 working-directory: product-mini/platforms/${{ matrix.platform }} diff --git a/.github/workflows/compilation_on_macos.yml b/.github/workflows/compilation_on_macos.yml index 872da9316..8387ee0c7 100644 --- a/.github/workflows/compilation_on_macos.yml +++ b/.github/workflows/compilation_on_macos.yml @@ -107,7 +107,7 @@ jobs: - name: Build wamrc run: | mkdir build && cd build - cmake .. + cmake .. -DCMAKE_C_FLAGS="-Werror" cmake --build . --config Release --parallel 4 working-directory: wamr-compiler @@ -213,7 +213,7 @@ jobs: - name: Build iwasm run: | mkdir build && cd build - cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} + cmake .. -DCMAKE_C_FLAGS="-Werror" ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} cmake --build . --config Release --parallel 4 working-directory: product-mini/platforms/${{ matrix.platform }} diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index b62249146..73fb683ee 100644 --- a/.github/workflows/supply_chain.yml +++ b/.github/workflows/supply_chain.yml @@ -60,6 +60,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@5b49155c7f37b5ec074ffd26b428e6b64b1bf412 + uses: github/codeql-action/upload-sarif@144880b6f0c9977178ab4000985a49023783178f with: sarif_file: results.sarif diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b28fa89c..c33b211e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,11 +126,9 @@ include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) if (NOT WIN32) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security \ -ffunction-sections -fdata-sections \ - -Wno-unused-parameter -Wno-pedantic \ -fvisibility=hidden") # Remove the extra spaces for better make log string (REGEX REPLACE " *" " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused") endif() if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") diff --git a/README.md b/README.md index 859ee3540..9d79661c8 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ WebAssembly Micro Runtime (WAMR) is a lightweight standalone WebAssembly (Wasm) - [128-bit SIMD](https://github.com/WebAssembly/simd), ref to [samples/workload](samples/workload) - [Reference Types](https://github.com/WebAssembly/reference-types), ref to [document](doc/ref_types.md) and [sample](samples/ref-types) - [Bulk memory operations](https://github.com/WebAssembly/bulk-memory-operations), [Shared memory](https://github.com/WebAssembly/threads/blob/main/proposals/threads/Overview.md#shared-linear-memory), [Memory64](https://github.com/WebAssembly/memory64) -- [Tail-call](https://github.com/WebAssembly/tail-call), [Garbage Collection](https://github.com/WebAssembly/gc), [Exception Handling](https://github.com/WebAssembly/exception-handling) +- [Tail-call](https://github.com/WebAssembly/tail-call), [Garbage Collection](https://github.com/WebAssembly/gc), [Exception Handling](https://github.com/WebAssembly/exception-handling), [Branch Hinting](https://github.com/WebAssembly/branch-hinting) - [Extended Constant Expressions](https://github.com/WebAssembly/extended-const) ### Supported architectures and platforms @@ -117,4 +117,3 @@ Any contributions you make will be under the same license. - [WAMR Blogs](https://bytecodealliance.github.io/wamr.dev/blog/) - [Community news and events](https://bytecodealliance.github.io/wamr.dev/events/) - [WAMR TSC meetings](https://github.com/bytecodealliance/wasm-micro-runtime/wiki/TSC-meeting-notes) - diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index d21ca9c3a..838baab9d 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -81,6 +81,8 @@ elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*") set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-mthumb") endif () +include (${CMAKE_CURRENT_LIST_DIR}/warnings.cmake) + if (NOT WAMR_BUILD_INTERP EQUAL 1) if (NOT WAMR_BUILD_AOT EQUAL 1) message (FATAL_ERROR "-- WAMR Interpreter and AOT must be enabled at least one") @@ -737,6 +739,7 @@ message ( " \"Non-trapping float-to-int Conversions\"\n" " \"Sign-extension Operators\"\n" " \"WebAssembly C and C++ API\"\n" +" \"Branch Hinting\"\n" " Configurable. 0 is OFF. 1 is ON:\n" " \"Bulk Memory Operation\" via WAMR_BUILD_BULK_MEMORY: ${WAMR_BUILD_BULK_MEMORY}\n" " \"Extended Constant Expressions\" via WAMR_BUILD_EXTENDED_CONST_EXPR: ${WAMR_BUILD_EXTENDED_CONST_EXPR}\n" @@ -751,7 +754,6 @@ message ( " \"Threads\" via WAMR_BUILD_SHARED_MEMORY: ${WAMR_BUILD_SHARED_MEMORY}\n" " \"Typed Function References\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n" " Unsupported (>= Phase4):\n" -" \"Branch Hinting\"\n" " \"Custom Annotation Syntax in the Text Format\"\n" " \"Exception Handling\"\n" " \"JS String Builtins\"\n" diff --git a/build-scripts/runtime_lib.cmake b/build-scripts/runtime_lib.cmake index f7639f6a6..bac81c4f2 100644 --- a/build-scripts/runtime_lib.cmake +++ b/build-scripts/runtime_lib.cmake @@ -162,8 +162,7 @@ endif () ####################### Common sources ####################### if (NOT MSVC) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \ - -Wall -Wno-unused-parameter -Wno-pedantic") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections") endif () # include the build config template file diff --git a/build-scripts/warnings.cmake b/build-scripts/warnings.cmake new file mode 100644 index 000000000..fbe6966cc --- /dev/null +++ b/build-scripts/warnings.cmake @@ -0,0 +1,46 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# global additional warnings. +if (MSVC) + # warning level 4 + add_compile_options(/W4) +else () + # refer to https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html + add_compile_options( + -Wall -Wextra -Wformat -Wformat-security + $<$:-Wshadow> + ) + # -pedantic causes warnings like "ISO C forbids initialization between function pointer and ‘void *’" which + # is widely used in the codebase. + # + # -fpermissive causes warnings like "-fpermissive is valid for C++/ObjC++ but not for C" + # + # Reference: + # - gcc-4.8 https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Warning-Options.html + # - gcc-11.5 https://gcc.gnu.org/onlinedocs/gcc-11.5.0/gcc/Warning-Options.html + add_compile_options ( + $<$:-Wimplicit-function-declaration> + ) + + # https://gcc.gnu.org/gcc-5/changes.html introduces incompatible-pointer-types + # https://releases.llvm.org/7.0.0/tools/clang/docs/DiagnosticsReference.html#wincompatible-pointer-types + # is the earliest version that supports this option I can found. + # Assume AppClang versioning is compatible with Clang. + if ((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "5.1") + OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0.0") + OR (CMAKE_C_COMPILER_ID STREQUAL "AppClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0.0")) + add_compile_options($<$:-Wincompatible-pointer-types>) + endif() + + # options benefit embedded system. + add_compile_options ( + -Wdouble-promotion + ) + + # waivers + add_compile_options ( + -Wno-unused + -Wno-unused-parameter + ) +endif () diff --git a/core/config.h b/core/config.h index 3ee0b2cd9..060bb3259 100644 --- a/core/config.h +++ b/core/config.h @@ -579,6 +579,10 @@ unless used elsewhere */ #define WASM_ENABLE_REF_TYPES 0 #endif +#ifndef WASM_ENABLE_BRANCH_HINTS +#define WASM_ENABLE_BRANCH_HINTS 0 +#endif + #ifndef WASM_ENABLE_GC #define WASM_ENABLE_GC 0 #endif diff --git a/core/iwasm/aot/aot_intrinsic.c b/core/iwasm/aot/aot_intrinsic.c index a0e59e1d2..f296b4a25 100644 --- a/core/iwasm/aot/aot_intrinsic.c +++ b/core/iwasm/aot/aot_intrinsic.c @@ -152,7 +152,7 @@ float64 aot_intrinsic_fmin_f64(float64 a, float64 b) { if (isnan(a) || isnan(b)) - return NAN; + return (float64)NAN; else if (a == 0 && a == b) return signbit(a) ? a : b; else @@ -174,7 +174,7 @@ float64 aot_intrinsic_fmax_f64(float64 a, float64 b) { if (isnan(a) || isnan(b)) - return NAN; + return (float64)NAN; else if (a == 0 && a == b) return signbit(a) ? b : a; else diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 876e4b1f0..3bf33e127 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -4607,16 +4607,16 @@ aot_dump_perf_profiling(const AOTModuleInstance *module_inst) os_printf( " func %s, execution time: %.3f ms, execution count: %" PRIu32 " times, children execution time: %.3f ms\n", - func_name, perf_prof->total_exec_time / 1000.0f, + func_name, perf_prof->total_exec_time / 1000.0, perf_prof->total_exec_cnt, - perf_prof->children_exec_time / 1000.0f); + perf_prof->children_exec_time / 1000.0); else os_printf(" func %" PRIu32 ", execution time: %.3f ms, execution count: %" PRIu32 " times, children execution time: %.3f ms\n", - i, perf_prof->total_exec_time / 1000.0f, + i, perf_prof->total_exec_time / 1000.0, perf_prof->total_exec_cnt, - perf_prof->children_exec_time / 1000.0f); + perf_prof->children_exec_time / 1000.0); } } @@ -4632,7 +4632,7 @@ aot_summarize_wasm_execute_time(const AOTModuleInstance *inst) AOTFuncPerfProfInfo *perf_prof = (AOTFuncPerfProfInfo *)inst->func_perf_profilings + i; ret += (perf_prof->total_exec_time - perf_prof->children_exec_time) - / 1000.0f; + / 1000.0; } return ret; @@ -4651,7 +4651,7 @@ aot_get_wasm_func_exec_time(const AOTModuleInstance *inst, AOTFuncPerfProfInfo *perf_prof = (AOTFuncPerfProfInfo *)inst->func_perf_profilings + i; return (perf_prof->total_exec_time - perf_prof->children_exec_time) - / 1000.0f; + / 1000.0; } } diff --git a/core/iwasm/common/wasm_native.c b/core/iwasm/common/wasm_native.c index 060bb2c3d..42aa55db2 100644 --- a/core/iwasm/common/wasm_native.c +++ b/core/iwasm/common/wasm_native.c @@ -347,7 +347,8 @@ static dtor_t g_context_dtors[WASM_MAX_INSTANCE_CONTEXTS]; static void dtor_noop(WASMModuleInstanceCommon *inst, void *ctx) -{} +{ +} void * wasm_native_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst, @@ -485,7 +486,8 @@ wasm_native_init() || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \ || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \ || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 \ - || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 + || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 \ + || WASM_ENABLE_SHARED_HEAP != 0 NativeSymbol *native_symbols; uint32 n_native_symbols; #endif @@ -602,7 +604,8 @@ wasm_native_init() || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \ || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \ || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 \ - || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 + || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 \ + || WASM_ENABLE_SHARED_HEAP != 0 goto fail; #else return false; @@ -616,7 +619,8 @@ wasm_native_init() || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \ || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \ || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 \ - || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 + || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 \ + || WASM_ENABLE_SHARED_HEAP != 0 fail: wasm_native_destroy(); return false; diff --git a/core/iwasm/compilation/aot.c b/core/iwasm/compilation/aot.c index 5e1e554ac..8e3eeec13 100644 --- a/core/iwasm/compilation/aot.c +++ b/core/iwasm/compilation/aot.c @@ -416,6 +416,9 @@ aot_create_funcs(const WASMModule *module, uint32 pointer_size) aot_func->local_types_wp = func->local_types; aot_func->code = func->code; aot_func->code_size = func->code_size; +#if WASM_ENABLE_BRANCH_HINTS != 0 + aot_func->code_body_begin = func->code_body_begin; +#endif /* Resolve local offsets */ for (j = 0; j < func_type->param_count; j++) { @@ -872,6 +875,10 @@ aot_create_comp_data(WASMModule *module, const char *target_arch, comp_data->name_section_buf_end = module->name_section_buf_end; #endif +#if WASM_ENABLE_BRANCH_HINTS != 0 + comp_data->function_hints = module->function_hints; +#endif + aot_init_aux_data(comp_data, module); comp_data->wasm_module = module; diff --git a/core/iwasm/compilation/aot.h b/core/iwasm/compilation/aot.h index 973d198ca..f1ecccfb3 100644 --- a/core/iwasm/compilation/aot.h +++ b/core/iwasm/compilation/aot.h @@ -217,6 +217,9 @@ typedef struct AOTFunc { /* offset of each local, including function parameters and local variables */ uint16 *local_offsets; +#if WASM_ENABLE_BRANCH_HINTS != 0 + uint8 *code_body_begin; +#endif } AOTFunc; typedef struct AOTCompData { @@ -296,6 +299,10 @@ typedef struct AOTCompData { #if WASM_ENABLE_DEBUG_AOT != 0 dwarf_extractor_handle_t extractor; #endif + +#if WASM_ENABLE_BRANCH_HINTS != 0 + struct WASMCompilationHint **function_hints; +#endif } AOTCompData; typedef struct AOTNativeSymbol { diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index 82f70ca3d..60c772570 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -1158,9 +1158,7 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) case WASM_OP_BR_IF: { - read_leb_uint32(frame_ip, frame_ip_end, br_depth); - if (!aot_compile_op_br_if(comp_ctx, func_ctx, br_depth, - &frame_ip)) + if (!aot_compile_op_br_if(comp_ctx, func_ctx, &frame_ip)) return false; break; } diff --git a/core/iwasm/compilation/aot_compiler.h b/core/iwasm/compilation/aot_compiler.h index 889e2304b..70d01c578 100644 --- a/core/iwasm/compilation/aot_compiler.h +++ b/core/iwasm/compilation/aot_compiler.h @@ -668,7 +668,7 @@ set_local_gc_ref(AOTCompFrame *frame, int n, LLVMValueRef value, uint8 ref_type) #define I32_CONST(v) LLVMConstInt(I32_TYPE, v, true) #define I64_CONST(v) LLVMConstInt(I64_TYPE, v, true) -#define F32_CONST(v) LLVMConstReal(F32_TYPE, v) +#define F32_CONST(v) LLVMConstReal(F32_TYPE, (double)(v)) #define F64_CONST(v) LLVMConstReal(F64_TYPE, v) #define I8_CONST(v) LLVMConstInt(INT8_TYPE, v, true) diff --git a/core/iwasm/compilation/aot_emit_control.c b/core/iwasm/compilation/aot_emit_control.c index 80e379513..6817295f8 100644 --- a/core/iwasm/compilation/aot_emit_control.c +++ b/core/iwasm/compilation/aot_emit_control.c @@ -12,6 +12,7 @@ #endif #include "../aot/aot_runtime.h" #include "../interpreter/wasm_loader.h" +#include "../common/wasm_loader_common.h" #if WASM_ENABLE_DEBUG_AOT != 0 #include "debug/dwarf_extractor.h" @@ -87,6 +88,15 @@ format_block_name(char *name, uint32 name_size, uint32 block_index, } \ } while (0) +#define BUILD_COND_BR_V(value_if, block_then, block_else, instr) \ + do { \ + if (!(instr = LLVMBuildCondBr(comp_ctx->builder, value_if, block_then, \ + block_else))) { \ + aot_set_last_error("llvm build cond br failed."); \ + goto fail; \ + } \ + } while (0) + #define SET_BUILDER_POS(llvm_block) \ LLVMPositionBuilderAtEnd(comp_ctx->builder, llvm_block) @@ -255,6 +265,36 @@ restore_frame_sp_for_op_end(AOTBlock *block, AOTCompFrame *aot_frame) aot_frame->sp = block->frame_sp_begin; } +#if WASM_ENABLE_BRANCH_HINTS != 0 +static void +aot_emit_branch_hint(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, + uint32 offset, LLVMValueRef br_if_instr) +{ + struct WASMCompilationHint *hint = func_ctx->function_hints; + while (hint != NULL) { + if (hint->type == WASM_COMPILATION_BRANCH_HINT + && ((struct WASMCompilationHintBranchHint *)hint)->offset + == offset) { + break; + } + hint = hint->next; + } + if (hint != NULL) { + // same weight llvm MDBuilder::createLikelyBranchWeights assigns + const uint32_t likely_weight = (1U << 20) - 1; + const uint32_t unlikely_weight = 1; + aot_set_cond_br_weights( + comp_ctx, br_if_instr, + ((struct WASMCompilationHintBranchHint *)hint)->is_likely + ? likely_weight + : unlikely_weight, + ((struct WASMCompilationHintBranchHint *)hint)->is_likely + ? unlikely_weight + : likely_weight); + } +} +#endif + static bool handle_next_reachable_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint8 **p_frame_ip) @@ -673,13 +713,31 @@ aot_compile_op_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, MOVE_BLOCK_AFTER(block->llvm_else_block, block->llvm_entry_block); /* Create condition br IR */ +#if WASM_ENABLE_BRANCH_HINTS != 0 + LLVMValueRef br_if_val = NULL; + BUILD_COND_BR_V(value, block->llvm_entry_block, + block->llvm_else_block, br_if_val); + const uint32 off = + *p_frame_ip - func_ctx->aot_func->code_body_begin; + aot_emit_branch_hint(comp_ctx, func_ctx, off, br_if_val); +#else BUILD_COND_BR(value, block->llvm_entry_block, block->llvm_else_block); +#endif } else { /* Create condition br IR */ +#if WASM_ENABLE_BRANCH_HINTS != 0 + LLVMValueRef br_if_val = NULL; + BUILD_COND_BR_V(value, block->llvm_entry_block, + block->llvm_end_block, br_if_val); + const uint32 off = + *p_frame_ip - func_ctx->aot_func->code_body_begin; + aot_emit_branch_hint(comp_ctx, func_ctx, off, br_if_val); +#else BUILD_COND_BR(value, block->llvm_entry_block, block->llvm_end_block); +#endif block->is_reachable = true; } if (!push_aot_block_to_stack_and_pass_params(comp_ctx, func_ctx, @@ -1026,8 +1084,7 @@ fail: static bool aot_compile_conditional_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint32 br_depth, LLVMValueRef value_cmp, - uint8 **p_frame_ip) + LLVMValueRef value_cmp, uint8 **p_frame_ip) { AOTBlock *block_dst; LLVMValueRef value, *values = NULL; @@ -1036,6 +1093,17 @@ aot_compile_conditional_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 i, param_index, result_index; uint64 size; + // ip is advanced by one byte for the opcode +#if WASM_ENABLE_BRANCH_HINTS != 0 + uint32 instr_offset = + (*p_frame_ip - 0x1) - (func_ctx->aot_func->code_body_begin); +#else + uint32 instr_offset = 0; +#endif + uint64 br_depth; + if (!read_leb(p_frame_ip, *p_frame_ip + 5, 32, false, &br_depth, NULL, 0)) + return false; + if (!(block_dst = get_target_block(func_ctx, br_depth))) { return false; } @@ -1108,8 +1176,15 @@ aot_compile_conditional_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, values = NULL; } +#if WASM_ENABLE_BRANCH_HINTS != 0 + LLVMValueRef br_if_val = NULL; + BUILD_COND_BR_V(value_cmp, block_dst->llvm_entry_block, + llvm_else_block, br_if_val); + aot_emit_branch_hint(comp_ctx, func_ctx, instr_offset, br_if_val); +#else BUILD_COND_BR(value_cmp, block_dst->llvm_entry_block, llvm_else_block); +#endif /* Move builder to else block */ SET_BUILDER_POS(llvm_else_block); @@ -1152,9 +1227,15 @@ aot_compile_conditional_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } /* Condition jump to end block */ +#if WASM_ENABLE_BRANCH_HINTS != 0 + LLVMValueRef br_if_val = NULL; + BUILD_COND_BR_V(value_cmp, block_dst->llvm_end_block, + llvm_else_block, br_if_val); + aot_emit_branch_hint(comp_ctx, func_ctx, instr_offset, br_if_val); +#else BUILD_COND_BR(value_cmp, block_dst->llvm_end_block, llvm_else_block); - +#endif /* Move builder to else block */ SET_BUILDER_POS(llvm_else_block); } @@ -1178,13 +1259,13 @@ fail: bool aot_compile_op_br_if(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint32 br_depth, uint8 **p_frame_ip) + uint8 **p_frame_ip) { LLVMValueRef value_cmp; POP_COND(value_cmp); - return aot_compile_conditional_br(comp_ctx, func_ctx, br_depth, value_cmp, + return aot_compile_conditional_br(comp_ctx, func_ctx, value_cmp, p_frame_ip); fail: return false; diff --git a/core/iwasm/compilation/aot_emit_control.h b/core/iwasm/compilation/aot_emit_control.h index fd538495d..7ea527a20 100644 --- a/core/iwasm/compilation/aot_emit_control.h +++ b/core/iwasm/compilation/aot_emit_control.h @@ -32,7 +32,7 @@ aot_compile_op_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, bool aot_compile_op_br_if(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint32 br_depth, uint8 **p_frame_ip); + uint8 **p_frame_ip); bool aot_compile_op_br_table(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 5190a39d4..ed36749be 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -1963,6 +1963,13 @@ aot_create_func_context(const AOTCompData *comp_data, AOTCompContext *comp_ctx, goto fail; } +#if WASM_ENABLE_BRANCH_HINTS != 0 + func_ctx->function_hints = + comp_ctx->comp_data->function_hints + ? comp_ctx->comp_data->function_hints[func_index] + : NULL; +#endif + return func_ctx; fail: diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index 9f62f6616..a83fddb49 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -270,6 +270,9 @@ typedef struct AOTFuncContext { #if WASM_ENABLE_DEBUG_AOT != 0 LLVMMetadataRef debug_func; #endif +#if WASM_ENABLE_BRANCH_HINTS != 0 + struct WASMCompilationHint *function_hints; +#endif unsigned int stack_consumption_for_func_call; diff --git a/core/iwasm/compilation/simd/simd_common.c b/core/iwasm/compilation/simd/simd_common.c index 95bcdfdb0..c495ee410 100644 --- a/core/iwasm/compilation/simd/simd_common.c +++ b/core/iwasm/compilation/simd/simd_common.c @@ -137,7 +137,7 @@ simd_build_splat_const_float_vector(const AOTCompContext *comp_ctx, return NULL; } - if (!(element = LLVMConstReal(element_type, element_value))) { + if (!(element = LLVMConstReal(element_type, (double)element_value))) { HANDLE_FAILURE("LLVMConstReal"); goto fail; } diff --git a/core/iwasm/fast-jit/fe/jit_emit_numberic.c b/core/iwasm/fast-jit/fe/jit_emit_numberic.c index 00f608f84..347c21827 100644 --- a/core/iwasm/fast-jit/fe/jit_emit_numberic.c +++ b/core/iwasm/fast-jit/fe/jit_emit_numberic.c @@ -1564,7 +1564,7 @@ static float64 f64_min(float64 a, float64 b) { if (isnan(a) || isnan(b)) - return NAN; + return (float64)NAN; else if (a == 0 && a == b) return signbit(a) ? a : b; else @@ -1575,7 +1575,7 @@ static float64 f64_max(float64 a, float64 b) { if (isnan(a) || isnan(b)) - return NAN; + return (float64)NAN; else if (a == 0 && a == b) return signbit(a) ? b : a; else diff --git a/core/iwasm/fast-jit/jit_dump.c b/core/iwasm/fast-jit/jit_dump.c index d61ed5dc7..7e45dd83d 100644 --- a/core/iwasm/fast-jit/jit_dump.c +++ b/core/iwasm/fast-jit/jit_dump.c @@ -40,7 +40,7 @@ jit_dump_reg(JitCompContext *cc, JitReg reg) case JIT_REG_KIND_F32: if (jit_reg_is_const(reg)) - os_printf("%f", jit_cc_get_const_F32(cc, reg)); + os_printf("%f", (double)jit_cc_get_const_F32(cc, reg)); else os_printf("f%d", no); break; diff --git a/core/iwasm/interpreter/wasm.h b/core/iwasm/interpreter/wasm.h index 0dd73958e..87552455e 100644 --- a/core/iwasm/interpreter/wasm.h +++ b/core/iwasm/interpreter/wasm.h @@ -751,6 +751,10 @@ struct WASMFunction { void *call_to_fast_jit_from_llvm_jit; #endif #endif + +#if WASM_ENABLE_BRANCH_HINTS != 0 + uint8 *code_body_begin; +#endif }; #if WASM_ENABLE_TAGS != 0 @@ -761,6 +765,23 @@ struct WASMTag { }; #endif +#if WASM_ENABLE_BRANCH_HINTS != 0 +enum WASMCompilationHintType { + DUMMY = 0, + WASM_COMPILATION_BRANCH_HINT = 0, +}; +struct WASMCompilationHint { + struct WASMCompilationHint *next; + enum WASMCompilationHintType type; +}; +struct WASMCompilationHintBranchHint { + struct WASMCompilationHint *next; + enum WASMCompilationHintType type; + uint32 offset; + bool is_likely; +}; +#endif + struct WASMGlobal { WASMGlobalType type; #if WASM_ENABLE_GC != 0 @@ -1049,6 +1070,10 @@ struct WASMModule { const uint8 *name_section_buf_end; #endif +#if WASM_ENABLE_BRANCH_HINTS != 0 + struct WASMCompilationHint **function_hints; +#endif + #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0 WASMCustomSection *custom_section_list; #endif diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index edc473f2c..8f5f1821a 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -223,7 +223,7 @@ static inline float64 f64_min(float64 a, float64 b) { if (isnan(a) || isnan(b)) - return NAN; + return (float64)NAN; else if (a == 0 && a == b) return signbit(a) ? a : b; else @@ -234,7 +234,7 @@ static inline float64 f64_max(float64 a, float64 b) { if (isnan(a) || isnan(b)) - return NAN; + return (float64)NAN; else if (a == 0 && a == b) return signbit(a) ? b : a; else @@ -1685,7 +1685,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, goto got_exception; } - HANDLE_OP(WASM_OP_NOP) { HANDLE_OP_END(); } + HANDLE_OP(WASM_OP_NOP) + { + HANDLE_OP_END(); + } #if WASM_ENABLE_EXCE_HANDLING != 0 HANDLE_OP(WASM_OP_RETHROW) @@ -5622,7 +5625,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP(WASM_OP_I32_REINTERPRET_F32) HANDLE_OP(WASM_OP_I64_REINTERPRET_F64) HANDLE_OP(WASM_OP_F32_REINTERPRET_I32) - HANDLE_OP(WASM_OP_F64_REINTERPRET_I64) { HANDLE_OP_END(); } + HANDLE_OP(WASM_OP_F64_REINTERPRET_I64) + { + HANDLE_OP_END(); + } HANDLE_OP(WASM_OP_I32_EXTEND8_S) { @@ -5697,7 +5703,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, true); break; case WASM_OP_I64_TRUNC_SAT_U_F64: - DEF_OP_TRUNC_SAT_F64(-1.0f, 18446744073709551616.0, + DEF_OP_TRUNC_SAT_F64(-1.0, 18446744073709551616.0, false, false); break; #if WASM_ENABLE_BULK_MEMORY != 0 diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 36d4538ff..5cbb3cbe9 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -164,7 +164,7 @@ static inline float64 f64_min(float64 a, float64 b) { if (isnan(a) || isnan(b)) - return NAN; + return (float64)NAN; else if (a == 0 && a == b) return signbit(a) ? a : b; else @@ -175,7 +175,7 @@ static inline float64 f64_max(float64 a, float64 b) { if (isnan(a) || isnan(b)) - return NAN; + return (float64)NAN; else if (a == 0 && a == b) return signbit(a) ? b : a; else diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 55128795c..2346b2952 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -3908,6 +3908,9 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, /* Resolve local set count */ p_code_end = p_code + code_size; +#if WASM_ENABLE_BRANCH_HINTS != 0 + uint8 *p_body_start = (uint8 *)p_code; +#endif local_count = 0; read_leb_uint32(p_code, buf_code_end, local_set_count); p_code_save = p_code; @@ -3988,6 +3991,9 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, if (local_count > 0) func->local_types = (uint8 *)func + sizeof(WASMFunction); func->code_size = code_size; +#if WASM_ENABLE_BRANCH_HINTS != 0 + func->code_body_begin = p_body_start; +#endif /* * we shall make a copy of code body [p_code, p_code + code_size] * when we are worrying about inappropriate releasing behaviour. @@ -5560,6 +5566,88 @@ fail: } #endif +#if WASM_ENABLE_BRANCH_HINTS != 0 +static bool +handle_branch_hint_section(const uint8 *buf, const uint8 *buf_end, + WASMModule *module, char *error_buf, + uint32 error_buf_size) +{ + if (module->function_hints == NULL) { + module->function_hints = loader_malloc( + sizeof(struct WASMCompilationHint) * module->function_count, + error_buf, error_buf_size); + } + uint32 numFunctionHints = 0; + read_leb_uint32(buf, buf_end, numFunctionHints); + for (uint32 i = 0; i < numFunctionHints; ++i) { + uint32 func_idx; + read_leb_uint32(buf, buf_end, func_idx); + if (!check_function_index(module, func_idx, error_buf, + error_buf_size)) { + goto fail; + } + if (func_idx < module->import_function_count) { + set_error_buf(error_buf, error_buf_size, + "branch hint for imported function is not allowed"); + goto fail; + } + + struct WASMCompilationHint *current_hint = + (struct WASMCompilationHint *)&module + ->function_hints[func_idx - module->import_function_count]; + while (current_hint->next != NULL) { + current_hint = current_hint->next; + } + + uint32 num_hints; + read_leb_uint32(buf, buf_end, num_hints); + struct WASMCompilationHintBranchHint *new_hints = loader_malloc( + sizeof(struct WASMCompilationHintBranchHint) * num_hints, error_buf, + error_buf_size); + for (uint32 j = 0; j < num_hints; ++j) { + struct WASMCompilationHintBranchHint *new_hint = &new_hints[j]; + new_hint->next = NULL; + new_hint->type = WASM_COMPILATION_BRANCH_HINT; + read_leb_uint32(buf, buf_end, new_hint->offset); + + uint32 size; + read_leb_uint32(buf, buf_end, size); + if (size != 1) { + set_error_buf_v(error_buf, error_buf_size, + "invalid branch hint size, expected 1, got %d.", + size); + wasm_runtime_free(new_hint); + goto fail; + } + + uint8 data = *buf++; + if (data == 0x00) + new_hint->is_likely = false; + else if (data == 0x01) + new_hint->is_likely = true; + else { + set_error_buf_v(error_buf, error_buf_size, + "invalid branch hint, expected 0 or 1, got %d", + data); + wasm_runtime_free(new_hint); + goto fail; + } + + current_hint->next = (struct WASMCompilationHint *)new_hint; + current_hint = (struct WASMCompilationHint *)new_hint; + } + } + if (buf != buf_end) { + set_error_buf(error_buf, error_buf_size, + "invalid branch hint section, not filled until end"); + goto fail; + } + return true; +fail: + return false; +} +#endif + static bool load_user_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, bool is_load_from_file_buf, char *error_buf, @@ -5609,6 +5697,24 @@ load_user_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, } #endif +#if WASM_ENABLE_BRANCH_HINTS != 0 + if (name_len == 25 + && memcmp((const char *)p, "metadata.code.branch_hint", 25) == 0) { + p += name_len; + if (!handle_branch_hint_section(p, p_end, module, error_buf, + error_buf_size)) { + return false; + } + LOG_VERBOSE("Load branch hint section success."); + } +#else + if (name_len == 25 + && memcmp((const char *)p, "metadata.code.branch_hint", 25) == 0) { + LOG_VERBOSE("Found branch hint section, but branch hints are disabled " + "in this build, skipping."); + } +#endif + #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0 { WASMCustomSection *section = @@ -7388,7 +7494,17 @@ wasm_loader_unload(WASMModule *module) } #endif #endif - +#if WASM_ENABLE_BRANCH_HINTS != 0 + for (i = 0; i < module->function_count; i++) { + // be carefull when adding more hints. This only works as long as + // the hint structs have been allocated all at once as an array. + // With only branch-hints at the moment, this is the case. + if (module->function_hints != NULL && module->function_hints[i] != NULL) + wasm_runtime_free(module->function_hints[i]); + } + if (module->function_hints != NULL) + wasm_runtime_free(module->function_hints); +#endif wasm_runtime_free(module); } diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 55e65142a..3642adf9b 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -3744,16 +3744,16 @@ wasm_dump_perf_profiling(const WASMModuleInstance *module_inst) os_printf( " func %s, execution time: %.3f ms, execution count: %" PRIu32 " times, children execution time: %.3f ms\n", - func_name, func_inst->total_exec_time / 1000.0f, + func_name, func_inst->total_exec_time / 1000.0, func_inst->total_exec_cnt, - func_inst->children_exec_time / 1000.0f); + func_inst->children_exec_time / 1000.0); else os_printf(" func %" PRIu32 ", execution time: %.3f ms, execution count: %" PRIu32 " times, children execution time: %.3f ms\n", - i, func_inst->total_exec_time / 1000.0f, + i, func_inst->total_exec_time / 1000.0, func_inst->total_exec_cnt, - func_inst->children_exec_time / 1000.0f); + func_inst->children_exec_time / 1000.0); } } @@ -3765,7 +3765,7 @@ wasm_summarize_wasm_execute_time(const WASMModuleInstance *inst) unsigned i; for (i = 0; i < inst->e->function_count; i++) { WASMFunctionInstance *func = inst->e->functions + i; - ret += (func->total_exec_time - func->children_exec_time) / 1000.0f; + ret += (func->total_exec_time - func->children_exec_time) / 1000.0; } return ret; @@ -3780,7 +3780,7 @@ wasm_get_wasm_func_exec_time(const WASMModuleInstance *inst, char *name_in_wasm = get_func_name_from_index(inst, i); if (name_in_wasm && strcmp(name_in_wasm, func_name) == 0) { WASMFunctionInstance *func = inst->e->functions + i; - return (func->total_exec_time - func->children_exec_time) / 1000.0f; + return (func->total_exec_time - func->children_exec_time) / 1000.0; } } diff --git a/core/iwasm/libraries/wasi-nn/src/wasi_nn.c b/core/iwasm/libraries/wasi-nn/src/wasi_nn.c index 787c3a432..f857835eb 100644 --- a/core/iwasm/libraries/wasi-nn/src/wasi_nn.c +++ b/core/iwasm/libraries/wasi-nn/src/wasi_nn.c @@ -795,6 +795,22 @@ wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx, if (success != (res = is_model_initialized(wasi_nn_ctx))) goto fail; +#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0 + if (!wasm_runtime_validate_native_addr(instance, output_tensor, + output_tensor_len)) { + NN_ERR_PRINTF("output_tensor is invalid"); + res = invalid_argument; + goto fail; + } +#else + if (!wasm_runtime_validate_native_addr(instance, output_tensor, + *output_tensor_size)) { + NN_ERR_PRINTF("output_tensor is invalid"); + res = invalid_argument; + goto fail; + } +#endif + if (!wasm_runtime_validate_native_addr(instance, output_tensor_size, (uint64)sizeof(uint32_t))) { NN_ERR_PRINTF("output_tensor_size is invalid"); diff --git a/core/shared/platform/alios/platform_internal.h b/core/shared/platform/alios/platform_internal.h index 125aa0b63..c5032f9b2 100644 --- a/core/shared/platform/alios/platform_internal.h +++ b/core/shared/platform/alios/platform_internal.h @@ -66,8 +66,12 @@ float fmaxf(float x, float y); float rintf(float x); float fabsf(float x); float truncf(float x); -int signbit(double x); -int isnan(double x); +int isnan_double(double x); +int isnan_float(float x); +int signbit_double(double x); +int signbit_float(float x); +#define isnan(x) (sizeof(x) == sizeof(double) ? isnan_double((double)x) : isnan_float(x)) +#define signbit(x) (sizeof(x) == sizeof(double) ? signbit_double((double)x) : signbit_float(x)) /* clang-format on */ /* The below types are used in platform_api_extension.h, diff --git a/core/shared/platform/common/math/math.c b/core/shared/platform/common/math/math.c index 2ba9f4d28..ac0c40221 100644 --- a/core/shared/platform/common/math/math.c +++ b/core/shared/platform/common/math/math.c @@ -1005,6 +1005,21 @@ freebsd_isnan(double d) } } +static int +freebsd_isnanf(float f) +{ + if (is_little_endian()) { + IEEEf2bits_L u; + u.f = f; + return (u.bits.exp == 0xff && u.bits.man != 0); + } + else { + IEEEf2bits_B u; + u.f = f; + return (u.bits.exp == 0xff && u.bits.man != 0); + } +} + static float freebsd_fabsf(float x) { @@ -1601,7 +1616,13 @@ fabs(double x) } int -isnan(double x) +isnan_float(float x) +{ + return freebsd_isnanf(x); +} + +int +isnan_double(double x) { return freebsd_isnan(x); } @@ -1613,7 +1634,15 @@ trunc(double x) } int -signbit(double x) +signbit_float(float x) +{ + unsigned int i; + GET_FLOAT_WORD(i, x); + return (int)(i >> 31); +} + +int +signbit_double(double x) { return ((__HI(x) & 0x80000000) >> 31); } diff --git a/core/shared/platform/common/math/platform_api_math.cmake b/core/shared/platform/common/math/platform_api_math.cmake index 09c74bfc5..6be55262b 100644 --- a/core/shared/platform/common/math/platform_api_math.cmake +++ b/core/shared/platform/common/math/platform_api_math.cmake @@ -3,6 +3,6 @@ set (PLATFORM_COMMON_MATH_DIR ${CMAKE_CURRENT_LIST_DIR}) -file (GLOB_RECURSE source_all ${PLATFORM_COMMON_MATH_DIR}/*.c) +file (GLOB_RECURSE math_source_all ${PLATFORM_COMMON_MATH_DIR}/*.c) -set (PLATFORM_COMMON_MATH_SOURCE ${source_all} ) +set (PLATFORM_COMMON_MATH_SOURCE ${math_source_all} ) diff --git a/core/shared/platform/riot/platform_internal.h b/core/shared/platform/riot/platform_internal.h index fd9e40da7..6eaae2caf 100644 --- a/core/shared/platform/riot/platform_internal.h +++ b/core/shared/platform/riot/platform_internal.h @@ -86,8 +86,12 @@ float fmaxf(float x, float y); float rintf(float x); float fabsf(float x); float truncf(float x); -int signbit(double x); -int isnan(double x); +int isnan_double(double x); +int isnan_float(float x); +int signbit_double(double x); +int signbit_float(float x); +#define isnan(x) (sizeof(x) == sizeof(double) ? isnan_double((double)x) : isnan_float(x)) +#define signbit(x) (sizeof(x) == sizeof(double) ? signbit_double((double)x) : signbit_float(x)) /* clang-format on */ #endif diff --git a/core/shared/platform/zephyr/platform_internal.h b/core/shared/platform/zephyr/platform_internal.h index 05481e65e..7bb14dd33 100644 --- a/core/shared/platform/zephyr/platform_internal.h +++ b/core/shared/platform/zephyr/platform_internal.h @@ -190,12 +190,16 @@ float fmaxf(float x, float y); float rintf(float x); float fabsf(float x); float truncf(float x); -int isnan(double x); +int isnan_double(double x); +int isnan_float(float x); +#define isnan(x) (sizeof(x) == sizeof(double) ? isnan_double((double)x) : isnan_float(x)) double pow(double x, double y); double scalbn(double x, int n); #ifndef BH_HAS_SIGNBIT -int signbit(double x); +int signbit_double(double x); +int signbit_float(float x); +#define signbit(x) (sizeof(x) == sizeof(double) ? signbit_double((double)x) : signbit_float(x)) #endif unsigned long long int strtoull(const char *nptr, char **endptr, int base); diff --git a/doc/stability_wasm_proposals.md b/doc/stability_wasm_proposals.md index fe93d31d1..c8b90d5e4 100644 --- a/doc/stability_wasm_proposals.md +++ b/doc/stability_wasm_proposals.md @@ -12,16 +12,17 @@ Users can turn those features on or off by using compilation options. If a relev ## On-by-default Wasm Proposals -| Proposal | >= Phase 4 | Compilation Option | -| ------------------------------------- | ---------- | ------------------------ | -| Bulk Memory Operations | Yes | `WAMR_BUILD_BULK_MEMORY` | -| Fixed-width SIMD[^1] | Yes | `WAMR_BUILD_SIMD` | -| Import/Export of Mutable Globals[^2] | Yes | N/A | -| Multi-value | Yes | N/A | -| Non-trapping float-to-int Conversions | Yes | N/A | -| Reference Types | Yes | `WAMR_BUILD_REF_TYPES` | -| Sign-extension Operators | Yes | N/A | -| WebAssembly C and C++ API | No | N/A | +| Proposal | >= Phase 4 | Compilation Option | +| ------------------------------------- | ---------- |----------------------------| +| Bulk Memory Operations | Yes | `WAMR_BUILD_BULK_MEMORY` | +| Fixed-width SIMD[^1] | Yes | `WAMR_BUILD_SIMD` | +| Import/Export of Mutable Globals[^2] | Yes | N/A | +| Multi-value | Yes | N/A | +| Non-trapping float-to-int Conversions | Yes | N/A | +| Reference Types | Yes | `WAMR_BUILD_REF_TYPES` | +| Sign-extension Operators | Yes | N/A | +| WebAssembly C and C++ API | No | N/A | +| Branch Hinting | Yes | `WASM_ENABLE_BRANCH_HINTS` | [^1]: llvm-jit and aot only. @@ -54,7 +55,6 @@ Users can turn those features on or off by using compilation options. If a relev | Proposal | >= Phase 4 | | ------------------------------------------- | ---------- | -| Branch Hinting | Yes | | Custom Annotation Syntax in the Text Format | Yes | | Exception Handling[^6] | Yes | | JS String Builtins | Yes | diff --git a/product-mini/platforms/android/CMakeLists.txt b/product-mini/platforms/android/CMakeLists.txt index 19bc1b11e..9cc8cc6b9 100644 --- a/product-mini/platforms/android/CMakeLists.txt +++ b/product-mini/platforms/android/CMakeLists.txt @@ -111,9 +111,6 @@ set_version_info (vmlib) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE") -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") -# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") - 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") diff --git a/product-mini/platforms/cosmopolitan/CMakeLists.txt b/product-mini/platforms/cosmopolitan/CMakeLists.txt index 7676ea6fb..37641497a 100644 --- a/product-mini/platforms/cosmopolitan/CMakeLists.txt +++ b/product-mini/platforms/cosmopolitan/CMakeLists.txt @@ -136,11 +136,6 @@ set_version_info (vmlib) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow") -# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused") - 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") diff --git a/product-mini/platforms/ios/CMakeLists.txt b/product-mini/platforms/ios/CMakeLists.txt index ca54aa155..bc8542ffe 100644 --- a/product-mini/platforms/ios/CMakeLists.txt +++ b/product-mini/platforms/ios/CMakeLists.txt @@ -113,9 +113,6 @@ include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE") -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") -# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") - 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") diff --git a/product-mini/platforms/linux/CMakeLists.txt b/product-mini/platforms/linux/CMakeLists.txt index cef8329d7..e369197dc 100644 --- a/product-mini/platforms/linux/CMakeLists.txt +++ b/product-mini/platforms/linux/CMakeLists.txt @@ -139,11 +139,6 @@ check_pie_supported() set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow") -# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused") - 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") diff --git a/product-mini/platforms/windows/CMakeLists.txt b/product-mini/platforms/windows/CMakeLists.txt index 2a4017d68..39b373deb 100644 --- a/product-mini/platforms/windows/CMakeLists.txt +++ b/product-mini/platforms/windows/CMakeLists.txt @@ -114,9 +114,6 @@ if (NOT MINGW) set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") endif () -# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") -# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") - 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" OR MSVC)) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") diff --git a/samples/basic/CMakeLists.txt b/samples/basic/CMakeLists.txt index 3be19df8c..e7417e634 100644 --- a/samples/basic/CMakeLists.txt +++ b/samples/basic/CMakeLists.txt @@ -60,7 +60,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/debug-tools/CMakeLists.txt b/samples/debug-tools/CMakeLists.txt index 512507d6e..32d219faa 100644 --- a/samples/debug-tools/CMakeLists.txt +++ b/samples/debug-tools/CMakeLists.txt @@ -60,7 +60,6 @@ set(WAMR_BUILD_DUMP_CALL_STACK 1) # Otherwise stack trace is not printed (addr2l if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") # build out vmlib set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) diff --git a/samples/file/src/CMakeLists.txt b/samples/file/src/CMakeLists.txt index 19775a08e..d54e93c08 100644 --- a/samples/file/src/CMakeLists.txt +++ b/samples/file/src/CMakeLists.txt @@ -61,7 +61,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/inst-context-threads/CMakeLists.txt b/samples/inst-context-threads/CMakeLists.txt index 5ce8696d8..b32d3053b 100644 --- a/samples/inst-context-threads/CMakeLists.txt +++ b/samples/inst-context-threads/CMakeLists.txt @@ -61,7 +61,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/inst-context/CMakeLists.txt b/samples/inst-context/CMakeLists.txt index af387ca26..b9866a5eb 100644 --- a/samples/inst-context/CMakeLists.txt +++ b/samples/inst-context/CMakeLists.txt @@ -60,7 +60,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/multi-module/CMakeLists.txt b/samples/multi-module/CMakeLists.txt index 3c2e8bd20..7d0499e4c 100644 --- a/samples/multi-module/CMakeLists.txt +++ b/samples/multi-module/CMakeLists.txt @@ -65,7 +65,6 @@ set(WAMR_BUILD_MULTI_MODULE 1) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/multi-thread/CMakeLists.txt b/samples/multi-thread/CMakeLists.txt index 67819eca2..71a1cc5b4 100644 --- a/samples/multi-thread/CMakeLists.txt +++ b/samples/multi-thread/CMakeLists.txt @@ -54,7 +54,6 @@ set(WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 1) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") # build out vmlib set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) diff --git a/samples/native-lib/CMakeLists.txt b/samples/native-lib/CMakeLists.txt index d8201bae4..497727cb0 100644 --- a/samples/native-lib/CMakeLists.txt +++ b/samples/native-lib/CMakeLists.txt @@ -52,7 +52,6 @@ set (WAMR_BUILD_FAST_INTERP 1) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") # build out libiwasm set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) diff --git a/samples/native-stack-overflow/CMakeLists.txt b/samples/native-stack-overflow/CMakeLists.txt index efe5b5dc0..a2079bf4f 100644 --- a/samples/native-stack-overflow/CMakeLists.txt +++ b/samples/native-stack-overflow/CMakeLists.txt @@ -60,7 +60,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/ref-types/CMakeLists.txt b/samples/ref-types/CMakeLists.txt index fd18e6378..0d0852a2e 100644 --- a/samples/ref-types/CMakeLists.txt +++ b/samples/ref-types/CMakeLists.txt @@ -74,7 +74,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/shared-heap/CMakeLists.txt b/samples/shared-heap/CMakeLists.txt index 03906f7c3..94690a4ed 100644 --- a/samples/shared-heap/CMakeLists.txt +++ b/samples/shared-heap/CMakeLists.txt @@ -61,7 +61,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/shared-module/CMakeLists.txt b/samples/shared-module/CMakeLists.txt index c094b071c..4c9201e51 100644 --- a/samples/shared-module/CMakeLists.txt +++ b/samples/shared-module/CMakeLists.txt @@ -65,7 +65,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/socket-api/CMakeLists.txt b/samples/socket-api/CMakeLists.txt index a68d0caba..f09da910a 100644 --- a/samples/socket-api/CMakeLists.txt +++ b/samples/socket-api/CMakeLists.txt @@ -177,7 +177,6 @@ set(WAMR_BUILD_REF_TYPES 1) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") # build vmlib static lib set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) diff --git a/samples/spawn-thread/CMakeLists.txt b/samples/spawn-thread/CMakeLists.txt index 29c4dc429..6733ca13f 100644 --- a/samples/spawn-thread/CMakeLists.txt +++ b/samples/spawn-thread/CMakeLists.txt @@ -53,7 +53,6 @@ set(WAMR_BUILD_SHARED_MEMORY 1) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") # build out vmlib set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) diff --git a/samples/terminate/CMakeLists.txt b/samples/terminate/CMakeLists.txt index 246b835dd..380733258 100644 --- a/samples/terminate/CMakeLists.txt +++ b/samples/terminate/CMakeLists.txt @@ -68,7 +68,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/samples/wasi-threads/CMakeLists.txt b/samples/wasi-threads/CMakeLists.txt index 08cc3a7ff..d53213966 100644 --- a/samples/wasi-threads/CMakeLists.txt +++ b/samples/wasi-threads/CMakeLists.txt @@ -55,7 +55,6 @@ set(WAMR_BUILD_REF_TYPES 1) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") # build out vmlib set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) diff --git a/samples/wasm-c-api-imports/CMakeLists.txt b/samples/wasm-c-api-imports/CMakeLists.txt index 1325e110c..bf318a298 100644 --- a/samples/wasm-c-api-imports/CMakeLists.txt +++ b/samples/wasm-c-api-imports/CMakeLists.txt @@ -75,7 +75,6 @@ set(WAMR_BUILD_SIMD 0) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") # build out vmlib set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) diff --git a/samples/wasm-c-api/CMakeLists.txt b/samples/wasm-c-api/CMakeLists.txt index 06dc92d5e..c15cd2802 100644 --- a/samples/wasm-c-api/CMakeLists.txt +++ b/samples/wasm-c-api/CMakeLists.txt @@ -86,7 +86,6 @@ if (NOT MSVC) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") 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") diff --git a/test-tools/aot-analyzer/CMakeLists.txt b/test-tools/aot-analyzer/CMakeLists.txt index 6f5f588cb..04d3b636c 100644 --- a/test-tools/aot-analyzer/CMakeLists.txt +++ b/test-tools/aot-analyzer/CMakeLists.txt @@ -61,11 +61,6 @@ if (NOT DEFINED WAMR_BIG_ENDIAN) set (WAMR_BIG_ENDIAN 0) endif () -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Wno-unused-parameter") -# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused") - 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") diff --git a/tests/standalone/test-invoke-native/CMakeLists.txt b/tests/standalone/test-invoke-native/CMakeLists.txt index 9ba585842..ce659ae42 100644 --- a/tests/standalone/test-invoke-native/CMakeLists.txt +++ b/tests/standalone/test-invoke-native/CMakeLists.txt @@ -103,11 +103,6 @@ if (NOT WAMR_BUILD_PLATFORM STREQUAL "darwin") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE") endif () -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow") -# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") - -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused") - 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") diff --git a/tests/standalone/test-module-malloc/CMakeLists.txt b/tests/standalone/test-module-malloc/CMakeLists.txt index bdaff6834..c63d6678c 100644 --- a/tests/standalone/test-module-malloc/CMakeLists.txt +++ b/tests/standalone/test-module-malloc/CMakeLists.txt @@ -58,7 +58,6 @@ set (WAMR_BUILD_LIBC_WASI 1) if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") endif () -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") ################ wasm application ############### add_subdirectory(wasm-app) diff --git a/tests/standalone/test-running-modes/c-embed/CMakeLists.txt b/tests/standalone/test-running-modes/c-embed/CMakeLists.txt index a79ca33b5..9b3cf43fd 100644 --- a/tests/standalone/test-running-modes/c-embed/CMakeLists.txt +++ b/tests/standalone/test-running-modes/c-embed/CMakeLists.txt @@ -43,8 +43,6 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") if (NOT WAMR_BUILD_PLATFORM STREQUAL "darwin") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE") endif () -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused") # build out vmlib include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) diff --git a/tests/unit/wasm-c-api/CMakeLists.txt b/tests/unit/wasm-c-api/CMakeLists.txt index 9556c600e..95cbfbd54 100644 --- a/tests/unit/wasm-c-api/CMakeLists.txt +++ b/tests/unit/wasm-c-api/CMakeLists.txt @@ -25,7 +25,6 @@ set(WAMR_BUILD_FAST_INTERP 0) # compiling and linking flags set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -mindirect-branch-register") # build out vmlib # hard code path here diff --git a/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index 00940c62d..c01c4fd0f 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -46,6 +46,7 @@ add_definitions(-DWASM_ENABLE_SHARED_MEMORY=1) add_definitions(-DWASM_ENABLE_THREAD_MGR=1) add_definitions(-DWASM_ENABLE_TAIL_CALL=1) add_definitions(-DWASM_ENABLE_REF_TYPES=1) +add_definitions(-DWASM_ENABLE_BRANCH_HINTS=1) add_definitions(-DWASM_ENABLE_CUSTOM_NAME_SECTION=1) add_definitions(-DWASM_ENABLE_AOT_STACK_FRAME=1) add_definitions(-DWASM_ENABLE_DUMP_CALL_STACK=1) @@ -204,13 +205,13 @@ if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".* endif() if (NOT MSVC) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security \ - -ffunction-sections -fdata-sections \ - -Wno-unused-parameter -Wno-pedantic") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections") # Remove the extra spaces for better make log string (REGEX REPLACE " *" " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) endif() +include (${PROJECT_SOURCE_DIR}/../build-scripts/warnings.cmake) + set (SHARED_DIR ../core/shared) set (IWASM_DIR ../core/iwasm)