From 9cb1cc4af619ea8a0820a408a5b2eb5e468a1a62 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Wed, 27 Aug 2025 07:15:08 +0800 Subject: [PATCH 01/39] fix: cast file descriptor to size_t for comparison in fd_prestats functions (#4582) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` comparison of integer expressions of different signedness: ‘__wasi_fd_t’ {aka ‘int’} and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] 288 | if (fd >= pt->size) ``` --- .../libc-wasi/sandboxed-system-primitives/src/posix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 684233558b..3d90811bca 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 @@ -285,7 +285,7 @@ fd_prestats_get_entry(struct fd_prestats *pt, __wasi_fd_t fd, struct fd_prestat **ret) REQUIRES_SHARED(pt->lock) { // Test for file descriptor existence. - if (fd >= pt->size) + if ((size_t)fd >= pt->size) return __WASI_EBADF; struct fd_prestat *prestat = &pt->prestats[fd]; if (prestat->dir == NULL) @@ -301,7 +301,7 @@ static __wasi_errno_t fd_prestats_remove_entry(struct fd_prestats *pt, __wasi_fd_t fd) { // Test for file descriptor existence. - if (fd >= pt->size) + if ((size_t)fd >= pt->size) return __WASI_EBADF; struct fd_prestat *prestat = &pt->prestats[fd]; @@ -356,7 +356,7 @@ fd_table_get_entry(struct fd_table *ft, __wasi_fd_t fd, REQUIRES_SHARED(ft->lock) { // Test for file descriptor existence. - if (fd >= ft->size) { + if ((size_t)fd >= ft->size) { return __WASI_EBADF; } From 1a56951a6a1e142a632ffb38edb2a30985a89138 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Aug 2025 07:16:41 +0800 Subject: [PATCH 02/39] build(deps): Bump requests from 2.32.4 to 2.32.5 in /build-scripts (#4580) Bumps [requests](https://github.com/psf/requests) from 2.32.4 to 2.32.5. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.32.4...v2.32.5) --- updated-dependencies: - dependency-name: requests dependency-version: 2.32.5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build-scripts/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-scripts/requirements.txt b/build-scripts/requirements.txt index 480d0c4bbf..1e1bdeb6c6 100644 --- a/build-scripts/requirements.txt +++ b/build-scripts/requirements.txt @@ -1 +1 @@ -requests==2.32.4 \ No newline at end of file +requests==2.32.5 \ No newline at end of file From 42851ca821103a240142ede8bdac224e23b4d0a4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Aug 2025 07:31:06 +0800 Subject: [PATCH 03/39] build(deps): Bump github/codeql-action from 3.29.10 to 3.29.11 (#4579) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.29.10 to 3.29.11. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.29.10...v3.29.11) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.29.11 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 6 +++--- .github/workflows/supply_chain.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 453193acae..fcd0117401 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.10 + uses: github/codeql-action/init@v3.29.11 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.10 + uses: github/codeql-action/analyze@v3.29.11 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.10 + uses: github/codeql-action/upload-sarif@v3.29.11 with: sarif_file: ${{ steps.step1.outputs.sarif-output }} category: "/language:${{matrix.language}}" diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index f05372ee4e..b62249146f 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@e96e340c1e95e91449de06aabfa9525b7b98113f + uses: github/codeql-action/upload-sarif@5b49155c7f37b5ec074ffd26b428e6b64b1bf412 with: sarif_file: results.sarif From 6c3f6fd01761e8f722576f36d70fd298b1be1737 Mon Sep 17 00:00:00 2001 From: Oscar Spencer Date: Wed, 27 Aug 2025 00:57:30 -0500 Subject: [PATCH 04/39] Update note on WAMR_BUILD_LIBC_UVWASI for Windows (#4583) --- doc/build_wamr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/build_wamr.md b/doc/build_wamr.md index 78e0711ec9..e5487cbf0a 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -57,7 +57,7 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM - **WAMR_BUILD_LIBC_UVWASI**=1/0 (Experiment), build the [WASI](https://github.com/WebAssembly/WASI) libc subset for WASM app based on [uvwasi](https://github.com/nodejs/uvwasi) implementation, default to disable if not set -> Note: for platform which doesn't support **WAMR_BUILD_LIBC_WASI**, e.g. Windows, developer can try using **WAMR_BUILD_LIBC_UVWASI**. +> Note: WAMR doesn't support a safe sandbox on all platforms. For platforms that do not support **WAMR_BUILD_LIBC_WASI**, e.g. Windows, developers can try using an unsafe uvwasi-based WASI implementation by using **WAMR_BUILD_LIBC_UVWASI**. ### **Enable Multi-Module feature** From 9295d52508bae4918d676f98aa53b4b49abae9be Mon Sep 17 00:00:00 2001 From: Cur1ed Date: Mon, 1 Sep 2025 23:26:17 +0800 Subject: [PATCH 05/39] Correct the build command in the doc --- doc/build_wamr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/build_wamr.md b/doc/build_wamr.md index e5487cbf0a..6d4e60741a 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -341,7 +341,7 @@ And the wasm app can calls below APIs to allocate/free memory from/to the shared We can combine the configurations. For example, if we want to disable interpreter, enable AOT and WASI, we can run command: ``` Bash -cmake .. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_LIBC_WASI=0 -DWAMR_BUILD_PLATFORM=linux +cmake .. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_LIBC_WASI=1 -DWAMR_BUILD_PLATFORM=linux ``` Or if we want to enable interpreter, disable AOT and WASI, and build as X86_32, we can run command: From d55852d99255f57184132bee47200693c0b60f8e Mon Sep 17 00:00:00 2001 From: Zhenwei Jin <109658203+kylo5aby@users.noreply.github.com> Date: Tue, 2 Sep 2025 08:33:06 +0800 Subject: [PATCH 06/39] fix potential overflow in memory size calculation (#4549) Signed-off-by: zhenweijin --- core/iwasm/aot/aot_runtime.c | 6 +++--- core/iwasm/interpreter/wasm_runtime.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 5709a94d41..876e4b1f09 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1026,14 +1026,14 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent, /* If only one page and at most one page, we just append the app heap to the end of linear memory, enlarge the num_bytes_per_page, and don't change the page count */ - heap_offset = num_bytes_per_page; - num_bytes_per_page += heap_size; - if (num_bytes_per_page < heap_size) { + if (heap_size > UINT32_MAX - num_bytes_per_page) { set_error_buf(error_buf, error_buf_size, "failed to insert app heap into linear memory, " "try using `--heap-size=0` option"); return NULL; } + heap_offset = num_bytes_per_page; + num_bytes_per_page += heap_size; } else if (heap_size > 0) { if (init_page_count == max_page_count && init_page_count == 0) { diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index b4aa483d71..55e65142a7 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -335,14 +335,14 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent, /* If only one page and at most one page, we just append the app heap to the end of linear memory, enlarge the num_bytes_per_page, and don't change the page count */ - heap_offset = num_bytes_per_page; - num_bytes_per_page += heap_size; - if (num_bytes_per_page < heap_size) { + if (heap_size > UINT32_MAX - num_bytes_per_page) { set_error_buf(error_buf, error_buf_size, "failed to insert app heap into linear memory, " "try using `--heap-size=0` option"); return NULL; } + heap_offset = num_bytes_per_page; + num_bytes_per_page += heap_size; } else if (heap_size > 0) { if (init_page_count == max_page_count && init_page_count == 0) { From 6253bd1b5269565142e2a5a4f33777847059f9ee Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 4 Sep 2025 11:58:09 +0900 Subject: [PATCH 07/39] Reduce the code duplication a bit (#4596) This is a preparation for https://github.com/bytecodealliance/wasm-micro-runtime/issues/4364 No functional changes are intended. --- core/iwasm/aot/aot_loader.c | 10 +--------- core/iwasm/common/wasm_runtime_common.c | 15 +++++++++++++++ core/iwasm/common/wasm_runtime_common.h | 3 +++ core/iwasm/interpreter/wasm_loader.c | 10 +--------- core/iwasm/interpreter/wasm_mini_loader.c | 10 +--------- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index a87aee0a72..2f7e6c9f25 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -4226,15 +4226,7 @@ create_module(char *name, char *error_buf, uint32 error_buf_size) #endif #if WASM_ENABLE_LIBC_WASI != 0 -#if WASM_ENABLE_UVWASI == 0 - module->wasi_args.stdio[0] = os_invalid_raw_handle(); - module->wasi_args.stdio[1] = os_invalid_raw_handle(); - module->wasi_args.stdio[2] = os_invalid_raw_handle(); -#else - module->wasi_args.stdio[0] = os_get_invalid_handle(); - module->wasi_args.stdio[1] = os_get_invalid_handle(); - module->wasi_args.stdio[2] = os_get_invalid_handle(); -#endif /* WASM_ENABLE_UVWASI == 0 */ + wasi_args_set_defaults(&module->wasi_args); #endif /* WASM_ENABLE_LIBC_WASI != 0 */ return module; diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 943b46fc4c..26283b3f8b 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3438,6 +3438,21 @@ wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst, #if WASM_ENABLE_LIBC_WASI != 0 +void +wasi_args_set_defaults(WASIArguments *args) +{ + memset(args, 0, sizeof(*args)); +#if WASM_ENABLE_UVWASI == 0 + args->stdio[0] = os_invalid_raw_handle(); + args->stdio[1] = os_invalid_raw_handle(); + args->stdio[2] = os_invalid_raw_handle(); +#else + args->stdio[0] = os_get_invalid_handle(); + args->stdio[1] = os_get_invalid_handle(); + args->stdio[2] = os_get_invalid_handle(); +#endif /* WASM_ENABLE_UVWASI == 0 */ +} + static WASIArguments * get_wasi_args_from_module(wasm_module_t module) { diff --git a/core/iwasm/common/wasm_runtime_common.h b/core/iwasm/common/wasm_runtime_common.h index 324620bef3..a315c75da6 100644 --- a/core/iwasm/common/wasm_runtime_common.h +++ b/core/iwasm/common/wasm_runtime_common.h @@ -1118,6 +1118,9 @@ wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst); WASM_RUNTIME_API_EXTERN uint32_t wasm_runtime_get_wasi_exit_code(WASMModuleInstanceCommon *module_inst); +void +wasi_args_set_defaults(WASIArguments *args); + bool wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, const char *dir_list[], uint32 dir_count, diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index e89e91e0d2..55128795ce 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -6712,15 +6712,7 @@ create_module(char *name, char *error_buf, uint32 error_buf_size) #endif #if WASM_ENABLE_LIBC_WASI != 0 -#if WASM_ENABLE_UVWASI == 0 - module->wasi_args.stdio[0] = os_invalid_raw_handle(); - module->wasi_args.stdio[1] = os_invalid_raw_handle(); - module->wasi_args.stdio[2] = os_invalid_raw_handle(); -#else - module->wasi_args.stdio[0] = os_get_invalid_handle(); - module->wasi_args.stdio[1] = os_get_invalid_handle(); - module->wasi_args.stdio[2] = os_get_invalid_handle(); -#endif /* WASM_ENABLE_UVWASI == 0 */ + wasi_args_set_defaults(&module->wasi_args); #endif /* WASM_ENABLE_LIBC_WASI != 0 */ (void)ret; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 771538a142..6fff2fa17f 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -3316,15 +3316,7 @@ create_module(char *name, char *error_buf, uint32 error_buf_size) #endif #if WASM_ENABLE_LIBC_WASI != 0 -#if WASM_ENABLE_LIBC_UVWASI == 0 - module->wasi_args.stdio[0] = os_invalid_raw_handle(); - module->wasi_args.stdio[1] = os_invalid_raw_handle(); - module->wasi_args.stdio[2] = os_invalid_raw_handle(); -#else - module->wasi_args.stdio[0] = os_get_invalid_handle(); - module->wasi_args.stdio[1] = os_get_invalid_handle(); - module->wasi_args.stdio[2] = os_get_invalid_handle(); -#endif /* WASM_ENABLE_UVWASI == 0 */ + wasi_args_set_defaults(&module->wasi_args); #endif /* WASM_ENABLE_LIBC_WASI != 0 */ (void)ret; From ce3358f58e3c525b35428cc6f653d8c111089845 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 9 Sep 2025 13:23:20 +0800 Subject: [PATCH 08/39] build(deps): Bump actions/setup-node from 4 to 5 (#4608) Bumps [actions/setup-node](https://github.com/actions/setup-node) from 4 to 5. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/setup-node dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/build_wamr_vscode_ext.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wamr_vscode_ext.yml b/.github/workflows/build_wamr_vscode_ext.yml index 5b72612baf..02a6ac7a32 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 From 9f8a6ab2d617cf6c3cb19d47b01475a929752136 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 9 Sep 2025 13:23:34 +0800 Subject: [PATCH 09/39] build(deps): Bump github/codeql-action from 3.29.11 to 3.30.1 (#4607) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.29.11 to 3.30.1. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.29.11...v3.30.1) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.30.1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 6 +++--- .github/workflows/supply_chain.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index fcd0117401..a2548f1d90 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/supply_chain.yml b/.github/workflows/supply_chain.yml index b62249146f..73fb683ee0 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 From 7263a04e4355cd7eed78fc8e2bfcf9f323ef473d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 11 Sep 2025 07:31:22 +0900 Subject: [PATCH 10/39] wasi-nn: add a missing address validation for get_output (#4535) cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4533 --- core/iwasm/libraries/wasi-nn/src/wasi_nn.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/iwasm/libraries/wasi-nn/src/wasi_nn.c b/core/iwasm/libraries/wasi-nn/src/wasi_nn.c index 787c3a432d..f857835eb3 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"); From 0264686eeae8f14567074b96a040b3ed6880e8bb Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Thu, 11 Sep 2025 06:31:51 +0800 Subject: [PATCH 11/39] fix the source_all override in platform_api_math.cmake for alios, riot, rt-thread, zephyr platform (#4604) --- core/shared/platform/common/math/platform_api_math.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/shared/platform/common/math/platform_api_math.cmake b/core/shared/platform/common/math/platform_api_math.cmake index 09c74bfc50..6be55262bf 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} ) From e2cf59cc266589b8e5660200c02462711f4440b4 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 11 Sep 2025 06:32:15 +0800 Subject: [PATCH 12/39] Fix an undefined reference problem (#4612) The issue was previously covered by WAMR_BUILD_LIBC_BUILTIN and WAMR_BUILD_LIBC_WASI. Reproduced by ``` $ cmake -S . -B build -DWAMR_BUILD_SHARE_HEAP=1 -DWAMR_BUILD_LIBC_BUILTIN=0 -DWAMR_BUILD_LIBC_WASI=0 $ cmake --build build ``` --- core/iwasm/common/wasm_native.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/iwasm/common/wasm_native.c b/core/iwasm/common/wasm_native.c index 060bb2c3d3..42aa55db28 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; From b71a6bf58f0fbc3f9c2a930bb693b1943fa862e2 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 11 Sep 2025 06:33:04 +0800 Subject: [PATCH 13/39] Turn warnings into errors in CI (#4397) - Apply global warnings in warnings.cmake instead of maintaining them in separate files. - Enable errors during CI when building iwasm and wamrc. - Since GCC and Clang are the default compilers on Ubuntu and macOS, enabling `-Werror` on both platforms can be treated as checking with different compilers. --- .../compilation_on_android_ubuntu.yml | 6 ++-- .github/workflows/compilation_on_macos.yml | 4 +-- CMakeLists.txt | 2 -- build-scripts/config_common.cmake | 2 ++ build-scripts/runtime_lib.cmake | 3 +- build-scripts/warnings.cmake | 28 +++++++++++++++++++ product-mini/platforms/android/CMakeLists.txt | 3 -- .../platforms/cosmopolitan/CMakeLists.txt | 5 ---- product-mini/platforms/ios/CMakeLists.txt | 3 -- product-mini/platforms/linux/CMakeLists.txt | 5 ---- product-mini/platforms/windows/CMakeLists.txt | 3 -- samples/basic/CMakeLists.txt | 1 - samples/debug-tools/CMakeLists.txt | 1 - samples/file/src/CMakeLists.txt | 1 - samples/inst-context-threads/CMakeLists.txt | 1 - samples/inst-context/CMakeLists.txt | 1 - samples/multi-module/CMakeLists.txt | 1 - samples/multi-thread/CMakeLists.txt | 1 - samples/native-lib/CMakeLists.txt | 1 - samples/native-stack-overflow/CMakeLists.txt | 1 - samples/ref-types/CMakeLists.txt | 1 - samples/shared-heap/CMakeLists.txt | 1 - samples/shared-module/CMakeLists.txt | 1 - samples/socket-api/CMakeLists.txt | 1 - samples/spawn-thread/CMakeLists.txt | 1 - samples/terminate/CMakeLists.txt | 1 - samples/wasi-threads/CMakeLists.txt | 1 - samples/wasm-c-api-imports/CMakeLists.txt | 1 - samples/wasm-c-api/CMakeLists.txt | 1 - test-tools/aot-analyzer/CMakeLists.txt | 5 ---- .../test-invoke-native/CMakeLists.txt | 5 ---- .../test-module-malloc/CMakeLists.txt | 1 - .../test-running-modes/c-embed/CMakeLists.txt | 2 -- tests/unit/wasm-c-api/CMakeLists.txt | 1 - wamr-compiler/CMakeLists.txt | 6 ++-- 35 files changed, 39 insertions(+), 63 deletions(-) create mode 100644 build-scripts/warnings.cmake diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 032560db10..8a4a6aefef 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 872da9316c..8387ee0c75 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/CMakeLists.txt b/CMakeLists.txt index 4b28fa89c1..c33b211e61 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/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index d21ca9c3a9..bd9e424092 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") diff --git a/build-scripts/runtime_lib.cmake b/build-scripts/runtime_lib.cmake index f7639f6a61..bac81c4f2d 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 0000000000..14abf74a35 --- /dev/null +++ b/build-scripts/warnings.cmake @@ -0,0 +1,28 @@ +# 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" + # + add_compile_options ( + $<$:-Wincompatible-pointer-types> + $<$:-Wimplicit-function-declaration> + ) + # waivers + add_compile_options ( + -Wno-unused + -Wno-unused-parameter + ) +endif () diff --git a/product-mini/platforms/android/CMakeLists.txt b/product-mini/platforms/android/CMakeLists.txt index 19bc1b11e7..9cc8cc6b94 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 7676ea6fb8..37641497aa 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 ca54aa1556..bc8542ffe9 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 cef8329d77..e369197dc9 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 2a4017d686..39b373deb0 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 3be19df8c1..e7417e634c 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 512507d6ee..32d219faa5 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 19775a08ea..d54e93c082 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 5ce8696d8d..b32d3053bf 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 af387ca267..b9866a5ebd 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 3c2e8bd207..7d0499e4cc 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 67819eca2d..71a1cc5b44 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 d8201bae4f..497727cb09 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 efe5b5dc05..a2079bf4f5 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 fd18e63780..0d0852a2ee 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 03906f7c32..94690a4ed5 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 c094b071c9..4c9201e51c 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 a68d0caba9..f09da910a9 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 29c4dc429c..6733ca13fe 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 246b835ddc..3807332588 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 08cc3a7ffb..d532139665 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 1325e110cb..bf318a2989 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 06dc92d5ef..c15cd28026 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 6f5f588cb8..04d3b636ce 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 9ba5858425..ce659ae42a 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 bdaff68347..c63d6678c0 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 a79ca33b57..9b3cf43fda 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 9556c600e1..95cbfbd544 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 00940c62d2..24afdd49dc 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -204,13 +204,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) From 0d3b5caff0f77ecb0a8a3f9a89182bdf3b245c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20D=C3=B6llerer?= Date: Fri, 12 Sep 2025 02:42:48 +0200 Subject: [PATCH 14/39] Add support for metadata.code.branch_hint section (#4460) Add support for metadata.code.branch_hint section --- README.md | 3 +- build-scripts/config_common.cmake | 2 +- core/config.h | 4 + core/iwasm/compilation/aot.c | 7 ++ core/iwasm/compilation/aot.h | 7 ++ core/iwasm/compilation/aot_compiler.c | 4 +- core/iwasm/compilation/aot_emit_control.c | 91 ++++++++++++++++- core/iwasm/compilation/aot_emit_control.h | 2 +- core/iwasm/compilation/aot_llvm.c | 7 ++ core/iwasm/compilation/aot_llvm.h | 3 + core/iwasm/interpreter/wasm.h | 25 +++++ core/iwasm/interpreter/wasm_loader.c | 118 +++++++++++++++++++++- doc/stability_wasm_proposals.md | 22 ++-- wamr-compiler/CMakeLists.txt | 1 + 14 files changed, 272 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 859ee3540f..9d79661c8f 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 bd9e424092..838baab9da 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -739,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" @@ -753,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/core/config.h b/core/config.h index 3ee0b2cd92..060bb32594 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/compilation/aot.c b/core/iwasm/compilation/aot.c index 5e1e554ac1..8e3eeec134 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 973d198caa..f1ecccfb37 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 82f70ca3dc..60c772570c 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_emit_control.c b/core/iwasm/compilation/aot_emit_control.c index 80e379513c..6817295f86 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 @@ aot_compile_op_br(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, 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 @@ aot_compile_conditional_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) { 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 fd538495d6..7ea527a20c 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 5190a39d4b..ed36749be4 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 9f62f66162..a83fddb49a 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/interpreter/wasm.h b/core/iwasm/interpreter/wasm.h index 0dd73958eb..87552455e6 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_loader.c b/core/iwasm/interpreter/wasm_loader.c index 55128795ce..0cf82b6498 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 @@ handle_name_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, } #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 (size_t 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/doc/stability_wasm_proposals.md b/doc/stability_wasm_proposals.md index fe93d31d1d..c8b90d5e44 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/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index 24afdd49dc..c01c4fd0f6 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) From d7afa4c0cfe36eba9ce2a5581d5d48e325103564 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Fri, 12 Sep 2025 08:44:42 +0800 Subject: [PATCH 15/39] Enable -Wdouble-promotion by default and fix related warnings (#4603) - fix float to double implicit conversion - add isnanf and signbitf macros, map them to existing double version when float versions are absent - enable -Wdouble-promotion by default - define isnan as macro for platform use core\sahred\platform\common\math.c --- build-scripts/warnings.cmake | 3 ++ core/iwasm/aot/aot_intrinsic.c | 4 +-- core/iwasm/aot/aot_runtime.c | 12 +++---- core/iwasm/compilation/aot_compiler.h | 2 +- core/iwasm/compilation/simd/simd_common.c | 2 +- core/iwasm/fast-jit/fe/jit_emit_numberic.c | 4 +-- core/iwasm/fast-jit/jit_dump.c | 2 +- core/iwasm/interpreter/wasm_interp_classic.c | 16 ++++++--- core/iwasm/interpreter/wasm_interp_fast.c | 4 +-- core/iwasm/interpreter/wasm_runtime.c | 12 +++---- .../shared/platform/alios/platform_internal.h | 8 +++-- core/shared/platform/common/math/math.c | 33 +++++++++++++++++-- core/shared/platform/riot/platform_internal.h | 8 +++-- .../platform/zephyr/platform_internal.h | 8 +++-- 14 files changed, 84 insertions(+), 34 deletions(-) diff --git a/build-scripts/warnings.cmake b/build-scripts/warnings.cmake index 14abf74a35..5e8df43f1c 100644 --- a/build-scripts/warnings.cmake +++ b/build-scripts/warnings.cmake @@ -20,6 +20,9 @@ else () $<$:-Wincompatible-pointer-types> $<$:-Wimplicit-function-declaration> ) + add_compile_options ( + -Wdouble-promotion + ) # waivers add_compile_options ( -Wno-unused diff --git a/core/iwasm/aot/aot_intrinsic.c b/core/iwasm/aot/aot_intrinsic.c index a0e59e1d21..f296b4a25f 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 876e4b1f09..3bf33e1276 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/compilation/aot_compiler.h b/core/iwasm/compilation/aot_compiler.h index 889e2304b5..70d01c578d 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/simd/simd_common.c b/core/iwasm/compilation/simd/simd_common.c index 95bcdfdb04..c495ee4104 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 00f608f84d..347c21827e 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 d61ed5dc78..7e45dd83df 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_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index edc473f2c2..8f5f1821ae 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 36d4538ffc..5cbb3cbe9a 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_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 55e65142a7..3642adf9b0 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/shared/platform/alios/platform_internal.h b/core/shared/platform/alios/platform_internal.h index 125aa0b63f..c5032f9b2e 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 2ba9f4d28b..ac0c402210 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/riot/platform_internal.h b/core/shared/platform/riot/platform_internal.h index fd9e40da71..6eaae2caf0 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 7e59faa746..d5f0c80d81 100644 --- a/core/shared/platform/zephyr/platform_internal.h +++ b/core/shared/platform/zephyr/platform_internal.h @@ -189,12 +189,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); From ad21524573816f3b71f3b3d946e8de7015817399 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Fri, 12 Sep 2025 16:00:23 +0800 Subject: [PATCH 16/39] fix: few CI errors caused by recently enabled compilation flags (#4620) - add missing warning for incompatible pointer types in CMake configuration - fix a shadow warning --- build-scripts/warnings.cmake | 17 ++++++++++++++++- core/iwasm/interpreter/wasm_loader.c | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build-scripts/warnings.cmake b/build-scripts/warnings.cmake index 5e8df43f1c..fbe6966ccc 100644 --- a/build-scripts/warnings.cmake +++ b/build-scripts/warnings.cmake @@ -16,13 +16,28 @@ else () # # -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 ( - $<$:-Wincompatible-pointer-types> $<$:-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 diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 0cf82b6498..2346b29527 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -7495,7 +7495,7 @@ wasm_loader_unload(WASMModule *module) #endif #endif #if WASM_ENABLE_BRANCH_HINTS != 0 - for (size_t i = 0; i < module->function_count; i++) { + 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. From 4f8646867059d26b6a961bfe61c9ab665d1ce015 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sun, 14 Sep 2025 15:01:55 +0900 Subject: [PATCH 17/39] wasi-nn: retire is_model_loaded flag (#4613) this flag doesn't make much sense anymore because: - backends validate given graph/ctx by themselves - some of them support loading multiple models for a context --- core/iwasm/libraries/wasi-nn/src/wasi_nn.c | 26 ------------------- .../libraries/wasi-nn/src/wasi_nn_private.h | 1 - 2 files changed, 27 deletions(-) diff --git a/core/iwasm/libraries/wasi-nn/src/wasi_nn.c b/core/iwasm/libraries/wasi-nn/src/wasi_nn.c index f857835eb3..2282534b0f 100644 --- a/core/iwasm/libraries/wasi-nn/src/wasi_nn.c +++ b/core/iwasm/libraries/wasi-nn/src/wasi_nn.c @@ -66,7 +66,6 @@ wasi_nn_ctx_destroy(WASINNContext *wasi_nn_ctx) } NN_DBG_PRINTF("[WASI NN] DEINIT..."); NN_DBG_PRINTF("Freeing wasi-nn"); - NN_DBG_PRINTF("-> is_model_loaded: %d", wasi_nn_ctx->is_model_loaded); NN_DBG_PRINTF("-> current_encoding: %d", wasi_nn_ctx->backend); bh_assert(!wasi_nn_ctx->busy); @@ -202,15 +201,6 @@ wasi_nn_destroy() } /* Utils */ -static wasi_nn_error -is_model_initialized(WASINNContext *wasi_nn_ctx) -{ - if (!wasi_nn_ctx->is_model_loaded) { - NN_ERR_PRINTF("Model not initialized."); - return runtime_error; - } - return success; -} /* *TODO: choose a proper backend based on @@ -510,8 +500,6 @@ wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder, if (res != success) goto fail; - wasi_nn_ctx->is_model_loaded = true; - fail: // XXX: Free intermediate structure pointers if (builder_native.buf) @@ -587,7 +575,6 @@ wasi_nn_load_by_name(wasm_exec_env_t exec_env, char *name, uint32_t name_len, if (res != success) goto fail; - wasi_nn_ctx->is_model_loaded = true; res = success; fail: if (nul_terminated_name != NULL) { @@ -651,7 +638,6 @@ wasi_nn_load_by_name_with_config(wasm_exec_env_t exec_env, char *name, if (res != success) goto fail; - wasi_nn_ctx->is_model_loaded = true; res = success; fail: if (nul_terminated_name != NULL) { @@ -684,9 +670,6 @@ wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph g, goto fail; } - if (success != (res = is_model_initialized(wasi_nn_ctx))) - goto fail; - if (!wasm_runtime_validate_native_addr( instance, ctx, (uint64)sizeof(graph_execution_context))) { NN_ERR_PRINTF("ctx is invalid"); @@ -719,9 +702,6 @@ wasi_nn_set_input(wasm_exec_env_t exec_env, graph_execution_context ctx, goto fail; } - if (success != (res = is_model_initialized(wasi_nn_ctx))) - goto fail; - tensor input_tensor_native = { 0 }; if (success != (res = tensor_app_native(instance, input_tensor, @@ -756,9 +736,6 @@ wasi_nn_compute(wasm_exec_env_t exec_env, graph_execution_context ctx) goto fail; } - if (success != (res = is_model_initialized(wasi_nn_ctx))) - goto fail; - call_wasi_nn_func(wasi_nn_ctx->backend, compute, res, wasi_nn_ctx->backend_ctx, ctx); fail: @@ -792,9 +769,6 @@ wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx, goto fail; } - 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)) { diff --git a/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h b/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h index 466f2cef45..1bff2c514d 100644 --- a/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h +++ b/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h @@ -15,7 +15,6 @@ typedef struct { korp_mutex lock; bool busy; bool is_backend_ctx_initialized; - bool is_model_loaded; graph_encoding backend; void *backend_ctx; } WASINNContext; From 5e779b3d7b18e5cc8d3c9504dde53994f6fd599d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sun, 14 Sep 2025 15:02:48 +0900 Subject: [PATCH 18/39] libc-wasi: add missing pointer validations to socket functions (#4611) cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4463 the fix for sock_addr_resolve is incomplete. cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4610 --- .../libraries/libc-wasi/libc_wasi_wrapper.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c index acd7c31c96..5ab189e71d 100644 --- a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c +++ b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c @@ -1159,6 +1159,9 @@ wasi_sock_accept(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_fdflags_t flags, if (!wasi_ctx) return __WASI_EACCES; + if (!validate_native_addr(fd_new, sizeof(*fd_new))) + return __WASI_EINVAL; + curfds = wasi_ctx_get_curfds(wasi_ctx); return wasi_ssp_sock_accept(exec_env, curfds, fd, flags, fd_new); @@ -1217,6 +1220,19 @@ wasi_sock_addr_resolve(wasm_exec_env_t exec_env, const char *host, if (!wasi_ctx) return __WASI_EACCES; + if (!validate_native_addr(hints, sizeof(*hints))) + return __WASI_EINVAL; + + uint64_t addr_info_byte_size = sizeof(*addr_info) * addr_info_size; + if (addr_info_byte_size / addr_info_size != sizeof(*addr_info)) + return __WASI_EINVAL; + + if (!validate_native_addr(addr_info, addr_info_byte_size)) + return __WASI_EINVAL; + + if (!validate_native_addr(max_info_size, sizeof(*max_info_size))) + return __WASI_EINVAL; + curfds = wasi_ctx_get_curfds(wasi_ctx); ns_lookup_list = wasi_ctx_get_ns_lookup_list(wasi_ctx); @@ -1236,6 +1252,9 @@ wasi_sock_bind(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr) if (!wasi_ctx) return __WASI_EACCES; + if (!validate_native_addr(addr, sizeof(*addr))) + return __WASI_EINVAL; + curfds = wasi_ctx_get_curfds(wasi_ctx); addr_pool = wasi_ctx_get_addr_pool(wasi_ctx); @@ -1262,6 +1281,9 @@ wasi_sock_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr) if (!wasi_ctx) return __WASI_EACCES; + if (!validate_native_addr(addr, sizeof(*addr))) + return __WASI_EINVAL; + curfds = wasi_ctx_get_curfds(wasi_ctx); addr_pool = wasi_ctx_get_addr_pool(wasi_ctx); @@ -1641,6 +1663,9 @@ wasi_sock_open(wasm_exec_env_t exec_env, wasi_fd_t poolfd, if (!wasi_ctx) return __WASI_EACCES; + if (!validate_native_addr(sockfd, sizeof(*sockfd))) + return __WASI_EINVAL; + curfds = wasi_ctx_get_curfds(wasi_ctx); return wasi_ssp_sock_open(exec_env, curfds, poolfd, af, socktype, sockfd); @@ -2080,6 +2105,10 @@ wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock, return __WASI_EINVAL; } + /* note: src_addr is NULL when called by wasi_sock_recv */ + if (src_addr != NULL && !validate_native_addr(src_addr, sizeof(*src_addr))) + return __WASI_EINVAL; + if (!validate_native_addr(ro_data_len, (uint64)sizeof(uint32))) return __WASI_EINVAL; @@ -2118,6 +2147,9 @@ wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data, wasm_module_inst_t module_inst = get_module_inst(exec_env); wasi_errno_t error; + if (!validate_native_addr(ro_data_len, sizeof(*ro_data_len))) + return __WASI_EINVAL; + if (!validate_native_addr(ro_flags, (uint64)sizeof(wasi_roflags_t))) return __WASI_EINVAL; @@ -2227,6 +2259,9 @@ wasi_sock_send_to(wasm_exec_env_t exec_env, wasi_fd_t sock, return __WASI_EINVAL; } + if (!validate_native_addr((void *)dest_addr, sizeof(*dest_addr))) + return __WASI_EINVAL; + if (!validate_native_addr(so_data_len, (uint64)sizeof(uint32))) return __WASI_EINVAL; From 92b065a3ac903feadcc9b98b8cbac776de9d585a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sun, 14 Sep 2025 15:07:54 +0900 Subject: [PATCH 19/39] sync iwasm between windows and posix a bit (#4593) this commit includes: * update windows for * WASM_MEM_ALLOC_WITH_USAGE * InstantiationArgs2 * --jit-codecache-size * --disable-bounds-checks * wasm_proposal_print_status * fix WASM_ENABLE_SHARED_HEAP for windows (https://github.com/bytecodealliance/wasm-micro-runtime/issues/4592) * cosmetic changes to reduce the diff --- product-mini/platforms/posix/main.c | 15 +-- product-mini/platforms/windows/main.c | 167 ++++++++++++++++++-------- 2 files changed, 126 insertions(+), 56 deletions(-) diff --git a/product-mini/platforms/posix/main.c b/product-mini/platforms/posix/main.c index 342eef0fd8..f013ec9d0b 100644 --- a/product-mini/platforms/posix/main.c +++ b/product-mini/platforms/posix/main.c @@ -80,7 +80,7 @@ print_help(void) printf(" Use comma to separate, e.g. --enable-segue=i32.load,i64.store\n"); printf(" and --enable-segue means all flags are added.\n"); #endif -#endif /* WASM_ENABLE_JIT != 0*/ +#endif /* WASM_ENABLE_JIT != 0 */ #if WASM_ENABLE_LINUX_PERF != 0 printf(" --enable-linux-perf Enable linux perf support. It works in aot and llvm-jit.\n"); #endif @@ -404,7 +404,7 @@ unregister_and_unload_native_libs(uint32 native_lib_count, static char * handle_module_path(const char *module_path) { - /* next character after = */ + /* next character after '=' */ return (strchr(module_path, '=')) + 1; } @@ -583,7 +583,7 @@ main(int argc, char *argv[]) uint32 heap_size = 16 * 1024; #endif #if WASM_ENABLE_SHARED_HEAP != 0 - SharedHeapInitArgs heap_init_args; + SharedHeapInitArgs shared_heap_init_args; uint32 shared_heap_size = 0; void *shared_heap = NULL; #endif @@ -1025,15 +1025,16 @@ main(int argc, char *argv[]) #if WASM_ENABLE_SHARED_HEAP != 0 if (shared_heap_size > 0) { - memset(&heap_init_args, 0, sizeof(heap_init_args)); - heap_init_args.size = shared_heap_size; - shared_heap = wasm_runtime_create_shared_heap(&heap_init_args); + memset(&shared_heap_init_args, 0, sizeof(shared_heap_init_args)); + shared_heap_init_args.size = shared_heap_size; + shared_heap = wasm_runtime_create_shared_heap(&shared_heap_init_args); + if (!shared_heap) { printf("Create preallocated shared heap failed\n"); goto fail6; } - /* attach module instance 2 to the shared heap */ + /* attach module instance to the shared heap */ if (!wasm_runtime_attach_shared_heap(wasm_module_inst, shared_heap)) { printf("Attach shared heap failed.\n"); goto fail6; diff --git a/product-mini/platforms/windows/main.c b/product-mini/platforms/windows/main.c index 31680da8a8..4be3a76cbe 100644 --- a/product-mini/platforms/windows/main.c +++ b/product-mini/platforms/windows/main.c @@ -14,70 +14,77 @@ #include "../common/libc_wasi.c" #endif +#include "../common/wasm_proposal.c" + static int app_argc; static char **app_argv; -#define MODULE_PATH ("--module-path=") - /* clang-format off */ static int -print_help() +print_help(void) { printf("Usage: iwasm [-options] wasm_file [args...]\n"); printf("options:\n"); - printf(" -f|--function name Specify a function name of the module to run rather\n" - " than main\n"); + printf(" -f|--function name Specify a function name of the module to run rather\n" + " than main\n"); #if WASM_ENABLE_LOG != 0 - printf(" -v=n Set log verbose level (0 to 5, default is 2) larger\n" - " level with more log\n"); + printf(" -v=n Set log verbose level (0 to 5, default is 2) larger\n" + " level with more log\n"); #endif #if WASM_ENABLE_INTERP != 0 - printf(" --interp Run the wasm app with interpreter mode\n"); + printf(" --interp Run the wasm app with interpreter mode\n"); #endif #if WASM_ENABLE_FAST_JIT != 0 - printf(" --fast-jit Run the wasm app with fast jit mode\n"); + printf(" --fast-jit Run the wasm app with fast jit mode\n"); #endif #if WASM_ENABLE_JIT != 0 - printf(" --llvm-jit Run the wasm app with llvm jit mode\n"); + printf(" --llvm-jit Run the wasm app with llvm jit mode\n"); #endif #if WASM_ENABLE_JIT != 0 && WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0 - printf(" --multi-tier-jit Run the wasm app with multi-tier jit mode\n"); + printf(" --multi-tier-jit Run the wasm app with multi-tier jit mode\n"); #endif - printf(" --stack-size=n Set maximum stack size in bytes, default is 64 KB\n"); + printf(" --stack-size=n Set maximum stack size in bytes, default is 64 KB\n"); #if WASM_ENABLE_LIBC_WASI !=0 printf(" --heap-size=n Set maximum heap size in bytes, default is 0 KB when libc wasi is enabled\n"); #else printf(" --heap-size=n Set maximum heap size in bytes, default is 16 KB when libc wasi is diabled\n"); #endif -#if WASM_ENABLE_GC != 0 - printf(" --gc-heap-size=n Set maximum gc heap size in bytes,\n"); - printf(" default is %u KB\n", GC_HEAP_SIZE_DEFAULT / 1024); -#endif #if WASM_ENABLE_SHARED_HEAP != 0 printf(" --shared-heap-size=n Create shared heap of n bytes and attach to the wasm app.\n"); printf(" The size n will be adjusted to a minumum number aligned to page size\n"); #endif +#if WASM_ENABLE_FAST_JIT != 0 + printf(" --jit-codecache-size=n Set fast jit maximum code cache size in bytes,\n"); + printf(" default is %u KB\n", FAST_JIT_DEFAULT_CODE_CACHE_SIZE / 1024); +#endif +#if WASM_ENABLE_GC != 0 + printf(" --gc-heap-size=n Set maximum gc heap size in bytes,\n"); + printf(" default is %u KB\n", GC_HEAP_SIZE_DEFAULT / 1024); +#endif #if WASM_ENABLE_JIT != 0 printf(" --llvm-jit-size-level=n Set LLVM JIT size level, default is 3\n"); printf(" --llvm-jit-opt-level=n Set LLVM JIT optimization level, default is 3\n"); +#endif /* WASM_ENABLE_JIT != 0 */ + printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n" + " that runs commands in the form of `FUNC ARG...`\n"); +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + printf(" --disable-bounds-checks Disable bounds checks for memory accesses\n"); #endif - printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n" - " that runs commands in the form of `FUNC ARG...`\n"); #if WASM_ENABLE_LIBC_WASI != 0 libc_wasi_print_help(); #endif #if WASM_ENABLE_MULTI_MODULE != 0 - printf(" --module-path= Indicate a module search path. default is current\n" - " directory('./')\n"); + printf(" --module-path= Indicate a module search path. default is current\n" + " directory('./')\n"); #endif #if WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 - printf(" --max-threads=n Set maximum thread number per cluster, default is 4\n"); + printf(" --max-threads=n Set maximum thread number per cluster, default is 4\n"); #endif #if WASM_ENABLE_DEBUG_INTERP != 0 - printf(" -g=ip:port Set the debug sever address, default is debug disabled\n"); + printf(" -g=ip:port Set the debug sever address, default is debug disabled\n"); printf(" if port is 0, then a random port will be used\n"); #endif - printf(" --version Show version information\n"); + printf(" --version Show version information\n"); return 1; } /* clang-format on */ @@ -190,6 +197,9 @@ static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 }; #else static void * malloc_func( +#if WASM_MEM_ALLOC_WITH_USAGE != 0 + mem_alloc_usage_t usage, +#endif #if WASM_MEM_ALLOC_WITH_USER_DATA != 0 void *user_data, #endif @@ -200,6 +210,9 @@ malloc_func( static void * realloc_func( +#if WASM_MEM_ALLOC_WITH_USAGE != 0 + mem_alloc_usage_t usage, bool full_size_mmaped, +#endif #if WASM_MEM_ALLOC_WITH_USER_DATA != 0 void *user_data, #endif @@ -210,6 +223,9 @@ realloc_func( static void free_func( +#if WASM_MEM_ALLOC_WITH_USAGE != 0 + mem_alloc_usage_t usage, +#endif #if WASM_MEM_ALLOC_WITH_USER_DATA != 0 void *user_data, #endif @@ -228,6 +244,7 @@ handle_module_path(const char *module_path) } static char *module_search_path = "."; + static bool module_reader_callback(package_type_t module_type, const char *module_name, uint8 **p_buffer, uint32 *p_size) @@ -283,6 +300,14 @@ main(int argc, char *argv[]) #else uint32 heap_size = 16 * 1024; #endif +#if WASM_ENABLE_SHARED_HEAP != 0 + SharedHeapInitArgs shared_heap_init_args; + uint32 shared_heap_size = 0; + void *shared_heap = NULL; +#endif +#if WASM_ENABLE_FAST_JIT != 0 + uint32 jit_code_cache_size = FAST_JIT_DEFAULT_CODE_CACHE_SIZE; +#endif #if WASM_ENABLE_GC != 0 uint32 gc_heap_size = GC_HEAP_SIZE_DEFAULT; #endif @@ -294,12 +319,16 @@ main(int argc, char *argv[]) wasm_module_inst_t wasm_module_inst = NULL; RunningMode running_mode = 0; RuntimeInitArgs init_args; + struct InstantiationArgs2 *inst_args; char error_buf[128] = { 0 }; #if WASM_ENABLE_LOG != 0 int log_verbose_level = 2; #endif bool is_repl_mode = false; bool is_xip_file = false; +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + bool disable_bounds_checks = false; +#endif #if WASM_ENABLE_LIBC_WASI != 0 libc_wasi_parse_context_t wasi_parse_ctx; #endif @@ -351,6 +380,11 @@ main(int argc, char *argv[]) else if (!strcmp(argv[0], "--repl")) { is_repl_mode = true; } +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + else if (!strcmp(argv[0], "--disable-bounds-checks")) { + disable_bounds_checks = true; + } +#endif else if (!strncmp(argv[0], "--stack-size=", 13)) { if (argv[0][13] == '\0') return print_help(); @@ -361,13 +395,6 @@ main(int argc, char *argv[]) return print_help(); heap_size = atoi(argv[0] + 12); } -#if WASM_ENABLE_GC != 0 - else if (!strncmp(argv[0], "--gc-heap-size=", 15)) { - if (argv[0][15] == '\0') - return print_help(); - gc_heap_size = atoi(argv[0] + 15); - } -#endif #if WASM_ENABLE_SHARED_HEAP != 0 else if (!strncmp(argv[0], "--shared-heap-size=", 19)) { if (argv[0][19] == '\0') @@ -375,6 +402,20 @@ main(int argc, char *argv[]) shared_heap_size = atoi(argv[0] + 19); } #endif +#if WASM_ENABLE_FAST_JIT != 0 + else if (!strncmp(argv[0], "--jit-codecache-size=", 21)) { + if (argv[0][21] == '\0') + return print_help(); + jit_code_cache_size = atoi(argv[0] + 21); + } +#endif +#if WASM_ENABLE_GC != 0 + else if (!strncmp(argv[0], "--gc-heap-size=", 15)) { + if (argv[0][15] == '\0') + return print_help(); + gc_heap_size = atoi(argv[0] + 15); + } +#endif #if WASM_ENABLE_JIT != 0 else if (!strncmp(argv[0], "--llvm-jit-size-level=", 22)) { if (argv[0][22] == '\0') @@ -408,7 +449,8 @@ main(int argc, char *argv[]) } #endif #if WASM_ENABLE_MULTI_MODULE != 0 - else if (!strncmp(argv[0], MODULE_PATH, strlen(MODULE_PATH))) { + else if (!strncmp(argv[0], + "--module-path=", strlen("--module-path="))) { module_search_path = handle_module_path(argv[0]); if (!strlen(module_search_path)) { return print_help(); @@ -440,6 +482,8 @@ main(int argc, char *argv[]) wasm_runtime_get_version(&major, &minor, &patch); printf("iwasm %" PRIu32 ".%" PRIu32 ".%" PRIu32 "\n", major, minor, patch); + printf("\n"); + wasm_proposal_print_status(); return 0; } else { @@ -485,6 +529,10 @@ main(int argc, char *argv[]) init_args.mem_alloc_option.allocator.free_func = free_func; #endif +#if WASM_ENABLE_FAST_JIT != 0 + init_args.fast_jit_code_cache_size = jit_code_cache_size; +#endif + #if WASM_ENABLE_GC != 0 init_args.gc_heap_size = gc_heap_size; #endif @@ -554,28 +602,27 @@ main(int argc, char *argv[]) libc_wasi_init(wasm_module, argc, argv, &wasi_parse_ctx); #endif + if (!wasm_runtime_instantiation_args_create(&inst_args)) { + printf("failed to create instantiate args\n"); + goto fail3; + } + wasm_runtime_instantiation_args_set_default_stack_size(inst_args, + stack_size); + wasm_runtime_instantiation_args_set_host_managed_heap_size(inst_args, + heap_size); + /* instantiate the module */ - if (!(wasm_module_inst = - wasm_runtime_instantiate(wasm_module, stack_size, heap_size, - error_buf, sizeof(error_buf)))) { + wasm_module_inst = wasm_runtime_instantiate_ex2( + wasm_module, inst_args, error_buf, sizeof(error_buf)); + wasm_runtime_instantiation_args_destroy(inst_args); + if (!wasm_module_inst) { printf("%s\n", error_buf); goto fail3; } -#if WASM_ENABLE_SHARED_HEAP != 0 - if (shared_heap_size > 0) { - memset(&shared_heap_init_args, 0, sizeof(shared_heap_init_args)); - shared_heap_init_args.size = shared_heap_size; - shared_heap = wasm_runtime_create_shared_heap(&shared_heap_init_args); - - if (!shared_heap) { - printf("Create shared heap failed.\n"); - goto fail5; - } - if (!wasm_runtime_attach_shared_heap(wasm_module_inst, shared_heap)) { - printf("Attach shared heap failed.\n"); - goto fail5; - } +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + if (disable_bounds_checks) { + wasm_runtime_set_bounds_checks(wasm_module_inst, false); } #endif @@ -596,6 +643,25 @@ main(int argc, char *argv[]) } #endif +#if WASM_ENABLE_SHARED_HEAP != 0 + if (shared_heap_size > 0) { + memset(&shared_heap_init_args, 0, sizeof(shared_heap_init_args)); + shared_heap_init_args.size = shared_heap_size; + shared_heap = wasm_runtime_create_shared_heap(&shared_heap_init_args); + + if (!shared_heap) { + printf("Create preallocated shared heap failed\n"); + goto fail6; + } + + /* attach module instance to the shared heap */ + if (!wasm_runtime_attach_shared_heap(wasm_module_inst, shared_heap)) { + printf("Attach shared heap failed.\n"); + goto fail6; + } + } +#endif + ret = 0; const char *exception = NULL; if (is_repl_mode) { @@ -627,8 +693,11 @@ main(int argc, char *argv[]) printf("%s\n", exception); #if WASM_ENABLE_SHARED_HEAP != 0 -fail5: +fail6: #endif + + /* fail5: label is used by posix/main.c */ + #if WASM_ENABLE_DEBUG_INTERP != 0 fail4: #endif From e6fe6060e40b9e53ba98f1ad95432cd4730c4dbc Mon Sep 17 00:00:00 2001 From: Zhenwei Jin <109658203+kylo5aby@users.noreply.github.com> Date: Sun, 14 Sep 2025 14:08:27 +0800 Subject: [PATCH 20/39] add micro AMR_BUILD_LIME1 to enable minimal lime1 feature set (#4571) Signed-off-by: zhenweijin --- .../compilation_on_android_ubuntu.yml | 1 + build-scripts/config_common.cmake | 40 +++++++++++++++ core/config.h | 8 +++ core/iwasm/compilation/aot_compiler.c | 23 +++++++-- core/iwasm/compilation/aot_emit_memory.c | 6 ++- core/iwasm/compilation/aot_emit_memory.h | 2 + core/iwasm/compilation/aot_llvm.c | 12 ++++- core/iwasm/compilation/aot_llvm.h | 7 +++ core/iwasm/fast-jit/fe/jit_emit_memory.c | 2 + core/iwasm/fast-jit/fe/jit_emit_memory.h | 2 + core/iwasm/fast-jit/jit_frontend.c | 6 ++- core/iwasm/include/aot_comp_option.h | 3 ++ core/iwasm/interpreter/wasm_interp_classic.c | 10 ++-- core/iwasm/interpreter/wasm_interp_fast.c | 8 +-- core/iwasm/interpreter/wasm_loader.c | 49 ++++++++++++------- core/iwasm/interpreter/wasm_mini_loader.c | 18 +++++-- doc/build_wamr.md | 19 +++++++ doc/build_wasm_app.md | 5 ++ wamr-compiler/CMakeLists.txt | 2 + wamr-compiler/main.c | 31 ++++++++++++ 20 files changed, 217 insertions(+), 37 deletions(-) diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 8a4a6aefef..01356dc66e 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -166,6 +166,7 @@ jobs: "-DWAMR_BUILD_MULTI_MEMORY=1", "-DWAMR_BUILD_SHARED=1", "-DWAMR_BUILD_EXTENDED_CONST_EXPR=1", + "-DWAMR_BUILD_LIME1=1 -DWAMR_BUILD_BULK_MEMORY=0 -DWAMR_BUILD_REF_TYPES=0 -DWAMR_BUILD_SIMD=0", ] os: [ubuntu-22.04] platform: [android, linux] diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index 838baab9da..52c6d94afa 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -221,6 +221,14 @@ if (NOT DEFINED WAMR_BUILD_BULK_MEMORY) set (WAMR_BUILD_BULK_MEMORY 1) endif () +if (NOT DEFINED WAMR_BUILD_BULK_MEMORY_OPT) + set (WAMR_BUILD_BULK_MEMORY_OPT 0) +endif () + +if (NOT DEFINED WAMR_BUILD_CALL_INDIRECT_OVERLONG) + set (WAMR_BUILD_CALL_INDIRECT_OVERLONG 0) +endif () + if (NOT DEFINED WAMR_BUILD_EXCE_HANDLING) set (WAMR_BUILD_EXCE_HANDLING 0) endif () @@ -253,10 +261,27 @@ if (NOT DEFINED WAMR_BUILD_EXTENDED_CONST_EXPR) set (WAMR_BUILD_EXTENDED_CONST_EXPR 0) endif () +if (NOT DEFINED WAMR_BUILD_LIME1) + set (WAMR_BUILD_LIME1 0) +endif () + ######################################## # Compilation options to marco ######################################## +if (WAMR_BUILD_LIME1 EQUAL 1) + set (WAMR_BUILD_BULK_MEMORY_OPT 1) + set (WAMR_BUILD_CALL_INDIRECT_OVERLONG 1) + set (WAMR_BUILD_EXTENDED_CONST_EXPR 1) +endif () + +if (WAMR_BUILD_BULK_MEMORY EQUAL 1) + set (WAMR_BUILD_BULK_MEMORY_OPT 1) +endif () +if (WAMR_BUILD_REF_TYPES EQUAL 1) + set (WAMR_BUILD_CALL_INDIRECT_OVERLONG 1) +endif () + message ("-- Build Configurations:") message (" Build as target ${WAMR_BUILD_TARGET}") message (" Build for platform ${WAMR_BUILD_PLATFORM}") @@ -366,6 +391,11 @@ if (WAMR_BUILD_BULK_MEMORY EQUAL 1) else () add_definitions (-DWASM_ENABLE_BULK_MEMORY=0) endif () +if (WAMR_BUILD_BULK_MEMORY_OPT EQUAL 1) + add_definitions (-DWASM_ENABLE_BULK_MEMORY_OPT=1) +else() + add_definitions (-DWASM_ENABLE_BULK_MEMORY_OPT=0) +endif () if (WAMR_BUILD_SHARED_MEMORY EQUAL 1) add_definitions (-DWASM_ENABLE_SHARED_MEMORY=1) message (" Shared memory enabled") @@ -457,6 +487,11 @@ endif () if (WAMR_BUILD_REF_TYPES EQUAL 1) add_definitions (-DWASM_ENABLE_REF_TYPES=1) endif () +if (WAMR_BUILD_CALL_INDIRECT_OVERLONG EQUAL 1) + add_definitions (-DWASM_ENABLE_CALL_INDIRECT_OVERLONG=1) +else () + add_definitions(-DWASM_ENABLE_CALL_INDIRECT_OVERLONG=0) +endif () if (WAMR_BUILD_GC EQUAL 1) if (WAMR_TEST_GC EQUAL 1) message(" GC testing enabled") @@ -727,6 +762,9 @@ else() message (" Extended constant expression disabled") add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=0) endif () +if (WAMR_BUILD_LIME1 EQUAL 1) + message (" Lime1 enabled") +endif () ######################################## # Show Phase4 Wasm proposals status. ######################################## @@ -742,6 +780,8 @@ message ( " \"Branch Hinting\"\n" " Configurable. 0 is OFF. 1 is ON:\n" " \"Bulk Memory Operation\" via WAMR_BUILD_BULK_MEMORY: ${WAMR_BUILD_BULK_MEMORY}\n" +" \"Bulk-memory-opt\" via WAMR_BUILD_BULK_MEMORY_OPT: ${WAMR_BUILD_BULK_MEMORY_OPT}\n" +" \"Call-indirect-overlong\" via WAMR_BUILD_CALL_INDIRECT_OVERLONG: ${WAMR_BUILD_CALL_INDIRECT_OVERLONG}\n" " \"Extended Constant Expressions\" via WAMR_BUILD_EXTENDED_CONST_EXPR: ${WAMR_BUILD_EXTENDED_CONST_EXPR}\n" " \"Fixed-width SIMD\" via WAMR_BUILD_SIMD: ${WAMR_BUILD_SIMD}\n" " \"Garbage Collection\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n" diff --git a/core/config.h b/core/config.h index 060bb32594..cb5db1d0cf 100644 --- a/core/config.h +++ b/core/config.h @@ -214,6 +214,10 @@ #define WASM_ENABLE_BULK_MEMORY 0 #endif +#ifndef WASM_ENABLE_BULK_MEMORY_OPT +#define WASM_ENABLE_BULK_MEMORY_OPT 0 +#endif + /* Shared memory */ #ifndef WASM_ENABLE_SHARED_MEMORY #define WASM_ENABLE_SHARED_MEMORY 0 @@ -579,6 +583,10 @@ unless used elsewhere */ #define WASM_ENABLE_REF_TYPES 0 #endif +#ifndef WASM_ENABLE_CALL_INDIRECT_OVERLONG +#define WASM_ENABLE_CALL_INDIRECT_OVERLONG 0 +#endif + #ifndef WASM_ENABLE_BRANCH_HINTS #define WASM_ENABLE_BRANCH_HINTS 0 #endif diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index 60c772570c..29026e8008 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -1236,8 +1236,8 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) uint32 tbl_idx; read_leb_uint32(frame_ip, frame_ip_end, type_idx); - - if (comp_ctx->enable_gc || comp_ctx->enable_ref_types) { + if (comp_ctx->enable_gc + || comp_ctx->enable_call_indirect_overlong) { read_leb_uint32(frame_ip, frame_ip_end, tbl_idx); } else { @@ -2462,6 +2462,14 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) UINT8_MAX */ opcode = (uint8)opcode1; +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 + if (WASM_OP_MEMORY_COPY <= opcode + && opcode <= WASM_OP_MEMORY_FILL + && !comp_ctx->enable_bulk_memory_opt) { + goto unsupport_bulk_memory_opt; + } +#endif + #if WASM_ENABLE_BULK_MEMORY != 0 if (WASM_OP_MEMORY_INIT <= opcode && opcode <= WASM_OP_MEMORY_FILL @@ -2530,6 +2538,8 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) return false; break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { frame_ip += 2; @@ -2544,7 +2554,7 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) return false; break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 case WASM_OP_TABLE_INIT: { @@ -3971,6 +3981,13 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) return false; #endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 +unsupport_bulk_memory_opt: + aot_set_last_error("bulk memory opt instruction was found, " + "try enabling bulk-memory-opt or bulk-memory option"); + return false; +#endif + #if WASM_ENABLE_BULK_MEMORY != 0 unsupport_bulk_memory: aot_set_last_error("bulk memory instruction was found, " diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index 0659c2b408..0dec2ed365 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -1481,7 +1481,7 @@ aot_compile_op_memory_grow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) return false; } -#if WASM_ENABLE_BULK_MEMORY != 0 || WASM_ENABLE_STRINGREF != 0 +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 || WASM_ENABLE_STRINGREF != 0 LLVMValueRef check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef offset, LLVMValueRef bytes) @@ -1769,7 +1769,9 @@ aot_compile_op_data_drop(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, fail: return false; } +#endif /* end of WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 bool aot_compile_op_memory_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) { @@ -1931,7 +1933,7 @@ aot_compile_op_memory_fill(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) fail: return false; } -#endif /* end of WASM_ENABLE_BULK_MEMORY */ +#endif /* end of WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_SHARED_MEMORY != 0 bool diff --git a/core/iwasm/compilation/aot_emit_memory.h b/core/iwasm/compilation/aot_emit_memory.h index 1eb95993cb..5b87377beb 100644 --- a/core/iwasm/compilation/aot_emit_memory.h +++ b/core/iwasm/compilation/aot_emit_memory.h @@ -78,7 +78,9 @@ aot_compile_op_memory_init(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, bool aot_compile_op_data_drop(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 seg_index); +#endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 bool aot_compile_op_memory_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx); diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index ed36749be4..ab351e6d44 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -2731,6 +2731,9 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) if (option->enable_bulk_memory) comp_ctx->enable_bulk_memory = true; + if (option->enable_bulk_memory_opt) + comp_ctx->enable_bulk_memory_opt = true; + if (option->enable_thread_mgr) comp_ctx->enable_thread_mgr = true; @@ -2740,6 +2743,9 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) if (option->enable_ref_types) comp_ctx->enable_ref_types = true; + if (option->enable_call_indirect_overlong) + comp_ctx->enable_call_indirect_overlong = true; + comp_ctx->aux_stack_frame_type = option->aux_stack_frame_type; comp_ctx->call_stack_features = option->call_stack_features; @@ -3324,7 +3330,7 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) /* Return error if ref-types and GC are disabled by command line but ref-types instructions are used */ - if (!option->enable_ref_types && !option->enable_gc + if (!option->enable_call_indirect_overlong && !option->enable_gc && wasm_module->is_ref_types_used) { aot_set_last_error("ref-types instruction was found, " "try removing --disable-ref-types option " @@ -3338,9 +3344,13 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) } if (!wasm_module->is_ref_types_used) { option->enable_ref_types = comp_ctx->enable_ref_types = false; + option->enable_call_indirect_overlong = + comp_ctx->enable_call_indirect_overlong = false; } if (!wasm_module->is_bulk_memory_used) { option->enable_bulk_memory = comp_ctx->enable_bulk_memory = false; + option->enable_bulk_memory_opt = comp_ctx->enable_bulk_memory_opt = + false; } #endif diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index a83fddb49a..5bd75a38ce 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -416,6 +416,10 @@ typedef struct AOTCompContext { /* Bulk memory feature */ bool enable_bulk_memory; + /* Bulk memory opt feature. will be enabled alongside the + * enable_bulk_memory */ + bool enable_bulk_memory_opt; + /* Boundary Check */ bool enable_bound_check; @@ -452,6 +456,9 @@ typedef struct AOTCompContext { /* Reference Types */ bool enable_ref_types; + /* Call Indirect Overlong. will be enabled alongside the enable_ref_types */ + bool enable_call_indirect_overlong; + /* Disable LLVM built-in intrinsics */ bool disable_llvm_intrinsics; diff --git a/core/iwasm/fast-jit/fe/jit_emit_memory.c b/core/iwasm/fast-jit/fe/jit_emit_memory.c index bbe82cf674..07269a6551 100644 --- a/core/iwasm/fast-jit/fe/jit_emit_memory.c +++ b/core/iwasm/fast-jit/fe/jit_emit_memory.c @@ -713,7 +713,9 @@ jit_compile_op_data_drop(JitCompContext *cc, uint32 seg_idx) return jit_emit_callnative(cc, wasm_data_drop, 0, args, sizeof(args) / sizeof(args[0])); } +#endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 static int wasm_copy_memory(WASMModuleInstance *inst, uint32 src_mem_idx, uint32 dst_mem_idx, uint32 len, uint32 src_offset, diff --git a/core/iwasm/fast-jit/fe/jit_emit_memory.h b/core/iwasm/fast-jit/fe/jit_emit_memory.h index 6565cdc11b..2fdacccf52 100644 --- a/core/iwasm/fast-jit/fe/jit_emit_memory.h +++ b/core/iwasm/fast-jit/fe/jit_emit_memory.h @@ -55,7 +55,9 @@ jit_compile_op_memory_init(JitCompContext *cc, uint32 mem_idx, uint32 seg_idx); bool jit_compile_op_data_drop(JitCompContext *cc, uint32 seg_idx); +#endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 bool jit_compile_op_memory_copy(JitCompContext *cc, uint32 src_mem_idx, uint32 dst_mem_idx); diff --git a/core/iwasm/fast-jit/jit_frontend.c b/core/iwasm/fast-jit/jit_frontend.c index 566783b6f6..c96b5410ba 100644 --- a/core/iwasm/fast-jit/jit_frontend.c +++ b/core/iwasm/fast-jit/jit_frontend.c @@ -1627,7 +1627,7 @@ jit_compile_func(JitCompContext *cc) read_leb_uint32(frame_ip, frame_ip_end, type_idx); -#if WASM_ENABLE_REF_TYPES != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 read_leb_uint32(frame_ip, frame_ip_end, tbl_idx); #else frame_ip++; @@ -2336,6 +2336,8 @@ jit_compile_func(JitCompContext *cc) return false; break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { uint32 src_mem_idx, dst_mem_idx; @@ -2353,7 +2355,7 @@ jit_compile_func(JitCompContext *cc) return false; break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 case WASM_OP_TABLE_INIT: { diff --git a/core/iwasm/include/aot_comp_option.h b/core/iwasm/include/aot_comp_option.h index 069ceab319..9a9023ee2e 100644 --- a/core/iwasm/include/aot_comp_option.h +++ b/core/iwasm/include/aot_comp_option.h @@ -62,13 +62,16 @@ typedef struct AOTCompOption { char *cpu_features; bool is_sgx_platform; bool enable_bulk_memory; + bool enable_bulk_memory_opt; bool enable_thread_mgr; bool enable_tail_call; bool enable_simd; bool enable_ref_types; + bool enable_call_indirect_overlong; bool enable_gc; bool enable_aux_stack_check; bool enable_extended_const; + bool enable_lime1; AOTStackFrameType aux_stack_frame_type; AOTCallStackFeatures call_stack_features; bool enable_perf_profiling; diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 8f5f1821ae..9ba3a5f4f0 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -1567,7 +1567,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, WASMMemoryInstance *memory = wasm_get_default_memory(module); #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 + || WASM_ENABLE_BULK_MEMORY_OPT != 0 uint64 linear_mem_size = 0; if (memory) #if WASM_ENABLE_THREAD_MGR == 0 @@ -2370,7 +2370,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, cur_type = wasm_types[tidx]; /* clang-format off */ -#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 || WASM_ENABLE_GC != 0 read_leb_uint32(frame_ip, frame_ip_end, tbl_idx); #else frame_ip++; @@ -5774,6 +5774,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, segment); break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { mem_offset_t dst, src, len; @@ -5894,7 +5896,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, memset(mdst, fill_val, len); break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 case WASM_OP_TABLE_INIT: { @@ -6879,7 +6881,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 + || WASM_ENABLE_BULK_MEMORY_OPT != 0 out_of_bounds: wasm_set_exception(module, "out of bounds memory access"); #endif diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 5cbb3cbe9a..a326018efc 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -1501,7 +1501,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, WASMMemoryInstance *memory = wasm_get_default_memory(module); #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 + || WASM_ENABLE_BULK_MEMORY_OPT != 0 uint64 linear_mem_size = 0; if (memory) #if WASM_ENABLE_THREAD_MGR == 0 @@ -5200,6 +5200,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, segment); break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { uint32 dst, src, len; @@ -5290,7 +5292,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, memset(mdst, fill_val, len); break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 case WASM_OP_TABLE_INIT: { @@ -7805,7 +7807,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 + || WASM_ENABLE_BULK_MEMORY_OPT != 0 out_of_bounds: wasm_set_exception(module, "out of bounds memory access"); #endif diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 2346b29527..19ca249496 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -5869,6 +5869,9 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, #if WASM_ENABLE_BULK_MEMORY != 0 option.enable_bulk_memory = true; #endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 + option.enable_bulk_memory_opt = true; +#endif #if WASM_ENABLE_THREAD_MGR != 0 option.enable_thread_mgr = true; #endif @@ -5882,6 +5885,9 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, option.enable_ref_types = true; #elif WASM_ENABLE_GC != 0 option.enable_gc = true; +#endif +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 + option.enable_call_indirect_overlong = true; #endif option.enable_aux_stack_check = true; #if WASM_ENABLE_PERF_PROFILING != 0 || WASM_ENABLE_DUMP_CALL_STACK != 0 \ @@ -7739,7 +7745,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_RETURN_CALL_INDIRECT: #endif skip_leb_uint32(p, p_end); /* typeidx */ -#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 || WASM_ENABLE_GC != 0 skip_leb_uint32(p, p_end); /* tableidx */ #else u8 = read_uint8(p); /* 0x00 */ @@ -8164,6 +8170,8 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_DATA_DROP: skip_leb_uint32(p, p_end); break; +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: skip_leb_memidx(p, p_end); skip_leb_memidx(p, p_end); @@ -8171,7 +8179,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_MEMORY_FILL: skip_leb_memidx(p, p_end); break; -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 case WASM_OP_TABLE_INIT: case WASM_OP_TABLE_COPY: @@ -12987,7 +12995,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #endif pb_read_leb_uint32(p, p_end, type_idx); -#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 || WASM_ENABLE_GC != 0 #if WASM_ENABLE_WAMR_COMPILER != 0 if (p + 1 < p_end && *p != 0x00) { /* @@ -15673,8 +15681,11 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, emit_uint32(loader_ctx, data_seg_idx); #endif if (module->import_memory_count == 0 - && module->memory_count == 0) - goto fail_unknown_memory; + && module->memory_count == 0) { + set_error_buf(error_buf, error_buf_size, + "unknown memory 0"); + goto fail; + } pb_read_leb_uint32(p, p_end, memidx); check_memidx(module, memidx); @@ -15723,6 +15734,12 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #endif break; } + fail_data_cnt_sec_require: + set_error_buf(error_buf, error_buf_size, + "data count section required"); + goto fail; +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { CHECK_BUF(p, p_end, sizeof(int16)); @@ -15733,8 +15750,11 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, check_memidx(module, memidx); if (module->import_memory_count == 0 - && module->memory_count == 0) - goto fail_unknown_memory; + && module->memory_count == 0) { + set_error_buf(error_buf, error_buf_size, + "unknown memory 0"); + goto fail; + } POP_MEM_OFFSET(); POP_MEM_OFFSET(); @@ -15753,7 +15773,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, check_memidx(module, memidx); if (module->import_memory_count == 0 && module->memory_count == 0) { - goto fail_unknown_memory; + set_error_buf(error_buf, error_buf_size, + "unknown memory 0"); + goto fail; } POP_MEM_OFFSET(); POP_I32(); @@ -15766,16 +15788,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #endif break; } - - fail_unknown_memory: - set_error_buf(error_buf, error_buf_size, - "unknown memory 0"); - goto fail; - fail_data_cnt_sec_require: - set_error_buf(error_buf, error_buf_size, - "data count section required"); - goto fail; -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 case WASM_OP_TABLE_INIT: { diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 6fff2fa17f..b9dcc9877a 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -2388,6 +2388,9 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, #if WASM_ENABLE_BULK_MEMORY != 0 option.enable_bulk_memory = true; #endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 + option.enable_bulk_memory_opt = true; +#endif #if WASM_ENABLE_THREAD_MGR != 0 option.enable_thread_mgr = true; #endif @@ -2399,6 +2402,9 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, #endif #if WASM_ENABLE_REF_TYPES != 0 option.enable_ref_types = true; +#endif +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 + option.enable_call_indirect_overlong = true; #endif option.enable_aux_stack_check = true; #if WASM_ENABLE_PERF_PROFILING != 0 || WASM_ENABLE_DUMP_CALL_STACK != 0 \ @@ -3849,7 +3855,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_RETURN_CALL_INDIRECT: #endif skip_leb_uint32(p, p_end); /* typeidx */ -#if WASM_ENABLE_REF_TYPES != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 skip_leb_uint32(p, p_end); /* tableidx */ #else u8 = read_uint8(p); /* 0x00 */ @@ -4111,6 +4117,8 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_DATA_DROP: skip_leb_uint32(p, p_end); break; +#endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: skip_leb_memidx(p, p_end); skip_leb_memidx(p, p_end); @@ -4118,7 +4126,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_MEMORY_FILL: skip_leb_memidx(p, p_end); break; -#endif +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 case WASM_OP_TABLE_INIT: case WASM_OP_TABLE_COPY: @@ -7069,7 +7077,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, pb_read_leb_uint32(p, p_end, type_idx); -#if WASM_ENABLE_REF_TYPES != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 pb_read_leb_uint32(p, p_end, table_idx); #else CHECK_BUF(p, p_end, 1); @@ -8274,6 +8282,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #endif break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { CHECK_MEMORY(); @@ -8306,7 +8316,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #endif break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 case WASM_OP_TABLE_INIT: { diff --git a/doc/build_wamr.md b/doc/build_wamr.md index 6d4e60741a..798c792643 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -297,6 +297,18 @@ Currently we only profile the memory consumption of module, module_instance and - **WAMR_BUILD_EXTENDED_CONST_EXPR**=1/0, default to disable if not set. > Note: See [Extended Constant Expressions](https://github.com/WebAssembly/extended-const/blob/main/proposals/extended-const/Overview.md) for more details. +### **Enable bulk-memory-opt** +- **WAMR_BUILD_BULK_MEMORY_OPT**=1/0, default to disable if not set. +> Note: See [bulk-memory-opt](https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#bulk-memory-opt) for more details. + +### **Enable call-indirect-overlong** +- **WAMR_BUILD_CALL_INDIRECT_OVERLONG**=1/0, default to disable if not set. +> Note: See [call-indirect-overlong](https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#call-indirect-overlong) for more details. + +### **Enable Lime1 target** +- **WAMR_BUILD_LIME1**=1/0, default to disable if not set. +> Note: See [Lime1](https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1) for more details. + ### **Configurable memory access boundary check** - **WAMR_CONFIGURABLE_BOUNDS_CHECKS**=1/0, default to disable if not set > Note: If it is enabled, allow to run `iwasm --disable-bounds-checks` to disable the memory access boundary checks for interpreter mode. @@ -366,3 +378,10 @@ For Valgrind, begin with the following configurations and add additional ones as -DWAMR_DISABLE_WRITE_GS_BASE=0 #... ``` + +To enable the minimal Lime1 feature set, we need to disable some features that are on by default, such as +bulk memory and reference types: + +```Bash +cmake .. -DWAMR_BUILD_LIME1=1 -DWAMR_BUILD_BULK_MEMORY=0 -DWAMR_BUILD_REF_TYPES=0 -DDWAMR_BUILD_SIMD=0 +``` diff --git a/doc/build_wasm_app.md b/doc/build_wasm_app.md index 3c4b519b64..648d21534a 100644 --- a/doc/build_wasm_app.md +++ b/doc/build_wasm_app.md @@ -355,6 +355,8 @@ Usage: wamrc [options] -o output_file wasm_file llvmir-unopt Unoptimized LLVM IR llvmir-opt Optimized LLVM IR --disable-bulk-memory Disable the MVP bulk memory feature + --enable-bulk-memory-opt Enable bulk memory opt feature + --enable-extended-const Enable extended const expr feature --enable-multi-thread Enable multi-thread feature, the dependent features bulk-memory and thread-mgr will be enabled automatically --enable-tail-call Enable the post-MVP tail call feature @@ -363,6 +365,9 @@ Usage: wamrc [options] -o output_file wasm_file and by default it is enabled in x86-64 target and disabled in other targets --disable-ref-types Disable the MVP reference types feature + --enable-call-indirect-overlong + Enable call indirect overlong feature + --enable-lime1 Enable Lime1 --disable-aux-stack-check Disable auxiliary stack overflow/underflow check --enable-dump-call-stack Enable stack trace feature --enable-perf-profiling Enable function performance profiling diff --git a/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index c01c4fd0f6..513fd0049c 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -41,11 +41,13 @@ endif() add_definitions(-DWASM_ENABLE_INTERP=1) add_definitions(-DWASM_ENABLE_WAMR_COMPILER=1) add_definitions(-DWASM_ENABLE_BULK_MEMORY=1) +add_definitions(-DWASM_ENABLE_BULK_MEMORY_OPT=1) add_definitions(-DWASM_DISABLE_HW_BOUND_CHECK=1) 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_CALL_INDIRECT_OVERLONG=1) add_definitions(-DWASM_ENABLE_BRANCH_HINTS=1) add_definitions(-DWASM_ENABLE_CUSTOM_NAME_SECTION=1) add_definitions(-DWASM_ENABLE_AOT_STACK_FRAME=1) diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index 2ca9a175db..f0675a3511 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -159,6 +159,8 @@ print_help() printf(" llvmir-unopt Unoptimized LLVM IR\n"); printf(" llvmir-opt Optimized LLVM IR\n"); printf(" --disable-bulk-memory Disable the MVP bulk memory feature\n"); + printf(" --enable-bulk-memory-opt Enable bulk memory opt feature\n"); + printf(" --enable-extended-const Enable extended const expr feature\n"); printf(" --enable-multi-thread Enable multi-thread feature, the dependent features bulk-memory and\n"); printf(" thread-mgr will be enabled automatically\n"); printf(" --enable-tail-call Enable the post-MVP tail call feature\n"); @@ -167,6 +169,9 @@ print_help() printf(" and by default it is enabled in them and disabled in other targets\n"); printf(" --disable-ref-types Disable the MVP reference types feature, it will be disabled forcibly if\n"); printf(" GC is enabled\n"); + printf(" --enable-call-indirect-overlong\n"); + printf(" Enable call indirect overlong feature\n"); + printf(" --enable-lime1 Enable Lime1\n"); printf(" --disable-aux-stack-check Disable auxiliary stack overflow/underflow check\n"); printf(" --enable-dump-call-stack Enable stack trace feature\n"); printf(" --call-stack-features=\n"); @@ -423,9 +428,12 @@ main(int argc, char *argv[]) option.enable_simd = true; option.enable_aux_stack_check = true; option.enable_bulk_memory = true; + option.enable_bulk_memory_opt = false; option.enable_ref_types = true; + option.enable_call_indirect_overlong = false; option.enable_gc = false; option.enable_extended_const = false; + option.enable_lime1 = false; aot_call_stack_features_init_default(&option.call_stack_features); /* Process options */ @@ -519,6 +527,9 @@ main(int argc, char *argv[]) else if (!strcmp(argv[0], "--disable-bulk-memory")) { option.enable_bulk_memory = false; } + else if (!strcmp(argv[0], "--enable-bulk-memory-opt")) { + option.enable_bulk_memory_opt = true; + } else if (!strcmp(argv[0], "--enable-multi-thread")) { option.enable_bulk_memory = true; option.enable_thread_mgr = true; @@ -536,12 +547,18 @@ main(int argc, char *argv[]) else if (!strcmp(argv[0], "--disable-ref-types")) { option.enable_ref_types = false; } + else if (!strcmp(argv[0], "--enable-call-indirect-overlong")) { + option.enable_call_indirect_overlong = true; + } else if (!strcmp(argv[0], "--disable-aux-stack-check")) { option.enable_aux_stack_check = false; } else if (!strcmp(argv[0], "--enable-extended-const")) { option.enable_extended_const = true; } + else if (!strcmp(argv[0], "--enable-lime1")) { + option.enable_lime1 = true; + } else if (!strcmp(argv[0], "--enable-dump-call-stack")) { option.aux_stack_frame_type = AOT_STACK_FRAME_TYPE_STANDARD; } @@ -747,6 +764,20 @@ main(int argc, char *argv[]) option.bounds_checks = true; } + if (option.enable_bulk_memory) { + option.enable_bulk_memory_opt = true; + } + + if (option.enable_ref_types) { + option.enable_call_indirect_overlong = true; + } + + if (option.enable_lime1) { + option.enable_call_indirect_overlong = true; + option.enable_bulk_memory_opt = true; + option.enable_extended_const = true; + } + if (!use_dummy_wasm) { wasm_file_name = argv[0]; From 95f506a6e77d3ac7588eac7263f95558edfa7f3b Mon Sep 17 00:00:00 2001 From: Liu Jia Date: Mon, 15 Sep 2025 15:19:51 +0800 Subject: [PATCH 21/39] Merge commit from fork * fix overflow in check_bulk_memory_overflow * add comment --- core/iwasm/compilation/aot_emit_memory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index 0dec2ed365..f5bd859df1 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -1486,7 +1486,7 @@ LLVMValueRef check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef offset, LLVMValueRef bytes) { - LLVMValueRef maddr, max_addr, cmp, cmp1; + LLVMValueRef maddr, max_addr, cmp, cmp1, offset1; LLVMValueRef mem_base_addr; LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder); LLVMBasicBlockRef check_succ; @@ -1539,8 +1539,18 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, if (mem_data_size > 0 && mem_offset + mem_len <= mem_data_size) { /* inside memory space */ /* maddr = mem_base_addr + moffset */ + /* Perform zero extension in advance to avoid LLVMBuildInBoundsGEP2 + * interpreting a negative address due to sign extension when + * mem_offset >= 2GiB */ + if (comp_ctx->pointer_size == sizeof(uint64)) { + offset1 = I64_CONST(mem_offset); + } + else { + offset1 = I32_CONST((uint32)mem_offset); + } + CHECK_LLVM_CONST(offset1); if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, - mem_base_addr, &offset, 1, + mem_base_addr, &offset1, 1, "maddr"))) { aot_set_last_error("llvm build add failed."); goto fail; From a6a9f1f45d9f7ebf044ceac71bcf7a9ea2f90f23 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 18 Sep 2025 08:30:34 +0900 Subject: [PATCH 22/39] CI: use windows-2022 image for now (#4633) github is currently rolling out windows-2025 image. for some reasons, the "path_symlink_trailing_slashes" test case in wasi testsuite fails on windows-2025 image. someone familar with windows need to investigate what was the key difference between 2022 and 2025. until that happens, this commit makes our CI use windows-2022 image. cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4632 https://github.com/actions/runner-images/issues/12677 --- .github/workflows/build_iwasm_release.yml | 4 ++-- .github/workflows/build_llvm_libraries.yml | 4 ++-- .github/workflows/build_wamrc.yml | 4 ++-- .github/workflows/compilation_on_windows.yml | 10 +++++----- .github/workflows/release_process.yml | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build_iwasm_release.yml b/.github/workflows/build_iwasm_release.yml index 7be7db524f..0ecd48bf1c 100644 --- a/.github/workflows/build_iwasm_release.yml +++ b/.github/workflows/build_iwasm_release.yml @@ -151,7 +151,7 @@ jobs: working-directory: ${{ inputs.cwd }} - name: Compress the binary on Windows - if: inputs.runner == 'windows-latest' + if: inputs.runner == 'windows-2022' run: | tar -czf iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm.exe Compress-Archive -Path iwasm.exe -DestinationPath iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip @@ -159,7 +159,7 @@ jobs: working-directory: ${{ inputs.cwd }}/build/Release - name: compress the binary on non-Windows - if: inputs.runner != 'windows-latest' + if: inputs.runner != 'windows-2022' run: | # Follow the symlink to the actual binary file tar --dereference -czf iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm diff --git a/.github/workflows/build_llvm_libraries.yml b/.github/workflows/build_llvm_libraries.yml index 2f07d617a3..54f8781a44 100644 --- a/.github/workflows/build_llvm_libraries.yml +++ b/.github/workflows/build_llvm_libraries.yml @@ -118,11 +118,11 @@ jobs: key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }} restore-keys: | 0-ccache-${{ inputs.os }} - if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest' + if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-2022' # Install tools on Windows - run: choco install -y ccache ninja - if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest' + if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-2022' - name: Build LLVM libraries if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' diff --git a/.github/workflows/build_wamrc.yml b/.github/workflows/build_wamrc.yml index 419edec384..d74805c3cd 100644 --- a/.github/workflows/build_wamrc.yml +++ b/.github/workflows/build_wamrc.yml @@ -87,7 +87,7 @@ jobs: working-directory: wamr-compiler - name: Compress the binary on Windows - if: inputs.runner == 'windows-latest' && inputs.release + if: inputs.runner == 'windows-2022' && inputs.release run: | tar -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc.exe Compress-Archive -Path wamrc.exe -DestinationPath wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip @@ -95,7 +95,7 @@ jobs: working-directory: wamr-compiler/build/Release - name: compress the binary on non-Windows - if: inputs.runner != 'windows-latest' && inputs.release + if: inputs.runner != 'windows-2022' && inputs.release run: | # Follow the symlink to the actual binary file tar --dereference -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc diff --git a/.github/workflows/compilation_on_windows.yml b/.github/workflows/compilation_on_windows.yml index 543880048d..003a6ba988 100644 --- a/.github/workflows/compilation_on_windows.yml +++ b/.github/workflows/compilation_on_windows.yml @@ -1,7 +1,7 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -name: compilation on windows-latest +name: compilation on windows-2022 on: # will be triggered on PR events @@ -63,11 +63,11 @@ jobs: actions: write uses: ./.github/workflows/build_llvm_libraries.yml with: - os: "windows-latest" + os: "windows-2022" arch: "AArch64 ARM Mips RISCV X86" build_iwasm: - runs-on: windows-latest + runs-on: windows-2022 strategy: matrix: build_options: @@ -105,7 +105,7 @@ jobs: strategy: matrix: include: - - os: windows-latest + - os: windows-2022 llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }} steps: - name: checkout @@ -136,7 +136,7 @@ jobs: working-directory: wamr-compiler test: - runs-on: windows-latest + runs-on: windows-2022 needs: [build_iwasm, build_wamrc] strategy: fail-fast: false diff --git a/.github/workflows/release_process.yml b/.github/workflows/release_process.yml index 857036662d..621f8c2f89 100644 --- a/.github/workflows/release_process.yml +++ b/.github/workflows/release_process.yml @@ -105,7 +105,7 @@ jobs: needs: [create_tag, create_release] uses: ./.github/workflows/build_llvm_libraries.yml with: - os: "windows-latest" + os: "windows-2022" arch: "AArch64 ARM Mips RISCV X86" # @@ -142,7 +142,7 @@ jobs: with: llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }} release: true - runner: windows-latest + runner: windows-2022 upload_url: ${{ needs.create_release.outputs.upload_url }} ver_num: ${{ needs.create_tag.outputs.new_ver }} @@ -180,7 +180,7 @@ jobs: with: cwd: product-mini/platforms/windows llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }} - runner: windows-latest + runner: windows-2022 upload_url: ${{ needs.create_release.outputs.upload_url }} ver_num: ${{ needs.create_tag.outputs.new_ver}} From 5ba1b331c3cbed17d0d922d9f8e9488ef4165835 Mon Sep 17 00:00:00 2001 From: James Marsh Date: Mon, 22 Sep 2025 22:58:05 +0100 Subject: [PATCH 23/39] Add missing condition for V128 in WASM_OP_TEE_LOCAL --- core/iwasm/interpreter/wasm_interp_fast.c | 4 ++ .../ba-issues/issues/issue-4643/test.wasm | Bin 0 -> 77 bytes .../ba-issues/issues/issue-4643/test.wat | 43 ++++++++++++++++++ .../regression/ba-issues/running_config.json | 16 +++++++ 4 files changed, 63 insertions(+) create mode 100644 tests/regression/ba-issues/issues/issue-4643/test.wasm create mode 100644 tests/regression/ba-issues/issues/issue-4643/test.wat diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index a326018efc..90bdb8f17d 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -5057,6 +5057,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, PUT_I64_TO_ADDR((uint32 *)(frame_lp + local_offset), GET_I64_FROM_ADDR(frame_lp + addr1)); } + else if (local_type == VALUE_TYPE_V128) { + PUT_V128_TO_ADDR((frame_lp + local_offset), + GET_V128_FROM_ADDR(frame_lp + addr1)); + } #if WASM_ENABLE_GC != 0 else if (wasm_is_type_reftype(local_type)) { PUT_REF_TO_ADDR((uint32 *)(frame_lp + local_offset), diff --git a/tests/regression/ba-issues/issues/issue-4643/test.wasm b/tests/regression/ba-issues/issues/issue-4643/test.wasm new file mode 100644 index 0000000000000000000000000000000000000000..0b6d62b5a95914dfb9e18b87fc95b12676d9d425 GIT binary patch literal 77 zcmZQbEY4+QU|?WmVN76PU}j=uU}a`xU}P6&V#`g<%`d8CVql9eE=epZVPN2rXOv}X ZVyt7V{>uZ>!vw_4K+FQfN==MX+yJdC3akJC literal 0 HcmV?d00001 diff --git a/tests/regression/ba-issues/issues/issue-4643/test.wat b/tests/regression/ba-issues/issues/issue-4643/test.wat new file mode 100644 index 0000000000..1fecee5944 --- /dev/null +++ b/tests/regression/ba-issues/issues/issue-4643/test.wat @@ -0,0 +1,43 @@ +(module + (memory 1) + (export "memory" (memory 0)) + + (func $test + ;; Add 130 i64 locals (260 slots) to push v128 past offset 256 + (local $d0 i64) (local $d1 i64) (local $d2 i64) (local $d3 i64) (local $d4 i64) + (local $d5 i64) (local $d6 i64) (local $d7 i64) (local $d8 i64) (local $d9 i64) + (local $d10 i64) (local $d11 i64) (local $d12 i64) (local $d13 i64) (local $d14 i64) + (local $d15 i64) (local $d16 i64) (local $d17 i64) (local $d18 i64) (local $d19 i64) + (local $d20 i64) (local $d21 i64) (local $d22 i64) (local $d23 i64) (local $d24 i64) + (local $d25 i64) (local $d26 i64) (local $d27 i64) (local $d28 i64) (local $d29 i64) + (local $d30 i64) (local $d31 i64) (local $d32 i64) (local $d33 i64) (local $d34 i64) + (local $d35 i64) (local $d36 i64) (local $d37 i64) (local $d38 i64) (local $d39 i64) + (local $d40 i64) (local $d41 i64) (local $d42 i64) (local $d43 i64) (local $d44 i64) + (local $d45 i64) (local $d46 i64) (local $d47 i64) (local $d48 i64) (local $d49 i64) + (local $d50 i64) (local $d51 i64) (local $d52 i64) (local $d53 i64) (local $d54 i64) + (local $d55 i64) (local $d56 i64) (local $d57 i64) (local $d58 i64) (local $d59 i64) + (local $d60 i64) (local $d61 i64) (local $d62 i64) (local $d63 i64) (local $d64 i64) + (local $d65 i64) (local $d66 i64) (local $d67 i64) (local $d68 i64) (local $d69 i64) + (local $d70 i64) (local $d71 i64) (local $d72 i64) (local $d73 i64) (local $d74 i64) + (local $d75 i64) (local $d76 i64) (local $d77 i64) (local $d78 i64) (local $d79 i64) + (local $d80 i64) (local $d81 i64) (local $d82 i64) (local $d83 i64) (local $d84 i64) + (local $d85 i64) (local $d86 i64) (local $d87 i64) (local $d88 i64) (local $d89 i64) + (local $d90 i64) (local $d91 i64) (local $d92 i64) (local $d93 i64) (local $d94 i64) + (local $d95 i64) (local $d96 i64) (local $d97 i64) (local $d98 i64) (local $d99 i64) + (local $d100 i64) (local $d101 i64) (local $d102 i64) (local $d103 i64) (local $d104 i64) + (local $d105 i64) (local $d106 i64) (local $d107 i64) (local $d108 i64) (local $d109 i64) + (local $d110 i64) (local $d111 i64) (local $d112 i64) (local $d113 i64) (local $d114 i64) + (local $d115 i64) (local $d116 i64) (local $d117 i64) (local $d118 i64) (local $d119 i64) + (local $d120 i64) (local $d121 i64) (local $d122 i64) (local $d123 i64) (local $d124 i64) + (local $d125 i64) (local $d126 i64) (local $d127 i64) (local $d128 i64) (local $d129 i64) + + (local $vec v128) + + ;; Should hit WASM_OP_TEE_LOCAL rather than EXT_OP_TEE_LOCAL_FAST_V128 + (v128.const i32x4 1 2 3 4) + (local.tee $vec) + (drop) + ) + + (export "_start" (func $test)) +) diff --git a/tests/regression/ba-issues/running_config.json b/tests/regression/ba-issues/running_config.json index 9288eb9704..decc6861aa 100644 --- a/tests/regression/ba-issues/running_config.json +++ b/tests/regression/ba-issues/running_config.json @@ -1754,6 +1754,22 @@ "stdout content": "", "description": "no sanitizer 'heap-buffer-overflow'" } + }, + { + "deprecated": false, + "ids": [ + 4643 + ], + "runtime": "iwasm-default-wasi-disabled", + "file": "test.wasm", + "mode": "fast-interp", + "options": "-f _start", + "argument": "", + "expected return": { + "ret code": 0, + "stdout content": "", + "description": "no 'invalid local type'" + } } ] } From 49ac85472d70f7eaddb05c16c6e3bbb09afae417 Mon Sep 17 00:00:00 2001 From: Kiyoshi Nakao <449732+ikehara@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:24:12 +0900 Subject: [PATCH 24/39] Fix memory grow on SGX platform (#4651) * SGX: zero-initialize reserved memory in os_mmap after allocation * Add SGX-specific os_mremap to zero-clear remaining memory after memcpy * Modify core/shared/platform/linux-sgx/shared_platform.cmake not to include platform_api_memory.cmake * Modify core/shared/platform/linux-sgx/shared_platform.cmake to remove unnecessary PLATFORM_COMMON_MEMORY_SOURCE --- core/shared/platform/linux-sgx/sgx_platform.c | 39 +++++++++++++++++-- .../platform/linux-sgx/shared_platform.cmake | 3 -- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/core/shared/platform/linux-sgx/sgx_platform.c b/core/shared/platform/linux-sgx/sgx_platform.c index db350bc8f4..d259908634 100644 --- a/core/shared/platform/linux-sgx/sgx_platform.c +++ b/core/shared/platform/linux-sgx/sgx_platform.c @@ -131,8 +131,9 @@ os_is_handle_valid(os_file_handle *handle) /* implemented in posix_file.c */ #endif -void * -os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) +static void * +os_mmap_internal(void *hint, size_t size, int prot, int flags, + os_file_handle file, bool clear) { int mprot = 0; uint64 aligned_size, page_size; @@ -161,6 +162,10 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) return NULL; } + if (clear) { + memset(ret, 0, aligned_size); + } + if (prot & MMAP_PROT_READ) mprot |= SGX_PROT_READ; if (prot & MMAP_PROT_WRITE) @@ -179,6 +184,30 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) return ret; } +void * +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) +{ + return os_mmap_internal(hint, size, prot, flags, file, true); +} + +void * +os_mremap(void *old_addr, size_t old_size, size_t new_size) +{ + void *new_memory = + os_mmap_internal(NULL, new_size, MMAP_PROT_WRITE | MMAP_PROT_READ, 0, + os_get_invalid_handle(), false); + if (!new_memory) { + return NULL; + } + size_t copy_size = new_size < old_size ? new_size : old_size; + memcpy(new_memory, old_addr, copy_size); + if (new_size > copy_size) { + memset((char *)new_memory + copy_size, 0, new_size - copy_size); + } + os_munmap(old_addr, old_size); + return new_memory; +} + void os_munmap(void *addr, size_t size) { @@ -216,8 +245,10 @@ os_mprotect(void *addr, size_t size, int prot) void os_dcache_flush(void) -{} +{ +} void os_icache_flush(void *start, size_t len) -{} +{ +} diff --git a/core/shared/platform/linux-sgx/shared_platform.cmake b/core/shared/platform/linux-sgx/shared_platform.cmake index 9cd765be4e..e8e1670058 100644 --- a/core/shared/platform/linux-sgx/shared_platform.cmake +++ b/core/shared/platform/linux-sgx/shared_platform.cmake @@ -37,9 +37,6 @@ else() set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE}) endif() -include (${CMAKE_CURRENT_LIST_DIR}/../common/memory/platform_api_memory.cmake) -set (source_all ${source_all} ${PLATFORM_COMMON_MEMORY_SOURCE}) - file (GLOB source_all_untrusted ${PLATFORM_SHARED_DIR}/untrusted/*.c) set (PLATFORM_SHARED_SOURCE ${source_all}) From 57cd389dfd7d9ccd8da7d52aea00166d4b534945 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 11:26:02 +0800 Subject: [PATCH 25/39] build(deps): Bump ossf/scorecard-action from 2.4.2 to 2.4.3 (#4660) Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.4.2 to 2.4.3. - [Release notes](https://github.com/ossf/scorecard-action/releases) - [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md) - [Commits](https://github.com/ossf/scorecard-action/compare/05b42c624433fc40578a4040d5cf5e36ddca8cde...4eaacf0543bb3f2c246792bd56e8cdeffafb205a) --- updated-dependencies: - dependency-name: ossf/scorecard-action dependency-version: 2.4.3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/supply_chain.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index 73fb683ee0..22b382a191 100644 --- a/.github/workflows/supply_chain.yml +++ b/.github/workflows/supply_chain.yml @@ -39,7 +39,7 @@ jobs: persist-credentials: false - name: "Run analysis" - uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2 + uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3 with: results_file: results.sarif results_format: sarif From fbef624118038e0b763245270189e8af9bc16977 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 11:26:10 +0800 Subject: [PATCH 26/39] build(deps): Bump github/codeql-action from 3.30.1 to 3.30.6 (#4659) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.30.1 to 3.30.6. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.30.1...v3.30.6) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.30.6 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 6 +++--- .github/workflows/supply_chain.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a2548f1d90..5a5afec1fc 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.30.1 + uses: github/codeql-action/init@v3.30.6 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.30.1 + uses: github/codeql-action/analyze@v3.30.6 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.30.1 + uses: github/codeql-action/upload-sarif@v3.30.6 with: sarif_file: ${{ steps.step1.outputs.sarif-output }} category: "/language:${{matrix.language}}" diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index 22b382a191..407a7113fd 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@144880b6f0c9977178ab4000985a49023783178f + uses: github/codeql-action/upload-sarif@065c6cfb7809de8db2167a953b5b622491cda914 with: sarif_file: results.sarif From 326eeec615b6971c04cdfb88baed2f97171e5fed Mon Sep 17 00:00:00 2001 From: Liu Jia Date: Thu, 9 Oct 2025 11:35:12 +0800 Subject: [PATCH 27/39] Add new cases in ARC relocation of AOT (#4653) * add new case for arc relocation. R_ARC_S21H_PCREL, R_ARC_S21W_PCREL --- core/iwasm/aot/arch/aot_reloc_arc.c | 78 ++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/core/iwasm/aot/arch/aot_reloc_arc.c b/core/iwasm/aot/arch/aot_reloc_arc.c index 3329629987..2ce1154426 100644 --- a/core/iwasm/aot/arch/aot_reloc_arc.c +++ b/core/iwasm/aot/arch/aot_reloc_arc.c @@ -310,6 +310,80 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, int32 symbol_index, char *error_buf, uint32 error_buf_size) { switch (reloc_type) { + case R_ARC_S21H_PCREL: + { + uint32 insn = LOAD_I32(target_section_addr + reloc_offset); + int32 addend, value; + uintptr_t S, P; + intptr_t A; + + CHECK_RELOC_OFFSET(sizeof(void *)); + + /* Convert from middle endian */ + insn = middle_endian_convert(insn); + + /* Extract the first 10 bits from Position 6 to 15 in insn */ + addend = (insn << 16) >> 22; + addend = addend << 10; + /* Extract the remaining 10 bits from Position 17 to 26 in insn */ + addend |= ((insn << 5) >> 22); + /* Fill in 1 bits to get the 21 bit Offset Value */ + addend = addend << 1; + + /* (S + A) - P */ + S = (uintptr_t)(uint8 *)symbol_addr; + A = (intptr_t)reloc_addend; + P = (uintptr_t)(target_section_addr + reloc_offset); + P &= (uintptr_t)~1; + value = (int32)(S + A + addend - P); + + insn = insn & 0xf801003f; + insn |= ((((value >> 1) & 0x3ff) << 17) + | (((value >> 1) & 0xffc00) >> 4)); + + /* Convert to middle endian */ + insn = middle_endian_convert(insn); + + STORE_U32(target_section_addr + reloc_offset, insn); + break; + } + case R_ARC_S21W_PCREL: + { + uint32 insn = LOAD_I32(target_section_addr + reloc_offset); + int32 addend, value; + uintptr_t S, P; + intptr_t A; + + CHECK_RELOC_OFFSET(sizeof(void *)); + + /* Convert from middle endian */ + insn = middle_endian_convert(insn); + + /* Extract the first 10 bits from Position 6 to 15 in insn */ + addend = (insn << 16) >> 22; + addend = addend << 9; + /* Extract the remaining 9 bits from Position 18 to 26 in insn */ + addend |= ((insn << 5) >> 23); + /* Fill in 2 bits to get the 21 bit Offset Value */ + addend = addend << 2; + + /* (S + A) - P */ + S = (uintptr_t)(uint8 *)symbol_addr; + A = (intptr_t)reloc_addend; + P = (uintptr_t)(target_section_addr + reloc_offset); + P &= (uintptr_t)~3; + value = (int32)(S + A + addend - P); + + insn = insn & 0xf803003f; + insn |= ((((value >> 2) & 0x1ff) << 18) + | (((value >> 2) & 0x7fe00) >> 3)); + + /* Convert to middle endian */ + insn = middle_endian_convert(insn); + + STORE_U32(target_section_addr + reloc_offset, insn); + break; + } case R_ARC_S25H_PCREL: { uint32 insn = LOAD_I32(target_section_addr + reloc_offset); @@ -340,8 +414,8 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, insn = insn & 0xf8010030; insn |= ((((value >> 1) & 0x3ff) << 17) - | (((value >> 1) & 0xffc00) >> 3) - | (((value >> 1) & 0xf00000) >> 19)); + | (((value >> 1) & 0xffc00) >> 4) + | (((value >> 1) & 0xf00000) >> 20)); /* Convert to middle endian */ insn = middle_endian_convert(insn); From 74cdf0b8c1b869d711e34f540bde8fb879bbb39e Mon Sep 17 00:00:00 2001 From: Zhenwei Jin <109658203+kylo5aby@users.noreply.github.com> Date: Thu, 9 Oct 2025 12:04:29 +0800 Subject: [PATCH 28/39] Add import functions callback (#4606) Signed-off-by: zhenweijin --- .../compilation_on_android_ubuntu.yml | 8 ++ .github/workflows/compilation_on_macos.yml | 8 ++ .github/workflows/nightly_run.yml | 8 ++ core/iwasm/include/wasm_export.h | 16 +++ samples/import-func-callback/CMakeLists.txt | 106 ++++++++++++++++++ samples/import-func-callback/README.md | 14 +++ samples/import-func-callback/src/main.c | 97 ++++++++++++++++ samples/import-func-callback/wasm-apps/test.c | 17 +++ 8 files changed, 274 insertions(+) create mode 100644 samples/import-func-callback/CMakeLists.txt create mode 100644 samples/import-func-callback/README.md create mode 100644 samples/import-func-callback/src/main.c create mode 100644 samples/import-func-callback/wasm-apps/test.c diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 01356dc66e..98d4b1b723 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -622,6 +622,14 @@ jobs: ./shared_heap_test ./shared_heap_test --aot + - name: Build Sample [import-func-callback] + run: | + cd samples/import-func-callback + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + ./import-func-callback + test: needs: [ diff --git a/.github/workflows/compilation_on_macos.yml b/.github/workflows/compilation_on_macos.yml index 8387ee0c75..912bf7dea7 100644 --- a/.github/workflows/compilation_on_macos.yml +++ b/.github/workflows/compilation_on_macos.yml @@ -422,3 +422,11 @@ jobs: cmake --build . --config Debug --parallel 4 ./shared_heap_test ./shared_heap_test --aot + + - name: Build Sample [import-func-callback] + run: | + cd samples/import-func-callback + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + ./import-func-callback diff --git a/.github/workflows/nightly_run.yml b/.github/workflows/nightly_run.yml index 260a7e97c4..58532aac85 100644 --- a/.github/workflows/nightly_run.yml +++ b/.github/workflows/nightly_run.yml @@ -568,6 +568,14 @@ jobs: ./shared_heap_test ./shared_heap_test --aot + - name: Build Sample [import-func-callback] + run: | + cd samples/import-func-callback + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + ./import-func-callback + test: needs: [build_iwasm, build_llvm_libraries_on_ubuntu, build_wamrc] runs-on: ${{ matrix.os }} diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 81efb8f6f7..0ab22f7112 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1526,6 +1526,14 @@ wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst, /** * Get the number of import items for a WASM module * + * Typical usage scenario: + * Combine this function with wasm_runtime_get_import_count() to traverse + * all import items in a module. Use import_type.kind to filter and identify + * different types of import items. + * + * Example usage (as wasm_runtime_for_each_import_func() in + * samples/import-func-callback) + * * @param module the WASM module * * @return the number of imports (zero for none), or -1 for failure @@ -1536,6 +1544,14 @@ wasm_runtime_get_import_count(const wasm_module_t module); /** * Get information about a specific WASM module import * + * Typical usage scenario: + * Combine this function with wasm_runtime_get_import_count() to traverse + * all import items in a module. Use import_type.kind to filter and identify + * different types of import items. + * + * Example usage (as wasm_runtime_for_each_import_func() in + * samples/import-func-callback) + * * @param module the WASM module * @param import_index the desired import index * @param import_type the location to store information about the import diff --git a/samples/import-func-callback/CMakeLists.txt b/samples/import-func-callback/CMakeLists.txt new file mode 100644 index 0000000000..be0cc5032a --- /dev/null +++ b/samples/import-func-callback/CMakeLists.txt @@ -0,0 +1,106 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required (VERSION 3.14) + +include(CheckPIESupported) +include(ExternalProject) + +project (import-func-callback) + +set (CMAKE_CXX_STANDARD 17) + +################ runtime settings ################ +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +if (APPLE) + add_definitions(-DBH_PLATFORM_DARWIN) +endif () + +# Reset default linker flags +set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") + +# WAMR features switch + +# Set WAMR_BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" +if (NOT DEFINED WAMR_BUILD_TARGET) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") + set (WAMR_BUILD_TARGET "AARCH64") + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set (WAMR_BUILD_TARGET "RISCV64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (WAMR_BUILD_TARGET "X86_64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) + # Build as X86_32 by default in 32-bit platform + set (WAMR_BUILD_TARGET "X86_32") + else () + message(SEND_ERROR "Unsupported build target platform!") + endif () +endif () + +if (NOT CMAKE_BUILD_TYPE) + set (CMAKE_BUILD_TYPE Debug) +endif () + +set (WAMR_BUILD_INTERP 1) + +if (NOT MSVC) + # linker flags + 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") + endif () + endif () +endif () + +# build out vmlib +set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) + +################ wasm application ################ +if (NOT DEFINED WASI_SDK_DIR) + set (WASI_SDK_DIR "/opt/wasi-sdk") +endif () + +ExternalProject_Add(wasm_app + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps + BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/wasm-apps + CONFIGURE_COMMAND "" + BUILD_COMMAND ${CMAKE_COMMAND} -E env + ${WASI_SDK_DIR}/bin/clang + -nostdlib + --target=wasm32 + -Wl,--no-entry + -Wl,--export=test + -Wl,--allow-undefined + -o ${CMAKE_CURRENT_BINARY_DIR}/wasm-apps/test.wasm + ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps/test.c + BUILD_ALWAYS TRUE + INSTALL_COMMAND "" +) + +################ application related ################ +include_directories(${CMAKE_CURRENT_LIST_DIR}/src) +include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) + +add_executable (import-func-callback src/main.c ${UNCOMMON_SHARED_SOURCE}) + +add_dependencies(import-func-callback wasm_app) + +check_pie_supported() +set_target_properties (import-func-callback PROPERTIES POSITION_INDEPENDENT_CODE ON) + +if (APPLE) + target_link_libraries (import-func-callback vmlib -lm -ldl -lpthread ${LLVM_AVAILABLE_LIBS}) +else () + target_link_libraries (import-func-callback vmlib -lm -ldl -lpthread -lrt ${LLVM_AVAILABLE_LIBS}) +endif () diff --git a/samples/import-func-callback/README.md b/samples/import-func-callback/README.md new file mode 100644 index 0000000000..ee822388b5 --- /dev/null +++ b/samples/import-func-callback/README.md @@ -0,0 +1,14 @@ +# "import function callback" sample introduction + +This sample demonstrates how to use import function callbacks to handle WebAssembly modules that import external functions. The sample shows how to register callback functions for imported functions and execute them when the WASM module loads these imported functions. + +The sample includes a WASM module that imports external functions and a host application that provides callback `import_func_type_callback` for these imported functions. + +## Build and run the sample + +```bash +mkdir build && cd build +cmake .. +cmake --build . --config Release +./import-func-callback +``` diff --git a/samples/import-func-callback/src/main.c b/samples/import-func-callback/src/main.c new file mode 100644 index 0000000000..a5f9a9acfe --- /dev/null +++ b/samples/import-func-callback/src/main.c @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "wasm_export.h" +#include "bh_read_file.h" +#include "bh_getopt.h" +#include "assert.h" + +typedef void (*wasm_func_type_callback_t)(const wasm_import_t *import_type); + +const char *import_func_names[] = { "import_func1", "import_func2" }; + +void +import_func_type_callback(const wasm_import_t *import_type) +{ + int ret = 0; + for (uint32_t i = 0; + i < sizeof(import_func_names) / sizeof(import_func_names[0]); i++) { + if (strcmp(import_type->name, import_func_names[i]) == 0) { + ret = 1; + break; + } + } + assert(ret == 1); + return; +} + +/* Iterate over all import functions in the module */ +void +wasm_runtime_for_each_import_func(const wasm_module_t module, + wasm_func_type_callback_t callback) +{ + int32_t import_count = wasm_runtime_get_import_count(module); + if (import_count <= 0) + return; + if (callback == NULL) + return; + + for (int32_t i = 0; i < import_count; ++i) { + wasm_import_t import_type; + wasm_runtime_get_import_type(module, i, &import_type); + + if (import_type.kind != WASM_IMPORT_EXPORT_KIND_FUNC) { + continue; + } + + callback(&import_type); + } +} + +int +main(int argc, char *argv_main[]) +{ + static char global_heap_buf[512 * 1024]; + wasm_module_t module = NULL; + uint32 buf_size; + char *buffer = NULL; + const char *wasm_path = "wasm-apps/test.wasm"; + char error_buf[128]; + + RuntimeInitArgs init_args; + memset(&init_args, 0, sizeof(RuntimeInitArgs)); + + init_args.mem_alloc_type = Alloc_With_Pool; + init_args.mem_alloc_option.pool.heap_buf = global_heap_buf; + init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); + + if (!wasm_runtime_full_init(&init_args)) { + printf("Init runtime environment failed.\n"); + return -1; + } + buffer = bh_read_file_to_buffer(wasm_path, &buf_size); + + if (!buffer) { + printf("Open wasm app file [%s] failed.\n", wasm_path); + goto fail; + } + + module = wasm_runtime_load((uint8 *)buffer, buf_size, error_buf, + sizeof(error_buf)); + if (!module) { + printf("Load wasm app file [%s] failed.\n", wasm_path); + goto fail; + } + + wasm_runtime_for_each_import_func(module, import_func_type_callback); + +fail: + if (module) + wasm_runtime_unload(module); + if (buffer) + BH_FREE(buffer); + wasm_runtime_destroy(); + return 0; +} diff --git a/samples/import-func-callback/wasm-apps/test.c b/samples/import-func-callback/wasm-apps/test.c new file mode 100644 index 0000000000..5e6f30b5c6 --- /dev/null +++ b/samples/import-func-callback/wasm-apps/test.c @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +extern int +import_func1(int a, int b); +extern int +import_func2(int a); + +int +test() +{ + int a = import_func1(1, 2); + int b = import_func2(3); + return a + b; +} From 635576c607bd77f65776db75f767d0b33fb28e74 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 9 Oct 2025 12:05:59 +0800 Subject: [PATCH 29/39] Enhance security guidelines for identifying vulnerabilities (#4584) * Enhance security guidelines for identifying vulnerabilities. It includes a tiered-support-list * Update issue templates. Follow [the instructions at GitHub Documentation](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#creating-issue-templates) to recreate issue templates. Apply the new format and add new fields. --- .github/ISSUE_TEMPLATE/blank_issue.md | 5 - .github/ISSUE_TEMPLATE/bug_report.md | 41 ++++ .github/ISSUE_TEMPLATE/config.yml | 1 + .github/ISSUE_TEMPLATE/feature_request.md | 20 ++ .github/ISSUE_TEMPLATE/improvement.md | 28 --- .github/ISSUE_TEMPLATE/report_bug.md | 36 ---- .github/workflows/compilation_on_zephyr.yml | 2 + doc/build_wamr.md | 2 + doc/security_need_to_know.md | 41 +++- doc/tiered_support.md | 196 ++++++++++++++++++++ 10 files changed, 296 insertions(+), 76 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/blank_issue.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md delete mode 100644 .github/ISSUE_TEMPLATE/improvement.md delete mode 100644 .github/ISSUE_TEMPLATE/report_bug.md create mode 100644 doc/tiered_support.md diff --git a/.github/ISSUE_TEMPLATE/blank_issue.md b/.github/ISSUE_TEMPLATE/blank_issue.md deleted file mode 100644 index 57febe7d5f..0000000000 --- a/.github/ISSUE_TEMPLATE/blank_issue.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -name: Blank Issue -about: Create a blank issue. -title: '' ---- diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000000..9fa3fad944 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,41 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "Add a placeholder for issue title. ex: [BUG]" +labels: bug +assignees: "" +--- + +**Is it a security vulnerability?** +If it results in a crash or hang, please refer to [a quick checklist](../../doc/security_need_to_know.md#is-this-bug-considered-a-security-vulnerability) to determine if it is a security vulnerability. If you are still unsure, please report it through [a security advisor](https://github.com/bytecodealliance/wasm-micro-runtime/security/advisories) and allow the maintainer to make a decision. Thank you. + +**Describe the bug** +A clear and concise description of what the bug is. + +**Version** +Information like tags, release version, commits. + +**To Reproduce** +Steps to reproduce the behavior: + +1. Compile iwasm with flags like '...' +2. (Optional) Compile wamrc with flags like '....' +3. (Optional) Run wamrc with CLI options like '...' to generate .aot +4. Run iwasm with CLI options like '...' +5. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Actual Result** +What you've got. + +**Desktop (please complete the following information):** + +- Arch [e.g. x86_64, arm64, 32bit] +- Board [e.g. STM32F407] +- OS [e.g. Linux, Windows, macOS, FreeRTOS] +- Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000000..0086358db1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000000..f20f45edee --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: 'Add a placeholder for issue title. ex: [RFC]' +labels: help wanted +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/improvement.md b/.github/ISSUE_TEMPLATE/improvement.md deleted file mode 100644 index ffdf0906ff..0000000000 --- a/.github/ISSUE_TEMPLATE/improvement.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -name: Improvement -about: A feature request or code improvement. -title: '' -labels: '' -assignees: '' ---- - -Thanks for filing a feature request! Please fill out the TODOs below. - -#### Feature - -TODO: Brief description of the feature/improvement you'd like to see in WAMR - -#### Benefit - -TODO: What is the value of adding this in WAMR? What problems does it solve? - -#### Implementation - -TODO: Do you have an implementation plan, and/or ideas for data structures or -algorithms to use? - -#### Alternatives - -TODO: What are the alternative implementation approaches or alternative ways to -solve the problem that this feature would solve? How do these alternatives -compare to this proposal? diff --git a/.github/ISSUE_TEMPLATE/report_bug.md b/.github/ISSUE_TEMPLATE/report_bug.md deleted file mode 100644 index d3058c9ca1..0000000000 --- a/.github/ISSUE_TEMPLATE/report_bug.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -name: WAMR bug or defect report -about: Report a bug or defect in WAMR -title: '' ---- - -Thanks for filing a bug or defect report! Please fill out the TODOs below. - -### Subject of the issue - -Describe the bug or defect here. - -### Test case - -Upload the related wasm file, wast file or the source files if you can. - -### Your environment - -* Host OS -* WAMR version, platform, cpu architecture, running mode, etc. - -### Steps to reproduce - -Tell us how to reproduce this bug or defect. - -### Expected behavior - -Tell us what should happen - -### Actual behavior - -Tell us what happens instead - -### Extra Info - -Anything else you'd like to add? diff --git a/.github/workflows/compilation_on_zephyr.yml b/.github/workflows/compilation_on_zephyr.yml index 7342804ac8..06ff334f1e 100644 --- a/.github/workflows/compilation_on_zephyr.yml +++ b/.github/workflows/compilation_on_zephyr.yml @@ -11,6 +11,7 @@ on: - synchronize paths: - ".github/**" + - "!.github/ISSUE_TEMPLATE/**" - "build-scripts/**" - "core/**" - "!core/deps/**" @@ -27,6 +28,7 @@ on: - "dev/**" paths: - ".github/**" + - "!.github/ISSUE_TEMPLATE/**" - "build-scripts/**" - "core/**" - "!core/deps/**" diff --git a/doc/build_wamr.md b/doc/build_wamr.md index 798c792643..fa6c6af8db 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -20,6 +20,8 @@ add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) The script `runtime_lib.cmake` defines a number of variables for configuring the WAMR runtime features. You can set these variables in your CMakeList.txt or pass the configurations from cmake command line. +Please refer to [a full list of configuration options](./tired_support.md#appendix-all-compilation-flags). + ### **Configure platform and architecture** - **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). diff --git a/doc/security_need_to_know.md b/doc/security_need_to_know.md index b0d076d38d..f760e1e110 100644 --- a/doc/security_need_to_know.md +++ b/doc/security_need_to_know.md @@ -15,10 +15,41 @@ It is commonly stated that a security issue is an issue that: Given that WASI is a set of Capability-based APIs, all unauthorized actions are not supposed to happen. Most of the above security concerns can be alleviated. What remains for us is to ensure that the execution of Wasm modules is secure. In other words, do not compromise the sandbox. Unless it is explicitly disabled beforehand. -Thus, we share most of the criteria for judging security issues with [the Bytecode Alliance](https://github.com/bytecodealliance/rfcs/blob/main/accepted/what-is-considered-a-security-bug.md#definition). +### Is this bug considered a security vulnerability? -> [!NOTE] -> keep updating this document as the project evolves. +#### For someone who finds a problem + +if a bug **results in crash or hang**, please treat it as a security problem and report it to a security advisor. The maintainer will look into it and change its category if needed. It is better safe than sorry. + +If the author of an issue(results in crash or hang) can go through the following checklist and answer all questions with "No", it is fine to mark it as a regular bug. If not, please report it as a security issue. + +--- + +#### For those maintainers + +please use the following guidelines to determine if a bug or advisory is a security issue: + +Only bugs that affect [tier A platforms or features](./tiered_support.md) should be considered. + +Actions that differ from Wasm rules (like calculating wrong values) are not seen as security issues as long as they stay within the sandbox. + +By default, native APIs and CLIs are following the principle of **caller guarantee**. If the caller provides incorrect parameters or users input malformed options, it is not a security issue. For example, if a user passes an invalid file descriptor to `fd_read`, it is not a security issue. + +.wasm are not trusted. Malformed .wasm files should be handled gracefully. If a .wasm file causes a runtime crash or hang, it is a security issue. On the other hand, it's expected that aot runtime alone doesn't provide the same guarantee. So user-crafted .aot can cause anything, including crashes or hangs. They are not considered security issues. + +A denial-of-service (DoS) attack is a cyberattack that aims to make a computer or network resource unavailable to its users. If the service (runtime in this case) can recover and start another module or run another function within the same instance, it is not considered unavailable, and thus not a Denial of Service (DoS). + +Another type of execution problem we usually do not classify as a security one is if it is caused by an infinite loop or incorrect recursive function call chain. + +### When a maintainer identify a problem that should be classified as a security vulnerability + +Once a maintainer realizes an issue or PR describes a real or possible security vulnerability, act quickly to minimize exposure. Do not share technical details publicly on the issue or PR anymore. Maintainers should: + +- Close or edit the public discussion. Thank the person who reported it and explain that security-related issues should go through the Security Advisory process. Close the public issue or pull request as soon as possible to prevent further public sharing. If details have already been shared, consider editing or asking GitHub staff to remove sensitive content. + +- Create a Security Advisory. Invite the reporter to join as a collaborator or reporter. If the reporter is uncomfortable using GitHub Security Advisories, offer another private communication method, such as email. + +- Follow the guidelines in [the security issue runbook](./security_issue_runbook.md) for the next steps. ## reporting a security issue @@ -26,8 +57,4 @@ Follow the [same guidelines](https://bytecodealliance.org/security) as other pro ## managing a security issue -Before reporting an issue, particularly one related to crashing, consult [the cheat sheet](https://github.com/bytecodealliance/rfcs/blob/main/accepted/what-is-considered-a-security-bug.md#cheat-sheet-is-this-bug-considered-a-security-vulnerability), _Report a security vulnerability_ if it qualifies. - -Upon receiving an issue, thoroughly review [the cheat sheet](https://github.com/bytecodealliance/rfcs/blob/main/accepted/what-is-considered-a-security-bug.md#cheat-sheet-is-this-bug-considered-a-security-vulnerability) to assess and _Report a security vulnerability_ if the issue is indeed a security vulnerability. - Once a security issue is confirmed, please refer to [the runbook](./security_issue_runbook.md) for the subsequent steps to take. diff --git a/doc/tiered_support.md b/doc/tiered_support.md new file mode 100644 index 0000000000..565d347b29 --- /dev/null +++ b/doc/tiered_support.md @@ -0,0 +1,196 @@ +# Tiered Supported + +**Tier definitions** + +- **A — Production Ready:** fully tested and stable. +- **B — Almost Production Ready:** partially tested; close to production. +- **C — Experimental / Not Production Ready:** unfinished or volatile. + +The condition _tested_ mentioned above specifically refers to whether there are enough tests in CI. + +## Architecture Support + +| Architecture | Tier | +| ------------ | ----- | +| **x86-64** | **A** | +| **x86-32** | **A** | +| AArch64 | B | +| ARC | B | +| ARM | B | +| RISCV32 | B | +| RISCV64 | B | +| THUMB | B | +| XTENSA | B | +| MIPS | C | + +## OS / Platform Support + +| Platform | Tier | +| ------------------ | ----- | +| **NuttX** | **A** | +| **Ubuntu** | **A** | +| Android | B | +| macOS | B | +| Windows | B | +| Zephyr | B | +| AliOS-Things | C | +| Cosmopolitan | C | +| ESP-IDF (FreeRTOS) | C | +| FreeBSD | C | +| iOS | C | +| RT-Thread | C | +| RIOT | C | +| VxWorks | C | + +## WebAssembly Proposal Support + +> During configuration, It is able to disable or enable the following features by setting the corresponding flags (see Appendix). It is also possible to check features status in the configuration output. + +| WASM Proposal / Extension | Tier | +| -------------------------------------- | ----------- | +| **Bulk Memory** | A | +| **Extended Constant Expressions** | A | +| **Import/Export of Mutable Globals** | A | +| **Memory64** | A | +| **Multi-value** | A | +| **Non-trapping float-to-int** | A | +| **Reference Types** | A | +| **Shared Memory (Threads)** | A | +| **SIMD (128-bit)** | A | +| **Sign-extension Operators** | A | +| GC (Garbage Collection) | B | +| Stringref | B | +| Tail Calls | B | +| Multi-memory | C | +| Legacy Exception Handling | C | +| Branch Hinting | Unsupported | +| Custom Annotation Syntax (text format) | Unsupported | +| Exception Handling (new spec) | Unsupported | +| JS String Builtins | Unsupported | +| Relaxed SIMD | Unsupported | + +# WAMR-Specific Feature Support + +> During configuration, It is able to disable or enable the following features by setting the corresponding flags (see Appendix). It is also possible to check features status in the configuration output. + +| WAMR Feature | Tier | +| --------------------------------- | ---- | +| **AoT (wamrc)** | A | +| **AOT intrinsics** | A | +| **Fast Interpreter** | A | +| **Interpreter (classic)** | A | +| **Libc builtin** | A | +| **Libc WASI** | A | +| **Quick AOT/JIT entries** | A | +| **Shrunk memory** | A | +| **Wakeup of blocking operations** | A | +| **WASM C API** | A | +| Fast JIT | B | +| LLVM ORC JIT | B | +| Memory profiling | B | +| Module instance context[^7] | B | +| Multi-module | B | +| Perf profiling | B | +| Pthread | B | +| Shared heap | B | +| WASI threads | B | +| WASI-NN (neural network APIs) | B | +| Debug Interpreter | B | +| Debug AOT | C | +| Tier-up (Fast JIT → LLVM JIT) | C | + +--- + +# Appendix: All compilation flags + +| Compilation flags | Tiered | Default | on Ubuntu | +| ------------------------------------------- | ------ | ------- | --------- | +| WAMR_APP_THREAD_STACK_SIZE_MAX | B | ND[^1] | | +| WAMR_BH_LOG | B | ND | | +| WAMR_BH_VPRINTF | B | ND | | +| WAMR_BUILD_ALLOC_WITH_USAGE | B | ND | | +| WAMR_BUILD_ALLOC_WITH_USER_DATA | B | ND | | +| WAMR_BUILD_AOT | A | ND | 1 | +| WAMR_BUILD_AOT_INTRINSICS | A | 1[^2] | | +| WAMR_BUILD_AOT_STACK_FRAME | A | ND | | +| WAMR_BUILD_AOT_VALIDATOR | B | ND | | +| WAMR_BUILD_BULK_MEMORY | A | 1 | | +| WAMR_BUILD_COPY_CALL_STACK | B | ND | | +| WAMR_BUILD_CUSTOM_NAME_SECTION | B | ND | | +| WAMR_BUILD_DEBUG_AOT | C | ND | | +| WAMR_BUILD_DEBUG_INTERP | B | ND | | +| WAMR_BUILD_DUMP_CALL_STACK | B | ND | | +| WAMR_BUILD_DYNAMIC_AOT_DEBUG | C | ND | | +| WAMR_BUILD_EXCE_HANDLING | C | 0 | | +| WAMR_BUILD_EXTENDED_CONST_EXPR | A | 0 | | +| WAMR_BUILD_FAST_INTERP | A | ND | 1 | +| WAMR_BUILD_FAST_JIT | B | ND | | +| WAMR_BUILD_FAST_JIT_DUMP | B | ND | | +| WAMR_BUILD_GC | B | 0 | | +| WAMR_BUILD_GC_HEAP_VERIFY | B | ND | | +| WAMR_BUILD_GLOBAL_HEAP_POOL | A | ND | | +| WAMR_BUILD_GLOBAL_HEAP_SIZE | A | ND | | +| WAMR_BUILD_INSTRUCTION_METERING | C | ND | | +| WAMR_BUILD_INTERP | A | ND | 1 | +| WAMR_BUILD_INVOKE_NATIVE_GENERAL | B | ND | | +| WAMR_BUILD_JIT | B | ND | | +| WAMR_BUILD_LAZY_JIT | B | 1[^3] | | +| WAMR_BUILD_LIBC_BUILTIN | A | ND | 1 | +| WAMR_BUILD_LIBC_EMCC | C | ND | | +| WAMR_BUILD_LIBC_UVWASI | C | ND | | +| WAMR_BUILD_LIBC_WASI | A | ND | 1 | +| WAMR_BUILD_LIB_PTHREAD | B | ND | | +| WAMR_BUILD_LIB_PTHREAD_SEMAPHORE | B | ND | | +| WAMR_BUILD_LIB_RATS | C | ND | | +| WAMR_BUILD_LIB_WASI_THREADS | B | ND | | +| WAMR_BUILD_LINUX_PERF | B | ND | | +| WAMR_BUILD_LIME1 | A | NO | | +| WAMR_BUILD_LOAD_CUSTOM_SECTION | A | ND | | +| WAMR_BUILD_MEMORY64 | A | 0 | | +| WAMR_BUILD_MEMORY_PROFILING | B | ND | | +| WAMR_BUILD_MINI_LOADER | B | ND | | +| WAMR_BUILD_MODULE_INST_CONTEXT | B | ND | 1 | +| WAMR_BUILD_MULTI_MEMORY | C | 0 | | +| WAMR_BUILD_MULTI_MODULE | B | ND | | +| WAMR_BUILD_PERF_PROFILING | B | ND | | +| WAMR_BUILD_PLATFORM | - | ND | linux | +| WAMR_BUILD_QUICK_AOT_ENTRY | A | 1[^4] | | +| WAMR_BUILD_REF_TYPES | A | ND | 1 | +| WAMR_BUILD_SANITIZER | B | ND | | +| WAMR_BUILD_SGX_IPFS | C | ND | | +| WAMR_BUILD_SHARED_HEAP | A | ND | | +| WAMR_BUILD_SHARED_MEMORY | A | 0 | 1 | +| WAMR_BUILD_SHRUNK_MEMORY | A | ND | 1 | +| WAMR_BUILD_SIMD | A | ND | 1 | +| WAMR_BUILD_SIMDE | A | ND | 1 | +| WAMR_BUILD_SPEC_TEST | A | ND | | +| WAMR_BUILD_STACK_GUARD_SIZE | B | ND | | +| WAMR_BUILD_STATIC_PGO | B | ND | | +| WAMR_BUILD_STRINGREF | B | 0 | | +| WAMR_BUILD_TAIL_CALL | A | 0 | 1 | +| WAMR_BUILD_TARGET | - | ND | X86-64 | +| WAMR_BUILD_THREAD_MGR | A | ND | | +| WAMR_BUILD_WAMR_COMPILER | A | ND | | +| WAMR_BUILD_WASI_EPHEMERAL_NN | B | ND | | +| WAMR_BUILD_WASI_NN | B | ND | | +| WAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE | B | ND | | +| WAMR_BUILD_WASI_NN_ENABLE_GPU | B | ND | | +| WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH | B | ND | | +| WAMR_BUILD_WASI_NN_LLAMACPP | B | ND | | +| WAMR_BUILD_WASI_NN_ONNX | B | ND | | +| WAMR_BUILD_WASI_NN_OPENVINO | B | ND | | +| WAMR_BUILD_WASI_NN_TFLITE | B | ND | | +| WAMR_BUILD_WASI_TEST | B | ND | | +| WAMR_BUILD_WASM_CACHE | B | ND | | +| WAMR_CONFIGURABLE_BOUNDS_CHECKS | C | ND | | +| WAMR_DISABLE_APP_ENTRY | A | ND | | +| WAMR_DISABLE_HW_BOUND_CHECK | A | ND | | +| WAMR_DISABLE_STACK_HW_BOUND_CHECK | A | ND | | +| WAMR_DISABLE_WAKEUP_BLOCKING_OP | B | ND | | +| WAMR_DISABLE_WRITE_GS_BASE | B | ND | | +| WAMR_TEST_GC | B | ND | | + +[^1]: _ND_ represents _not defined_ +[^2]: active if `WAMR_BUILD_AOT` is 1 +[^3]: active if `WAMR_BUILD_FAST_JIT` or `WAMR_BUILD_JIT1` is 1 +[^4]: active if `WAMR_BUILD_AOT` or `WAMR_BUILD_JIT` is 1 From 1b9542830e9fa3d6eaabf4df16a9b7224db85473 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Thu, 9 Oct 2025 13:09:00 +0900 Subject: [PATCH 30/39] Implement invokeNative asm code for armasm64 assembler on ARM64 Windows (#4636) * Implement invokeNative asm code for armasm64 assembler on ARM64 Windows * Use more solid wrapper for armasm64 executable Signed-off-by: Hiroshi Hatake --- .../common/arch/invokeNative_armasm64.asm | 73 +++++++++++++++++++ .../arch/invokeNative_armasm64_simd.asm | 73 +++++++++++++++++++ core/iwasm/common/iwasm_common.cmake | 68 ++++++++++++++++- 3 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 core/iwasm/common/arch/invokeNative_armasm64.asm create mode 100644 core/iwasm/common/arch/invokeNative_armasm64_simd.asm diff --git a/core/iwasm/common/arch/invokeNative_armasm64.asm b/core/iwasm/common/arch/invokeNative_armasm64.asm new file mode 100644 index 0000000000..0abe160e61 --- /dev/null +++ b/core/iwasm/common/arch/invokeNative_armasm64.asm @@ -0,0 +1,73 @@ + ; Copyright (C) 2019 Intel Corporation. All rights reserved. + ; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + + AREA |.text|, CODE, READONLY, ALIGN=2 + + EXPORT invokeNative + +; ------------------------ direct call path ------------------------ + +call_func + mov x20, x30 ; save x30(lr) + blr x19 + mov sp, x22 ; restore sp saved before function call + +return_label + mov x30, x20 ; restore x30(lr) + ldp x19, x20, [sp, #0x20] + ldp x21, x22, [sp, #0x10] + ldp x23, x24, [sp, #0x0] + add sp, sp, #0x30 + ret + +; ------------------------ stack-args path ------------------------ + +handle_stack + ; Reserve aligned stack space for stack arguments and copy them + mov x23, sp + bic sp, x23, #15 ; Ensure 16-byte alignment + lsl x23, x21, #3 ; x23 = nstacks * 8 + add x23, x23, #15 + bic x23, x23, #15 + sub sp, sp, x23 + mov x23, sp + +copy_loop + cmp x21, #0 + b.eq call_func ; when done, branch back to call path + ldr x24, [x20], #8 + str x24, [x23], #8 + sub x21, x21, #1 + b copy_loop + +; ------------------------ function entry ------------------------ + +invokeNative + sub sp, sp, #0x30 + stp x19, x20, [sp, #0x20] ; save the registers + stp x21, x22, [sp, #0x10] + stp x23, x24, [sp, #0x0] + + mov x19, x0 ; x19 = function ptr + mov x20, x1 ; x20 = argv + mov x21, x2 ; x21 = nstacks + mov x22, sp ; save the sp before call function + + ; Fill in floating-point registers + ldp d0, d1, [x20], #16 + ldp d2, d3, [x20], #16 + ldp d4, d5, [x20], #16 + ldp d6, d7, [x20], #16 + + ; Fill integer registers + ldp x0, x1, [x20], #16 ; x0 = argv[8] = exec_env, x1 = argv[9] + ldp x2, x3, [x20], #16 + ldp x4, x5, [x20], #16 + ldp x6, x7, [x20], #16 + + ; Now x20 points to stack args + cmp x21, #0 + b.ne handle_stack ; backward: there are stack args + b call_func ; backward: no stack args + + END diff --git a/core/iwasm/common/arch/invokeNative_armasm64_simd.asm b/core/iwasm/common/arch/invokeNative_armasm64_simd.asm new file mode 100644 index 0000000000..d209f10751 --- /dev/null +++ b/core/iwasm/common/arch/invokeNative_armasm64_simd.asm @@ -0,0 +1,73 @@ + ; Copyright (C) 2019 Intel Corporation. All rights reserved. + ; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + + AREA |.text|, CODE, READONLY, ALIGN=2 + + EXPORT invokeNative + +; ------------------------ direct call path ------------------------ + +call_func + mov x20, x30 ; save x30(lr) + blr x19 + mov sp, x22 ; restore sp saved before function call + +return_label + mov x30, x20 ; restore x30(lr) + ldp x19, x20, [sp, #0x20] + ldp x21, x22, [sp, #0x10] + ldp x23, x24, [sp, #0x0] + add sp, sp, #0x30 + ret + +; ------------------------ stack-args path ------------------------ + +handle_stack + ; Reserve aligned stack space for stack arguments and copy them + mov x23, sp + bic sp, x23, #15 ; Ensure 16-byte alignment + lsl x23, x21, #3 ; x23 = nstacks * 8 + add x23, x23, #15 + bic x23, x23, #15 + sub sp, sp, x23 + mov x23, sp + +copy_loop + cmp x21, #0 + b.eq call_func ; when done, branch back to call path + ldr x24, [x20], #8 + str x24, [x23], #8 + sub x21, x21, #1 + b copy_loop + +; ------------------------ function entry ------------------------ + +invokeNative + sub sp, sp, #0x30 + stp x19, x20, [sp, #0x20] ; save the registers + stp x21, x22, [sp, #0x10] + stp x23, x24, [sp, #0x0] + + mov x19, x0 ; x19 = function ptr + mov x20, x1 ; x20 = argv + mov x21, x2 ; x21 = nstacks + mov x22, sp ; save the sp before call function + + ; Fill in floating-point registers + ; v0 = argv[0], v1 = argv[1], v2 = argv[2], v3 = argv[3] + ld1 {v0.2D, v1.2D, v2.2D, v3.2D}, [x20], #64 + ; v4 = argv[4], v5 = argv[5], v6 = argv[6], v7 = argv[7] + ld1 {v4.2D, v5.2D, v6.2D, v7.2D}, [x20], #64 + + ; Fill integer registers + ldp x0, x1, [x20], #16 ; x0 = argv[8] = exec_env, x1 = argv[9] + ldp x2, x3, [x20], #16 + ldp x4, x5, [x20], #16 + ldp x6, x7, [x20], #16 + + ; Now x20 points to stack args + cmp x21, #0 + b.ne handle_stack ; (backward) there are stack args + b call_func ; (backward) no stack args + + END diff --git a/core/iwasm/common/iwasm_common.cmake b/core/iwasm/common/iwasm_common.cmake index 15895b8e5e..c3653f156c 100644 --- a/core/iwasm/common/iwasm_common.cmake +++ b/core/iwasm/common/iwasm_common.cmake @@ -4,6 +4,42 @@ set (IWASM_COMMON_DIR ${CMAKE_CURRENT_LIST_DIR}) include_directories (${IWASM_COMMON_DIR}) +if (MSVC AND WAMR_BUILD_PLATFORM STREQUAL "windows" AND WAMR_BUILD_TARGET MATCHES "AARCH64.*") + if (DEFINED ENV{VCToolsInstallDir}) + # Detect host tool dir + set(_ARMASM64_CANDIDATES + "$ENV{VCToolsInstallDir}/bin/HostX64/ARM64/armasm64.exe" + "$ENV{VCToolsInstallDir}/bin/HostARM64/arm64/armasm64.exe") + set(_ARMASM64_EXE "") + foreach(_p IN LISTS _ARMASM64_CANDIDATES) + if (EXISTS "${_p}") + set(_ARMASM64_EXE "${_p}") + break() + endif() + endforeach() + if (_ARMASM64_EXE STREQUAL "") + message(FATAL_ERROR "armasm64.exe not found under VCToolsInstallDir") + endif() + + # Wrapper without spaces to avoid quoting hell on NMake/cmd.exe + set(_WRAP "${CMAKE_BINARY_DIR}/armasm64_wrapper.bat") + file(WRITE "${_WRAP}" +"@echo off\r\n\"${_ARMASM64_EXE}\" %*\r\n") + + # Use wrapper as compiler (no spaces in path) + set(CMAKE_ASM_MASM_COMPILER + "${_WRAP}" + CACHE FILEPATH "" FORCE) + + # Quote ONLY object and source (compiler path has no spaces now) + set(CMAKE_ASM_MASM_COMPILE_OBJECT + " /nologo -o \"\" \"\"" + CACHE STRING "" FORCE) + + else() + message(FATAL_ERROR "VCToolsInstallDir is not defined. Please run from a Developer Command Prompt or specify armasm64.exe manually.") + endif() +endif() add_definitions(-DBH_MALLOC=wasm_runtime_malloc) add_definitions(-DBH_FREE=wasm_runtime_free) @@ -79,9 +115,37 @@ elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*") endif () elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*") if (NOT WAMR_BUILD_SIMD EQUAL 1) - set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_aarch64.s) + if (WAMR_BUILD_PLATFORM STREQUAL "windows") + if (MSVC) + set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_armasm64.asm) + set(_WAMR_ARM64_MASM_SOURCES ${IWASM_COMMON_DIR}/arch/invokeNative_armasm64.asm) + set_source_files_properties(${_WAMR_ARM64_MASM_SOURCES} + PROPERTIES + LANGUAGE ASM_MASM + COMPILE_DEFINITIONS "" + INCLUDE_DIRECTORIES "" + COMPILE_OPTIONS "/nologo" + ) + endif () + else () + set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_aarch64.s) + endif () else() - set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_aarch64_simd.s) + if (WAMR_BUILD_PLATFORM STREQUAL "windows") + if (MSVC) + set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_armasm64_simd.asm) + set(_WAMR_ARM64_MASM_SOURCES_SIMD ${IWASM_COMMON_DIR}/arch/invokeNative_armasm64_simd.asm) + set_source_files_properties(${_WAMR_ARM64_MASM_SOURCES_SIMD} + PROPERTIES + LANGUAGE ASM_MASM + COMPILE_DEFINITIONS "" + INCLUDE_DIRECTORIES "" + COMPILE_OPTIONS "/nologo" + ) + endif () + else () + set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_aarch64_simd.s) + endif () endif() elseif (WAMR_BUILD_TARGET STREQUAL "MIPS") set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_mips.s) From df908048de3990c9a74056d44c0870c5efb9dd04 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Wed, 8 Oct 2025 22:33:11 -0700 Subject: [PATCH 31/39] Switch from deprecated overload of createTargetMachine (#4650) The overload accepting the string version of a triple will be removed soon, so switch over to the one that accepts a triple object. https://github.com/llvm/llvm-project/pull/161053 --- core/iwasm/compilation/aot_llvm_extra2.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/iwasm/compilation/aot_llvm_extra2.cpp b/core/iwasm/compilation/aot_llvm_extra2.cpp index 5e1fdf6ce6..bc49c54bbb 100644 --- a/core/iwasm/compilation/aot_llvm_extra2.cpp +++ b/core/iwasm/compilation/aot_llvm_extra2.cpp @@ -157,8 +157,13 @@ LLVMCreateTargetMachineWithOpts(LLVMTargetRef ctarget, const char *triple, auto ol = convert(opt_level); bool jit; auto cm = convert(code_model, &jit); +#if LLVM_VERSION_MAJOR >= 21 + auto targetmachine = target->createTargetMachine( + llvm::Triple(triple), cpu, features, opts, rm, cm, ol, jit); +#else auto targetmachine = target->createTargetMachine(triple, cpu, features, opts, rm, cm, ol, jit); +#endif #if LLVM_VERSION_MAJOR >= 18 // always place data in normal data section. // From d7b6bc5aca989f8a558249518d51274d0b0c92ba Mon Sep 17 00:00:00 2001 From: Liu Jia Date: Sun, 12 Oct 2025 20:18:25 +0800 Subject: [PATCH 32/39] Add a watchdog to prevent the similar crash in AOT mode (#4625) --- core/iwasm/aot/aot_runtime.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 3bf33e1276..2c7df68e69 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -114,6 +114,13 @@ set_error_buf_v(char *error_buf, uint32 error_buf_size, const char *format, ...) } } +static void +aot_unlinked_import_func_trap(WASMExecEnv *exec_env) +{ + AOTModuleInstance *module_inst = (AOTModuleInstance *)exec_env->module_inst; + aot_set_exception_with_id(module_inst, EXCE_CALL_UNLINKED_IMPORT_FUNC); +} + static void * runtime_malloc(uint64 size, char *error_buf, uint32 error_buf_size) { @@ -1397,6 +1404,7 @@ init_func_ptrs(AOTModuleInstance *module_inst, AOTModule *module, * Debugging: Check if the import is resolved at link time */ LOG_WARNING("warning: failed to link import function (%s, %s)", module_name, field_name); + *func_ptrs = (void *)aot_unlinked_import_func_trap; } } From 7aff7372e210d29c48cffcb0fea452be1394c869 Mon Sep 17 00:00:00 2001 From: William Furr <519506+wffurr@users.noreply.github.com> Date: Tue, 14 Oct 2025 22:39:05 -0400 Subject: [PATCH 33/39] Merge version update to 2.4.2 back into main branch (#4661) * Add release notes for WAMR-2.4.2 (#4624) * bump version to 2.4.2 (#4626) --- RELEASE_NOTES.md | 16 ++++++++++++++++ build-scripts/version.cmake | 2 +- core/version.h | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4904d39492..15fe80d81b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,19 @@ +## WAMR-2.4.2 + +### Breaking Changes + +### New Features + +### Bug Fixes + +- CVE-2025-58749. Fix a potential hang issue in LLVMJIT mode + +### Enhancements + +### Others + +--- + ## WAMR-2.4.1 ### Breaking Changes diff --git a/build-scripts/version.cmake b/build-scripts/version.cmake index 637b3ba7b6..1d8437da3f 100644 --- a/build-scripts/version.cmake +++ b/build-scripts/version.cmake @@ -8,7 +8,7 @@ endif() set(WAMR_VERSION_MAJOR 2) set(WAMR_VERSION_MINOR 4) -set(WAMR_VERSION_PATCH 1) +set(WAMR_VERSION_PATCH 2) message("-- WAMR version: ${WAMR_VERSION_MAJOR}.${WAMR_VERSION_MINOR}.${WAMR_VERSION_PATCH}") diff --git a/core/version.h b/core/version.h index 261c9b8cf9..7892846808 100644 --- a/core/version.h +++ b/core/version.h @@ -18,7 +18,7 @@ /* clang-format off */ #define WAMR_VERSION_MAJOR 2 #define WAMR_VERSION_MINOR 4 -#define WAMR_VERSION_PATCH 1 +#define WAMR_VERSION_PATCH 2 /* clang-format on */ #endif From 8be32732ffbfbd60af1cb93c809cb9d5dbd2f346 Mon Sep 17 00:00:00 2001 From: Keisuke Horii Date: Thu, 16 Oct 2025 11:19:19 +0900 Subject: [PATCH 34/39] Resolved a bug in the socket API example (#4667) * Fixed a bug in its script * Applied the wasi-sdk-pthread toolchain file Related issue: #4649 --- samples/socket-api/CMakeLists.txt | 11 ++++------- samples/socket-api/sample_test_run.py | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/samples/socket-api/CMakeLists.txt b/samples/socket-api/CMakeLists.txt index f09da910a9..ca3484668d 100644 --- a/samples/socket-api/CMakeLists.txt +++ b/samples/socket-api/CMakeLists.txt @@ -34,7 +34,7 @@ endif() message(CHECK_START "Detecting WASI_TOOLCHAIN_FILE at ${WASI_SDK_DIR}") find_file(WASI_TOOLCHAIN_FILE - wasi-sdk.cmake + wasi-sdk-pthread.cmake PATHS "${WASI_SDK_DIR}/share/cmake" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH @@ -46,7 +46,7 @@ else() endif() if(WASI_TOOLCHAIN_FILE-NOTFOUND) - message(FATAL_ERROR "Can not find wasi-sdk.cmake under ${WASI_SDK_DIR}") + message(FATAL_ERROR "Can not find wasi-sdk-pthread.cmake under ${WASI_SDK_DIR}") endif() message(CHECK_START "Detecting WASI_SYS_ROOT at ${WASI_SDK_DIR}") @@ -80,10 +80,7 @@ ExternalProject_Add(wasm-app SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wasm-src UPDATE_COMMAND "" PATCH_COMMAND "" - CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/../../wamr-sdk/app/libc-builtin-sysroot/include/pthread.h - ${CMAKE_CURRENT_SOURCE_DIR}/wasm-src/inc - && ${CMAKE_COMMAND} + CONFIGURE_COMMAND ${CMAKE_COMMAND} -DWASI_SDK_PREFIX=${WASI_SDK_DIR} -DCMAKE_TOOLCHAIN_FILE=${WASI_TOOLCHAIN_FILE} -DCMAKE_SYSROOT=${WASI_SYS_ROOT} @@ -170,8 +167,8 @@ set(WAMR_BUILD_AOT 1) set(WAMR_BUILD_JIT 0) set(WAMR_BUILD_LIBC_BUILTIN 1) set(WAMR_BUILD_LIBC_WASI 1) -set(WAMR_BUILD_LIB_PTHREAD 1) set(WAMR_BUILD_REF_TYPES 1) +set(WAMR_BUILD_LIB_WASI_THREADS 1) # compiling and linking flags if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) diff --git a/samples/socket-api/sample_test_run.py b/samples/socket-api/sample_test_run.py index 6e9153b248..9951a3766f 100755 --- a/samples/socket-api/sample_test_run.py +++ b/samples/socket-api/sample_test_run.py @@ -31,7 +31,7 @@ def run_cmd(cmd, cwd): shlex.split(cmd), cwd=cwd, check=False, capture_output=True ) if (qry_prc.returncode != 0): - print("Run {} failed, return {}".format(cmd), qry_prc.returncode) + print("Run {} failed, return {}".format(cmd, qry_prc.returncode)) return print("return code: {}, output:\n{}".format(qry_prc.returncode, qry_prc.stdout.decode())) From 163acd2259ba8489621dfcecbd2395e8d39141b7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Oct 2025 10:19:32 +0800 Subject: [PATCH 35/39] build(deps): Bump github/codeql-action from 3.30.6 to 4.30.8 (#4666) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.30.6 to 4.30.8. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.30.6...v4.30.8) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 4.30.8 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 6 +++--- .github/workflows/supply_chain.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5a5afec1fc..7fd0c2d260 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.30.6 + uses: github/codeql-action/init@v4.30.8 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.30.6 + uses: github/codeql-action/analyze@v4.30.8 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.30.6 + uses: github/codeql-action/upload-sarif@v4.30.8 with: sarif_file: ${{ steps.step1.outputs.sarif-output }} category: "/language:${{matrix.language}}" diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index 407a7113fd..8d64949c01 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@065c6cfb7809de8db2167a953b5b622491cda914 + uses: github/codeql-action/upload-sarif@17783bfb99b07f70fae080b654aed0c514057477 with: sarif_file: results.sarif From 826ae6eb01a9e722d3d5f46d8a5c9872afbb93a7 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 16 Oct 2025 10:19:44 +0800 Subject: [PATCH 36/39] Prevent `BuildPhi` from encountering a null llvm_entry_block (#4663) There is a scenario where `aot_compile_op_block()` does not prepare a block for `if`. As a result, the return value of `LLVMBuildPhi()` in `push_aot_block_to_stack_and_pass_params()` will be dangling, leading to a memory leak as it cannot be released. --- core/iwasm/compilation/aot_emit_control.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_control.c b/core/iwasm/compilation/aot_emit_control.c index 6817295f86..ce4c2e1bdb 100644 --- a/core/iwasm/compilation/aot_emit_control.c +++ b/core/iwasm/compilation/aot_emit_control.c @@ -495,15 +495,17 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx, /* Create param phis */ for (i = 0; i < block->param_count; i++) { - SET_BUILDER_POS(block->llvm_entry_block); - snprintf(name, sizeof(name), "%s%d_phi%d", - block_name_prefix[block->label_type], block->block_index, - i); - if (!(block->param_phis[i] = LLVMBuildPhi( - comp_ctx->builder, TO_LLVM_TYPE(block->param_types[i]), - name))) { - aot_set_last_error("llvm build phi failed."); - goto fail; + if (block->llvm_entry_block) { + SET_BUILDER_POS(block->llvm_entry_block); + snprintf(name, sizeof(name), "%s%d_phi%d", + block_name_prefix[block->label_type], + block->block_index, i); + if (!(block->param_phis[i] = LLVMBuildPhi( + comp_ctx->builder, + TO_LLVM_TYPE(block->param_types[i]), name))) { + aot_set_last_error("llvm build phi failed."); + goto fail; + } } if (block->label_type == LABEL_TYPE_IF From d25fdc37095358d8986c809f7814fd39641d10de Mon Sep 17 00:00:00 2001 From: Xenia Lu Date: Thu, 16 Oct 2025 10:20:16 +0800 Subject: [PATCH 37/39] fix: typo in AOT stack dump with GC (#4657) --- core/iwasm/aot/aot_runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 2c7df68e69..a5760f4918 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -4503,7 +4503,7 @@ aot_create_call_stack(struct WASMExecEnv *exec_env) frame.frame_ref = (uint8 *)frame.lp + (frame_ref - (uint8 *)lp); /* copy local ref flags from AOT module */ bh_memcpy_s(frame.frame_ref, local_ref_flags_cell_num, - local_ref_flags, lp_size); + local_ref_flags, local_ref_flags_cell_num); #endif } From 3bf08a0eda39d97324dac99fff087012bf0407bf Mon Sep 17 00:00:00 2001 From: Xenia Lu Date: Thu, 16 Oct 2025 10:20:50 +0800 Subject: [PATCH 38/39] loader: fix block/loop ref params type checking (#4647) * loader: fix block/loop ref params type checking --- core/iwasm/interpreter/wasm_loader.c | 29 ++++++++++++++++ .../ba-issues/issues/issue-4646/test.wasm | Bin 0 -> 157 bytes .../ba-issues/issues/issue-4646/test.wat | 31 ++++++++++++++++++ .../regression/ba-issues/running_config.json | 16 +++++++++ 4 files changed, 76 insertions(+) create mode 100644 tests/regression/ba-issues/issues/issue-4646/test.wasm create mode 100644 tests/regression/ba-issues/issues/issue-4646/test.wat diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 19ca249496..5874931e05 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -12050,9 +12050,25 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, WASMFuncType *wasm_type = block_type.u.type; BranchBlock *cur_block = loader_ctx->frame_csp - 1; +#if WASM_ENABLE_GC != 0 + WASMRefType *ref_type; + uint32 j = 0; +#endif #if WASM_ENABLE_FAST_INTERP != 0 uint32 cell_num; available_params = block_type.u.type->param_count; +#endif +#if WASM_ENABLE_GC != 0 + /* find the index of the last param + * in wasm_type->ref_type_maps as j */ + for (i = 0; i < block_type.u.type->param_count; i++) { + if (wasm_is_type_multi_byte_type(wasm_type->types[i])) { + j += 1; + } + } + if (j > 0) { + j -= 1; + } #endif for (i = 0; i < block_type.u.type->param_count; i++) { @@ -12066,6 +12082,19 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #endif break; } +#if WASM_ENABLE_GC != 0 + if (wasm_is_type_multi_byte_type( + wasm_type + ->types[wasm_type->param_count - i - 1])) { + bh_assert(wasm_type->ref_type_maps[j].index + == wasm_type->param_count - i - 1); + ref_type = wasm_type->ref_type_maps[j].ref_type; + bh_memcpy_s(&wasm_ref_type, sizeof(WASMRefType), + ref_type, + wasm_reftype_struct_size(ref_type)); + j--; + } +#endif POP_TYPE( wasm_type->types[wasm_type->param_count - i - 1]); diff --git a/tests/regression/ba-issues/issues/issue-4646/test.wasm b/tests/regression/ba-issues/issues/issue-4646/test.wasm new file mode 100644 index 0000000000000000000000000000000000000000..e163405eec49af2539875c7c9b672d1d0afe4aa5 GIT binary patch literal 157 zcmXxWF%E(-7zWVq`&+=ks1u2CFwUN#UZhmY;80AU4lecz9>jxq5O2{%7T)yW=0E`4 z7nX^ZFIq{5~@ptN&zQv~W0k1)0QAp>T2`7(o|+lBdv id8-U*+6HGmx-hUJba1y(9~3rooF09&j_a literal 0 HcmV?d00001 diff --git a/tests/regression/ba-issues/issues/issue-4646/test.wat b/tests/regression/ba-issues/issues/issue-4646/test.wat new file mode 100644 index 0000000000..3fd503c550 --- /dev/null +++ b/tests/regression/ba-issues/issues/issue-4646/test.wat @@ -0,0 +1,31 @@ +;; define different reference types +(type $struct_a (struct (field (mut i32)))) +(type $struct_b (struct (field (mut i64)))) +(type $struct_c (struct (field (mut i32)) (field (mut i32)))) + +(func $main + ;; prepare parameters: i32, ref_a, i32, ref_b + (i32.const 10) + (struct.new $struct_a (i32.const 100)) + (i32.const 20) + (struct.new $struct_b (i64.const 200)) + + ;; block with interleaved parameters: i32, ref_a, i32, ref_b -> ref_c + (block (param i32 (ref $struct_a) i32 (ref $struct_b)) (result (ref $struct_c)) + ;; clean up parameters from stack + drop ;; drop ref_b + drop ;; drop i32 + drop ;; drop ref_a + drop ;; drop i32 + + ;; return new type reference struct_c + (struct.new $struct_c (i32.const 300) (i32.const 400)) + ) + + ;; drop return value + drop +) + +(memory 1) +(export "memory" (memory 0)) +(export "_start" (func $main)) \ No newline at end of file diff --git a/tests/regression/ba-issues/running_config.json b/tests/regression/ba-issues/running_config.json index decc6861aa..bc62c54915 100644 --- a/tests/regression/ba-issues/running_config.json +++ b/tests/regression/ba-issues/running_config.json @@ -1770,6 +1770,22 @@ "stdout content": "", "description": "no 'invalid local type'" } + }, + { + "deprecated": false, + "ids": [ + 4646 + ], + "runtime": "iwasm-default-gc-enabled", + "file": "test.wasm", + "mode": "classic-interp", + "options": "-f _start", + "argument": "", + "expected return": { + "ret code": 0, + "stdout content": "", + "description": "load successfully" + } } ] } From 8b614145d323ba27b066763a64940ae55f314ec4 Mon Sep 17 00:00:00 2001 From: Dan Kouba Date: Tue, 21 Oct 2025 12:44:47 -0700 Subject: [PATCH 39/39] Fix mismatch of enum sizes between WASM and host Signed-off-by: Dan Kouba --- .../platform/include/platform_wasi_types.h | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/core/shared/platform/include/platform_wasi_types.h b/core/shared/platform/include/platform_wasi_types.h index 56ea7514ed..1883b1caef 100644 --- a/core/shared/platform/include/platform_wasi_types.h +++ b/core/shared/platform/include/platform_wasi_types.h @@ -530,12 +530,6 @@ assert_wasi_layout(offsetof(__wasi_subscription_t, userdata) == 0, "witx calcula assert_wasi_layout(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset"); /* keep syncing with wasi_socket_ext.h */ -typedef enum { - /* Used only for sock_addr_resolve hints */ - SOCKET_ANY = -1, - SOCKET_DGRAM = 0, - SOCKET_STREAM, -} __wasi_sock_type_t; typedef uint16_t __wasi_ip_port_t; @@ -589,20 +583,36 @@ typedef struct __wasi_addr_t { } addr; } __wasi_addr_t; -typedef enum { INET4 = 0, INET6, INET_UNSPEC } __wasi_address_family_t; +/* Force 32-bit wire width for cross-boundary fields */ +typedef int32_t __wasi_sock_type_t; +enum { SOCKET_ANY = -1, SOCKET_DGRAM = 0, SOCKET_STREAM = 1 }; + +typedef int32_t __wasi_address_family_t; +enum { INET4 = 0, INET6 = 1, INET_UNSPEC = 2 }; typedef struct __wasi_addr_info_t { - __wasi_addr_t addr; + __wasi_addr_t addr; __wasi_sock_type_t type; } __wasi_addr_info_t; typedef struct __wasi_addr_info_hints_t { - __wasi_sock_type_t type; - __wasi_address_family_t family; - // this is to workaround lack of optional parameters - uint8_t hints_enabled; + __wasi_sock_type_t type; // 4 bytes + __wasi_address_family_t family; // 4 bytes + uint8_t hints_enabled; // 1 byte + uint8_t _pad[3]; // enforce layout } __wasi_addr_info_hints_t; +assert_wasi_layout(sizeof(__wasi_sock_type_t) == 4, "sock_type must be 4 bytes"); +assert_wasi_layout(sizeof(__wasi_address_family_t) == 4, "addr_family must be 4 bytes"); + +assert_wasi_layout(sizeof(__wasi_addr_info_hints_t) == 12, "hints_t must be 12 bytes"); +assert_wasi_layout(offsetof(__wasi_addr_info_hints_t, type) == 0, "hints.type@0"); +assert_wasi_layout(offsetof(__wasi_addr_info_hints_t, family) == 4, "hints.family@4"); +assert_wasi_layout(offsetof(__wasi_addr_info_hints_t, hints_enabled) == 8, "hints.enabled@8"); + +assert_wasi_layout(offsetof(__wasi_addr_info_t, type) == sizeof(__wasi_addr_t), + "addr_info.type follows addr"); + #undef assert_wasi_layout /* clang-format on */