From e87f7a920d568d769652dad7f67bb159aa2bce3a Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Wed, 25 Sep 2024 16:43:00 +0800 Subject: [PATCH 001/105] Fix Windows compile error when uvwasi is enabled (#3810) No need to compile win_file.c when uvwasi is enabled. --- core/iwasm/aot/aot_loader.c | 2 +- core/iwasm/common/wasm_runtime_common.c | 1 - core/shared/platform/windows/platform_internal.h | 9 +++++++-- core/shared/platform/windows/shared_platform.cmake | 3 +++ core/shared/platform/windows/win_socket.c | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 5c8131833..0304bd096 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -2520,7 +2520,7 @@ try_merge_data_and_text(const uint8 **buf, const uint8 **buf_end, /* order not essential just as compiler does: .text section first */ *buf = sections; *buf_end = sections + code_size; - bh_memcpy_s(sections, code_size, old_buf, code_size); + bh_memcpy_s(sections, (uint32)code_size, old_buf, (uint32)code_size); os_munmap(old_buf, code_size); sections += align_uint((uint32)code_size, page_size); diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 667cbba03..453cf9e3c 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -340,7 +340,6 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info) PEXCEPTION_RECORD ExceptionRecord = exce_info->ExceptionRecord; uint8 *sig_addr = (uint8 *)ExceptionRecord->ExceptionInformation[1]; WASMModuleInstance *module_inst; - WASMMemoryInstance *memory_inst; WASMJmpBuf *jmpbuf_node; uint8 *mapped_mem_start_addr = NULL; uint8 *mapped_mem_end_addr = NULL; diff --git a/core/shared/platform/windows/platform_internal.h b/core/shared/platform/windows/platform_internal.h index ed021a9aa..1cd8187af 100644 --- a/core/shared/platform/windows/platform_internal.h +++ b/core/shared/platform/windows/platform_internal.h @@ -168,12 +168,13 @@ typedef struct windows_dir_stream { windows_handle *handle; } windows_dir_stream; -typedef windows_handle *os_file_handle; typedef windows_dir_stream *os_dir_stream; -#if WASM_ENABLE_UVWASI != 1 +#if WASM_ENABLE_UVWASI == 0 +typedef windows_handle *os_file_handle; typedef HANDLE os_raw_file_handle; #else +typedef uint32_t os_file_handle; typedef uint32_t os_raw_file_handle; #endif @@ -190,7 +191,11 @@ typedef uint32_t os_raw_file_handle; static inline os_file_handle os_get_invalid_handle(void) { +#if WASM_ENABLE_UVWASI == 0 return NULL; +#else + return -1; +#endif } #ifdef __cplusplus diff --git a/core/shared/platform/windows/shared_platform.cmake b/core/shared/platform/windows/shared_platform.cmake index 502a8a2ed..c2d74463f 100644 --- a/core/shared/platform/windows/shared_platform.cmake +++ b/core/shared/platform/windows/shared_platform.cmake @@ -15,6 +15,9 @@ file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1) list(REMOVE_ITEM source_all ${PLATFORM_SHARED_DIR}/win_file.c) +elseif (WAMR_BUILD_LIBC_UVWASI EQUAL 1) + # uvwasi doesn't need to compile win_file.c + list(REMOVE_ITEM source_all ${PLATFORM_SHARED_DIR}/win_file.c) else() include (${CMAKE_CURRENT_LIST_DIR}/../common/libc-util/platform_common_libc_util.cmake) set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE}) diff --git a/core/shared/platform/windows/win_socket.c b/core/shared/platform/windows/win_socket.c index b19e5b097..8d61c45cc 100644 --- a/core/shared/platform/windows/win_socket.c +++ b/core/shared/platform/windows/win_socket.c @@ -182,8 +182,8 @@ os_socket_accept(bh_socket_t server_sock, bh_socket_t *sock, void *addr, (*sock)->type = windows_handle_type_socket; (*sock)->access_mode = windows_access_mode_read | windows_access_mode_write; (*sock)->fdflags = 0; - (*sock)->raw.socket = - accept(server_sock->raw.socket, (struct sockaddr *)&addr_tmp, &len); + (*sock)->raw.socket = accept(server_sock->raw.socket, + (struct sockaddr *)&addr_tmp, (int *)&len); if ((*sock)->raw.socket == INVALID_SOCKET) { BH_FREE(*sock); From 86926aa9d2e643304864a5c33bda0eccc8494087 Mon Sep 17 00:00:00 2001 From: palchikov Date: Wed, 25 Sep 2024 11:59:52 +0300 Subject: [PATCH 002/105] Fix unused param warning when GC is enabled (#3814) --- core/iwasm/interpreter/wasm.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/iwasm/interpreter/wasm.h b/core/iwasm/interpreter/wasm.h index e043465d4..0aefd30c3 100644 --- a/core/iwasm/interpreter/wasm.h +++ b/core/iwasm/interpreter/wasm.h @@ -1238,6 +1238,9 @@ wasm_value_type_size_internal(uint8 value_type, uint8 pointer_size) else { bh_assert(0); } +#if WASM_ENABLE_GC == 0 + (void)pointer_size; +#endif return 0; } From 5ce6f90bd6442a7d30dd84e459a14ea7091a2d7f Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:52:00 +0800 Subject: [PATCH 003/105] Add scoreboard CI for supply-chain security (#3819) --- .github/workflows/supply_chain.yml | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/supply_chain.yml diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml new file mode 100644 index 000000000..2307756ab --- /dev/null +++ b/.github/workflows/supply_chain.yml @@ -0,0 +1,65 @@ +# This workflow uses actions that are not certified by GitHub. They are provided +# by a third-party and are governed by separate terms of service, privacy +# policy, and support documentation. + +# Check current WASM Micro Runtime results here: https://securityscorecards.dev/viewer/?uri=github.com/bytecodealliance/wasm-micro-runtime + +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + # midnight UTC + schedule: + - cron: "0 0 * * *" + # allow to be triggered manually + workflow_dispatch: + +# Declare default permissions as read only. +permissions: + contents: read + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + if: github.repository == 'bytecodealliance/wasm-micro-runtime' + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + + steps: + - name: "Checkout code" + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1 + with: + results_file: results.sarif + results_format: sarif + + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + publish_results: true + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: "Upload artifact" + uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard. + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v2.2.4 + with: + sarif_file: results.sarif From 438b81bd04a64c79d11457923d46f08c8da9313b Mon Sep 17 00:00:00 2001 From: Kvencc <43509398+Kvencc@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:55:09 +0800 Subject: [PATCH 004/105] Fix missing symbols when using aot mode on riscv platforms (#3812) Add symbol __atomic_compare_exchange_4 and __atomic_store_4. --- core/iwasm/aot/arch/aot_reloc_riscv.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/iwasm/aot/arch/aot_reloc_riscv.c b/core/iwasm/aot/arch/aot_reloc_riscv.c index 058ad0e10..8df9f9f8e 100644 --- a/core/iwasm/aot/arch/aot_reloc_riscv.c +++ b/core/iwasm/aot/arch/aot_reloc_riscv.c @@ -24,6 +24,7 @@ #undef NEED_SOFT_I32_DIV #undef NEED_SOFT_I64_MUL #undef NEED_SOFT_I64_DIV +#undef NEED_SOFT_ATOMIC #ifdef __riscv_flen #if __riscv_flen == 32 @@ -48,6 +49,10 @@ #define NEED_SOFT_I64_DIV #endif +#ifndef __riscv_atomic +#define NEED_SOFT_ATOMIC +#endif + /* clang-format off */ void __adddf3(void); void __addsf3(void); @@ -101,6 +106,9 @@ void __umoddi3(void); void __umodsi3(void); void __unorddf2(void); void __unordsf2(void); +bool __atomic_compare_exchange_4(volatile void *, void *, unsigned int, + bool, int, int); +void __atomic_store_4(volatile void *, unsigned int, int); /* clang-format on */ static SymbolMap target_sym_map[] = { @@ -127,6 +135,7 @@ static SymbolMap target_sym_map[] = { * to convert float and long long */ REG_SYM(__floatundisf), + REG_SYM(__floatdisf), #endif #ifdef NEED_SOFT_DP REG_SYM(__adddf3), @@ -175,6 +184,10 @@ static SymbolMap target_sym_map[] = { REG_SYM(__moddi3), REG_SYM(__udivdi3), REG_SYM(__umoddi3), +#endif +#ifdef NEED_SOFT_ATOMIC + REG_SYM(__atomic_compare_exchange_4), + REG_SYM(__atomic_store_4), #endif /* clang-format on */ }; From 0e05b0a451008c4ae95527613537ab02e6f86e5e Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Sun, 29 Sep 2024 12:54:00 +0800 Subject: [PATCH 005/105] Add CODEOWNERS (#3822) --- CODEOWNERS | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 000000000..d8ec4c1b3 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,29 @@ +# In this project, we use CODEOWNERS to identify people who are likely to know +# who should review a pull request. +# +# People listed in this file are committing to respond in a timely fashion to +# PRs in the selected areas. However, that response doesn't have to be a full +# code review; it could also take any of these forms: +# +# - "I intend to review this but I can't yet. Please leave me a message if I +# haven't responded by (a specific date in the near future)." +# +# - "I think (a specific other contributor) should review this." (Note that the +# best reviewer for a PR may not necessarily be listed in this file.) +# +# People must only be added to this file if they've agreed to provide one of +# the above responses in a reasonable amount of time for every PR to which +# they're assigned. +# +# We only ask for this commitment from people who are employed full-time to +# work on this project. We gratefully welcome reviews from other contributors, +# but we don't believe it's fair to ask volunteers to respond quickly. + +# If none of the later patterns match, assign to anyone. This team is the +# parent of all the other teams and automatically includes everyone on those +# teams. +* @loganek @lum1n0us @no1wudi @wenyongh @xujuntwt95329 @yamt + +# Some parts of the project require more specialized knowledge. In those areas +# we designate smaller groups who are more likely to be aware of who's working +# in specific areas. From bd8c7a3a64f553975a8bc1224009170b1ab57c8c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:45:28 +0000 Subject: [PATCH 006/105] build(deps): bump github/codeql-action from 2.2.4 to 3.26.9 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.2.4 to 3.26.9. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v2.2.4...v3.26.9) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .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 5a9c12d33..9a6f4fef2 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -49,7 +49,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v3 + uses: github/codeql-action/init@v3.26.9 with: languages: ${{ matrix.language }} @@ -66,7 +66,7 @@ jobs: - run: | ./.github/scripts/codeql_buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 + uses: github/codeql-action/analyze@v3.26.9 with: category: "/language:${{matrix.language}}" upload: false @@ -95,7 +95,7 @@ jobs: output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif - name: Upload CodeQL results to code scanning - uses: github/codeql-action/upload-sarif@v3 + uses: github/codeql-action/upload-sarif@v3.26.9 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 2307756ab..66214efc6 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@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v2.2.4 + uses: github/codeql-action/upload-sarif@2617ff2d3f2bf8dd95abadcd289352a4023a4758 # v2.2.4 with: sarif_file: results.sarif From 2baac8d9e0fbacbafaecbdcd27a2b1f1599600cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:45:34 +0000 Subject: [PATCH 007/105] build(deps): bump actions/upload-artifact from 3.1.0 to 4.4.0 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.0 to 4.4.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3.1.0...v4.4.0) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql.yml | 2 +- .github/workflows/spec_test_on_nuttx.yml | 2 +- .github/workflows/supply_chain.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5a9c12d33..8089a917a 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -102,7 +102,7 @@ jobs: - name: Upload CodeQL results as an artifact if: success() || failure() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v4.4.0 with: name: codeql-results path: ${{ steps.step1.outputs.sarif-output }} diff --git a/.github/workflows/spec_test_on_nuttx.yml b/.github/workflows/spec_test_on_nuttx.yml index 712bd06bc..dfabad103 100644 --- a/.github/workflows/spec_test_on_nuttx.yml +++ b/.github/workflows/spec_test_on_nuttx.yml @@ -341,7 +341,7 @@ jobs: - name: upload the log if: always() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v4.4.0 with: name: spec-test-log-${{ github.run_id }}-${{ strategy.job-index }}-${{ matrix.target_config.target }} path: log diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index 2307756ab..b9c2da729 100644 --- a/.github/workflows/supply_chain.yml +++ b/.github/workflows/supply_chain.yml @@ -52,7 +52,7 @@ jobs: # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # format to the repository Actions tab. - name: "Upload artifact" - uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0 + uses: actions/upload-artifact@3eadd8b791cabf7cd572f194da82158c24125bd8 # v3.1.0 with: name: SARIF file path: results.sarif From 2e60f372020f46d7e8f0efaba748a1579981071b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:45:37 +0000 Subject: [PATCH 008/105] build(deps): bump ossf/scorecard-action from 2.3.1 to 2.4.0 Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.3.1 to 2.4.0. - [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/0864cf19026789058feabb7e87baa5f140aac736...62b2cac7ed8198b15735ed49ab1e5cf35480ba46) --- updated-dependencies: - dependency-name: ossf/scorecard-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .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 2307756ab..6e78cc1df 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@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1 + uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0 with: results_file: results.sarif results_format: sarif From 72872cbd44d7c2448ea4ed52ac7a168dbd7edf32 Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Sat, 5 Oct 2024 00:46:23 -0700 Subject: [PATCH 009/105] Fix mac build of libc_emcc_wrapper.c (#3836) --- core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c b/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c index 427bfd656..11795069f 100644 --- a/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c +++ b/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c @@ -168,12 +168,21 @@ statbuf_native2app(const struct stat *statbuf_native, statbuf_app->st_blksize = (unsigned)statbuf_native->st_blksize; statbuf_app->st_blocks = (unsigned)statbuf_native->st_blocks; statbuf_app->st_ino = (int64)statbuf_native->st_ino; +#if defined(__APPLE__) + statbuf_app->st_atim.tv_sec = (int)statbuf_native->st_atimespec.tv_sec; + statbuf_app->st_atim.tv_nsec = (int)statbuf_native->st_atimespec.tv_nsec; + statbuf_app->st_mtim.tv_sec = (int)statbuf_native->st_mtimespec.tv_sec; + statbuf_app->st_mtim.tv_nsec = (int)statbuf_native->st_mtimespec.tv_nsec; + statbuf_app->st_ctim.tv_sec = (int)statbuf_native->st_ctimespec.tv_sec; + statbuf_app->st_ctim.tv_nsec = (int)statbuf_native->st_ctimespec.tv_nsec; +#else statbuf_app->st_atim.tv_sec = (int)statbuf_native->st_atim.tv_sec; statbuf_app->st_atim.tv_nsec = (int)statbuf_native->st_atim.tv_nsec; statbuf_app->st_mtim.tv_sec = (int)statbuf_native->st_mtim.tv_sec; statbuf_app->st_mtim.tv_nsec = (int)statbuf_native->st_mtim.tv_nsec; statbuf_app->st_ctim.tv_sec = (int)statbuf_native->st_ctim.tv_sec; statbuf_app->st_ctim.tv_nsec = (int)statbuf_native->st_ctim.tv_nsec; +#endif } static int @@ -261,7 +270,8 @@ getentropy_wrapper(wasm_exec_env_t exec_env, void *buffer, uint32 length) { if (buffer == NULL) return -1; -#if defined(_DEFAULT_SOURCE) || defined(BH_PLATFORM_LINUX_SGX) +#if defined(_DEFAULT_SOURCE) || defined(BH_PLATFORM_LINUX_SGX) \ + || defined(__APPLE__) return getentropy(buffer, length); #else return syscall(SYS_getrandom, buffer, length, 0); From 0c4b2da048b9ceee4e5367d5e502a5068c9dfb62 Mon Sep 17 00:00:00 2001 From: James Ring Date: Mon, 7 Oct 2024 15:35:46 -0700 Subject: [PATCH 010/105] aot_comp_option.h: Add missing stdint.h header (#3834) --- core/iwasm/include/aot_comp_option.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/iwasm/include/aot_comp_option.h b/core/iwasm/include/aot_comp_option.h index 98f33a160..bb612515a 100644 --- a/core/iwasm/include/aot_comp_option.h +++ b/core/iwasm/include/aot_comp_option.h @@ -6,6 +6,8 @@ #ifndef __AOT_COMP_OPTION_H__ #define __AOT_COMP_OPTION_H__ +#include + typedef struct { /* Enables or disables bounds checks for stack frames. When enabled, the AOT * compiler generates code to check if the stack pointer is within the From f9153fbff071d07f58f51d8d44579f3e56e9b9b9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 09:08:37 +0800 Subject: [PATCH 011/105] build(deps): bump github/codeql-action from 3.26.9 to 3.26.11 (#3843) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.9 to 3.26.11. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.26.9...v3.26.11) --- updated-dependencies: - dependency-name: github/codeql-action 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 fb7f063f4..ad60706bc 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -49,7 +49,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v3.26.9 + uses: github/codeql-action/init@v3.26.11 with: languages: ${{ matrix.language }} @@ -66,7 +66,7 @@ jobs: - run: | ./.github/scripts/codeql_buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3.26.9 + uses: github/codeql-action/analyze@v3.26.11 with: category: "/language:${{matrix.language}}" upload: false @@ -95,7 +95,7 @@ jobs: output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif - name: Upload CodeQL results to code scanning - uses: github/codeql-action/upload-sarif@v3.26.9 + uses: github/codeql-action/upload-sarif@v3.26.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 bdc249029..28b464e48 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@2617ff2d3f2bf8dd95abadcd289352a4023a4758 # v2.2.4 + uses: github/codeql-action/upload-sarif@56d197570aa047eae7fe04401603196e2f68521d # v2.2.4 with: sarif_file: results.sarif From 6b4d8aae2a353f08ba7bab230c177e4102860f39 Mon Sep 17 00:00:00 2001 From: James Ring Date: Mon, 7 Oct 2024 18:28:24 -0700 Subject: [PATCH 012/105] Emit load_addr and load_size if WAMR_ENABLE_COMPILER is set (#3835) Currently, the open-source builds of wamrc set WASM_ENABLE_DUMP_CALL_STACK, which causes these two fields to be emitted. They are required by aot_emit_exception.c. Internally at Google, we don't enable call stack dumps, so we've been using the attached patch to make sure the fields are emitted anyway. --- core/iwasm/interpreter/wasm.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/iwasm/interpreter/wasm.h b/core/iwasm/interpreter/wasm.h index 0aefd30c3..83597401a 100644 --- a/core/iwasm/interpreter/wasm.h +++ b/core/iwasm/interpreter/wasm.h @@ -976,8 +976,9 @@ struct WASMModule { uint64 buf_code_size; #endif -#if WASM_ENABLE_DEBUG_INTERP != 0 || WASM_ENABLE_FAST_JIT != 0 \ - || WASM_ENABLE_DUMP_CALL_STACK != 0 || WASM_ENABLE_JIT != 0 +#if WASM_ENABLE_DEBUG_INTERP != 0 || WASM_ENABLE_FAST_JIT != 0 \ + || WASM_ENABLE_DUMP_CALL_STACK != 0 || WASM_ENABLE_JIT != 0 \ + || WASM_ENABLE_WAMR_COMPILER != 0 uint8 *load_addr; uint64 load_size; #endif From 30539bf50c7b6234a8f2e9479a26f30068bb5091 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Tue, 8 Oct 2024 09:54:39 +0800 Subject: [PATCH 013/105] Fix compilation error found in tflite test (#3820) ps. https://github.com/bytecodealliance/wasm-micro-runtime/pull/3817 --- core/iwasm/libraries/wasi-nn/README.md | 8 ++--- .../libraries/wasi-nn/cmake/Findcjson.cmake | 22 +++++++++----- .../wasi-nn/cmake/Findllamacpp.cmake | 22 +++++++++----- .../wasi-nn/cmake/Findtensorflow_lite.cmake | 30 +++++++++++++------ .../wasi-nn/cmake/add_telemetry.patch | 12 ++++++++ .../libraries/wasi-nn/test/Dockerfile.cpu | 21 ++++++++++--- .../wasi-nn/test/Dockerfile.nvidia-gpu | 22 ++++++++++---- .../libraries/wasi-nn/test/Dockerfile.tpu | 23 ++++++++++---- .../wasi-nn/test/Dockerfile.vx-delegate | 17 +++++++++-- core/iwasm/libraries/wasi-nn/test/build.sh | 8 ++--- .../libraries/wasi-nn/test/requirements.txt | 2 +- core/iwasm/libraries/wasi-nn/test/utils.c | 3 +- 12 files changed, 139 insertions(+), 51 deletions(-) create mode 100644 core/iwasm/libraries/wasi-nn/cmake/add_telemetry.patch diff --git a/core/iwasm/libraries/wasi-nn/README.md b/core/iwasm/libraries/wasi-nn/README.md index 5536f6d57..99a766467 100644 --- a/core/iwasm/libraries/wasi-nn/README.md +++ b/core/iwasm/libraries/wasi-nn/README.md @@ -103,7 +103,6 @@ docker run \ wasi-nn-cpu \ --dir=/ \ --env="TARGET=cpu" \ - --native-lib=/lib/libwasi-nn-tflite.so \ /assets/test_tensorflow.wasm ``` @@ -119,7 +118,6 @@ docker run \ wasi-nn-nvidia-gpu \ --dir=/ \ --env="TARGET=gpu" \ - --native-lib=/lib/libwasi-nn-tflite.so \ /assets/test_tensorflow.wasm ``` @@ -131,7 +129,6 @@ docker run \ wasi-nn-vx-delegate \ --dir=/ \ --env="TARGET=gpu" \ - --native-lib=/lib/libwasi-nn-tflite.so \ /assets/test_tensorflow_quantized.wasm ``` @@ -147,7 +144,6 @@ docker run \ wasi-nn-tpu \ --dir=/ \ --env="TARGET=tpu" \ - --native-lib=/lib/libwasi-nn-tflite.so \ /assets/test_tensorflow_quantized.wasm ``` @@ -155,8 +151,8 @@ docker run \ Supported: -- Graph encoding: `tensorflowlite`. -- Execution target: `cpu`, `gpu` and `tpu`. +- Graph encoding: `tensorflowlite`, `openvino` and `ggml` +- Execution target: `cpu` for all. `gpu` and `tpu` for `tensorflowlite`. - Tensor type: `fp32`. ## Smoke test diff --git a/core/iwasm/libraries/wasi-nn/cmake/Findcjson.cmake b/core/iwasm/libraries/wasi-nn/cmake/Findcjson.cmake index 1136f41ad..6c921bbc9 100644 --- a/core/iwasm/libraries/wasi-nn/cmake/Findcjson.cmake +++ b/core/iwasm/libraries/wasi-nn/cmake/Findcjson.cmake @@ -4,13 +4,21 @@ include(FetchContent) set(CJSON_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/cjson") - -FetchContent_Declare( - cjson - GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git - GIT_TAG v1.7.18 - SOURCE_DIR ${CJSON_SOURCE_DIR} -) +if(EXISTS ${CJSON_SOURCE_DIR}) + message("Use existed source code under ${CJSON_SOURCE_DIR}") + FetchContent_Declare( + cjson + SOURCE_DIR ${CJSON_SOURCE_DIR} + ) +else() + message("download source code and store it at ${CJSON_SOURCE_DIR}") + FetchContent_Declare( + cjson + GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git + GIT_TAG v1.7.18 + SOURCE_DIR ${CJSON_SOURCE_DIR} + ) +endif() set(ENABLE_CJSON_TEST OFF CACHE INTERNAL "Turn off tests") set(ENABLE_CJSON_UNINSTALL OFF CACHE INTERNAL "Turn off uninstall to avoid targets conflict") diff --git a/core/iwasm/libraries/wasi-nn/cmake/Findllamacpp.cmake b/core/iwasm/libraries/wasi-nn/cmake/Findllamacpp.cmake index 431e15db5..8f4f8d1aa 100644 --- a/core/iwasm/libraries/wasi-nn/cmake/Findllamacpp.cmake +++ b/core/iwasm/libraries/wasi-nn/cmake/Findllamacpp.cmake @@ -4,13 +4,21 @@ include(FetchContent) set(LLAMA_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/llama.cpp") - -FetchContent_Declare( - llamacpp - GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git - GIT_TAG b3573 - SOURCE_DIR ${LLAMA_SOURCE_DIR} -) +if(EXISTS ${LLAMA_SOURCE_DIR}) + message("Use existed source code under ${LLAMA_SOURCE_DIR}") + FetchContent_Declare( + llamacpp + SOURCE_DIR ${LLAMA_SOURCE_DIR} + ) +else() + message("download source code and store it at ${LLAMA_SOURCE_DIR}") + FetchContent_Declare( + llamacpp + GIT_REPOSITORY https://github.com/ggerganov/llama.cpp.git + GIT_TAG b3573 + SOURCE_DIR ${LLAMA_SOURCE_DIR} + ) +endif() set(LLAMA_BUILD_TESTS OFF) set(LLAMA_BUILD_EXAMPLES OFF) diff --git a/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake b/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake index 39480741d..d2b3f74e0 100644 --- a/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake +++ b/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake @@ -4,20 +4,32 @@ include(FetchContent) set(TFLITE_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src") +if(EXISTS ${TFLITE_SOURCE_DIR}) + message("Use existed source code under ${TFLITE_SOURCE_DIR}") + FetchContent_Declare( + tensorflow_lite + SOURCE_DIR ${TFLITE_SOURCE_DIR} + SOURCE_SUBDIR tensorflow/lite + ) +else() + message("download source code and store it at ${TFLITE_SOURCE_DIR}") + FetchContent_Declare( + tensorflow_lite + GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git + GIT_TAG v2.12.0 + GIT_SHALLOW ON + GIT_PROGRESS ON + SOURCE_DIR ${TFLITE_SOURCE_DIR} + SOURCE_SUBDIR tensorflow/lite + PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/add_telemetry.patch + ) +endif() -FetchContent_Declare( - tensorflow_lite - GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git - GIT_TAG v2.12.0 - GIT_SHALLOW ON - GIT_PROGRESS ON - SOURCE_DIR ${TFLITE_SOURCE_DIR} - SOURCE_SUBDIR tensorflow/lite -) if(WAMR_BUILD_WASI_NN_ENABLE_GPU EQUAL 1) set(TFLITE_ENABLE_GPU ON) endif() + if (CMAKE_SIZEOF_VOID_P EQUAL 4) set(TFLITE_ENABLE_XNNPACK OFF) endif() diff --git a/core/iwasm/libraries/wasi-nn/cmake/add_telemetry.patch b/core/iwasm/libraries/wasi-nn/cmake/add_telemetry.patch new file mode 100644 index 000000000..8dbf5c355 --- /dev/null +++ b/core/iwasm/libraries/wasi-nn/cmake/add_telemetry.patch @@ -0,0 +1,12 @@ +diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt +index c71a3925ac..39591a3bd7 100644 +--- a/tensorflow/lite/CMakeLists.txt ++++ b/tensorflow/lite/CMakeLists.txt +@@ -493,6 +493,7 @@ set(TFLITE_PROFILER_SRCS + ${TFLITE_SOURCE_DIR}/profiling/root_profiler.h + ${TFLITE_SOURCE_DIR}/profiling/root_profiler.cc + ${TFLITE_SOURCE_DIR}/profiling/telemetry/profiler.cc ++ ${TFLITE_SOURCE_DIR}/profiling/telemetry/telemetry.cc + ) + if(CMAKE_SYSTEM_NAME MATCHES "Android") + list(APPEND TFLITE_PROFILER_SRCS diff --git a/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu b/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu index a33bebff5..67bfbfe0e 100644 --- a/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu +++ b/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu @@ -14,19 +14,32 @@ WORKDIR /usr/local/share/ca-certificates/cacert.org RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \ && update-ca-certificates +# need a newer cmake +RUN apt-get purge -y cmake + +ARG CMAKE_VER=3.27.0 +RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \ + -q -O /tmp/cmake-install.sh \ + && chmod u+x /tmp/cmake-install.sh \ + && mkdir /opt/cmake-${CMAKE_VER} \ + && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \ + && rm /tmp/cmake-install.sh \ + && ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin + WORKDIR /home/wamr COPY . . RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt WORKDIR /home/wamr/product-mini/platforms/linux RUN rm -rf build \ - && cmake -S . -B build -DWAMR_BUILD_WASI_NN=1 \ + && cmake -S . -B build\ + -DWAMR_BUILD_WASI_NN=1 -DWAMR_BUILD_WASI_NN_TFLITE=1\ && cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)" FROM ubuntu:22.04 -COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin/iwasm -COPY --from=base /home/wamr/product-mini/platforms/linux/build/libiwasm.so /lib/libiwasm.so -COPY --from=base /home/wamr/product-mini/platforms/linux/build/libwasi-nn-*.so /lib/ +COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin +COPY --from=base /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib +ENV LD_LIBRARY_PATH=/usr/lib ENTRYPOINT [ "iwasm" ] diff --git a/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu b/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu index 49ee51a15..8fe82510a 100644 --- a/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu +++ b/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu @@ -14,14 +14,26 @@ WORKDIR /usr/local/share/ca-certificates/cacert.org RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \ && update-ca-certificates +# need a newer cmake +RUN apt-get purge -y cmake + +ARG CMAKE_VER=3.27.0 +RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \ + -q -O /tmp/cmake-install.sh \ + && chmod u+x /tmp/cmake-install.sh \ + && mkdir /opt/cmake-${CMAKE_VER} \ + && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \ + && rm /tmp/cmake-install.sh \ + && ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin + WORKDIR /home/wamr COPY . . RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt -WORKDIR /home/wamr/product-mini/platforms/linux/build +WORKDIR /home/wamr/product-mini/platforms/linux RUN rm -rf build \ && cmake -S . -B build \ - -DWAMR_BUILD_WASI_NN=1 \ + -DWAMR_BUILD_WASI_NN=1 -DWAMR_BUILD_WASI_NN_TFLITE=1\ -DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \ && cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)" @@ -40,8 +52,8 @@ RUN mkdir -p /etc/OpenCL/vendors && \ ENV NVIDIA_VISIBLE_DEVICES=all ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility -COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin/iwasm -COPY --from=base /home/wamr/product-mini/platforms/linux/build/libiwasm.so /lib/libiwasm.so -COPY --from=base /home/wamr/product-mini/platforms/linux/build/libwasi-nn-*.so /lib/ +COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin +COPY --from=base /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib +ENV LD_LIBRARY_PATH=/usr/lib ENTRYPOINT [ "iwasm" ] diff --git a/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu b/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu index a0ae29a63..6a7dc1534 100644 --- a/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu +++ b/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu @@ -14,22 +14,35 @@ WORKDIR /usr/local/share/ca-certificates/cacert.org RUN wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \ && update-ca-certificates +# need a newer cmake +RUN apt-get purge -y cmake + +ARG CMAKE_VER=3.27.0 +RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \ + -q -O /tmp/cmake-install.sh \ + && chmod u+x /tmp/cmake-install.sh \ + && mkdir /opt/cmake-${CMAKE_VER} \ + && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \ + && rm /tmp/cmake-install.sh \ + && ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin + WORKDIR /home/wamr COPY . . RUN git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt WORKDIR /home/wamr/product-mini/platforms/linux RUN rm -rf build \ - && cmake -S . -B build -DWAMR_BUILD_WASI_NN=1 \ - -DWAMR_BUILD_WASI_NN=1 \ + && cmake -S . -B build\ + -DWAMR_BUILD_WASI_NN=1\ + -DWAMR_BUILD_WASI_NN_TFLITE=1\ -DWAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE=1 \ -DWAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH="libedgetpu.so.1.0" \ -DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \ && cmake --build build -j "$(grep -c ^processor /proc/cpuinfo)" -RUN cp /home/wamr/product-mini/platforms/linux/build/iwasm /usr/bin/iwasm \ - && cp /home/wamr/product-mini/platforms/linux/build/libiwasm.so /lib/libiwasm.so \ - && cp /home/wamr/product-mini/platforms/linux/build/libwasi-nn-*.so /lib/ +RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm \ + && cp /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib +ENV LD_LIBRARY_PATH=/usr/lib WORKDIR /assets ENTRYPOINT [ "iwasm" ] diff --git a/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate b/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate index f078045b9..e05b30119 100644 --- a/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate +++ b/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate @@ -21,6 +21,18 @@ RUN apt-get update && apt-get install -y wget ca-certificates --no-install-recom && update-ca-certificates \ && git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt +# need a newer cmake +RUN apt-get purge -y cmake + +ARG CMAKE_VER=3.27.0 +RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \ + -q -O /tmp/cmake-install.sh \ + && chmod u+x /tmp/cmake-install.sh \ + && mkdir /opt/cmake-${CMAKE_VER} \ + && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \ + && rm /tmp/cmake-install.sh \ + && ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin + # Build TensorFlow Lite VX delegate default built for x86-64 simulator WORKDIR /tmp RUN git clone https://github.com/VeriSilicon/TIM-VX.git tim-vx \ @@ -89,7 +101,6 @@ ENV VSIMULATOR_CONFIG=czl ENV LD_LIBRARY_PATH=/tmp/tim-vx/prebuilt-sdk/x86_64_linux/lib:/usr/local/lib:/lib/x86_64-linux-gnu/:/lib64/:/usr/lib:$LD_LIBRARY_PATH - # Build WASI-NN WORKDIR /home/wamr @@ -102,12 +113,14 @@ RUN cmake \ -DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}:/usr/local/lib/ \ -DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}:/usr/local/include/ \ -DWAMR_BUILD_WASI_NN=1 \ + -DWAMR_BUILD_WASI_NN_TFLITE=1\ -DWAMR_BUILD_WASI_NN_ENABLE_EXT=1 \ -DWASI_NN_EXT_DELEGATE_PATH="/usr/lib/libvx_delegate.so" \ .. RUN make -j "$(grep -c ^processor /proc/cpuinfo)" -RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm +RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm \ + && cp /home/wamr/product-mini/platforms/linux/build/lib*.so /usr/lib ENTRYPOINT [ "/run/iwasm" ] diff --git a/core/iwasm/libraries/wasi-nn/test/build.sh b/core/iwasm/libraries/wasi-nn/test/build.sh index da6cfa5f8..dda400f16 100755 --- a/core/iwasm/libraries/wasi-nn/test/build.sh +++ b/core/iwasm/libraries/wasi-nn/test/build.sh @@ -8,9 +8,9 @@ CURR_PATH=$(cd $(dirname $0) && pwd -P) # WASM application that uses WASI-NN /opt/wasi-sdk/bin/clang \ + --target=wasm32-wasi \ + -DNN_LOG_LEVEL=1 \ -Wl,--allow-undefined \ - -Wl,--strip-all,--no-entry \ - --sysroot=/opt/wasi-sdk/share/wasi-sysroot \ -I../include -I../src/utils \ -o test_tensorflow.wasm \ test_tensorflow.c utils.c @@ -28,9 +28,9 @@ python3 sum.py cd ${CURR_PATH} /opt/wasi-sdk/bin/clang \ + --target=wasm32-wasi \ + -DNN_LOG_LEVEL=1 \ -Wl,--allow-undefined \ - -Wl,--strip-all,--no-entry \ - --sysroot=/opt/wasi-sdk/share/wasi-sysroot \ -I../include -I../src/utils \ -o test_tensorflow_quantized.wasm \ test_tensorflow_quantized.c utils.c diff --git a/core/iwasm/libraries/wasi-nn/test/requirements.txt b/core/iwasm/libraries/wasi-nn/test/requirements.txt index 177c22c19..1643b91b0 100644 --- a/core/iwasm/libraries/wasi-nn/test/requirements.txt +++ b/core/iwasm/libraries/wasi-nn/test/requirements.txt @@ -1,2 +1,2 @@ tensorflow==2.12.1 -numpy==1.26.4 +numpy==1.24.4 diff --git a/core/iwasm/libraries/wasi-nn/test/utils.c b/core/iwasm/libraries/wasi-nn/test/utils.c index c499adc5b..9e43ec985 100644 --- a/core/iwasm/libraries/wasi-nn/test/utils.c +++ b/core/iwasm/libraries/wasi-nn/test/utils.c @@ -5,6 +5,7 @@ #include "utils.h" #include "logger.h" +#include "wasi_nn.h" #include #include @@ -57,7 +58,7 @@ wasm_load(char *model_name, graph *g, execution_target target) wasi_nn_error wasm_load_by_name(const char *model_name, graph *g) { - wasm_nn_error res = load_by_name(model_name, g); + wasi_nn_error res = load_by_name(model_name, g); return res; } From deacb7a8d8ca96b9dff797907b7e3b2ced4887df Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 8 Oct 2024 10:08:29 +0800 Subject: [PATCH 014/105] Fix exec_env_tls assertion in module instantiation (#3844) The execute_post_instantiate_functions may be triggered by wasm_cluster_spawn_exec_env, in which the exec_env_tls can be NULL and cause the assertion invalid. p.s. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3839. --- core/iwasm/aot/aot_runtime.c | 8 ++++++-- core/iwasm/interpreter/wasm_runtime.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 63a3c83c9..eb88fa6c3 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1560,8 +1560,12 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst, if (is_sub_inst) { bh_assert(exec_env_main); #ifdef OS_ENABLE_HW_BOUND_CHECK - bh_assert(exec_env_tls == exec_env_main); - (void)exec_env_tls; + /* May come from pthread_create_wrapper, thread_spawn_wrapper and + wasm_cluster_spawn_exec_env. If it comes from the former two, + the exec_env_tls must be not NULL and equal to exec_env_main, + else if it comes from the last one, it may be NULL. */ + if (exec_env_tls) + bh_assert(exec_env_tls == exec_env_main); #endif exec_env = exec_env_main; diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index e4142ab88..90299df97 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1594,8 +1594,12 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst, if (is_sub_inst) { bh_assert(exec_env_main); #ifdef OS_ENABLE_HW_BOUND_CHECK - bh_assert(exec_env_tls == exec_env_main); - (void)exec_env_tls; + /* May come from pthread_create_wrapper, thread_spawn_wrapper and + wasm_cluster_spawn_exec_env. If it comes from the former two, + the exec_env_tls must be not NULL and equal to exec_env_main, + else if it comes from the last one, it may be NULL. */ + if (exec_env_tls) + bh_assert(exec_env_tls == exec_env_main); #endif exec_env = exec_env_main; From 2b5e2d9c2c146203a2c6d89ffd47aeead307a29f Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Wed, 9 Oct 2024 19:57:47 -0700 Subject: [PATCH 015/105] libc-emcc: Use alternate method to check getrandom support (#3848) --- .../libraries/libc-emcc/libc_emcc_wrapper.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c b/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c index 11795069f..3bb6bc6b7 100644 --- a/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c +++ b/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c @@ -7,8 +7,13 @@ #include "bh_log.h" #include "wasm_export.h" #include "../interpreter/wasm.h" -#if !defined(_DEFAULT_SOURCE) && !defined(BH_PLATFORM_LINUX_SGX) -#include "sys/syscall.h" + +#if defined(__linux__) +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) +#define HAVE_SYSCALL_GETRANDOM +#include +#endif #endif /* clang-format off */ @@ -270,11 +275,10 @@ getentropy_wrapper(wasm_exec_env_t exec_env, void *buffer, uint32 length) { if (buffer == NULL) return -1; -#if defined(_DEFAULT_SOURCE) || defined(BH_PLATFORM_LINUX_SGX) \ - || defined(__APPLE__) - return getentropy(buffer, length); -#else +#if defined(HAVE_SYSCALL_GETRANDOM) return syscall(SYS_getrandom, buffer, length, 0); +#else + return getentropy(buffer, length); #endif } From 36d438051ec9955a7a88c79960625dda71638967 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:14:56 +0800 Subject: [PATCH 016/105] Support table64 extension in classic-interp and AOT running modes (#3811) Add table64 extension(in Memory64 proposal) support in classic-interp and AOT running modes, currently still use uint32 to represent table's initial and maximum size to keep AOT ABI unchanged. --- core/iwasm/aot/aot_loader.c | 6 + core/iwasm/aot/aot_runtime.c | 10 +- core/iwasm/common/wasm_loader_common.c | 62 +++++ core/iwasm/common/wasm_loader_common.h | 12 + core/iwasm/compilation/aot_compiler.c | 17 +- core/iwasm/compilation/aot_compiler.h | 11 + core/iwasm/compilation/aot_emit_function.c | 40 ++- core/iwasm/compilation/aot_emit_table.c | 145 ++++++++++- core/iwasm/interpreter/wasm.h | 6 + core/iwasm/interpreter/wasm_interp_classic.c | 142 ++++++++--- core/iwasm/interpreter/wasm_loader.c | 227 +++++++++++++----- core/iwasm/interpreter/wasm_mini_loader.c | 210 +++++++++++++--- core/iwasm/interpreter/wasm_runtime.c | 3 + core/iwasm/interpreter/wasm_runtime.h | 3 +- .../memory64_ignore_cases.patch | 197 +++++++++++++-- tests/wamr-test-suites/test_wamr.sh | 6 +- 16 files changed, 922 insertions(+), 175 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 0304bd096..3efb190e1 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -1382,6 +1382,12 @@ load_table_list(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, for (i = 0; i < module->table_count; i++, table++) { read_uint8(buf, buf_end, table->table_type.elem_type); read_uint8(buf, buf_end, table->table_type.flags); + + if (!wasm_table_check_flags(table->table_type.flags, error_buf, + error_buf_size, true)) { + return false; + } + read_uint8(buf, buf_end, table->table_type.possible_grow); #if WASM_ENABLE_GC != 0 if (wasm_is_type_multi_byte_type(table->table_type.elem_type)) { diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index eb88fa6c3..ebef54410 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -737,18 +737,24 @@ tables_instantiate(AOTModuleInstance *module_inst, AOTModule *module, #if WASM_ENABLE_REF_TYPES != 0 bh_assert( - table_seg->offset.init_expr_type == INIT_EXPR_TYPE_I32_CONST + table_seg->offset.init_expr_type + == (tbl_inst->is_table64 ? INIT_EXPR_TYPE_I64_CONST + : INIT_EXPR_TYPE_I32_CONST) || table_seg->offset.init_expr_type == INIT_EXPR_TYPE_GET_GLOBAL || table_seg->offset.init_expr_type == INIT_EXPR_TYPE_FUNCREF_CONST || table_seg->offset.init_expr_type == INIT_EXPR_TYPE_REFNULL_CONST); #else - bh_assert(table_seg->offset.init_expr_type == INIT_EXPR_TYPE_I32_CONST + bh_assert(table_seg->offset.init_expr_type + == (tbl_inst->is_table64 ? INIT_EXPR_TYPE_I64_CONST + : INIT_EXPR_TYPE_I32_CONST) || table_seg->offset.init_expr_type == INIT_EXPR_TYPE_GET_GLOBAL); #endif /* Resolve table data base offset */ + /* TODO: The table64 current implementation assumes table max size + * UINT32_MAX, so the offset conversion here is safe */ if (table_seg->offset.init_expr_type == INIT_EXPR_TYPE_GET_GLOBAL) { global_index = table_seg->offset.u.global_index; diff --git a/core/iwasm/common/wasm_loader_common.c b/core/iwasm/common/wasm_loader_common.c index 6dd31be2c..97ea5efd1 100644 --- a/core/iwasm/common/wasm_loader_common.c +++ b/core/iwasm/common/wasm_loader_common.c @@ -19,6 +19,37 @@ wasm_loader_set_error_buf(char *error_buf, uint32 error_buf_size, } } +#if WASM_ENABLE_MEMORY64 != 0 +bool +check_memory64_flags_consistency(WASMModule *module, char *error_buf, + uint32 error_buf_size, bool is_aot) +{ + uint32 i; + bool wasm64_flag, all_wasm64 = true, none_wasm64 = true; + + for (i = 0; i < module->import_memory_count; ++i) { + wasm64_flag = + module->import_memories[i].u.memory.mem_type.flags & MEMORY64_FLAG; + all_wasm64 &= wasm64_flag; + none_wasm64 &= !wasm64_flag; + } + + for (i = 0; i < module->memory_count; ++i) { + wasm64_flag = module->memories[i].flags & MEMORY64_FLAG; + all_wasm64 &= wasm64_flag; + none_wasm64 &= !wasm64_flag; + } + + if (!(all_wasm64 || none_wasm64)) { + wasm_loader_set_error_buf( + error_buf, error_buf_size, + "inconsistent limits wasm64 flags for memory sections", is_aot); + return false; + } + return true; +} +#endif + bool wasm_memory_check_flags(const uint8 mem_flag, char *error_buf, uint32 error_buf_size, bool is_aot) @@ -60,6 +91,37 @@ wasm_memory_check_flags(const uint8 mem_flag, char *error_buf, return true; } +bool +wasm_table_check_flags(const uint8 table_flag, char *error_buf, + uint32 error_buf_size, bool is_aot) +{ + /* Check whether certain features indicated by mem_flag are enabled in + * runtime */ + if (table_flag > MAX_TABLE_SIZE_FLAG) { + if (table_flag & SHARED_TABLE_FLAG) { + wasm_loader_set_error_buf(error_buf, error_buf_size, + "tables cannot be shared", is_aot); + } +#if WASM_ENABLE_MEMORY64 == 0 + if (table_flag & TABLE64_FLAG) { + wasm_loader_set_error_buf(error_buf, error_buf_size, + "invalid limits flags(table64 flag was " + "found, please enable memory64)", + is_aot); + return false; + } +#endif + } + + if (table_flag > MAX_TABLE_SIZE_FLAG + TABLE64_FLAG) { + wasm_loader_set_error_buf(error_buf, error_buf_size, + "invalid limits flags", is_aot); + return false; + } + + return true; +} + /* * compare with a bigger type set in `wasm_value_type_size_internal()`, * this function will only cover global value type, function's param diff --git a/core/iwasm/common/wasm_loader_common.h b/core/iwasm/common/wasm_loader_common.h index d574110ba..81174fb26 100644 --- a/core/iwasm/common/wasm_loader_common.h +++ b/core/iwasm/common/wasm_loader_common.h @@ -13,10 +13,22 @@ extern "C" { #endif +#if WASM_ENABLE_MEMORY64 != 0 +/* check consistency of memory64 flags across all memories, + * they must be either all wasm64 or all wasm32 */ +bool +check_memory64_flags_consistency(WASMModule *module, char *error_buf, + uint32 error_buf_size, bool is_aot); +#endif + bool wasm_memory_check_flags(const uint8 mem_flag, char *error_buf, uint32 error_buf_size, bool is_aot); +bool +wasm_table_check_flags(const uint8 table_flag, char *error_buf, + uint32 error_buf_size, bool is_aot); + bool is_valid_value_type(uint8 value_tpye); diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index e56004972..07734b3b4 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -146,9 +146,20 @@ aot_validate_wasm(AOTCompContext *comp_ctx) } #if WASM_ENABLE_MEMORY64 != 0 - if (comp_ctx->pointer_size < sizeof(uint64) && IS_MEMORY64) { - aot_set_last_error("Compiling wasm64 to 32bit platform is not allowed"); - return false; + if (comp_ctx->pointer_size < sizeof(uint64)) { + if (IS_MEMORY64) { + aot_set_last_error("Compiling wasm64(contains i64 memory section) " + "to 32bit platform is not allowed"); + return false; + } + + for (uint32 i = 0; i < comp_ctx->comp_data->table_count; ++i) { + if (IS_TABLE64(i)) { + aot_set_last_error("Compiling wasm64(contains i64 table " + "section) to 32bit platform is not allowed"); + return false; + } + } } #endif diff --git a/core/iwasm/compilation/aot_compiler.h b/core/iwasm/compilation/aot_compiler.h index 895d2416b..06d8e42bd 100644 --- a/core/iwasm/compilation/aot_compiler.h +++ b/core/iwasm/compilation/aot_compiler.h @@ -532,8 +532,13 @@ set_local_gc_ref(AOTCompFrame *frame, int n, LLVMValueRef value, uint8 ref_type) #define IS_MEMORY64 (comp_ctx->comp_data->memories[0].flags & MEMORY64_FLAG) #define MEMORY64_COND_VALUE(VAL_IF_ENABLED, VAL_IF_DISABLED) \ (IS_MEMORY64 ? VAL_IF_ENABLED : VAL_IF_DISABLED) +#define IS_TABLE64(i) \ + (comp_ctx->comp_data->tables[i].table_type.flags & TABLE64_FLAG) +#define TABLE64_COND_VALUE(i, VAL_IF_ENABLED, VAL_IF_DISABLED) \ + (IS_TABLE64(i) ? VAL_IF_ENABLED : VAL_IF_DISABLED) #else #define MEMORY64_COND_VALUE(VAL_IF_ENABLED, VAL_IF_DISABLED) (VAL_IF_DISABLED) +#define TABLE64_COND_VALUE(i, VAL_IF_ENABLED, VAL_IF_DISABLED) (VAL_IF_DISABLED) #endif #define POP_I32(v) POP(v, VALUE_TYPE_I32) @@ -548,6 +553,9 @@ set_local_gc_ref(AOTCompFrame *frame, int n, LLVMValueRef value, uint8 ref_type) POP(v, MEMORY64_COND_VALUE(VALUE_TYPE_I64, VALUE_TYPE_I32)) #define POP_PAGE_COUNT(v) \ POP(v, MEMORY64_COND_VALUE(VALUE_TYPE_I64, VALUE_TYPE_I32)) +#define POP_TBL_ELEM_IDX(v) \ + POP(v, TABLE64_COND_VALUE(tbl_idx, VALUE_TYPE_I64, VALUE_TYPE_I32)) +#define POP_TBL_ELEM_LEN(v) POP_TBL_ELEM_IDX(v) #define POP_COND(llvm_value) \ do { \ @@ -613,6 +621,9 @@ set_local_gc_ref(AOTCompFrame *frame, int n, LLVMValueRef value, uint8 ref_type) #define PUSH_GC_REF(v) PUSH(v, VALUE_TYPE_GC_REF) #define PUSH_PAGE_COUNT(v) \ PUSH(v, MEMORY64_COND_VALUE(VALUE_TYPE_I64, VALUE_TYPE_I32)) +#define PUSH_TBL_ELEM_IDX(v) \ + PUSH(v, TABLE64_COND_VALUE(tbl_idx, VALUE_TYPE_I64, VALUE_TYPE_I32)) +#define PUSH_TBL_ELEM_LEN(v) PUSH_TBL_ELEM_IDX(v) #define SET_CONST(v) \ do { \ diff --git a/core/iwasm/compilation/aot_emit_function.c b/core/iwasm/compilation/aot_emit_function.c index 85a9239aa..167acc62f 100644 --- a/core/iwasm/compilation/aot_emit_function.c +++ b/core/iwasm/compilation/aot_emit_function.c @@ -2089,6 +2089,9 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef ext_ret_offset, ext_ret_ptr, ext_ret, res; LLVMValueRef *param_values = NULL, *value_rets = NULL; LLVMValueRef *result_phis = NULL, value_ret, import_func_count; +#if WASM_ENABLE_MEMORY64 != 0 + LLVMValueRef u32_max, u32_cmp_result; +#endif LLVMTypeRef *param_types = NULL, ret_type; LLVMTypeRef llvm_func_type, llvm_func_ptr_type; LLVMTypeRef ext_ret_ptr_type; @@ -2153,7 +2156,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, func_param_count = func_type->param_count; func_result_count = func_type->result_count; - POP_I32(elem_idx); + POP_TBL_ELEM_IDX(elem_idx); /* get the cur size of the table instance */ if (!(offset = I32_CONST(get_tbl_inst_offset(comp_ctx, func_ctx, tbl_idx) @@ -2182,6 +2185,27 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; } +#if WASM_ENABLE_MEMORY64 != 0 + /* Check if elem index >= UINT32_MAX */ + if (IS_TABLE64(tbl_idx)) { + if (!(u32_max = I64_CONST(UINT32_MAX))) { + aot_set_last_error("llvm build const failed"); + goto fail; + } + if (!(u32_cmp_result = + LLVMBuildICmp(comp_ctx->builder, LLVMIntUGE, elem_idx, + u32_max, "cmp_elem_idx_u32_max"))) { + aot_set_last_error("llvm build icmp failed."); + goto fail; + } + if (!(elem_idx = LLVMBuildTrunc(comp_ctx->builder, elem_idx, I32_TYPE, + "elem_idx_i32"))) { + aot_set_last_error("llvm build trunc failed."); + goto fail; + } + } +#endif + /* Check if (uint32)elem index >= table size */ if (!(cmp_elem_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGE, elem_idx, table_size_const, "cmp_elem_idx"))) { @@ -2189,7 +2213,19 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; } - /* Throw exception if elem index >= table size */ +#if WASM_ENABLE_MEMORY64 != 0 + if (IS_TABLE64(tbl_idx)) { + if (!(cmp_elem_idx = + LLVMBuildOr(comp_ctx->builder, cmp_elem_idx, u32_cmp_result, + "larger_than_u32_max_or_cur_size"))) { + aot_set_last_error("llvm build or failed."); + goto fail; + } + } +#endif + + /* Throw exception if elem index >= table size or elem index >= UINT32_MAX + */ if (!(check_elem_idx_succ = LLVMAppendBasicBlockInContext( comp_ctx->context, func_ctx->func, "check_elem_idx_succ"))) { aot_set_last_error("llvm add basic block failed."); diff --git a/core/iwasm/compilation/aot_emit_table.c b/core/iwasm/compilation/aot_emit_table.c index f968bacdd..d65d2f413 100644 --- a/core/iwasm/compilation/aot_emit_table.c +++ b/core/iwasm/compilation/aot_emit_table.c @@ -10,6 +10,72 @@ #include "aot_emit_gc.h" #endif +static bool +zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name) +{ + if (comp_ctx->pointer_size == sizeof(uint64)) { + /* zero extend to uint64 if the target is 64-bit */ + *value = LLVMBuildZExt(comp_ctx->builder, *value, I64_TYPE, name); + if (!*value) { + aot_set_last_error("llvm build zero extend failed."); + return false; + } + } + return true; +} + +/* check whether a table64 elem idx is greater than UINT32_MAX, if so, throw + * exception, otherwise trunc it to uint32 */ +static bool +check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, + LLVMValueRef *elem_idx, uint32 tbl_idx) +{ + LLVMValueRef u32_max, u32_cmp_result; + LLVMBasicBlockRef check_elem_idx_succ; + +#if WASM_ENABLE_MEMORY64 != 0 + if (!IS_TABLE64(tbl_idx)) { + return true; + } + + /* Check if elem index >= UINT32_MAX */ + if (!(u32_max = I64_CONST(UINT32_MAX))) { + aot_set_last_error("llvm build const failed"); + goto fail; + } + if (!(u32_cmp_result = + LLVMBuildICmp(comp_ctx->builder, LLVMIntUGE, *elem_idx, u32_max, + "cmp_elem_idx_u32_max"))) { + aot_set_last_error("llvm build icmp failed."); + goto fail; + } + if (!(*elem_idx = LLVMBuildTrunc(comp_ctx->builder, *elem_idx, I32_TYPE, + "elem_idx_i32"))) { + aot_set_last_error("llvm build trunc failed."); + goto fail; + } + + /* Throw exception if elem index >= UINT32_MAX*/ + if (!(check_elem_idx_succ = LLVMAppendBasicBlockInContext( + comp_ctx->context, func_ctx->func, "check_elem_idx_succ"))) { + aot_set_last_error("llvm add basic block failed."); + goto fail; + } + + LLVMMoveBasicBlockAfter(check_elem_idx_succ, + LLVMGetInsertBlock(comp_ctx->builder)); + + if (!(aot_emit_exception(comp_ctx, func_ctx, + EXCE_OUT_OF_BOUNDS_TABLE_ACCESS, true, + u32_cmp_result, check_elem_idx_succ))) + goto fail; +#endif + + return true; +fail: + return false; +} + uint64 get_tbl_inst_offset(const AOTCompContext *comp_ctx, const AOTFuncContext *func_ctx, uint32 tbl_idx) @@ -158,6 +224,10 @@ aot_check_table_access(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; } + if (!check_tbl_elem_idx_and_trunc(comp_ctx, func_ctx, &elem_idx, tbl_idx)) { + goto fail; + } + /* Check if (uint32)elem index >= table size */ if (!(cmp_elem_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGE, elem_idx, tbl_sz, "cmp_elem_idx"))) { @@ -192,7 +262,7 @@ aot_compile_op_table_get(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef elem_idx, offset, func_idx; LLVMValueRef table_elem_base, table_elem_addr, table_elem; - POP_I32(elem_idx); + POP_TBL_ELEM_IDX(elem_idx); if (!aot_check_table_access(comp_ctx, func_ctx, tbl_idx, elem_idx)) { goto fail; @@ -289,7 +359,7 @@ aot_compile_op_table_set(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } } - POP_I32(elem_idx); + POP_TBL_ELEM_IDX(elem_idx); if (!aot_check_table_access(comp_ctx, func_ctx, tbl_idx, elem_idx)) { goto fail; @@ -388,7 +458,11 @@ aot_compile_op_table_init(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, /* s */ POP_I32(param_values[4]); /* d */ - POP_I32(param_values[5]); + POP_TBL_ELEM_IDX(param_values[5]); + if (!check_tbl_elem_idx_and_trunc(comp_ctx, func_ctx, ¶m_values[5], + tbl_idx)) { + goto fail; + } /* "" means return void */ if (!(LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values, 6, @@ -408,6 +482,7 @@ aot_compile_op_table_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMTypeRef param_types[6], ret_type, func_type, func_ptr_type; LLVMValueRef func, param_values[6], value; + uint32 tbl_idx; param_types[0] = INT8_PTR_TYPE; param_types[1] = I32_TYPE; @@ -434,12 +509,34 @@ aot_compile_op_table_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; } + /* In table64, the length should be i32 type if any one of src/dst table + * is i32 type, set the table index to the lesser-or-equal table when + * popping length n */ + if (!(comp_ctx->comp_data->tables[src_tbl_idx].table_type.flags + & TABLE64_FLAG)) + tbl_idx = src_tbl_idx; + else + tbl_idx = dst_tbl_idx; /* n */ - POP_I32(param_values[3]); + POP_TBL_ELEM_LEN(param_values[3]); + if (!check_tbl_elem_idx_and_trunc(comp_ctx, func_ctx, ¶m_values[3], + tbl_idx)) { + goto fail; + } /* s */ - POP_I32(param_values[4]); + tbl_idx = src_tbl_idx; + POP_TBL_ELEM_IDX(param_values[4]); + if (!check_tbl_elem_idx_and_trunc(comp_ctx, func_ctx, ¶m_values[4], + tbl_idx)) { + goto fail; + } /* d */ - POP_I32(param_values[5]); + tbl_idx = dst_tbl_idx; + POP_TBL_ELEM_IDX(param_values[5]); + if (!check_tbl_elem_idx_and_trunc(comp_ctx, func_ctx, ¶m_values[5], + tbl_idx)) { + goto fail; + } /* "" means return void */ if (!(LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values, 6, @@ -484,7 +581,14 @@ aot_compile_op_table_size(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; } - PUSH_I32(tbl_sz); +#if WASM_ENABLE_MEMORY64 != 0 + if (IS_TABLE64(tbl_idx)) { + if (!zero_extend_u64(comp_ctx, &tbl_sz, "length64")) { + goto fail; + } + } +#endif + PUSH_TBL_ELEM_IDX(tbl_sz); return true; fail: @@ -517,7 +621,11 @@ aot_compile_op_table_grow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } /* n */ - POP_I32(param_values[2]); + POP_TBL_ELEM_LEN(param_values[2]); + if (!check_tbl_elem_idx_and_trunc(comp_ctx, func_ctx, ¶m_values[2], + tbl_idx)) { + goto fail; + } /* v */ if (comp_ctx->enable_gc) { @@ -545,7 +653,14 @@ aot_compile_op_table_grow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; } - PUSH_I32(ret); +#if WASM_ENABLE_MEMORY64 != 0 + if (IS_TABLE64(tbl_idx)) { + if (!zero_extend_u64(comp_ctx, &ret, "table_size64")) { + goto fail; + } + } +#endif + PUSH_TBL_ELEM_LEN(ret); return true; fail: @@ -579,7 +694,11 @@ aot_compile_op_table_fill(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } /* n */ - POP_I32(param_values[2]); + POP_TBL_ELEM_LEN(param_values[2]); + if (!check_tbl_elem_idx_and_trunc(comp_ctx, func_ctx, ¶m_values[2], + tbl_idx)) { + goto fail; + } /* v */ if (comp_ctx->enable_gc) { @@ -601,7 +720,11 @@ aot_compile_op_table_fill(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } } /* i */ - POP_I32(param_values[4]); + POP_TBL_ELEM_IDX(param_values[4]); + if (!check_tbl_elem_idx_and_trunc(comp_ctx, func_ctx, ¶m_values[4], + tbl_idx)) { + goto fail; + } /* "" means return void */ if (!(LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values, 5, diff --git a/core/iwasm/interpreter/wasm.h b/core/iwasm/interpreter/wasm.h index 83597401a..6023b0702 100644 --- a/core/iwasm/interpreter/wasm.h +++ b/core/iwasm/interpreter/wasm.h @@ -93,6 +93,10 @@ extern "C" { #define MAX_PAGE_COUNT_FLAG 0x01 #define SHARED_MEMORY_FLAG 0x02 #define MEMORY64_FLAG 0x04 +#define MAX_TABLE_SIZE_FLAG 0x01 +/* the shared flag for table is not actual used now */ +#define SHARED_TABLE_FLAG 0x02 +#define TABLE64_FLAG 0x04 /** * In the multi-memory proposal, the memarg in loads and stores are @@ -494,6 +498,7 @@ typedef struct WASMTableType { * 0: no max size and not shared * 1: has max size * 2: shared + * 4: table64 */ uint8 flags; bool possible_grow; @@ -520,6 +525,7 @@ typedef uint64 mem_offset_t; typedef uint32 mem_offset_t; #define PR_MEM_OFFSET PRIu32 #endif +typedef mem_offset_t tbl_elem_idx_t; typedef struct WASMMemory { uint32 flags; diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 67f8c2d45..faa97f35c 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -511,9 +511,9 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame) #endif #if WASM_ENABLE_MEMORY64 != 0 -#define PUSH_MEM_OFFSET(value) \ +#define COND_PUSH_TEMPLATE(cond, value) \ do { \ - if (is_memory64) { \ + if (cond) { \ PUT_I64_TO_ADDR(frame_sp, value); \ frame_sp += 2; \ } \ @@ -521,8 +521,11 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame) *(int32 *)frame_sp++ = (int32)(value); \ } \ } while (0) +#define PUSH_MEM_OFFSET(value) COND_PUSH_TEMPLATE(is_memory64, value) +#define PUSH_TBL_ELEM_IDX(value) COND_PUSH_TEMPLATE(is_table64, value) #else #define PUSH_MEM_OFFSET(value) PUSH_I32(value) +#define PUSH_TBL_ELEM_IDX(value) PUSH_I32(value) #endif #define PUSH_PAGE_COUNT(value) PUSH_MEM_OFFSET(value) @@ -558,8 +561,10 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame) #if WASM_ENABLE_MEMORY64 != 0 #define POP_MEM_OFFSET() (is_memory64 ? POP_I64() : POP_I32()) +#define POP_TBL_ELEM_IDX() (is_table64 ? POP_I64() : POP_I32()) #else #define POP_MEM_OFFSET() POP_I32() +#define POP_TBL_ELEM_IDX() POP_I32() #endif #define POP_PAGE_COUNT() POP_MEM_OFFSET() @@ -1562,7 +1567,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, uint8 opcode; uint32 i, depth, cond, count, fidx, tidx, lidx, frame_size = 0; uint32 all_cell_num = 0; - int32 val; + tbl_elem_idx_t val; uint8 *else_addr, *end_addr, *maddr = NULL; uint32 local_idx, local_offset, global_idx; uint8 local_type, *global_addr; @@ -1602,6 +1607,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, /* TODO: multi-memories for now assuming the memory idx type is consistent * across multi-memories */ bool is_memory64 = false; + bool is_table64 = false; if (memory) is_memory64 = memory->is_memory64; #endif @@ -2315,7 +2321,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, /** * type check. compiler will make sure all like - * (call_indirect (type $x) (i32.const 1)) + * (call_indirect (type $x) (it.const 1)) * the function type has to be defined in the module also * no matter it is used or not */ @@ -2334,9 +2340,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, /* clang-format on */ tbl_inst = wasm_get_table_inst(module, tbl_idx); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = tbl_inst->is_table64; +#endif - val = POP_I32(); - if ((uint32)val >= tbl_inst->cur_size) { + val = POP_TBL_ELEM_IDX(); + if (val >= tbl_inst->cur_size) { wasm_set_exception(module, "undefined element"); goto got_exception; } @@ -2482,15 +2491,19 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP(WASM_OP_TABLE_GET) { - uint32 tbl_idx, elem_idx; + uint32 tbl_idx; + tbl_elem_idx_t elem_idx; WASMTableInstance *tbl_inst; read_leb_uint32(frame_ip, frame_ip_end, tbl_idx); bh_assert(tbl_idx < module->table_count); tbl_inst = wasm_get_table_inst(module, tbl_idx); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = tbl_inst->is_table64; +#endif - elem_idx = POP_I32(); + elem_idx = POP_TBL_ELEM_IDX(); if (elem_idx >= tbl_inst->cur_size) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; @@ -2507,20 +2520,24 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP(WASM_OP_TABLE_SET) { WASMTableInstance *tbl_inst; - uint32 tbl_idx, elem_idx; + uint32 tbl_idx; + tbl_elem_idx_t elem_idx; table_elem_type_t elem_val; read_leb_uint32(frame_ip, frame_ip_end, tbl_idx); bh_assert(tbl_idx < module->table_count); tbl_inst = wasm_get_table_inst(module, tbl_idx); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = tbl_inst->is_table64; +#endif #if WASM_ENABLE_GC == 0 elem_val = POP_I32(); #else elem_val = POP_REF(); #endif - elem_idx = POP_I32(); + elem_idx = POP_TBL_ELEM_IDX(); if (elem_idx >= tbl_inst->cur_size) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; @@ -4616,13 +4633,19 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP(WASM_OP_MEMORY_GROW) { - uint32 mem_idx, delta, prev_page_count; + uint32 mem_idx, prev_page_count; + mem_offset_t delta; read_leb_memidx(frame_ip, frame_ip_end, mem_idx); prev_page_count = memory->cur_page_count; - delta = (uint32)POP_PAGE_COUNT(); + delta = POP_PAGE_COUNT(); - if (!wasm_enlarge_memory_with_idx(module, delta, mem_idx)) { + if ( +#if WASM_ENABLE_MEMORY64 != 0 + delta > UINT32_MAX || +#endif + !wasm_enlarge_memory_with_idx(module, (uint32)delta, + mem_idx)) { /* failed to memory.grow, return -1 */ PUSH_PAGE_COUNT(-1); } @@ -5778,8 +5801,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 case WASM_OP_TABLE_INIT: { - uint32 tbl_idx, elem_idx; - uint32 n, s, d; + uint32 tbl_idx; + tbl_elem_idx_t elem_idx, d; + uint32 n, s; WASMTableInstance *tbl_inst; table_elem_type_t *table_elems; InitializerExpression *tbl_seg_init_values = NULL, @@ -5793,10 +5817,13 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, bh_assert(tbl_idx < module->module->table_count); tbl_inst = wasm_get_table_inst(module, tbl_idx); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = tbl_inst->is_table64; +#endif n = (uint32)POP_I32(); s = (uint32)POP_I32(); - d = (uint32)POP_I32(); + d = (tbl_elem_idx_t)POP_TBL_ELEM_IDX(); if (!bh_bitmap_get_bit(module->e->common.elem_dropped, elem_idx)) { @@ -5809,8 +5836,15 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, .value_count; } - if (offset_len_out_of_bounds(s, n, tbl_seg_len) - || offset_len_out_of_bounds(d, n, + /* TODO: memory64 current implementation of table64 + * still assumes the max table size UINT32_MAX + */ + if ( +#if WASM_ENABLE_MEMORY64 != 0 + d > UINT32_MAX || +#endif + offset_len_out_of_bounds(s, n, tbl_seg_len) + || offset_len_out_of_bounds((uint32)d, n, tbl_inst->cur_size)) { wasm_set_exception(module, "out of bounds table access"); @@ -5864,7 +5898,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, case WASM_OP_TABLE_COPY: { uint32 src_tbl_idx, dst_tbl_idx; - uint32 n, s, d; + tbl_elem_idx_t n, s, d; WASMTableInstance *src_tbl_inst, *dst_tbl_inst; read_leb_uint32(frame_ip, frame_ip_end, dst_tbl_idx); @@ -5877,14 +5911,29 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, src_tbl_inst = wasm_get_table_inst(module, src_tbl_idx); - n = (uint32)POP_I32(); - s = (uint32)POP_I32(); - d = (uint32)POP_I32(); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = src_tbl_inst->is_table64 + && dst_tbl_inst->is_table64; +#endif + n = (tbl_elem_idx_t)POP_TBL_ELEM_IDX(); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = src_tbl_inst->is_table64; +#endif + s = (tbl_elem_idx_t)POP_TBL_ELEM_IDX(); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = dst_tbl_inst->is_table64; +#endif + d = (tbl_elem_idx_t)POP_TBL_ELEM_IDX(); - if (offset_len_out_of_bounds(d, n, + if ( +#if WASM_ENABLE_MEMORY64 != 0 + n > UINT32_MAX || s > UINT32_MAX || d > UINT32_MAX + || +#endif + offset_len_out_of_bounds((uint32)d, (uint32)n, dst_tbl_inst->cur_size) || offset_len_out_of_bounds( - s, n, src_tbl_inst->cur_size)) { + (uint32)s, (uint32)n, src_tbl_inst->cur_size)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; @@ -5907,28 +5956,37 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, case WASM_OP_TABLE_GROW: { WASMTableInstance *tbl_inst; - uint32 tbl_idx, n, orig_tbl_sz; + uint32 tbl_idx, orig_tbl_sz; + tbl_elem_idx_t n; table_elem_type_t init_val; read_leb_uint32(frame_ip, frame_ip_end, tbl_idx); bh_assert(tbl_idx < module->table_count); tbl_inst = wasm_get_table_inst(module, tbl_idx); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = tbl_inst->is_table64; +#endif orig_tbl_sz = tbl_inst->cur_size; - n = POP_I32(); + n = POP_TBL_ELEM_IDX(); #if WASM_ENABLE_GC == 0 init_val = POP_I32(); #else init_val = POP_REF(); #endif - if (!wasm_enlarge_table(module, tbl_idx, n, init_val)) { - PUSH_I32(-1); + if ( +#if WASM_ENABLE_MEMORY64 != 0 + n > UINT32_MAX || +#endif + !wasm_enlarge_table(module, tbl_idx, (uint32)n, + init_val)) { + PUSH_TBL_ELEM_IDX(-1); } else { - PUSH_I32(orig_tbl_sz); + PUSH_TBL_ELEM_IDX(orig_tbl_sz); } break; } @@ -5941,13 +5999,17 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, bh_assert(tbl_idx < module->table_count); tbl_inst = wasm_get_table_inst(module, tbl_idx); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = tbl_inst->is_table64; +#endif - PUSH_I32(tbl_inst->cur_size); + PUSH_TBL_ELEM_IDX(tbl_inst->cur_size); break; } case WASM_OP_TABLE_FILL: { - uint32 tbl_idx, n; + uint32 tbl_idx; + tbl_elem_idx_t n, elem_idx; WASMTableInstance *tbl_inst; table_elem_type_t fill_val; @@ -5955,24 +6017,32 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, bh_assert(tbl_idx < module->table_count); tbl_inst = wasm_get_table_inst(module, tbl_idx); +#if WASM_ENABLE_MEMORY64 != 0 + is_table64 = tbl_inst->is_table64; +#endif - n = POP_I32(); + n = POP_TBL_ELEM_IDX(); #if WASM_ENABLE_GC == 0 fill_val = POP_I32(); #else fill_val = POP_REF(); #endif - i = POP_I32(); + elem_idx = POP_TBL_ELEM_IDX(); - if (offset_len_out_of_bounds(i, n, + if ( +#if WASM_ENABLE_MEMORY64 != 0 + n > UINT32_MAX || elem_idx > UINT32_MAX || +#endif + offset_len_out_of_bounds((uint32)elem_idx, + (uint32)n, tbl_inst->cur_size)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; } - for (; n != 0; i++, n--) { - tbl_inst->elems[i] = fill_val; + for (; n != 0; elem_idx++, n--) { + tbl_inst->elems[elem_idx] = fill_val; } break; } diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index ff3501e3d..e6b797f9b 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -51,6 +51,18 @@ has_module_memory64(WASMModule *module) return false; } + +static bool +is_table_64bit(WASMModule *module, uint32 table_idx) +{ + if (table_idx < module->import_table_count) + return !!(module->import_tables[table_idx].u.table.table_type.flags + & TABLE64_FLAG); + else + return !!(module->tables[table_idx].table_type.flags & TABLE64_FLAG); + + return false; +} #endif static void @@ -2201,10 +2213,14 @@ fail: } static void -adjust_table_max_size(uint32 init_size, uint32 max_size_flag, uint32 *max_size) +adjust_table_max_size(bool is_table64, uint32 init_size, uint32 max_size_flag, + uint32 *max_size) { uint32 default_max_size; + /* TODO: current still use UINT32_MAX as upper limit for table size to keep + * ABI unchanged */ + (void)is_table64; if (UINT32_MAX / 2 > init_size) default_max_size = init_size * 2; else @@ -2499,9 +2515,9 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end, const char *table_name, WASMTableImport *table, char *error_buf, uint32 error_buf_size) { - const uint8 *p = *p_buf, *p_end = buf_end; - uint32 declare_elem_type = 0, declare_max_size_flag = 0, - declare_init_size = 0, declare_max_size = 0; + const uint8 *p = *p_buf, *p_end = buf_end, *p_org; + uint32 declare_elem_type = 0, table_flag = 0, declare_init_size = 0, + declare_max_size = 0; #if WASM_ENABLE_MULTI_MODULE != 0 WASMModule *sub_module = NULL; WASMTable *linked_table = NULL; @@ -2510,6 +2526,7 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end, WASMRefType ref_type; bool need_ref_type_map; #endif + bool is_table64 = false; #if WASM_ENABLE_GC == 0 CHECK_BUF(p, p_end, 1); @@ -2548,23 +2565,29 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end, #endif #endif /* end of WASM_ENABLE_GC == 0 */ - read_leb_uint32(p, p_end, declare_max_size_flag); - if (declare_max_size_flag > 1) { - set_error_buf(error_buf, error_buf_size, "integer too large"); + p_org = p; + read_leb_uint32(p, p_end, table_flag); + is_table64 = table_flag & TABLE64_FLAG; + if (p - p_org > 1) { + LOG_VERBOSE("integer representation too long(import table)"); + set_error_buf(error_buf, error_buf_size, "invalid limits flags"); + return false; + } + + if (!wasm_table_check_flags(table_flag, error_buf, error_buf_size, false)) { return false; } read_leb_uint32(p, p_end, declare_init_size); - - if (declare_max_size_flag) { + if (table_flag & MAX_TABLE_SIZE_FLAG) { read_leb_uint32(p, p_end, declare_max_size); if (!check_table_max_size(declare_init_size, declare_max_size, error_buf, error_buf_size)) return false; } - adjust_table_max_size(declare_init_size, declare_max_size_flag, - &declare_max_size); + adjust_table_max_size(is_table64, declare_init_size, + table_flag & MAX_TABLE_SIZE_FLAG, &declare_max_size); *p_buf = p; @@ -2582,7 +2605,7 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end, declare_elem_type = linked_table->table_type.elem_type; declare_init_size = linked_table->table_type.init_size; declare_max_size = linked_table->table_type.max_size; - declare_max_size_flag = linked_table->table_type.flags; + table_flag = linked_table->table_type.flags; table->import_table_linked = linked_table; table->import_module = sub_module; } @@ -2591,12 +2614,17 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end, #endif /* WASM_ENABLE_MULTI_MODULE != 0 */ /* (table (export "table") 10 20 funcref) */ + /* (table (export "table64") 10 20 funcref) */ /* we need this section working in wamrc */ if (!strcmp("spectest", sub_module_name)) { const uint32 spectest_table_init_size = 10; const uint32 spectest_table_max_size = 20; - if (strcmp("table", table_name)) { + if (strcmp("table", table_name) +#if WASM_ENABLE_MEMORY64 != 0 + && strcmp("table64", table_name) +#endif + ) { set_error_buf(error_buf, error_buf_size, "incompatible import type or unknown import"); return false; @@ -2616,7 +2644,7 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end, /* now we believe all declaration are ok */ table->table_type.elem_type = declare_elem_type; table->table_type.init_size = declare_init_size; - table->table_type.flags = declare_max_size_flag; + table->table_type.flags = table_flag; table->table_type.max_size = declare_max_size; #if WASM_ENABLE_WAMR_COMPILER != 0 @@ -2709,7 +2737,7 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end, read_leb_uint32(p, p_end, mem_flag); is_memory64 = mem_flag & MEMORY64_FLAG; if (p - p_org > 1) { - LOG_VERBOSE("integer representation too long"); + LOG_VERBOSE("integer representation too long(import memory)"); set_error_buf(error_buf, error_buf_size, "invalid limits flags"); return false; } @@ -3024,6 +3052,7 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module, WASMRefType ref_type; bool need_ref_type_map; #endif + bool is_table64 = false; #if WASM_ENABLE_GC == 0 CHECK_BUF(p, p_end, 1); @@ -3061,34 +3090,20 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module, p_org = p; read_leb_uint32(p, p_end, table->table_type.flags); -#if WASM_ENABLE_SHARED_MEMORY == 0 - if (p - p_org > 1) { - set_error_buf(error_buf, error_buf_size, - "integer representation too long"); - return false; - } - if (table->table_type.flags > 1) { - set_error_buf(error_buf, error_buf_size, "integer too large"); - return false; - } -#else + is_table64 = table->table_type.flags & TABLE64_FLAG; if (p - p_org > 1) { + LOG_VERBOSE("integer representation too long(table)"); set_error_buf(error_buf, error_buf_size, "invalid limits flags"); return false; } - if (table->table_type.flags == 2) { - set_error_buf(error_buf, error_buf_size, "tables cannot be shared"); + + if (!wasm_table_check_flags(table->table_type.flags, error_buf, + error_buf_size, false)) { return false; } - if (table->table_type.flags > 1) { - set_error_buf(error_buf, error_buf_size, "invalid limits flags"); - return false; - } -#endif read_leb_uint32(p, p_end, table->table_type.init_size); - - if (table->table_type.flags) { + if (table->table_type.flags & MAX_TABLE_SIZE_FLAG) { read_leb_uint32(p, p_end, table->table_type.max_size); if (!check_table_max_size(table->table_type.init_size, table->table_type.max_size, error_buf, @@ -3096,7 +3111,8 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module, return false; } - adjust_table_max_size(table->table_type.init_size, table->table_type.flags, + adjust_table_max_size(is_table64, table->table_type.init_size, + table->table_type.flags & MAX_TABLE_SIZE_FLAG, &table->table_type.max_size); #if WASM_ENABLE_WAMR_COMPILER != 0 @@ -3128,7 +3144,7 @@ load_memory(const uint8 **p_buf, const uint8 *buf_end, WASMMemory *memory, read_leb_uint32(p, p_end, memory->flags); is_memory64 = memory->flags & MEMORY64_FLAG; if (p - p_org > 1) { - LOG_VERBOSE("integer representation too long"); + LOG_VERBOSE("integer representation too long(memory)"); set_error_buf(error_buf, error_buf_size, "invalid limits flags"); return false; } @@ -4402,6 +4418,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, uint32 error_buf_size) { const uint8 *p = buf, *p_end = buf_end; + uint8 table_elem_idx_type; uint32 table_segment_count, i; uint64 total_size; WASMTableSeg *table_segment; @@ -4424,6 +4441,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, "invalid elements segment kind"); return false; } + table_elem_idx_type = VALUE_TYPE_I32; #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 read_leb_uint32(p, p_end, table_segment->mode); @@ -4459,9 +4477,17 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, if (!check_table_index(module, table_segment->table_index, error_buf, error_buf_size)) return false; - if (!load_init_expr( - module, &p, p_end, &table_segment->base_offset, - VALUE_TYPE_I32, NULL, error_buf, error_buf_size)) + +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = + is_table_64bit(module, table_segment->table_index) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif + if (!load_init_expr(module, &p, p_end, + &table_segment->base_offset, + table_elem_idx_type, NULL, error_buf, + error_buf_size)) return false; if (table_segment->mode == 0) { @@ -4509,9 +4535,16 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, &table_segment->table_index, error_buf, error_buf_size)) return false; - if (!load_init_expr( - module, &p, p_end, &table_segment->base_offset, - VALUE_TYPE_I32, NULL, error_buf, error_buf_size)) +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = + is_table_64bit(module, table_segment->table_index) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif + if (!load_init_expr(module, &p, p_end, + &table_segment->base_offset, + table_elem_idx_type, NULL, error_buf, + error_buf_size)) return false; if (!load_elem_type(module, &p, p_end, &table_segment->elem_type, @@ -4563,7 +4596,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, "unknown element segment kind"); return false; } -#else /* else of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */ +#else /* else of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */ /* * like: 00 41 05 0b 04 00 01 00 01 * for: (elem 0 (offset (i32.const 5)) $f1 $f2 $f1 $f2) @@ -4572,8 +4605,14 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, &table_segment->table_index, error_buf, error_buf_size)) return false; +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = + is_table_64bit(module, table_segment->table_index) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif if (!load_init_expr(module, &p, p_end, &table_segment->base_offset, - VALUE_TYPE_I32, NULL, error_buf, + table_elem_idx_type, NULL, error_buf, error_buf_size)) return false; if (!load_func_index_vec(&p, p_end, module, table_segment, @@ -4588,6 +4627,16 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, return false; #endif /* end of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */ +#if WASM_ENABLE_MEMORY64 != 0 + if (table_elem_idx_type == VALUE_TYPE_I64 + && table_segment->base_offset.u.u64 > UINT32_MAX) { + set_error_buf(error_buf, error_buf_size, + "In table64, table base offset can't be " + "larger than UINT32_MAX"); + return false; + } +#endif + #if WASM_ENABLE_WAMR_COMPILER != 0 if (table_segment->elem_type == VALUE_TYPE_EXTERNREF) module->is_ref_types_used = true; @@ -6110,6 +6159,12 @@ load_from_sections(WASMModule *module, WASMSection *sections, #endif } +#if WASM_ENABLE_MEMORY64 != 0 + if (!check_memory64_flags_consistency(module, error_buf, error_buf_size, + false)) + return false; +#endif + calculate_global_data_offset(module); #if WASM_ENABLE_FAST_JIT != 0 @@ -9608,6 +9663,7 @@ fail: #define POP_REF(Type) TEMPLATE_POP_REF(Type) #define PUSH_MEM_OFFSET() TEMPLATE_PUSH_REF(mem_offset_type) #define PUSH_PAGE_COUNT() PUSH_MEM_OFFSET() +#define PUSH_TBL_ELEM_IDX() TEMPLATE_PUSH_REF(table_elem_idx_type) #define POP_I32() TEMPLATE_POP(I32) #define POP_F32() TEMPLATE_POP(F32) @@ -9618,6 +9674,7 @@ fail: #define POP_EXTERNREF() TEMPLATE_POP(EXTERNREF) #define POP_STRINGREF() TEMPLATE_POP(STRINGREF) #define POP_MEM_OFFSET() TEMPLATE_POP_REF(mem_offset_type) +#define POP_TBL_ELEM_IDX() TEMPLATE_POP_REF(table_elem_idx_type) #if WASM_ENABLE_FAST_INTERP != 0 @@ -10803,7 +10860,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, { uint8 *p = func->code, *p_end = func->code + func->code_size, *p_org; uint32 param_count, local_count, global_count; - uint8 *param_types, *local_types, local_type, global_type, mem_offset_type; + uint8 *param_types, *local_types, local_type, global_type, mem_offset_type, + table_elem_idx_type; BlockType func_block_type; uint16 *local_offsets, local_offset; uint32 type_idx, func_idx, local_idx, global_idx, table_idx; @@ -10838,6 +10896,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, mem_offset_type = is_memory64 ? VALUE_TYPE_I64 : VALUE_TYPE_I32; #else mem_offset_type = VALUE_TYPE_I32; + table_elem_idx_type = VALUE_TYPE_I32; #endif uint32 memidx; @@ -11997,8 +12056,13 @@ re_scan: emit_uint32(loader_ctx, table_idx); #endif +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif /* skip elem idx */ - POP_I32(); + POP_TBL_ELEM_IDX(); if (type_idx >= module->type_count) { set_error_buf(error_buf, error_buf_size, "unknown type"); @@ -12375,8 +12439,8 @@ re_scan: break; } - /* table.get x. tables[x]. [i32] -> [t] */ - /* table.set x. tables[x]. [i32 t] -> [] */ + /* table.get x. tables[x]. [it] -> [t] */ + /* table.set x. tables[x]. [it t] -> [] */ case WASM_OP_TABLE_GET: case WASM_OP_TABLE_SET: { @@ -12407,8 +12471,13 @@ re_scan: emit_uint32(loader_ctx, table_idx); #endif +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif if (opcode == WASM_OP_TABLE_GET) { - POP_I32(); + POP_TBL_ELEM_IDX(); #if WASM_ENABLE_FAST_INTERP != 0 PUSH_OFFSET_TYPE(decl_ref_type); #endif @@ -12419,7 +12488,7 @@ re_scan: POP_OFFSET_TYPE(decl_ref_type); #endif POP_TYPE(decl_ref_type); - POP_I32(); + POP_TBL_ELEM_IDX(); } #if WASM_ENABLE_WAMR_COMPILER != 0 @@ -14702,7 +14771,12 @@ re_scan: #endif POP_I32(); POP_I32(); - POP_I32(); +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif + POP_TBL_ELEM_IDX(); #if WASM_ENABLE_WAMR_COMPILER != 0 module->is_ref_types_used = true; @@ -14727,7 +14801,8 @@ re_scan: } case WASM_OP_TABLE_COPY: { - uint8 src_type, dst_type; + uint8 src_type, dst_type, src_tbl_idx_type, + dst_tbl_idx_type, min_tbl_idx_type; #if WASM_ENABLE_GC != 0 WASMRefType *src_ref_type = NULL, *dst_ref_type = NULL; #endif @@ -14773,9 +14848,31 @@ re_scan: emit_uint32(loader_ctx, dst_tbl_idx); emit_uint32(loader_ctx, src_tbl_idx); #endif - POP_I32(); - POP_I32(); - POP_I32(); + +#if WASM_ENABLE_MEMORY64 != 0 + src_tbl_idx_type = is_table_64bit(module, src_tbl_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; + dst_tbl_idx_type = is_table_64bit(module, dst_tbl_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; + min_tbl_idx_type = + (src_tbl_idx_type == VALUE_TYPE_I32 + || dst_tbl_idx_type == VALUE_TYPE_I32) + ? VALUE_TYPE_I32 + : VALUE_TYPE_I64; +#else + src_tbl_idx_type = VALUE_TYPE_I32; + dst_tbl_idx_type = VALUE_TYPE_I32; + min_tbl_idx_type = VALUE_TYPE_I32; +#endif + + table_elem_idx_type = min_tbl_idx_type; + POP_TBL_ELEM_IDX(); + table_elem_idx_type = src_tbl_idx_type; + POP_TBL_ELEM_IDX(); + table_elem_idx_type = dst_tbl_idx_type; + POP_TBL_ELEM_IDX(); #if WASM_ENABLE_WAMR_COMPILER != 0 module->is_ref_types_used = true; @@ -14795,7 +14892,12 @@ re_scan: emit_uint32(loader_ctx, table_idx); #endif - PUSH_I32(); +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif + PUSH_TBL_ELEM_IDX(); #if WASM_ENABLE_WAMR_COMPILER != 0 module->is_ref_types_used = true; @@ -14844,15 +14946,20 @@ re_scan: emit_uint32(loader_ctx, table_idx); #endif - POP_I32(); +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif + POP_TBL_ELEM_IDX(); #if WASM_ENABLE_FAST_INTERP != 0 POP_OFFSET_TYPE(decl_type); #endif POP_TYPE(decl_type); if (opcode1 == WASM_OP_TABLE_GROW) - PUSH_I32(); + PUSH_TBL_ELEM_IDX(); else - POP_I32(); + POP_TBL_ELEM_IDX(); #if WASM_ENABLE_WAMR_COMPILER != 0 module->is_ref_types_used = true; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 968eaf009..0c29ef3ce 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -33,12 +33,25 @@ has_module_memory64(WASMModule *module) /* TODO: multi-memories for now assuming the memory idx type is consistent * across multi-memories */ if (module->import_memory_count > 0) - return !!(module->import_memories[0].u.mem_type.flags & MEMORY64_FLAG); + return !!(module->import_memories[0].u.memory.mem_type.flags + & MEMORY64_FLAG); else if (module->memory_count > 0) return !!(module->memories[0].flags & MEMORY64_FLAG); return false; } + +static bool +is_table_64bit(WASMModule *module, uint32 table_idx) +{ + if (table_idx < module->import_table_count) + return !!(module->import_tables[table_idx].u.table.table_type.flags + & TABLE64_FLAG); + else + return !!(module->tables[table_idx].table_type.flags & TABLE64_FLAG); + + return false; +} #endif static void @@ -577,11 +590,15 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, } static void -adjust_table_max_size(uint32 init_size, uint32 max_size_flag, uint32 *max_size) +adjust_table_max_size(bool is_table64, uint32 init_size, uint32 max_size_flag, + uint32 *max_size) { uint32 default_max_size = init_size * 2 > WASM_TABLE_MAX_SIZE ? init_size * 2 : WASM_TABLE_MAX_SIZE; + /* TODO: current still use UINT32_MAX as upper limit for table size to keep + * ABI unchanged */ + (void)is_table64; if (max_size_flag) { /* module defines the table limitation */ @@ -642,8 +659,8 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end, char *error_buf, uint32 error_buf_size) { const uint8 *p = *p_buf, *p_end = buf_end; - uint32 declare_elem_type = 0, declare_max_size_flag = 0, - declare_init_size = 0, declare_max_size = 0; + uint32 declare_elem_type = 0, table_flag = 0, declare_init_size = 0, + declare_max_size = 0; CHECK_BUF(p, p_end, 1); /* 0x70 or 0x6F */ @@ -654,24 +671,29 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end, #endif ); - read_leb_uint32(p, p_end, declare_max_size_flag); + read_leb_uint32(p, p_end, table_flag); + + if (!wasm_table_check_flags(table_flag, error_buf, error_buf_size, false)) { + return false; + } + read_leb_uint32(p, p_end, declare_init_size); - if (declare_max_size_flag & 1) { + if (table_flag & MAX_TABLE_SIZE_FLAG) { read_leb_uint32(p, p_end, declare_max_size); bh_assert(table->table_type.init_size <= table->table_type.max_size); } - adjust_table_max_size(declare_init_size, declare_max_size_flag, - &declare_max_size); + adjust_table_max_size(table_flag & TABLE64_FLAG, declare_init_size, + table_flag & MAX_TABLE_SIZE_FLAG, &declare_max_size); *p_buf = p; - bh_assert( - !((declare_max_size_flag & 1) && declare_init_size > declare_max_size)); + bh_assert(!((table_flag & MAX_TABLE_SIZE_FLAG) + && declare_init_size > declare_max_size)); /* now we believe all declaration are ok */ table->table_type.elem_type = declare_elem_type; table->table_type.init_size = declare_init_size; - table->table_type.flags = declare_max_size_flag; + table->table_type.flags = table_flag; table->table_type.max_size = declare_max_size; return true; } @@ -789,16 +811,22 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMTable *table, p_org = p; read_leb_uint32(p, p_end, table->table_type.flags); bh_assert(p - p_org <= 1); - bh_assert(table->table_type.flags <= 1); (void)p_org; + if (!wasm_table_check_flags(table->table_type.flags, error_buf, + error_buf_size, false)) { + return false; + } + read_leb_uint32(p, p_end, table->table_type.init_size); - if (table->table_type.flags == 1) { + if (table->table_type.flags == MAX_TABLE_SIZE_FLAG) { read_leb_uint32(p, p_end, table->table_type.max_size); bh_assert(table->table_type.init_size <= table->table_type.max_size); } - adjust_table_max_size(table->table_type.init_size, table->table_type.flags, + adjust_table_max_size(table->table_type.flags & TABLE64_FLAG, + table->table_type.init_size, + table->table_type.flags & MAX_TABLE_SIZE_FLAG, &table->table_type.max_size); *p_buf = p; @@ -1575,6 +1603,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, uint32 error_buf_size) { const uint8 *p = buf, *p_end = buf_end; + uint8 table_elem_idx_type; uint32 table_segment_count, i, table_index, function_count; uint64 total_size; WASMTableSeg *table_segment; @@ -1592,6 +1621,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, table_segment = module->table_segments; for (i = 0; i < table_segment_count; i++, table_segment++) { bh_assert(p < p_end); + table_elem_idx_type = VALUE_TYPE_I32; #if WASM_ENABLE_REF_TYPES != 0 read_leb_uint32(p, p_end, table_segment->mode); @@ -1608,9 +1638,15 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, error_buf, error_buf_size)) return false; +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = + is_table_64bit(module, table_segment->table_index) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif if (!load_init_expr( module, &p, p_end, &table_segment->base_offset, - VALUE_TYPE_I32, error_buf, error_buf_size)) + table_elem_idx_type, error_buf, error_buf_size)) return false; if (table_segment->mode == 0) { @@ -1646,9 +1682,15 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, &table_segment->table_index, error_buf, error_buf_size)) return false; +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = + is_table_64bit(module, table_segment->table_index) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif if (!load_init_expr( module, &p, p_end, &table_segment->base_offset, - VALUE_TYPE_I32, error_buf, error_buf_size)) + table_elem_idx_type, error_buf, error_buf_size)) return false; if (!load_elem_type(&p, p_end, &table_segment->elem_type, table_segment->mode == 2 ? true : false, @@ -1691,13 +1733,29 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end, &table_segment->table_index, error_buf, error_buf_size)) return false; +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = + is_table_64bit(module, table_segment->table_index) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif if (!load_init_expr(module, &p, p_end, &table_segment->base_offset, - VALUE_TYPE_I32, error_buf, error_buf_size)) + table_elem_idx_type, error_buf, error_buf_size)) return false; if (!load_func_index_vec(&p, p_end, module, table_segment, error_buf, error_buf_size)) return false; #endif /* WASM_ENABLE_REF_TYPES != 0 */ + +#if WASM_ENABLE_MEMORY64 != 0 + if (table_elem_idx_type == VALUE_TYPE_I64 + && table_segment->base_offset.u.u64 > UINT32_MAX) { + set_error_buf(error_buf, error_buf_size, + "In table64, table base offset can't be " + "larger than UINT32_MAX"); + return false; + } +#endif } } @@ -1781,8 +1839,8 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end, /* This memory_flag is from memory instead of data segment */ uint8 memory_flag; if (module->import_memory_count > 0) { - memory_flag = - module->import_memories[mem_index].u.mem_type.flags; + memory_flag = module->import_memories[mem_index] + .u.memory.mem_type.flags; } else { memory_flag = @@ -2948,6 +3006,12 @@ load_from_sections(WASMModule *module, WASMSection *sections, } } +#if WASM_ENABLE_MEMORY64 != 0 + if (!check_memory64_flags_consistency(module, error_buf, error_buf_size, + false)) + return false; +#endif + calculate_global_data_offset(module); #if WASM_ENABLE_FAST_JIT != 0 @@ -5214,6 +5278,13 @@ fail: } while (0) #define PUSH_PAGE_COUNT() PUSH_MEM_OFFSET() +#define PUSH_TBL_ELEM_IDX() \ + do { \ + if (!(wasm_loader_push_frame_ref(loader_ctx, table_elem_idx_type, \ + error_buf, error_buf_size))) \ + goto fail; \ + } while (0) + #define POP_MEM_OFFSET() \ do { \ if (!wasm_loader_pop_frame_ref_offset(loader_ctx, mem_offset_type, \ @@ -5221,6 +5292,13 @@ fail: goto fail; \ } while (0) +#define POP_TBL_ELEM_IDX() \ + do { \ + if (!(wasm_loader_pop_frame_ref(loader_ctx, table_elem_idx_type, \ + error_buf, error_buf_size))) \ + goto fail; \ + } while (0) + #define POP_AND_PUSH(type_pop, type_push) \ do { \ if (!(wasm_loader_push_pop_frame_ref_offset( \ @@ -5284,6 +5362,13 @@ fail: #define PUSH_PAGE_COUNT() PUSH_MEM_OFFSET() +#define PUSH_TBL_ELEM_IDX() \ + do { \ + if (!(wasm_loader_push_frame_ref(loader_ctx, table_elem_idx_type, \ + error_buf, error_buf_size))) \ + goto fail; \ + } while (0) + #define POP_I32() \ do { \ if (!(wasm_loader_pop_frame_ref(loader_ctx, VALUE_TYPE_I32, error_buf, \ @@ -5326,6 +5411,13 @@ fail: goto fail; \ } while (0) +#define POP_TBL_ELEM_IDX() \ + do { \ + if (!(wasm_loader_pop_frame_ref(loader_ctx, table_elem_idx_type, \ + error_buf, error_buf_size))) \ + goto fail; \ + } while (0) + #define POP_AND_PUSH(type_pop, type_push) \ do { \ if (!(wasm_loader_push_pop_frame_ref(loader_ctx, 1, type_push, \ @@ -5945,7 +6037,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, { uint8 *p = func->code, *p_end = func->code + func->code_size, *p_org; uint32 param_count, local_count, global_count; - uint8 *param_types, *local_types, local_type, global_type, mem_offset_type; + uint8 *param_types, *local_types, local_type, global_type, mem_offset_type, + table_elem_idx_type; BlockType func_block_type; uint16 *local_offsets, local_offset; uint32 count, local_idx, global_idx, u32, align, i, memidx; @@ -5976,6 +6069,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, mem_offset_type = is_memory64 ? VALUE_TYPE_I64 : VALUE_TYPE_I32; #else mem_offset_type = VALUE_TYPE_I32; + table_elem_idx_type = VALUE_TYPE_I32; #endif global_count = module->import_global_count + module->global_count; @@ -6588,8 +6682,13 @@ re_scan: emit_uint32(loader_ctx, table_idx); #endif +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif /* skip elem idx */ - POP_I32(); + POP_TBL_ELEM_IDX(); bh_assert(type_idx < module->type_count); @@ -6865,8 +6964,8 @@ re_scan: break; } - /* table.get x. tables[x]. [i32] -> [t] */ - /* table.set x. tables[x]. [i32 t] -> [] */ + /* table.get x. tables[x]. [it] -> [t] */ + /* table.set x. tables[x]. [it t] -> [] */ case WASM_OP_TABLE_GET: case WASM_OP_TABLE_SET: { @@ -6882,8 +6981,13 @@ re_scan: emit_uint32(loader_ctx, table_idx); #endif +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif if (opcode == WASM_OP_TABLE_GET) { - POP_I32(); + POP_TBL_ELEM_IDX(); #if WASM_ENABLE_FAST_INTERP != 0 PUSH_OFFSET_TYPE(decl_ref_type); #endif @@ -6894,7 +6998,7 @@ re_scan: POP_OFFSET_TYPE(decl_ref_type); #endif POP_TYPE(decl_ref_type); - POP_I32(); + POP_TBL_ELEM_IDX(); } break; } @@ -7819,7 +7923,12 @@ re_scan: #endif POP_I32(); POP_I32(); - POP_I32(); +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif + POP_TBL_ELEM_IDX(); break; } case WASM_OP_ELEM_DROP: @@ -7838,7 +7947,8 @@ re_scan: case WASM_OP_TABLE_COPY: { uint8 src_ref_type, dst_ref_type; - uint32 src_tbl_idx, dst_tbl_idx; + uint32 src_tbl_idx, dst_tbl_idx, src_tbl_idx_type, + dst_tbl_idx_type, min_tbl_idx_type; read_leb_uint32(p, p_end, src_tbl_idx); if (!get_table_elem_type(module, src_tbl_idx, @@ -7862,9 +7972,31 @@ re_scan: emit_uint32(loader_ctx, src_tbl_idx); emit_uint32(loader_ctx, dst_tbl_idx); #endif - POP_I32(); - POP_I32(); - POP_I32(); + +#if WASM_ENABLE_MEMORY64 != 0 + src_tbl_idx_type = is_table_64bit(module, src_tbl_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; + dst_tbl_idx_type = is_table_64bit(module, dst_tbl_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; + min_tbl_idx_type = + (src_tbl_idx_type == VALUE_TYPE_I32 + || dst_tbl_idx_type == VALUE_TYPE_I32) + ? VALUE_TYPE_I32 + : VALUE_TYPE_I64; +#else + src_tbl_idx_type = VALUE_TYPE_I32; + dst_tbl_idx_type = VALUE_TYPE_I32; + min_tbl_idx_type = VALUE_TYPE_I32; +#endif + + table_elem_idx_type = min_tbl_idx_type; + POP_TBL_ELEM_IDX(); + table_elem_idx_type = src_tbl_idx_type; + POP_TBL_ELEM_IDX(); + table_elem_idx_type = dst_tbl_idx_type; + POP_TBL_ELEM_IDX(); break; } case WASM_OP_TABLE_SIZE: @@ -7882,7 +8014,12 @@ re_scan: emit_uint32(loader_ctx, table_idx); #endif - PUSH_I32(); +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif + PUSH_TBL_ELEM_IDX(); break; } case WASM_OP_TABLE_GROW: @@ -7914,15 +8051,20 @@ re_scan: emit_uint32(loader_ctx, table_idx); #endif - POP_I32(); +#if WASM_ENABLE_MEMORY64 != 0 + table_elem_idx_type = is_table_64bit(module, table_idx) + ? VALUE_TYPE_I64 + : VALUE_TYPE_I32; +#endif + POP_TBL_ELEM_IDX(); #if WASM_ENABLE_FAST_INTERP != 0 POP_OFFSET_TYPE(decl_ref_type); #endif POP_TYPE(decl_ref_type); if (opcode1 == WASM_OP_TABLE_GROW) - PUSH_I32(); + PUSH_TBL_ELEM_IDX(); else - POP_I32(); + PUSH_TBL_ELEM_IDX(); break; } #endif /* WASM_ENABLE_REF_TYPES */ diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 90299df97..06ac2dafd 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -678,6 +678,8 @@ tables_instantiate(const WASMModule *module, WASMModuleInstance *module_inst, uninitialized elements */ #endif + table->is_table64 = import->u.table.table_type.flags & TABLE64_FLAG; + #if WASM_ENABLE_MULTI_MODULE != 0 *table_linked = table_inst_linked; if (table_inst_linked != NULL) { @@ -736,6 +738,7 @@ tables_instantiate(const WASMModule *module, WASMModuleInstance *module_inst, /* For GC, all elements have already been set to NULL_REF (0) as uninitialized elements */ #endif + table->is_table64 = module->tables[i].table_type.flags & TABLE64_FLAG; table->elem_type = module->tables[i].table_type.elem_type; #if WASM_ENABLE_GC != 0 table->elem_ref_type.elem_ref_type = diff --git a/core/iwasm/interpreter/wasm_runtime.h b/core/iwasm/interpreter/wasm_runtime.h index e46b63cda..c5d09cb60 100644 --- a/core/iwasm/interpreter/wasm_runtime.h +++ b/core/iwasm/interpreter/wasm_runtime.h @@ -157,7 +157,8 @@ struct WASMMemoryInstance { struct WASMTableInstance { /* The element type */ uint8 elem_type; - uint8 __padding__[7]; + uint8 is_table64; + uint8 __padding__[6]; union { #if WASM_ENABLE_GC != 0 WASMRefType *elem_ref_type; diff --git a/tests/wamr-test-suites/spec-test-script/memory64_ignore_cases.patch b/tests/wamr-test-suites/spec-test-script/memory64_ignore_cases.patch index 5e7afd9d1..afd0536d9 100644 --- a/tests/wamr-test-suites/spec-test-script/memory64_ignore_cases.patch +++ b/tests/wamr-test-suites/spec-test-script/memory64_ignore_cases.patch @@ -1,5 +1,5 @@ diff --git a/test/core/address.wast b/test/core/address.wast -index 8e52030..de0d0cb 100644 +index 8e52030e..de0d0cb9 100644 --- a/test/core/address.wast +++ b/test/core/address.wast @@ -210,7 +210,7 @@ @@ -12,7 +12,7 @@ index 8e52030..de0d0cb 100644 "(memory 1)" "(func (drop (i32.load offset=4294967296 (i32.const 0))))" diff --git a/test/core/binary.wast b/test/core/binary.wast -index 4090b2c..18f66b4 100644 +index 4090b2cd..18f66b42 100644 --- a/test/core/binary.wast +++ b/test/core/binary.wast @@ -206,7 +206,7 @@ @@ -70,7 +70,7 @@ index 4090b2c..18f66b4 100644 ;; Start section (module binary diff --git a/test/core/data.wast b/test/core/data.wast -index 4f339be..0b5b3e6 100644 +index 4f339bed..0b5b3e6b 100644 --- a/test/core/data.wast +++ b/test/core/data.wast @@ -306,9 +306,10 @@ @@ -124,7 +124,7 @@ index 4f339be..0b5b3e6 100644 ;; Invalid offsets diff --git a/test/core/elem.wast b/test/core/elem.wast -index 575ecef..dd1106c 100644 +index 575ecef8..dd1106c7 100644 --- a/test/core/elem.wast +++ b/test/core/elem.wast @@ -562,6 +562,7 @@ @@ -151,7 +151,7 @@ index 575ecef..dd1106c 100644 (assert_return (invoke $module1 "call-9") (i32.const 70)) +;) diff --git a/test/core/global.wast b/test/core/global.wast -index e40a305..8f8f25b 100644 +index e40a305f..8f8f25bb 100644 --- a/test/core/global.wast +++ b/test/core/global.wast @@ -328,10 +328,12 @@ @@ -168,7 +168,7 @@ index e40a305..8f8f25b 100644 (assert_invalid (module (global (import "test" "global-i32") i32) (global i32 (global.get 0) (global.get 0))) diff --git a/test/core/if.wast b/test/core/if.wast -index 2ea45f6..b6dd504 100644 +index 2ea45f6f..b6dd5044 100644 --- a/test/core/if.wast +++ b/test/core/if.wast @@ -527,11 +527,12 @@ @@ -199,7 +199,7 @@ index 2ea45f6..b6dd504 100644 (assert_malformed (module quote diff --git a/test/core/imports.wast b/test/core/imports.wast -index 69f76a0..a3844c6 100644 +index 69f76a0b..a3844c65 100644 --- a/test/core/imports.wast +++ b/test/core/imports.wast @@ -572,6 +572,7 @@ @@ -219,7 +219,7 @@ index 69f76a0..a3844c6 100644 ;; Syntax errors diff --git a/test/core/linking.wast b/test/core/linking.wast -index 994e0f4..d0bfb5f 100644 +index 994e0f49..d0bfb5f6 100644 --- a/test/core/linking.wast +++ b/test/core/linking.wast @@ -64,6 +64,7 @@ @@ -376,7 +376,7 @@ index 994e0f4..d0bfb5f 100644 (assert_return (invoke $Ms "get table[0]") (i32.const 0xdead)) +;) diff --git a/test/core/memory.wast b/test/core/memory.wast -index 1dd5b84..497b69f 100644 +index 1dd5b845..497b69fc 100644 --- a/test/core/memory.wast +++ b/test/core/memory.wast @@ -76,17 +76,17 @@ @@ -404,7 +404,7 @@ index 1dd5b84..497b69f 100644 (module diff --git a/test/core/ref_func.wast b/test/core/ref_func.wast -index adb5cb7..590f626 100644 +index adb5cb78..590f6262 100644 --- a/test/core/ref_func.wast +++ b/test/core/ref_func.wast @@ -4,7 +4,8 @@ @@ -417,8 +417,65 @@ index adb5cb7..590f626 100644 (func $g (param $x i32) (result i32) (i32.add (local.get $x) (i32.const 1)) ) +diff --git a/test/core/table.wast b/test/core/table.wast +index 1b6afe9b..45dd1145 100644 +--- a/test/core/table.wast ++++ b/test/core/table.wast +@@ -8,16 +8,20 @@ + (module (table 0 65536 funcref)) + (module (table 0 0xffff_ffff funcref)) + ++(; TODO: wabt not unsupported gc yet + (module (table 1 (ref null func))) + (module (table 1 (ref null extern))) + (module (table 1 (ref null $t)) (type $t (func))) ++;) + + (module (table 0 funcref) (table 0 funcref)) + (module (table (import "spectest" "table") 0 funcref) (table 0 funcref)) + ++(; TODO: wabt not unsupported gc yet + (module (table 0 funcref (ref.null func))) + (module (table 1 funcref (ref.null func))) + (module (table 1 (ref null func) (ref.null func))) ++;) + + (assert_invalid (module (elem (i32.const 0))) "unknown table") + (assert_invalid (module (elem (i32.const 0) $f) (func $f)) "unknown table") +@@ -31,6 +35,7 @@ + "size minimum must not be greater than maximum" + ) + ++(; TODO: wabt not unsupported gc yet + (assert_invalid + (module quote "(table 0x1_0000_0000 funcref)") + "table size must be at most 2^32-1" +@@ -43,6 +48,7 @@ + (module quote "(table 0 0x1_0000_0000 funcref)") + "table size must be at most 2^32-1" + ) ++;) + + ;; Same as above but with i64 index types + +@@ -71,6 +77,7 @@ + (assert_invalid (module (elem (i32.const 0))) "unknown table") + (assert_invalid (module (elem (i32.const 0) $f) (func $f)) "unknown table") + ++(; TODO: wabt not unsupported gc yet + (assert_invalid + (module (table 1 (ref null func) (i32.const 0))) + "type mismatch" +@@ -159,6 +166,7 @@ + ) + "type mismatch" + ) ++;) + + + ;; Duplicate table identifiers diff --git a/test/core/table_copy.wast b/test/core/table_copy.wast -index 380e84e..f37e745 100644 +index 613fc529..abeca22c 100644 --- a/test/core/table_copy.wast +++ b/test/core/table_copy.wast @@ -14,11 +14,12 @@ @@ -728,8 +785,46 @@ index 380e84e..f37e745 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) +diff --git a/test/core/table_grow.wast b/test/core/table_grow.wast +index e0872d78..6a84f239 100644 +--- a/test/core/table_grow.wast ++++ b/test/core/table_grow.wast +@@ -147,19 +147,20 @@ + ) + (register "grown-table" $Tgt) + (assert_return (invoke $Tgt "grow") (i32.const 1)) ;; now size is 2 +-(module $Tgit1 +- ;; imported table limits should match, because external table size is 2 now +- (table (export "table") (import "grown-table" "table") 2 funcref) +- (func (export "grow") (result i32) (table.grow (ref.null func) (i32.const 1))) +-) +-(register "grown-imported-table" $Tgit1) +-(assert_return (invoke $Tgit1 "grow") (i32.const 2)) ;; now size is 3 +-(module $Tgit2 +- ;; imported table limits should match, because external table size is 3 now +- (import "grown-imported-table" "table" (table 3 funcref)) +- (func (export "size") (result i32) (table.size)) +-) +-(assert_return (invoke $Tgit2 "size") (i32.const 3)) ++;; TODO: No dynnamic linking yet ++;; (module $Tgit1 ++;; ;; imported table limits should match, because external table size is 2 now ++;; (table (export "table") (import "grown-table" "table") 2 funcref) ++;; (func (export "grow") (result i32) (table.grow (ref.null func) (i32.const 1))) ++;; ) ++;; (register "grown-imported-table" $Tgit1) ++;; (assert_return (invoke $Tgit1 "grow") (i32.const 2)) ;; now size is 3 ++;; (module $Tgit2 ++;; ;; imported table limits should match, because external table size is 3 now ++;; (import "grown-imported-table" "table" (table 3 funcref)) ++;; (func (export "size") (result i32) (table.size)) ++;; ) ++;; (assert_return (invoke $Tgit2 "size") (i32.const 3)) + + + ;; Type errors diff --git a/test/core/table_init.wast b/test/core/table_init.wast -index 0b2d26f..bdab6a0 100644 +index 5c3679ab..76782794 100644 --- a/test/core/table_init.wast +++ b/test/core/table_init.wast @@ -14,11 +14,12 @@ @@ -749,8 +844,8 @@ index 0b2d26f..bdab6a0 100644 + (func (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) - (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -72,11 +73,12 @@ + (table $t2 i64 30 30 funcref) +@@ -73,11 +74,12 @@ (module (type (func (result i32))) ;; type #0 @@ -767,8 +862,8 @@ index 0b2d26f..bdab6a0 100644 + (func (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) - (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -130,11 +132,12 @@ + (table $t2 i64 30 30 funcref) +@@ -132,11 +134,12 @@ (module (type (func (result i32))) ;; type #0 @@ -785,8 +880,8 @@ index 0b2d26f..bdab6a0 100644 + (func (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) - (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -196,11 +199,12 @@ + (table $t2 i64 30 30 funcref) +@@ -199,11 +202,12 @@ (module (type (func (result i32))) ;; type #0 @@ -803,8 +898,8 @@ index 0b2d26f..bdab6a0 100644 + (func (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) - (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -254,11 +258,12 @@ + (table $t2 i64 30 30 funcref) +@@ -258,11 +262,12 @@ (module (type (func (result i32))) ;; type #0 @@ -821,8 +916,8 @@ index 0b2d26f..bdab6a0 100644 + (func (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) - (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -312,11 +317,12 @@ + (table $t2 i64 30 30 funcref) +@@ -317,11 +322,12 @@ (module (type (func (result i32))) ;; type #0 @@ -839,9 +934,63 @@ index 0b2d26f..bdab6a0 100644 + (func (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) - (elem (table $t1) (i32.const 2) func 3 1 4 1) + (table $t2 i64 30 30 funcref) +@@ -384,11 +390,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (table $t2 i64 30 30 funcref) +@@ -443,11 +450,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (table $t2 i64 30 30 funcref) +@@ -502,11 +510,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (table $t2 i64 30 30 funcref) diff --git a/test/core/unreached-valid.wast b/test/core/unreached-valid.wast -index b7ebabf..4f2abfb 100644 +index b7ebabfd..4f2abfbf 100644 --- a/test/core/unreached-valid.wast +++ b/test/core/unreached-valid.wast @@ -46,6 +46,7 @@ diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 87e156865..4893bb65d 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -375,7 +375,7 @@ function sightglass_test() function setup_wabt() { - WABT_VERSION=1.0.34 + WABT_VERSION=1.0.36 if [ ${WABT_BINARY_RELEASE} == "YES" ]; then echo "download a binary release and install" local WAT2WASM=${WORK_DIR}/wabt/out/gcc/Release/wat2wasm @@ -384,7 +384,7 @@ function setup_wabt() cosmopolitan) ;; linux) - WABT_PLATFORM=ubuntu + WABT_PLATFORM=ubuntu-20.04 ;; darwin) WABT_PLATFORM=macos-12 @@ -502,6 +502,8 @@ function spec_test() # Reset to commit: "Merge remote-tracking branch 'upstream/main' into merge2" git reset --hard 48e69f394869c55b7bbe14ac963c09f4605490b6 git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast test/core/data.wast + # Patch table64 extension + git checkout 940398cd4823522a9b36bec4984be4b153dedb81 -- test/core/call_indirect.wast test/core/table.wast test/core/table_copy.wast test/core/table_copy_mixed.wast test/core/table_fill.wast test/core/table_get.wast test/core/table_grow.wast test/core/table_init.wast test/core/table_set.wast test/core/table_size.wast git apply ../../spec-test-script/memory64_ignore_cases.patch || exit 1 elif [[ ${ENABLE_MULTI_MEMORY} == 1 ]]; then echo "checkout spec for multi memory proposal" From b16b6044eeaa76bb21b50ab8a7578e0f747307a2 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 14 Oct 2024 09:52:25 +0800 Subject: [PATCH 017/105] Enable libc-wasi for windows msvc build (#3852) The default iwasm building in Windows MSVC enables libc-uvwasi because libc-wasi isn't supported at the beginning. Since libc-wasi had been refactored and is supported in Windows msys2 building, and libc-wasi supports more functionalities(e.g. sockets) than libc-uvwasi, this PR fixes some issues to enable libc-wasi in windows MSVC buidlings. --- core/iwasm/aot/aot_loader.c | 9 +++++ .../src/refcount.h | 29 ++++++++++++++++ .../src/ssp_config.h | 24 ++++++++++--- .../platform/windows/platform_internal.h | 6 ++++ core/shared/platform/windows/win_clock.c | 6 +++- core/shared/platform/windows/win_util.h | 10 ++++-- product-mini/platforms/windows/CMakeLists.txt | 6 ++-- wamr-compiler/CMakeLists.txt | 34 +++++++++---------- 8 files changed, 96 insertions(+), 28 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 3efb190e1..1a4a6d1e1 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -2512,6 +2512,15 @@ try_merge_data_and_text(const uint8 **buf, const uint8 **buf_end, /* merge failed but may be not critical for some targets */ return false; } + +#ifdef BH_PLATFORM_WINDOWS + if (!os_mem_commit(sections, code_size, + MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC)) { + os_munmap(sections, (uint32)total_size); + return false; + } +#endif + /* change the code part to be executable */ if (os_mprotect(sections, code_size, MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h index 03b4b87ac..79b16cc17 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h @@ -132,6 +132,35 @@ refcount_release(struct refcount *r) #error "Reference counter isn't implemented" #endif /* end of __GNUC_PREREQ (4.7) */ +#elif defined(_MSC_VER) + +/* Simple reference counter. */ +struct LOCKABLE refcount { + LONG count; +}; + +/* Initialize the reference counter. */ +static inline void +refcount_init(struct refcount *r, unsigned int count) +{ + InterlockedExchange(&r->count, (LONG)count); +} + +/* Increment the reference counter. */ +static inline void +refcount_acquire(struct refcount *r) +{ + InterlockedIncrement(&r->count); +} + +/* Decrement the reference counter, returning whether the reference + dropped to zero. */ +static inline bool +refcount_release(struct refcount *r) +{ + return InterlockedDecrement(&r->count) == 0 ? true : false; +} + #else /* else of CONFIG_HAS_STD_ATOMIC */ #error "Reference counter isn't implemented" #endif /* end of CONFIG_HAS_STD_ATOMIC */ diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h index 4ef29ccdb..829677213 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h @@ -70,9 +70,11 @@ #endif #if !defined(BH_PLATFORM_LINUX_SGX) + /* Clang's __GNUC_PREREQ macro has a different meaning than GCC one, so we have to handle this case specially */ #if defined(__clang__) + /* Clang provides stdatomic.h since 3.6.0 See https://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html */ #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6) @@ -80,7 +82,9 @@ See https://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html */ #else #define CONFIG_HAS_STD_ATOMIC 0 #endif + #elif defined(__GNUC_PREREQ) + /* Even though older versions of GCC support C11, atomics were not implemented until 4.9. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58016 */ @@ -89,11 +93,21 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58016 */ #else /* else of __GNUC_PREREQ(4, 9) */ #define CONFIG_HAS_STD_ATOMIC 0 #endif /* end of __GNUC_PREREQ(4, 9) */ -#else /* else of defined(__GNUC_PREREQ) */ -#define CONFIG_HAS_STD_ATOMIC 1 -#endif /* end of defined(__GNUC_PREREQ) */ -#else /* else of !defined(BH_PLATFORM_LINUX_SGX) */ + +#elif defined(_MSC_VER) + #define CONFIG_HAS_STD_ATOMIC 0 + +#else + +#define CONFIG_HAS_STD_ATOMIC 1 + +#endif /* end of defined(__clang__) */ + +#else /* else of !defined(BH_PLATFORM_LINUX_SGX) */ + +#define CONFIG_HAS_STD_ATOMIC 0 + #endif /* end of !defined(BH_PLATFORM_LINUX_SGX) */ -#endif +#endif /* end of SSP_CONFIG_H */ diff --git a/core/shared/platform/windows/platform_internal.h b/core/shared/platform/windows/platform_internal.h index 1cd8187af..8ff541016 100644 --- a/core/shared/platform/windows/platform_internal.h +++ b/core/shared/platform/windows/platform_internal.h @@ -6,6 +6,12 @@ #ifndef _PLATFORM_INTERNAL_H #define _PLATFORM_INTERNAL_H +/* + * Suppress the noisy warnings: + * winbase.h: warning C5105: macro expansion producing 'defined' has + * undefined behavior + */ +#pragma warning(disable : 5105) #include #include #include diff --git a/core/shared/platform/windows/win_clock.c b/core/shared/platform/windows/win_clock.c index c96bdfb3b..826004f7c 100644 --- a/core/shared/platform/windows/win_clock.c +++ b/core/shared/platform/windows/win_clock.c @@ -10,6 +10,10 @@ #define NANOSECONDS_PER_SECOND 1000000000ULL #define NANOSECONDS_PER_TICK 100 +extern NTSTATUS +NtQueryTimerResolution(PULONG MinimumResolution, PULONG MaximumResolution, + PULONG CurrentResolution); + static __wasi_errno_t calculate_monotonic_clock_frequency(uint64 *out_frequency) { @@ -140,4 +144,4 @@ os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision, default: return __WASI_EINVAL; } -} \ No newline at end of file +} diff --git a/core/shared/platform/windows/win_util.h b/core/shared/platform/windows/win_util.h index 033c393b5..7fda508c7 100644 --- a/core/shared/platform/windows/win_util.h +++ b/core/shared/platform/windows/win_util.h @@ -7,7 +7,13 @@ #define _WIN_UTIL_H #include "platform_wasi_types.h" -#include "windows.h" +/* + * Suppress the noisy warnings: + * winbase.h: warning C5105: macro expansion producing 'defined' has + * undefined behavior + */ +#pragma warning(disable : 5105) +#include __wasi_timestamp_t convert_filetime_to_wasi_timestamp(LPFILETIME filetime); @@ -23,4 +29,4 @@ convert_windows_error_code(DWORD windows_error_code); __wasi_errno_t convert_winsock_error_code(int error_code); -#endif /* end of _WIN_UTIL_H */ \ No newline at end of file +#endif /* end of _WIN_UTIL_H */ diff --git a/product-mini/platforms/windows/CMakeLists.txt b/product-mini/platforms/windows/CMakeLists.txt index 02aa3f31b..40e925b16 100644 --- a/product-mini/platforms/windows/CMakeLists.txt +++ b/product-mini/platforms/windows/CMakeLists.txt @@ -52,9 +52,9 @@ if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) set (WAMR_BUILD_LIBC_BUILTIN 1) endif () -if (NOT DEFINED WAMR_BUILD_LIBC_UVWASI) - # Enable libc uvwasi support by default - set (WAMR_BUILD_LIBC_UVWASI 1) +if (NOT DEFINED WAMR_BUILD_LIBC_WASI) + # Enable libc wasi support by default + set (WAMR_BUILD_LIBC_WASI 1) endif () if (NOT DEFINED WAMR_BUILD_FAST_INTERP) diff --git a/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index 2ab0462b2..34e920a3b 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -223,24 +223,14 @@ include_directories (${SHARED_DIR}/include enable_language (ASM) -if (NOT MINGW AND NOT MSVC) - if ((NOT DEFINED WAMR_BUILD_LIBC_WASI) AND (NOT DEFINED WAMR_BUILD_LIBC_UVWASI)) - set (WAMR_BUILD_LIBC_WASI 1) - endif () +if ((NOT DEFINED WAMR_BUILD_LIBC_WASI) AND (NOT DEFINED WAMR_BUILD_LIBC_UVWASI)) + # Enable WAMR_BUILD_LIBC_WASI if both are not set + set (WAMR_BUILD_LIBC_WASI 1) +endif () - if ((WAMR_BUILD_LIBC_WASI EQUAL 1) AND (WAMR_BUILD_LIBC_UVWASI EQUAL 1)) - message (WARNING "-- pick WAMR_BULID_LIBC_UVWASI when both are enabled") - set (WAMR_BUILD_LIBC_WASI 0) - endif () -else () - if (NOT DEFINED WAMR_BUILD_LIBC_UVWASI) - set (WAMR_BUILD_LIBC_UVWASI 1) - endif () - - if (WAMR_BUILD_LIBC_WASI EQUAL 1) - message (WARNING "-- don't accept WAMR_BUILD_LIBC_WASI=1 on MINGW or MSVC") - set (WAMR_BUILD_LIBC_WASI 0) - endif () +if ((WAMR_BUILD_LIBC_WASI EQUAL 1) AND (WAMR_BUILD_LIBC_UVWASI EQUAL 1)) + message (WARNING "-- pick WAMR_BULID_LIBC_UVWASI when both are enabled") + set (WAMR_BUILD_LIBC_WASI 0) endif () if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) @@ -308,6 +298,16 @@ if (WAMR_BUILD_LIBC_WASI EQUAL 1) include (${IWASM_DIR}/libraries/libc-wasi/libc_wasi.cmake) endif () +if (WAMR_BUILD_LIBC_WASI EQUAL 1) + # Enable _Static_assert + set (CMAKE_C_STANDARD 11) + if (MSVC) + add_compile_options(/experimental:c11atomics) + endif() +else() + set (CMAKE_C_STANDARD 99) +endif() + if (WAMR_BUILD_LIB_PTHREAD EQUAL 1) include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake) endif () From e2680e533230fdb5ffefc90ba5e9d6e3dc7f1b6d Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 14 Oct 2024 21:43:17 +0800 Subject: [PATCH 018/105] Remove unused folder samples/gui and samples/littlevgl (#3853) They had been moved to wamr-app-framework repo: https://github.com/bytecodealliance/wamr-app-framework/tree/main/samples --- samples/gui/wasm-apps/decrease/src/main.c | 84 ----- samples/gui/wasm-apps/increase/src/main.c | 84 ----- .../src/platform/zephyr/XPT2046.c | 348 ----------------- .../src/platform/zephyr/display_ili9340.h | 75 ---- .../src/platform/zephyr/iwasm_main.c | 195 ---------- .../src/platform/zephyr/XPT2046.c | 349 ------------------ .../src/platform/zephyr/display_ili9340.h | 75 ---- .../src/platform/zephyr/iwasm_main.c | 136 ------- 8 files changed, 1346 deletions(-) delete mode 100644 samples/gui/wasm-apps/decrease/src/main.c delete mode 100644 samples/gui/wasm-apps/increase/src/main.c delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h delete mode 100644 samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h delete mode 100644 samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c diff --git a/samples/gui/wasm-apps/decrease/src/main.c b/samples/gui/wasm-apps/decrease/src/main.c deleted file mode 100644 index 9635ebea8..000000000 --- a/samples/gui/wasm-apps/decrease/src/main.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include "wasm_app.h" -#include "wa-inc/lvgl/lvgl.h" -#include "wa-inc/timer_wasm_app.h" - -extern char g_widget_text[]; - -static void -btn_event_cb(lv_obj_t *btn, lv_event_t event); - -uint32_t count = 0; -char count_str[11] = { 0 }; -lv_obj_t *hello_world_label; -lv_obj_t *count_label; -lv_obj_t *btn1; -lv_obj_t *label_count1; -int label_count1_value = 100; -char label_count1_str[11] = { 0 }; - -void -timer1_update(user_timer_t timer1) -{ - if ((count % 100) == 0) { - snprintf(count_str, sizeof(count_str), "%d", count / 100); - lv_label_set_text(count_label, count_str); - } - ++count; -} - -void -on_init() -{ - char *text; - - hello_world_label = lv_label_create(NULL, NULL); - lv_label_set_text(hello_world_label, "Hello world!"); - text = lv_label_get_text(hello_world_label); - printf("Label text %lu %s \n", strlen(text), text); - lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); - - count_label = lv_label_create(NULL, NULL); - lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); - - /* Create a button on the currently loaded screen */ - btn1 = lv_btn_create(NULL, NULL); - /* Set function to be called when the button is released */ - lv_obj_set_event_cb(btn1, (lv_event_cb_t)btn_event_cb); - /* Align below the label */ - lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); - - /* Create a label on the button */ - lv_obj_t *btn_label = lv_label_create(btn1, NULL); - lv_label_set_text(btn_label, "Click --"); - - label_count1 = lv_label_create(NULL, NULL); - lv_label_set_text(label_count1, "100"); - lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); - - /* Set up a timer */ - user_timer_t timer; - timer = api_timer_create(10, true, false, timer1_update); - if (timer) - api_timer_restart(timer, 10); - else - printf("Fail to create timer.\n"); -} - -static void -btn_event_cb(lv_obj_t *btn, lv_event_t event) -{ - if (event == LV_EVENT_RELEASED) { - label_count1_value--; - snprintf(label_count1_str, sizeof(label_count1_str), "%d", - label_count1_value); - lv_label_set_text(label_count1, label_count1_str); - if (label_count1_value == 0) - label_count1_value = 100; - } -} diff --git a/samples/gui/wasm-apps/increase/src/main.c b/samples/gui/wasm-apps/increase/src/main.c deleted file mode 100644 index 31118f7be..000000000 --- a/samples/gui/wasm-apps/increase/src/main.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include -#include "wasm_app.h" -#include "wa-inc/lvgl/lvgl.h" -#include "wa-inc/timer_wasm_app.h" - -extern char g_widget_text[]; - -static void -btn_event_cb(lv_obj_t *btn, lv_event_t event); - -uint32_t count = 0; -char count_str[11] = { 0 }; -lv_obj_t *hello_world_label; -lv_obj_t *count_label; -lv_obj_t *btn1; -lv_obj_t *label_count1; -int label_count1_value = 1; -char label_count1_str[11] = { 0 }; - -void -timer1_update(user_timer_t timer1) -{ - if ((count % 100) == 0) { - snprintf(count_str, sizeof(count_str), "%d", count / 100); - lv_label_set_text(count_label, count_str); - } - ++count; -} - -void -on_init() -{ - char *text; - - hello_world_label = lv_label_create(NULL, NULL); - lv_label_set_text(hello_world_label, "Hello world!"); - text = lv_label_get_text(hello_world_label); - printf("Label text %lu %s \n", strlen(text), text); - lv_obj_align(hello_world_label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); - - count_label = lv_label_create(NULL, NULL); - lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); - - /* Create a button on the current loaded screen */ - btn1 = lv_btn_create(NULL, NULL); - /* Set function to be called when the button is released */ - lv_obj_set_event_cb(btn1, (lv_event_cb_t)btn_event_cb); - /* Align below the label */ - lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); - - /* Create a label on the button */ - lv_obj_t *btn_label = lv_label_create(btn1, NULL); - lv_label_set_text(btn_label, "Click ++"); - - label_count1 = lv_label_create(NULL, NULL); - lv_label_set_text(label_count1, "1"); - lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); - - /* Set up a timer */ - user_timer_t timer; - timer = api_timer_create(10, true, false, timer1_update); - if (timer) - api_timer_restart(timer, 10); - else - printf("Fail to create timer.\n"); -} - -static void -btn_event_cb(lv_obj_t *btn, lv_event_t event) -{ - if (event == LV_EVENT_RELEASED) { - label_count1_value++; - snprintf(label_count1_str, sizeof(label_count1_str), "%d", - label_count1_value); - lv_label_set_text(label_count1, label_count1_str); - if (label_count1_value == 100) - label_count1_value = 0; - } -} diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c deleted file mode 100644 index 5502cfd89..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c +++ /dev/null @@ -1,348 +0,0 @@ -/** - * @file XPT2046.c - */ -/********************* - * INCLUDES - *********************/ -#include "XPT2046.h" -#include "board_config.h" -#include "stdio.h" -#include -#include "drivers/spi.h" - -#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ -#include -#include -#else -#include -#endif - -#if USE_XPT2046 - -#include - -#define abs(x) ((x) < 0 ? -(x) : (x)) - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static void -xpt2046_corr(int16_t *x, int16_t *y); -#if 0 -static void xpt2046_avg(int16_t * x, int16_t * y); -#endif - -/********************** - * STATIC VARIABLES - **********************/ -int16_t avg_buf_x[XPT2046_AVG]; -int16_t avg_buf_y[XPT2046_AVG]; -uint8_t avg_last; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the XPT2046 - */ -struct device *input_dev; - -struct spi_config spi_conf_xpt2046; -struct spi_cs_control xpt2046_cs_ctrl; -struct device *xpt2046_pen_gpio_dev; -static struct gpio_callback gpio_cb; -lv_indev_data_t touch_point; -lv_indev_data_t last_touch_point; - -#define TOUCH_READ_THREAD_STACK_SIZE 4096 -static K_THREAD_STACK_DEFINE(touch_read_thread_stack, - TOUCH_READ_THREAD_STACK_SIZE); -static struct k_thread touch_thread_data; -static struct k_sem sem_touch_read; - -K_MUTEX_DEFINE(spi_display_touch_mutex); - -int cnt = 0; -int touch_read_times = 0; -int last_pen_interrupt_time = 0; -void -xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb, - u32_t pins) -{ - cnt++; - if ((k_uptime_get_32() - last_pen_interrupt_time) > 500) { - k_sem_give(&sem_touch_read); - touch_read_times++; - last_pen_interrupt_time = k_uptime_get_32(); - } -} - -void -disable_pen_interrupt() -{ - int ret = 0; - ret = gpio_disable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); - if (ret != 0) { - printf("gpio_pin_configure GPIO_INPUT failed\n"); - } -} -void -enable_pen_interrupt() -{ - int ret = 0; - ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); - if (ret != 0) { - printf("gpio_pin_configure failed\n"); - } -} - -void -touch_screen_read_thread() -{ - int i; - bool ret = false; - - for (;;) { - k_sem_take(&sem_touch_read, K_FOREVER); - memset(&last_touch_point, 0, sizeof(lv_indev_data_t)); - memset(&touch_point, 0, sizeof(lv_indev_data_t)); - memset(avg_buf_x, 0, sizeof(avg_buf_x)); - memset(avg_buf_y, 0, sizeof(avg_buf_y)); - k_mutex_lock(&spi_display_touch_mutex, K_FOREVER); - disable_pen_interrupt(); - for (i = 0; i < 100; i++) { - ret = xpt2046_read(&touch_point); - if (ret) { - if ((abs(last_touch_point.point.x - touch_point.point.x) < 4) - && (abs(last_touch_point.point.y - touch_point.point.y) - < 4)) { - break; - } - last_touch_point = touch_point; - } - } - enable_pen_interrupt(); - k_mutex_unlock(&spi_display_touch_mutex); - } -} - -void -xpt2046_init(void) -{ - int ret; - input_dev = device_get_binding(XPT2046_SPI_DEVICE_NAME); - - if (input_dev == NULL) { - printf("device not found. Aborting test."); - return; - } - memset((void *)&touch_point, 0, sizeof(lv_indev_data_t)); - - spi_conf_xpt2046.frequency = XPT2046_SPI_MAX_FREQUENCY; - spi_conf_xpt2046.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8); - spi_conf_xpt2046.slave = 0; - spi_conf_xpt2046.cs = NULL; -#ifdef XPT2046_CS_GPIO_CONTROLLER - xpt2046_cs_ctrl.gpio_dev = device_get_binding(XPT2046_CS_GPIO_CONTROLLER); - if (xpt2046_cs_ctrl.gpio_dev == NULL) { - printk("Cannot find %s!\n", XPT2046_CS_GPIO_CONTROLLER); - return; - } - gpio_pin_configure(xpt2046_cs_ctrl.gpio_dev, XPT2046_CS_GPIO_PIN, - GPIO_OUTPUT); - gpio_pin_set(xpt2046_cs_ctrl.gpio_dev, XPT2046_CS_GPIO_PIN, 1); - xpt2046_cs_ctrl.gpio_pin = XPT2046_CS_GPIO_PIN; - xpt2046_cs_ctrl.delay = 0; - spi_conf_xpt2046.cs = &xpt2046_cs_ctrl; - -#endif - -#ifdef XPT2046_PEN_GPIO_CONTROLLER - - xpt2046_pen_gpio_dev = device_get_binding(XPT2046_PEN_GPIO_CONTROLLER); - if (!xpt2046_pen_gpio_dev) { - printk("Cannot find %s!\n", XPT2046_PEN_GPIO_CONTROLLER); - return; - } - /* Setup GPIO input */ - ret = gpio_pin_configure(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN, - (GPIO_INPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE - | GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE)); - if (ret) { - printk("Error configuring pin %d!\n", XPT2046_PEN_GPIO_PIN); - } - - gpio_init_callback(&gpio_cb, xpt2046_pen_gpio_callback, - BIT(XPT2046_PEN_GPIO_PIN)); - - ret = gpio_add_callback(xpt2046_pen_gpio_dev, &gpio_cb); - if (ret) { - printk("gpio_add_callback error\n"); - } - ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); - if (ret) { - printk("gpio_enable_callback error\n"); - } -#endif - - k_sem_init(&sem_touch_read, 0, 1); - - k_thread_create(&touch_thread_data, touch_read_thread_stack, - TOUCH_READ_THREAD_STACK_SIZE, touch_screen_read_thread, - NULL, NULL, NULL, 5, 0, K_NO_WAIT); - printf("xpt2046_init ok \n"); -} - -/** - * Get the current position and state of the touchpad - * @param data store the read data here - * @return false: because no ore data to be read - */ -bool -xpt2046_read(lv_indev_data_t *data) -{ - static int16_t last_x = 0; - static int16_t last_y = 0; - bool valid = true; - int s32_ret = 0; - - int16_t x = 0; - int16_t y = 0; - - char tx1[16] = { 0 }; - char rx1[16] = { 0 }; - - struct spi_buf tx_buf = { .buf = &tx1, .len = 3 }; - struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 }; - struct spi_buf rx_buf = { .buf = &rx1, .len = 3 }; - struct spi_buf_set rx_bufs = { .buffers = &rx_buf, .count = 1 }; - - tx1[0] = CMD_X_READ; - s32_ret = spi_transceive(input_dev, &spi_conf_xpt2046, &tx_bufs, &rx_bufs); - if (s32_ret != 0) { - printf("spi_transceive return failed:%d\n", s32_ret); - } - x = rx1[1] << 8; - x += rx1[2]; - - tx1[0] = CMD_Y_READ; - s32_ret = spi_transceive(input_dev, &spi_conf_xpt2046, &tx_bufs, &rx_bufs); - if (s32_ret != 0) { - printf("spi_transceive return failed:%d\n", s32_ret); - } - y = rx1[1] << 8; - y += rx1[2]; - x = x >> 3; - y = y >> 3; - - xpt2046_corr(&x, &y); - if (y <= 0 || (x > 320)) { - valid = false; - } - - last_x = x; - last_y = y; - - data->point.x = x; - data->point.y = y; - data->state = valid == false ? LV_INDEV_STATE_REL : LV_INDEV_STATE_PR; - - return valid; -} - -/********************** - * STATIC FUNCTIONS - **********************/ -static void -xpt2046_corr(int16_t *x, int16_t *y) -{ -#if XPT2046_XY_SWAP != 0 - int16_t swap_tmp; - swap_tmp = *x; - *x = *y; - *y = swap_tmp; -#endif - - if ((*x) > XPT2046_X_MIN) - (*x) -= XPT2046_X_MIN; - else - (*x) = 0; - - if ((*y) > XPT2046_Y_MIN) - (*y) -= XPT2046_Y_MIN; - else - (*y) = 0; - - (*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES) - / (XPT2046_X_MAX - XPT2046_X_MIN); - - (*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES) - / (XPT2046_Y_MAX - XPT2046_Y_MIN); - -#if XPT2046_X_INV != 0 - (*x) = XPT2046_HOR_RES - (*x); -#endif - -#if XPT2046_Y_INV != 0 - (*y) = XPT2046_VER_RES - (*y); -#endif -} - -#if 0 -static void xpt2046_avg(int16_t * x, int16_t * y) -{ - /*Shift out the oldest data*/ - uint8_t i; - for (i = XPT2046_AVG - 1; i > 0; i--) { - avg_buf_x[i] = avg_buf_x[i - 1]; - avg_buf_y[i] = avg_buf_y[i - 1]; - } - - /*Insert the new point*/ - avg_buf_x[0] = *x; - avg_buf_y[0] = *y; - if (avg_last < XPT2046_AVG) - avg_last++; - - /*Sum the x and y coordinates*/ - int32_t x_sum = 0; - int32_t y_sum = 0; - for (i = 0; i < avg_last; i++) { - x_sum += avg_buf_x[i]; - y_sum += avg_buf_y[i]; - } - - /*Normalize the sums*/ - (*x) = (int32_t) x_sum / avg_last; - (*y) = (int32_t) y_sum / avg_last; -} -#endif - -bool -touchscreen_read(lv_indev_data_t *data) -{ - /*Store the collected data*/ - data->point.x = last_touch_point.point.x; - data->point.y = last_touch_point.point.y; - data->state = last_touch_point.state; - - if (last_touch_point.state == LV_INDEV_STATE_PR) { - last_touch_point.state = LV_INDEV_STATE_REL; - } - return false; -} - -#endif diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h deleted file mode 100644 index ddc396e1d..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2017 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_ -#define ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_ -#include "board_config.h" -#include - -#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ -#include -#else -#include -#endif - -#define ILI9340_CMD_ENTER_SLEEP 0x10 -#define ILI9340_CMD_EXIT_SLEEP 0x11 -#define ILI9340_CMD_GAMMA_SET 0x26 -#define ILI9340_CMD_DISPLAY_OFF 0x28 -#define ILI9340_CMD_DISPLAY_ON 0x29 -#define ILI9340_CMD_COLUMN_ADDR 0x2a -#define ILI9340_CMD_PAGE_ADDR 0x2b -#define ILI9340_CMD_MEM_WRITE 0x2c -#define ILI9340_CMD_MEM_ACCESS_CTRL 0x36 -#define ILI9340_CMD_PIXEL_FORMAT_SET 0x3A -#define ILI9340_CMD_FRAME_CTRL_NORMAL_MODE 0xB1 -#define ILI9340_CMD_DISPLAY_FUNCTION_CTRL 0xB6 -#define ILI9340_CMD_POWER_CTRL_1 0xC0 -#define ILI9340_CMD_POWER_CTRL_2 0xC1 -#define ILI9340_CMD_VCOM_CTRL_1 0xC5 -#define ILI9340_CMD_VCOM_CTRL_2 0xC7 -#define ILI9340_CMD_POSITVE_GAMMA_CORRECTION 0xE0 -#define ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION 0xE1 - -#define ILI9340_DATA_MEM_ACCESS_CTRL_MY 0x80 -#define ILI9340_DATA_MEM_ACCESS_CTRL_MX 0x40 -#define ILI9340_DATA_MEM_ACCESS_CTRL_MV 0x20 -#define ILI9340_DATA_MEM_ACCESS_CTRL_ML 0x10 -#define ILI9340_DATA_MEM_ACCESS_CTRL_BGR 0x08 -#define ILI9340_DATA_MEM_ACCESS_CTRL_MH 0x04 - -#define ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT 0x60 -#define ILI9340_DATA_PIXEL_FORMAT_RGB_16_BIT 0x50 -#define ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT 0x06 -#define ILI9340_DATA_PIXEL_FORMAT_MCU_16_BIT 0x05 - -struct ili9340_data; - -/** - * Send data to ILI9340 display controller - * - * @param data Device data structure - * @param cmd Command to send to display controller - * @param tx_data Data to transmit to the display controller - * In case no data should be transmitted pass a NULL pointer - * @param tx_len Number of bytes in tx_data buffer - * - */ -void -ili9340_transmit(struct ili9340_data *data, u8_t cmd, void *tx_data, - size_t tx_len); - -/** - * Perform LCD specific initialization - * - * @param data Device data structure - */ -void -ili9340_lcd_init(struct ili9340_data *data); - -#define DT_ILITEK_ILI9340_0_LABEL "DISPLAY" -#define CONFIG_DISPLAY_LOG_LEVEL 0 - -#endif /* ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_ */ diff --git a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c b/samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c deleted file mode 100644 index 9ce0c11cd..000000000 --- a/samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#include "bh_platform.h" -#include "runtime_lib.h" -#include "native_interface.h" -#include "app_manager_export.h" -#include "board_config.h" -#include "bh_common.h" -#include "bh_queue.h" -#include "runtime_sensor.h" -#include "bi-inc/attr_container.h" -#include "module_wasm_app.h" -#include "wasm_export.h" -#include "display.h" -#include "lvgl.h" - -extern bool -init_sensor_framework(); -extern void -exit_sensor_framework(); -extern int -aee_host_msg_callback(void *msg, uint32_t msg_len); -extern bool -touchscreen_read(lv_indev_data_t *data); -extern int -ili9340_init(); -extern void -xpt2046_init(void); -extern void -wgl_init(); - -#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ -#include -#else -#include -#endif - -#include -#include - -int uart_char_cnt = 0; - -static void -uart_irq_callback(struct device *dev) -{ - unsigned char ch; - - while (uart_poll_in(dev, &ch) == 0) { - uart_char_cnt++; - aee_host_msg_callback(&ch, 1); - } -} - -struct device *uart_dev = NULL; - -static bool -host_init() -{ - uart_dev = device_get_binding(HOST_DEVICE_COMM_UART_NAME); - if (!uart_dev) { - printf("UART: Device driver not found.\n"); - return false; - } - uart_irq_rx_enable(uart_dev); - uart_irq_callback_set(uart_dev, uart_irq_callback); - return true; -} - -int -host_send(void *ctx, const char *buf, int size) -{ - if (!uart_dev) - return 0; - - for (int i = 0; i < size; i++) - uart_poll_out(uart_dev, buf[i]); - - return size; -} - -void -host_destroy() -{} - -/* clang-format off */ -host_interface interface = { - .init = host_init, - .send = host_send, - .destroy = host_destroy -}; -/* clang-format on */ - -timer_ctx_t timer_ctx; - -static char global_heap_buf[270 * 1024] = { 0 }; - -static uint8_t color_copy[320 * 10 * 3]; - -static void -display_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color) -{ - u16_t w = area->x2 - area->x1 + 1; - u16_t h = area->y2 - area->y1 + 1; - struct display_buffer_descriptor desc; - int i; - uint8_t *color_p = color_copy; - - desc.buf_size = 3 * w * h; - desc.width = w; - desc.pitch = w; - desc.height = h; - - for (i = 0; i < w * h; i++, color++) { - color_p[i * 3] = color->ch.red; - color_p[i * 3 + 1] = color->ch.green; - color_p[i * 3 + 2] = color->ch.blue; - } - - display_write(NULL, area->x1, area->y1, &desc, (void *)color_p); - - lv_disp_flush_ready(disp_drv); /* in v5.3 is lv_flush_ready */ -} - -static bool -display_input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) -{ - return touchscreen_read(data); -} - -/** - * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics - * library - */ -static void -hal_init(void) -{ - xpt2046_init(); - ili9340_init(); - display_blanking_off(NULL); - - /*Create a display buffer*/ - static lv_disp_buf_t disp_buf1; - static lv_color_t buf1_1[320 * 10]; - lv_disp_buf_init(&disp_buf1, buf1_1, NULL, 320 * 10); - - /*Create a display*/ - lv_disp_drv_t disp_drv; - lv_disp_drv_init(&disp_drv); /*Basic initialization*/ - disp_drv.buffer = &disp_buf1; - disp_drv.flush_cb = display_flush; - // disp_drv.hor_res = 200; - // disp_drv.ver_res = 100; - lv_disp_drv_register(&disp_drv); - - lv_indev_drv_t indev_drv; - lv_indev_drv_init(&indev_drv); /*Basic initialization*/ - indev_drv.type = LV_INDEV_TYPE_POINTER; - indev_drv.read_cb = display_input_read; - lv_indev_drv_register(&indev_drv); -} - -int -iwasm_main() -{ - RuntimeInitArgs init_args; - host_init(); - - 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); - - /* initialize runtime environment */ - if (!wasm_runtime_full_init(&init_args)) { - printf("Init runtime environment failed.\n"); - return -1; - } - - wgl_init(); - hal_init(); - - /* timer manager */ - if (!init_wasm_timer()) { - goto fail; - } - - app_manager_startup(&interface); - -fail: - wasm_runtime_destroy(); - return -1; -} diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c deleted file mode 100644 index e3948e2f2..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c +++ /dev/null @@ -1,349 +0,0 @@ -/** - * @file XPT2046.c - */ -/********************* - * INCLUDES - *********************/ -#include "XPT2046.h" -#include "board_config.h" -#include "stdio.h" -#include -#include "drivers/spi.h" - -#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ -#include -#include -#else -#include -#endif - -#if USE_XPT2046 - -#include - -#define abs(x) ((x) < 0 ? -(x) : (x)) - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static void -xpt2046_corr(int16_t *x, int16_t *y); -#if 0 -static void xpt2046_avg(int16_t * x, int16_t * y); -#endif - -/********************** - * STATIC VARIABLES - **********************/ -int16_t avg_buf_x[XPT2046_AVG]; -int16_t avg_buf_y[XPT2046_AVG]; -uint8_t avg_last; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the XPT2046 - */ -struct device *input_dev; - -struct spi_config spi_conf_xpt2046; -struct spi_cs_control xpt2046_cs_ctrl; -struct device *xpt2046_pen_gpio_dev; -static struct gpio_callback gpio_cb; -lv_indev_data_t touch_point; -lv_indev_data_t last_touch_point; - -#define TOUCH_READ_THREAD_STACK_SIZE 4096 -static K_THREAD_STACK_DEFINE(touch_read_thread_stack, - TOUCH_READ_THREAD_STACK_SIZE); -static struct k_thread touch_thread_data; -static struct k_sem sem_touch_read; - -K_MUTEX_DEFINE(spi_display_touch_mutex); - -int cnt = 0; -int touch_read_times = 0; -int last_pen_interrupt_time = 0; - -void -xpt2046_pen_gpio_callback(struct device *port, struct gpio_callback *cb, - uint32_t pins) -{ - cnt++; - if ((k_uptime_get_32() - last_pen_interrupt_time) > 500) { - k_sem_give(&sem_touch_read); - touch_read_times++; - last_pen_interrupt_time = k_uptime_get_32(); - } -} - -void -disable_pen_interrupt() -{ - int ret = 0; - ret = gpio_disable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); - if (ret != 0) { - printf("gpio_pin_configure GPIO_INPUT failed\n"); - } -} -void -enable_pen_interrupt() -{ - int ret = 0; - ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); - if (ret != 0) { - printf("gpio_pin_configure failed\n"); - } -} - -void -touch_screen_read_thread() -{ - int i; - bool ret = false; - - for (;;) { - k_sem_take(&sem_touch_read, K_FOREVER); - memset(&last_touch_point, 0, sizeof(lv_indev_data_t)); - memset(&touch_point, 0, sizeof(lv_indev_data_t)); - memset(avg_buf_x, 0, sizeof(avg_buf_x)); - memset(avg_buf_y, 0, sizeof(avg_buf_y)); - k_mutex_lock(&spi_display_touch_mutex, K_FOREVER); - disable_pen_interrupt(); - for (i = 0; i < 100; i++) { - ret = xpt2046_read(&touch_point); - if (ret) { - if ((abs(last_touch_point.point.x - touch_point.point.x) < 4) - && (abs(last_touch_point.point.y - touch_point.point.y) - < 4)) { - break; - } - last_touch_point = touch_point; - } - } - enable_pen_interrupt(); - k_mutex_unlock(&spi_display_touch_mutex); - } -} - -void -xpt2046_init(void) -{ - int ret; - input_dev = device_get_binding(XPT2046_SPI_DEVICE_NAME); - - if (input_dev == NULL) { - printf("device not found. Aborting test."); - return; - } - memset((void *)&touch_point, 0, sizeof(lv_indev_data_t)); - - spi_conf_xpt2046.frequency = XPT2046_SPI_MAX_FREQUENCY; - spi_conf_xpt2046.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8); - spi_conf_xpt2046.slave = 0; - spi_conf_xpt2046.cs = NULL; -#ifdef XPT2046_CS_GPIO_CONTROLLER - xpt2046_cs_ctrl.gpio_dev = device_get_binding(XPT2046_CS_GPIO_CONTROLLER); - if (xpt2046_cs_ctrl.gpio_dev == NULL) { - printk("Cannot find %s!\n", XPT2046_CS_GPIO_CONTROLLER); - return; - } - gpio_pin_configure(xpt2046_cs_ctrl.gpio_dev, XPT2046_CS_GPIO_PIN, - GPIO_OUTPUT); - gpio_pin_set(xpt2046_cs_ctrl.gpio_dev, XPT2046_CS_GPIO_PIN, 1); - xpt2046_cs_ctrl.gpio_pin = XPT2046_CS_GPIO_PIN; - xpt2046_cs_ctrl.delay = 0; - spi_conf_xpt2046.cs = &xpt2046_cs_ctrl; - -#endif - -#ifdef XPT2046_PEN_GPIO_CONTROLLER - - xpt2046_pen_gpio_dev = device_get_binding(XPT2046_PEN_GPIO_CONTROLLER); - if (!xpt2046_pen_gpio_dev) { - printk("Cannot find %s!\n", XPT2046_PEN_GPIO_CONTROLLER); - return; - } - /* Setup GPIO input */ - ret = gpio_pin_configure(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN, - (GPIO_INPUT | GPIO_INT_ENABLE | GPIO_INT_EDGE - | GPIO_INT_LOW_0 | GPIO_INT_DEBOUNCE)); - if (ret) { - printk("Error configuring pin %d!\n", XPT2046_PEN_GPIO_PIN); - } - - gpio_init_callback(&gpio_cb, xpt2046_pen_gpio_callback, - BIT(XPT2046_PEN_GPIO_PIN)); - - ret = gpio_add_callback(xpt2046_pen_gpio_dev, &gpio_cb); - if (ret) { - printk("gpio_add_callback error\n"); - } - ret = gpio_enable_callback(xpt2046_pen_gpio_dev, XPT2046_PEN_GPIO_PIN); - if (ret) { - printk("gpio_enable_callback error\n"); - } -#endif - - k_sem_init(&sem_touch_read, 0, 1); - - k_thread_create(&touch_thread_data, touch_read_thread_stack, - TOUCH_READ_THREAD_STACK_SIZE, touch_screen_read_thread, - NULL, NULL, NULL, 5, 0, K_NO_WAIT); - printf("xpt2046_init ok \n"); -} - -/** - * Get the current position and state of the touchpad - * @param data store the read data here - * @return false: because no ore data to be read - */ -bool -xpt2046_read(lv_indev_data_t *data) -{ - static int16_t last_x = 0; - static int16_t last_y = 0; - bool valid = true; - int s32_ret = 0; - - int16_t x = 0; - int16_t y = 0; - - char tx1[16] = { 0 }; - char rx1[16] = { 0 }; - - struct spi_buf tx_buf = { .buf = &tx1, .len = 3 }; - struct spi_buf_set tx_bufs = { .buffers = &tx_buf, .count = 1 }; - struct spi_buf rx_buf = { .buf = &rx1, .len = 3 }; - struct spi_buf_set rx_bufs = { .buffers = &rx_buf, .count = 1 }; - - tx1[0] = CMD_X_READ; - s32_ret = spi_transceive(input_dev, &spi_conf_xpt2046, &tx_bufs, &rx_bufs); - if (s32_ret != 0) { - printf("spi_transceive return failed:%d\n", s32_ret); - } - x = rx1[1] << 8; - x += rx1[2]; - - tx1[0] = CMD_Y_READ; - s32_ret = spi_transceive(input_dev, &spi_conf_xpt2046, &tx_bufs, &rx_bufs); - if (s32_ret != 0) { - printf("spi_transceive return failed:%d\n", s32_ret); - } - y = rx1[1] << 8; - y += rx1[2]; - x = x >> 3; - y = y >> 3; - - xpt2046_corr(&x, &y); - if (y <= 0 || (x > 320)) { - valid = false; - } - - last_x = x; - last_y = y; - - data->point.x = x; - data->point.y = y; - data->state = valid == false ? LV_INDEV_STATE_REL : LV_INDEV_STATE_PR; - - return valid; -} - -/********************** - * STATIC FUNCTIONS - **********************/ -static void -xpt2046_corr(int16_t *x, int16_t *y) -{ -#if XPT2046_XY_SWAP != 0 - int16_t swap_tmp; - swap_tmp = *x; - *x = *y; - *y = swap_tmp; -#endif - - if ((*x) > XPT2046_X_MIN) - (*x) -= XPT2046_X_MIN; - else - (*x) = 0; - - if ((*y) > XPT2046_Y_MIN) - (*y) -= XPT2046_Y_MIN; - else - (*y) = 0; - - (*x) = (uint32_t)((uint32_t)(*x) * XPT2046_HOR_RES) - / (XPT2046_X_MAX - XPT2046_X_MIN); - - (*y) = (uint32_t)((uint32_t)(*y) * XPT2046_VER_RES) - / (XPT2046_Y_MAX - XPT2046_Y_MIN); - -#if XPT2046_X_INV != 0 - (*x) = XPT2046_HOR_RES - (*x); -#endif - -#if XPT2046_Y_INV != 0 - (*y) = XPT2046_VER_RES - (*y); -#endif -} - -#if 0 -static void xpt2046_avg(int16_t * x, int16_t * y) -{ - /*Shift out the oldest data*/ - uint8_t i; - for (i = XPT2046_AVG - 1; i > 0; i--) { - avg_buf_x[i] = avg_buf_x[i - 1]; - avg_buf_y[i] = avg_buf_y[i - 1]; - } - - /*Insert the new point*/ - avg_buf_x[0] = *x; - avg_buf_y[0] = *y; - if (avg_last < XPT2046_AVG) - avg_last++; - - /*Sum the x and y coordinates*/ - int32_t x_sum = 0; - int32_t y_sum = 0; - for (i = 0; i < avg_last; i++) { - x_sum += avg_buf_x[i]; - y_sum += avg_buf_y[i]; - } - - /*Normalize the sums*/ - (*x) = (int32_t) x_sum / avg_last; - (*y) = (int32_t) y_sum / avg_last; -} -#endif - -bool -touchscreen_read(lv_indev_data_t *data) -{ - /*Store the collected data*/ - data->point.x = last_touch_point.point.x; - data->point.y = last_touch_point.point.y; - data->state = last_touch_point.state; - - if (last_touch_point.state == LV_INDEV_STATE_PR) { - last_touch_point.state = LV_INDEV_STATE_REL; - } - return false; -} - -#endif diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h deleted file mode 100644 index 39257a29a..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2017 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_ -#define ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_ -#include "board_config.h" -#include - -#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ -#include -#else -#include -#endif - -#define ILI9340_CMD_ENTER_SLEEP 0x10 -#define ILI9340_CMD_EXIT_SLEEP 0x11 -#define ILI9340_CMD_GAMMA_SET 0x26 -#define ILI9340_CMD_DISPLAY_OFF 0x28 -#define ILI9340_CMD_DISPLAY_ON 0x29 -#define ILI9340_CMD_COLUMN_ADDR 0x2a -#define ILI9340_CMD_PAGE_ADDR 0x2b -#define ILI9340_CMD_MEM_WRITE 0x2c -#define ILI9340_CMD_MEM_ACCESS_CTRL 0x36 -#define ILI9340_CMD_PIXEL_FORMAT_SET 0x3A -#define ILI9340_CMD_FRAME_CTRL_NORMAL_MODE 0xB1 -#define ILI9340_CMD_DISPLAY_FUNCTION_CTRL 0xB6 -#define ILI9340_CMD_POWER_CTRL_1 0xC0 -#define ILI9340_CMD_POWER_CTRL_2 0xC1 -#define ILI9340_CMD_VCOM_CTRL_1 0xC5 -#define ILI9340_CMD_VCOM_CTRL_2 0xC7 -#define ILI9340_CMD_POSITVE_GAMMA_CORRECTION 0xE0 -#define ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION 0xE1 - -#define ILI9340_DATA_MEM_ACCESS_CTRL_MY 0x80 -#define ILI9340_DATA_MEM_ACCESS_CTRL_MX 0x40 -#define ILI9340_DATA_MEM_ACCESS_CTRL_MV 0x20 -#define ILI9340_DATA_MEM_ACCESS_CTRL_ML 0x10 -#define ILI9340_DATA_MEM_ACCESS_CTRL_BGR 0x08 -#define ILI9340_DATA_MEM_ACCESS_CTRL_MH 0x04 - -#define ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT 0x60 -#define ILI9340_DATA_PIXEL_FORMAT_RGB_16_BIT 0x50 -#define ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT 0x06 -#define ILI9340_DATA_PIXEL_FORMAT_MCU_16_BIT 0x05 - -struct ili9340_data; - -/** - * Send data to ILI9340 display controller - * - * @param data Device data structure - * @param cmd Command to send to display controller - * @param tx_data Data to transmit to the display controller - * In case no data should be transmitted pass a NULL pointer - * @param tx_len Number of bytes in tx_data buffer - * - */ -void -ili9340_transmit(struct ili9340_data *data, uint8_t cmd, void *tx_data, - size_t tx_len); - -/** - * Perform LCD specific initialization - * - * @param data Device data structure - */ -void -ili9340_lcd_init(struct ili9340_data *data); - -#define DT_ILITEK_ILI9340_0_LABEL "DISPLAY" -#define CONFIG_DISPLAY_LOG_LEVEL 0 - -#endif /* ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_ */ diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c deleted file mode 100644 index 10f498026..000000000 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#include "bh_platform.h" -#include "runtime_lib.h" -#include "native_interface.h" -#include "app_manager_export.h" -#include "board_config.h" -#include "bh_platform.h" -#include "runtime_sensor.h" -#include "bi-inc/attr_container.h" -#include "module_wasm_app.h" -#include "wasm_export.h" -#include "sensor_native_api.h" -#include "connection_native_api.h" -#include "display_indev.h" - -#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ -#include -#else -#include -#endif - -#include -#include - -extern bool -init_sensor_framework(); -extern void -exit_sensor_framework(); -extern int -aee_host_msg_callback(void *msg, uint32_t msg_len); - -int uart_char_cnt = 0; - -static void -uart_irq_callback(const struct device *dev, void *user_data) -{ - unsigned char ch; - - while (uart_poll_in(dev, &ch) == 0) { - uart_char_cnt++; - aee_host_msg_callback(&ch, 1); - } - (void)user_data; -} - -const struct device *uart_dev = NULL; - -static bool -host_init() -{ - uart_dev = device_get_binding(HOST_DEVICE_COMM_UART_NAME); - if (!uart_dev) { - printf("UART: Device driver not found.\n"); - return false; - } - uart_irq_rx_enable(uart_dev); - uart_irq_callback_set(uart_dev, uart_irq_callback); - return true; -} - -int -host_send(void *ctx, const char *buf, int size) -{ - if (!uart_dev) - return 0; - - for (int i = 0; i < size; i++) - uart_poll_out(uart_dev, buf[i]); - - return size; -} - -void -host_destroy() -{} - -/* clang-format off */ -host_interface interface = { - .init = host_init, - .send = host_send, - .destroy = host_destroy -}; -/* clang-format on */ - -timer_ctx_t timer_ctx; - -static char global_heap_buf[350 * 1024] = { 0 }; - -static NativeSymbol native_symbols[] = { - EXPORT_WASM_API_WITH_SIG(display_input_read, "(*)i"), - EXPORT_WASM_API_WITH_SIG(display_flush, "(iiii*)"), - EXPORT_WASM_API_WITH_SIG(display_fill, "(iiii*)"), - EXPORT_WASM_API_WITH_SIG(display_vdb_write, "(*iii*i)"), - EXPORT_WASM_API_WITH_SIG(display_map, "(iiii*)"), - EXPORT_WASM_API_WITH_SIG(time_get_ms, "()i") -}; - -int -iwasm_main() -{ - RuntimeInitArgs init_args; - - host_init(); - - 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); - - init_args.native_module_name = "env"; - init_args.n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol); - init_args.native_symbols = native_symbols; - - /* initialize runtime environment */ - if (!wasm_runtime_full_init(&init_args)) { - printf("Init runtime environment failed.\n"); - return -1; - } - - display_init(); - - /* timer manager */ - if (!init_wasm_timer()) { - goto fail; - } - - app_manager_startup(&interface); - -fail: - wasm_runtime_destroy(); - return -1; -} From 7d4b53085567b3c444fdcef85f45f1f842b6f9f0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 21:53:46 +0800 Subject: [PATCH 019/105] build(deps): bump actions/upload-artifact from 4.4.0 to 4.4.3 (#3855) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.4.0 to 4.4.3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4.4.0...v4.4.3) --- updated-dependencies: - dependency-name: actions/upload-artifact 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 | 2 +- .github/workflows/spec_test_on_nuttx.yml | 2 +- .github/workflows/supply_chain.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ad60706bc..9bbc39801 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -102,7 +102,7 @@ jobs: - name: Upload CodeQL results as an artifact if: success() || failure() - uses: actions/upload-artifact@v4.4.0 + uses: actions/upload-artifact@v4.4.3 with: name: codeql-results path: ${{ steps.step1.outputs.sarif-output }} diff --git a/.github/workflows/spec_test_on_nuttx.yml b/.github/workflows/spec_test_on_nuttx.yml index dfabad103..3b63deac8 100644 --- a/.github/workflows/spec_test_on_nuttx.yml +++ b/.github/workflows/spec_test_on_nuttx.yml @@ -341,7 +341,7 @@ jobs: - name: upload the log if: always() - uses: actions/upload-artifact@v4.4.0 + uses: actions/upload-artifact@v4.4.3 with: name: spec-test-log-${{ github.run_id }}-${{ strategy.job-index }}-${{ matrix.target_config.target }} path: log diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index 28b464e48..4b8a32938 100644 --- a/.github/workflows/supply_chain.yml +++ b/.github/workflows/supply_chain.yml @@ -52,7 +52,7 @@ jobs: # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # format to the repository Actions tab. - name: "Upload artifact" - uses: actions/upload-artifact@3eadd8b791cabf7cd572f194da82158c24125bd8 # v3.1.0 + uses: actions/upload-artifact@184d73b71b93c222403b2e7f1ffebe4508014249 # v3.1.0 with: name: SARIF file path: results.sarif From 0152e2c9f716fe3c11087f432443bde532b6c356 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 21:54:19 +0800 Subject: [PATCH 020/105] build(deps): bump github/codeql-action from 3.26.11 to 3.26.12 (#3856) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.11 to 3.26.12. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.26.11...v3.26.12) --- updated-dependencies: - dependency-name: github/codeql-action 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 9bbc39801..965a27aa6 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -49,7 +49,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v3.26.11 + uses: github/codeql-action/init@v3.26.12 with: languages: ${{ matrix.language }} @@ -66,7 +66,7 @@ jobs: - run: | ./.github/scripts/codeql_buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3.26.11 + uses: github/codeql-action/analyze@v3.26.12 with: category: "/language:${{matrix.language}}" upload: false @@ -95,7 +95,7 @@ jobs: output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif - name: Upload CodeQL results to code scanning - uses: github/codeql-action/upload-sarif@v3.26.11 + uses: github/codeql-action/upload-sarif@v3.26.12 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 4b8a32938..0b14397ba 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@56d197570aa047eae7fe04401603196e2f68521d # v2.2.4 + uses: github/codeql-action/upload-sarif@ea2cd92c21b192add69983116b8b3222b09da33b # v2.2.4 with: sarif_file: results.sarif From 327374cfee709821c5d519824e4154d96347a87b Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 15 Oct 2024 16:04:58 +0800 Subject: [PATCH 021/105] Fix some compile warnings and typos (#3854) - Clear some compile warnings - Fix some typos - Fix llvm LICENSE link error - Remove unused aot file and binarydump bin - Add checks when loading AOT exports --- ATTRIBUTIONS.md | 2 +- core/iwasm/aot/aot_loader.c | 60 ++++++++++++++++-- core/iwasm/aot/aot_runtime.c | 6 +- core/iwasm/common/wasm_runtime_common.c | 3 +- core/iwasm/compilation/aot_emit_control.c | 2 +- core/iwasm/compilation/aot_emit_function.c | 2 +- core/iwasm/compilation/aot_emit_table.c | 12 +++- core/iwasm/include/wasm_export.h | 4 +- .../libraries/libc-wasi/libc_wasi_wrapper.c | 9 +-- .../sandboxed-system-primitives/src/posix.c | 2 +- core/shared/platform/windows/win_clock.c | 2 +- samples/multi-thread/wasm-apps/CMakeLists.txt | 4 +- samples/spawn-thread/wasm-apps/CMakeLists.txt | 2 +- tests/unit/runtime-common/wasm-apps/main.aot | Bin 1164 -> 0 bytes tests/unit/wasm-vm/wasm-apps/binarydump | Bin 13448 -> 0 bytes tests/unit/wasm-vm/wasm-apps/build.sh | 11 ++++ tests/wamr-test-suites/test_wamr.sh | 2 +- 17 files changed, 94 insertions(+), 29 deletions(-) delete mode 100644 tests/unit/runtime-common/wasm-apps/main.aot delete mode 100755 tests/unit/wasm-vm/wasm-apps/binarydump diff --git a/ATTRIBUTIONS.md b/ATTRIBUTIONS.md index cba0e5c4b..ce0d4f852 100644 --- a/ATTRIBUTIONS.md +++ b/ATTRIBUTIONS.md @@ -60,7 +60,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the ### llvm -[LICENSE](./LICENCE.txt) +[LICENSE](./LICENSE) ### wasm-c-api diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 1a4a6d1e1..df06e8706 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -2760,7 +2760,7 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, const uint8 *buf = *p_buf; AOTExport *exports; uint64 size; - uint32 i; + uint32 i, j; /* Allocate memory */ size = sizeof(AOTExport) * (uint64)module->export_count; @@ -2774,14 +2774,60 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, read_uint32(buf, buf_end, exports[i].index); read_uint8(buf, buf_end, exports[i].kind); read_string(buf, buf_end, exports[i].name); -#if 0 /* TODO: check kind and index */ - if (export_funcs[i].index >= - module->func_count + module->import_func_count) { - set_error_buf(error_buf, error_buf_size, - "function index is out of range"); - return false; + + for (j = 0; j < i; j++) { + if (!strcmp(exports[i].name, exports[j].name)) { + set_error_buf(error_buf, error_buf_size, + "duplicate export name"); + return false; + } } + + /* Check export kind and index */ + switch (exports[i].kind) { + case EXPORT_KIND_FUNC: + if (exports[i].index + >= module->import_func_count + module->func_count) { + set_error_buf(error_buf, error_buf_size, + "unknown function"); + return false; + } + break; + case EXPORT_KIND_TABLE: + if (exports[i].index + >= module->import_table_count + module->table_count) { + set_error_buf(error_buf, error_buf_size, "unknown table"); + return false; + } + break; + case EXPORT_KIND_MEMORY: + if (exports[i].index + >= module->import_memory_count + module->memory_count) { + set_error_buf(error_buf, error_buf_size, "unknown memory"); + return false; + } + break; + case EXPORT_KIND_GLOBAL: + if (exports[i].index + >= module->import_global_count + module->global_count) { + set_error_buf(error_buf, error_buf_size, "unknown global"); + return false; + } + break; +#if WASM_ENABLE_TAGS != 0 + /* TODO + case EXPORT_KIND_TAG: + if (index >= module->import_tag_count + module->tag_count) { + set_error_buf(error_buf, error_buf_size, "unknown tag"); + return false; + } + break; + */ #endif + default: + set_error_buf(error_buf, error_buf_size, "invalid export kind"); + return false; + } } *p_buf = buf; diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 9f9783102..48b3b4b73 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -137,6 +137,7 @@ is_frame_per_function(WASMExecEnv *exec_env) return module->feature_flags & WASM_FEATURE_FRAME_PER_FUNCTION; } +#if WASM_ENABLE_DUMP_CALL_STACK != 0 static bool is_frame_func_idx_disabled(WASMExecEnv *exec_env) { @@ -145,6 +146,7 @@ is_frame_func_idx_disabled(WASMExecEnv *exec_env) return module->feature_flags & WASM_FEATURE_FRAME_NO_FUNC_IDX; } +#endif static void * get_top_frame(WASMExecEnv *exec_env) @@ -1478,9 +1480,7 @@ create_exports(AOTModuleInstance *module_inst, AOTModule *module, } } -#if WASM_ENABLE_MULTI_MEMORY == 0 - bh_assert(module_inst->export_memory_count <= 1); -#else +#if WASM_ENABLE_MULTI_MEMORY != 0 if (module_inst->export_memory_count) { module_inst->export_memories = export_memories_instantiate( module, module_inst, module_inst->export_memory_count, error_buf, diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 5f52652b0..cc3b4bb95 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3610,7 +3610,8 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, char mapping_copy_buf[256]; char *mapping_copy = mapping_copy_buf; char *map_mapped = NULL, *map_host = NULL; - const unsigned long max_len = strlen(map_dir_list[i]) * 2 + 3; + const unsigned long max_len = + (unsigned long)strlen(map_dir_list[i]) * 2 + 3; /* Allocation limit for runtime environments with reduced stack size */ if (max_len > 256) { diff --git a/core/iwasm/compilation/aot_emit_control.c b/core/iwasm/compilation/aot_emit_control.c index 945f63952..1c50fe75f 100644 --- a/core/iwasm/compilation/aot_emit_control.c +++ b/core/iwasm/compilation/aot_emit_control.c @@ -912,7 +912,7 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, aot_set_last_error("llvm build LOAD failed"); return false; } - /* Set terminate_flags memory accecc to volatile, so that the value + /* Set terminate_flags memory access to volatile, so that the value will always be loaded from memory rather than register */ LLVMSetVolatile(terminate_flags, true); diff --git a/core/iwasm/compilation/aot_emit_function.c b/core/iwasm/compilation/aot_emit_function.c index 167acc62f..49b1ac1cb 100644 --- a/core/iwasm/compilation/aot_emit_function.c +++ b/core/iwasm/compilation/aot_emit_function.c @@ -2090,7 +2090,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef *param_values = NULL, *value_rets = NULL; LLVMValueRef *result_phis = NULL, value_ret, import_func_count; #if WASM_ENABLE_MEMORY64 != 0 - LLVMValueRef u32_max, u32_cmp_result; + LLVMValueRef u32_max, u32_cmp_result = NULL; #endif LLVMTypeRef *param_types = NULL, ret_type; LLVMTypeRef llvm_func_type, llvm_func_ptr_type; diff --git a/core/iwasm/compilation/aot_emit_table.c b/core/iwasm/compilation/aot_emit_table.c index d65d2f413..e8dae410b 100644 --- a/core/iwasm/compilation/aot_emit_table.c +++ b/core/iwasm/compilation/aot_emit_table.c @@ -10,6 +10,8 @@ #include "aot_emit_gc.h" #endif +#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 +#if WASM_ENABLE_MEMORY64 != 0 static bool zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name) { @@ -23,6 +25,7 @@ zero_extend_u64(AOTCompContext *comp_ctx, LLVMValueRef *value, const char *name) } return true; } +#endif /* check whether a table64 elem idx is greater than UINT32_MAX, if so, throw * exception, otherwise trunc it to uint32 */ @@ -30,10 +33,10 @@ static bool check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef *elem_idx, uint32 tbl_idx) { +#if WASM_ENABLE_MEMORY64 != 0 LLVMValueRef u32_max, u32_cmp_result; LLVMBasicBlockRef check_elem_idx_succ; -#if WASM_ENABLE_MEMORY64 != 0 if (!IS_TABLE64(tbl_idx)) { return true; } @@ -69,12 +72,15 @@ check_tbl_elem_idx_and_trunc(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS, true, u32_cmp_result, check_elem_idx_succ))) goto fail; -#endif return true; fail: return false; +#else + return true; +#endif } +#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ uint64 get_tbl_inst_offset(const AOTCompContext *comp_ctx, @@ -738,4 +744,4 @@ fail: return false; } -#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ +#endif /* WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC !=0 */ diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 016cc2cb1..dfb6b8023 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1166,8 +1166,8 @@ wasm_application_execute_main(wasm_module_inst_t module_inst, int32_t argc, char *argv[]); /** - * Find the specified function in argv[0] from a WASM module instance - * and execute that function. + * Find the specified function from a WASM module instance and execute + * that function. * * @param module_inst the WASM module instance * @param name the name of the function to execute. diff --git a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c index aef8f1703..6d057a6a1 100644 --- a/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c +++ b/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c @@ -1022,8 +1022,8 @@ execute_interruptible_poll_oneoff( uint32 i; const __wasi_timestamp_t timeout = get_timeout_for_poll_oneoff( - in, nsubscriptions), - time_quant = 1e9; + in, (uint32)nsubscriptions), + time_quant = (__wasi_timestamp_t)1e9; const uint64 size_to_copy = nsubscriptions * (uint64)sizeof(wasi_subscription_t); __wasi_subscription_t *in_copy = NULL; @@ -1034,12 +1034,13 @@ execute_interruptible_poll_oneoff( return __WASI_ENOMEM; } - bh_memcpy_s(in_copy, size_to_copy, in, size_to_copy); + bh_memcpy_s(in_copy, (uint32)size_to_copy, in, (uint32)size_to_copy); while (timeout == (__wasi_timestamp_t)-1 || elapsed <= timeout) { /* update timeout for clock subscription events */ update_clock_subscription_data( - in_copy, nsubscriptions, min_uint64(time_quant, timeout - elapsed)); + in_copy, (uint32)nsubscriptions, + min_uint64(time_quant, timeout - elapsed)); err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out, nsubscriptions, nevents); elapsed += time_quant; diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index a313b9be5..d26c460fe 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -3130,7 +3130,7 @@ compare_address(const struct addr_pool *addr_pool_entry, } addr_size = 16; } - max_addr_mask = addr_size * 8; + max_addr_mask = (uint8)(addr_size * 8); /* IPv4 0.0.0.0 or IPv6 :: means any address */ if (basebuf[0] == 0 && !memcmp(basebuf, basebuf + 1, addr_size - 1)) { diff --git a/core/shared/platform/windows/win_clock.c b/core/shared/platform/windows/win_clock.c index 826004f7c..ec0bc8566 100644 --- a/core/shared/platform/windows/win_clock.c +++ b/core/shared/platform/windows/win_clock.c @@ -58,7 +58,7 @@ os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution) case __WASI_CLOCK_PROCESS_CPUTIME_ID: case __WASI_CLOCK_THREAD_CPUTIME_ID: { -#if WINAPI_PARTITION_DESKTOP +#if WINAPI_PARTITION_DESKTOP && WASM_ENABLE_WAMR_COMPILER == 0 ULONG maximum_time; ULONG minimum_time; ULONG current_time; diff --git a/samples/multi-thread/wasm-apps/CMakeLists.txt b/samples/multi-thread/wasm-apps/CMakeLists.txt index d7352e427..5442398f9 100644 --- a/samples/multi-thread/wasm-apps/CMakeLists.txt +++ b/samples/multi-thread/wasm-apps/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.14) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) @@ -43,4 +43,4 @@ add_executable(main_thread_exception.wasm main_thread_exception.c) target_link_libraries(main_thread_exception.wasm) add_executable(main_global_atomic.wasm main_global_atomic.c) -target_link_libraries(main_global_atomic.wasm) \ No newline at end of file +target_link_libraries(main_global_atomic.wasm) diff --git a/samples/spawn-thread/wasm-apps/CMakeLists.txt b/samples/spawn-thread/wasm-apps/CMakeLists.txt index 0996d5841..df21b4485 100644 --- a/samples/spawn-thread/wasm-apps/CMakeLists.txt +++ b/samples/spawn-thread/wasm-apps/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.14) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) diff --git a/tests/unit/runtime-common/wasm-apps/main.aot b/tests/unit/runtime-common/wasm-apps/main.aot deleted file mode 100644 index 79319145a9019df34a340da8f14f9a3f95e5175d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1164 zcmah|L2J}d5Pq%7#&+%IP_WuVSJ;E6(gi8qixAji7E%#x^`P|;H?Q4bHwnpeyDGTF z1!)LMPu~0sp1kN`DYPQqihsbH2v+Dx1%*1_OV(0WH{#)8J(|r2EK@PZl28MwaM^oE>?xPJj#~B+ZGc@0DqaytxyBVyA;*uX0rHJI@ zP>M!vK!1PsIH6L56zg<4DGWY&K*54NQUeM@4-C6?C~c4hFQDL$6OX>%=L>SeYq1;) zLf4Z^1Y?-FPl5?Ws)1k%YWniq*V72{;0{?Zt{c~k1!MlI+1(wpl2zSI{HfXG#SQ_C zC$oFKQ-m@rZwlS#aN-|UvOLopA-`7HE<9Q%$4VZI)soBS&DbjGwd83VrSW5Qcw5!- zgkZ06u2%f5hq2{%bMg022-lLF8COf%D}*Us{#t&2kUMS0AIwCSG&8A|^nJZ|j!?$h z!v?!Ms%Tl2FVT?VGFRD+&QJr@wY+I|x5sW6H;qN(mcbXdW@EL^=Z{MpW^#!(TnEKu z4Gg=Rd$H8=TZM@=>dubJ$Mc#-m?QK5t1oYEsk?SCB$K_&>e!xSDzjHI3xm7DI|7UA zJ(*eDJDzi-$Q@SXHnKb!%I8>9H2v^iie;?8e2+`FDMBt6g_s?X=VWA$J;&>UJcu%1Bm6ozjh+(X^e8;@TO|v{R-@ z6gG*4{@&g$csK$b_n*#mhO5E7eZTjyZ{O}6Z*Nz>9_Tn+<#I7qs@M~ZxJ%VO0a;hZ z-rOlziM6oR%*VE{PqS4(R^sOq5~5a3(FN&R(Hg1e23>()OO*w*RQW_j(N9}2TCj?W zkSMjcSbVZ-(GwdiR#C>d0LYGFt$$dspeIE|(epBnNlBF*v1HdE?HZ(=qBAluMOFW( zZ}baEf1xTLIO2UoSi86`QqrYz{CzV@^~?2w1@(!Fq8%2@6jgS=3_FVRlNRZob<6fD zPf^LTUGZ4|zCF9*(Z+ZzksWOuZQ0kjZ;v;V^zIh@CjX>+q^nnir1HqYQOx(_ zM{|JWpI_OqDgI8|_r9|IAOAf(^t&Hl{QTM-WUGFte&UjarknyLHlM11cU8dmSHNjL zmh=Bu1w2v#KT!b>RlwI*z+V8)@pBd*fO2s*R>0R(z>ieG8OA?C!@Z9UBvVF$4VXqe z&Qe)3!*o4kh9l4Gk)h}Hfp9F&1~P{6JR5*8!UiJoWX52_;dnd=ZX_Ku4K|QA!ci!s zV+nJBWz2MBI0ZM<2Kh>x`fxagHqwRxcyKtGkg(2{^ z5TXVf?pDg6O*UNJ(`*zh_Vu8n_KqfM;rdx$gbr73e|{^t;C;6-WvD42WeIW70DHvZoH@lf!_RMR>i({4;pttE0}?;0P= zAA#YI2kN%8-(;fpl}DuXNCX1Yn0Uiui~$e zyjT0u4}^p1du}+;a`W1B{z=VsU3=@E`9RUz8s)8S3+uaPwSVRd&4{06*Z0COpFm)J z*H=Ca$n_)9(p8Q>sM`3GEW2{<>#!?2`ym+=X8LAdfDP3#Gn%yA>DyW^JEKhmZeP); z-~ zE|AtC%lQJFFR<)=%J^F!7Yd@Gxo%R8AfnEB2p6u<%p=2bXygJPDuc6NCjuWH4CGIf zlLb=o6`iaDG&9kg&()Lc<~8c?)#K=2ekXLUeu-*ZsWwTqjZ~YVnuk2lEa?*_NRf|H zl*_)Y<$B-La-CB*0`F1h;1-Dsjc$$sZ&AiQXv^U-=5&RM0DtmHhj^C=_O2u^P^6FCTXyo_yWwtnPIh zyM-%%Xji@rWuSTOU|`-ft+uXT-3jabFht{l_goX5@4fL4w{G3az4_C3r$1Pco0+~- z<)X{>>D=GH^iQVD>Gi9etR9Ee+-A$s^c!wKR?vTnR`b7OYpw3fCy=~3*QC;==YXaA z7o?l8bj4`>-OrJ08eMC6DA&2uw=f&0qT0lYZ4Ho6?wY5x8-d$ka5o0-5FH=B<+hFrr?z=R-k5KZ8_hq%1r*r!!FgGVU?_k>8hOW31{cv4M z=Ja>aoM>lmm9WGRbuL7;$JUBW;}1hC)NWq$Kka|YpDXx#{h^MRw>`0*<6-r3Bhj8< z?rt#mPRDk7a@1(kAG`Cf{ud&8=_8Xj|BHIQb>u$i$lYy+hr<2;s*PWBY5V80AJ8A1 zFZTIQ`1}0N`Soj)i_gO!UBeKPKlvw#-Xo}_#g(z%OnA^Z!24r~aC$779ZvDaBtJ9| ziyKey#soi<2oIwcOW<8dCzKsanXzOdb3od2n?7Gsj>p3hgPTJJPi9THfFo16w;aH} z*vb-f9)cxBz>@SG#<=I5kNQ;pDsc;1COUX|Dl#$NB z58v%=;tkZNtx~jg`$2Lsmdx^DgqTR0Je#3z$1-hBEzs2yXhhV~sy7igGL(T|&BoH`asL<(rw~;n+>cn};Srup^Y9?vU85YMg)r!) zHY7Pcbv@y<<~tAHJ4iv6^7@QD0y*hFgP7(?*HeGk zv+-!%nvt3_?8!|BcRcpUR)R^V9ly^ZR-xzj)Ss(rTeqre4lP^qDCBn`r?n+h@`Mlz z`?G*oqmOawgOa-kU8F(&zlmQj`aV%2KPTkW_P6nyLQV`&*6OMM&8k+<#;>{q9{%!* zR!_rktkgVB=T>Q+mhtLNk1y?M@q3#5o`zNrhaU7>JvAb4YvDf+Kh~3woGq8-3@m40 zIRncXSkAz529`6hoPp&GEN9^VLk7;&_(Yf|B~>xYWm0jEW33cSuCnyiH~&5OEJ@`d zai#s%lcKg+^0Z!~vdJQBqmZ|j%L)y=Oo=H>0wEql5{}Q zQ<9#O^c6{+?H_4tJHQ)y`?Co%%lCTsdYc-XcV`9L{9^MyZ_}Rb7EE8K9&c`HZgP59 z%DXXpTdI6Z1hhjKDvP_BSr%VWoR@ZIZp_llW%XAvHE&Dxt6916cH=Hk^Q2UNHBzKOVOYwTlV4(hp4ia)?;JIPtx>_MF0D2IQFseN6$jho@FmCuDz{2_L} zEWU}+_L#G{nR@CiO6Y!H!G2g+M64P;PhD(j{PY~HLjLbK#)Ui+&K=Kbuf(0t?{?vT zF;4Z|=@IzSeA2lB@~{3LfEDE&uC6lU^2fl-_3JNzlb=74af)wUz^+UDmDN7f7!%*P zK;OcT^lwUBeA@z6DR1uz*#`E^1|MpRh1w~XPtqtC=P!imeM{yQ?S8q+%%2BE0+-Iu z?E+sq&kqSdOXpQL@D1oM?c!2Ve~0=7E})W&37nT87Qwu1f%fiHay%v8|-umWDFfIp0WQ9RCmJqmn7nLIpM0jG0V<@5)Em&+&Zbgr*@ zh)p`~>v6&nk$S$ZkTHBs`1i0WY{OGA#Fepc2wXBYQiJ~1<1Of-!~Y}Fk2-(1L)yGv z!Ouq&^r=_J`wo)J&!` zdN@1E#3qn|eG~8Fd-v}vuY}FEL`)ZZUb>Mm(_=VHgpDvATXe%?FtKquG|dv##oata zNk^5$)}3x9^?pQdq?tIlqz@VK6ti?K1=|0E@59~x&VU~1YDc%MKB{_2OHrn`KilQ+ z47NebCJ_gq0O6>d9?+yWt-YJ+M>>wR`aASvhY$AzLVC#G+7X}@#IdPJCM)_Z4o&%d z>X;NAj?#mnPJJ=Iq0TnSZiu$4!~w2SZE-fM6w-}o*bK{~Tn>@r?AM}nk97cS5fGs` z&v-e-)R1-7OCAd=Rgg!<93UM7 zNwrdU;y_y|r0e~ejEvMetVYM;96Co&>D_Wxx5dMm45qYo0?whQV@%Y9p}|tOLdj4u zZ)R-R4EKYYX^Rf28uo>abc%VgcWQY3t-(e!JSe%rMAqA%jp5{GEXusZ4TUp9%o`m` zz@J6Uv?al|9_{6oFgj#uBOWFLSxd!D<`v2EqUs$?f;Ej%Tq-p?N_9D*lxMU0i2NmUW>*htib&+?#kN%>)TJN;T zK-Ib&Dxx^^_Z(1K6RY;sy6CpF=ayOVJAl$t^m)i>jjedKep-H z>O^z++3nT(?vk`u@7>C#URD(SEr-2Y2VRsPI#j&M-pT*I!(P3=T$1)*R*7@8tNi_u z!(Oc`_s9=R>U)aPm&2-9_Gi*wjh}iy^GW*=nw+-cjQ=&rD1XXcowrx#@ae39y*S&y z3ZdOzt!HcK;5JH#gtp>r|0ZM}{8X6gyO}zd@6>nl@4&XsX0O)A8y^OU;?#HY--8Z? zsM=TSX#NT9zYklQYRX=%x7Gifp!EP1IUS4fsQGsRGJE@KUB0kIm=*OcZm~bAAOGR7 zFRtIYWpQ2^N~-J>T>x%xU#&OJbIU-*Db1I}a}NUYrTVYli!X4?LbYRYR$Ho0ln(h( z`%QKbb!D&C$4X4PR1~FYrrH()dHI`1tqPsduonj_{HVEa*PG!Mr|x5#4!iMF{ZY?9 Sxw;vk- diff --git a/tests/unit/wasm-vm/wasm-apps/build.sh b/tests/unit/wasm-vm/wasm-apps/build.sh index dbf062ae7..28496ff2f 100755 --- a/tests/unit/wasm-vm/wasm-apps/build.sh +++ b/tests/unit/wasm-vm/wasm-apps/build.sh @@ -1,6 +1,17 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +readonly CURR_DIR=$PWD +readonly BINARYDUMP_DIR=$PWD/../../../../test-tools/binarydump-tool + +# build binarydump +cd $BINARYDUMP_DIR +mkdir -p build && cd build +cmake .. && make -j +cp -a binarydump $CURR_DIR + +cd $CURR_DIR + ## build app1 /opt/wasi-sdk/bin/clang -O3 \ -z stack-size=4096 -Wl,--initial-memory=65536 \ diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 4893bb65d..70a8b687c 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -502,7 +502,7 @@ function spec_test() # Reset to commit: "Merge remote-tracking branch 'upstream/main' into merge2" git reset --hard 48e69f394869c55b7bbe14ac963c09f4605490b6 git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast test/core/data.wast - # Patch table64 extension + # Patch table64 extension git checkout 940398cd4823522a9b36bec4984be4b153dedb81 -- test/core/call_indirect.wast test/core/table.wast test/core/table_copy.wast test/core/table_copy_mixed.wast test/core/table_fill.wast test/core/table_get.wast test/core/table_grow.wast test/core/table_init.wast test/core/table_set.wast test/core/table_size.wast git apply ../../spec-test-script/memory64_ignore_cases.patch || exit 1 elif [[ ${ENABLE_MULTI_MEMORY} == 1 ]]; then From 1af474099ba26be7d597ccbfcd6222161ea1086e Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:01:56 +0800 Subject: [PATCH 022/105] Add Windows wamrc and iwasm build in release CI (#3857) - For Windows, llvm libs need to cache more directories, so use a multi-line environment variable for paths - Remove conditionally build directories `win32build`, just use `build` for all platform - Add Windows wamrc and iwasm(disable lib pthread semaphore and fast jit for now) build in release CI --- .github/workflows/build_iwasm_release.yml | 12 ++++++- .github/workflows/build_llvm_libraries.yml | 27 +++++++++++--- .github/workflows/build_wamrc.yml | 12 +++++-- .github/workflows/release_process.yml | 27 ++++++++++++++ build-scripts/build_llvm.py | 36 ++++++++++++++++--- build-scripts/config_common.cmake | 3 -- build-scripts/runtime_lib.cmake | 11 +++++- .../libraries/lib-pthread/lib_pthread.cmake | 2 +- wamr-compiler/CMakeLists.txt | 13 ++----- 9 files changed, 117 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build_iwasm_release.yml b/.github/workflows/build_iwasm_release.yml index 887020853..f0f25ab3f 100644 --- a/.github/workflows/build_iwasm_release.yml +++ b/.github/workflows/build_iwasm_release.yml @@ -51,6 +51,7 @@ jobs: fail-on-cache-miss: true - name: generate iwasm binary release + shell: bash run: | cmake -S . -B build \ -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \ @@ -81,7 +82,16 @@ jobs: cmake --build build --config Release --parallel 4 working-directory: ${{ inputs.cwd }} - - name: compress the binary + - name: Compress the binary on Windows + if: inputs.runner == 'windows-latest' + run: | + tar -czf iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm.exe + Compress-Archive -Path iwasm.exe -DestinationPath iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip + mv iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../ + working-directory: ${{ inputs.cwd }}/build/Release + + - name: compress the binary on non-Windows + if: inputs.runner != 'windows-latest' run: | tar czf iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm zip iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip iwasm diff --git a/.github/workflows/build_llvm_libraries.yml b/.github/workflows/build_llvm_libraries.yml index 5cde57209..80a2bf672 100644 --- a/.github/workflows/build_llvm_libraries.yml +++ b/.github/workflows/build_llvm_libraries.yml @@ -43,6 +43,7 @@ jobs: - name: install dependencies for non macos-14 if: inputs.os != 'macos-14' + shell: bash run: /usr/bin/env python3 -m pip install -r requirements.txt working-directory: build-scripts @@ -51,10 +52,13 @@ jobs: run: /usr/bin/env python3 -m pip install -r requirements.txt --break-system-packages working-directory: build-scripts - - name: retrieve the last commit ID + - name: Retrieve the last commit ID id: get_last_commit - run: echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --llvm-ver)" >> $GITHUB_OUTPUT - working-directory: build-scripts + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: bash + run: | + echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --llvm-ver)" >> $GITHUB_OUTPUT # Bump the prefix number to evict all previous caches and # enforce a clean build, in the unlikely case that some @@ -62,7 +66,9 @@ jobs: # suspect. - name: form the cache key of libraries id: create_lib_cache_key - run: echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}${{ inputs.cache_key_suffix }}" >> $GITHUB_OUTPUT + shell: bash + run: | + echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}${{ inputs.cache_key_suffix }}" >> $GITHUB_OUTPUT - name: Cache LLVM libraries id: retrieve_llvm_libs @@ -107,7 +113,20 @@ jobs: - run: brew install ccache ninja if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos') + - uses: actions/cache@v4 + with: + path: ~/.cache/ccache + 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' + + # Install tools on Windows + - run: choco install -y ccache ninja + if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest' + - name: Build LLVM libraries if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' + shell: bash run: /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --arch ${{ inputs.arch }} working-directory: build-scripts diff --git a/.github/workflows/build_wamrc.yml b/.github/workflows/build_wamrc.yml index 7c4dab039..e88a04a9e 100644 --- a/.github/workflows/build_wamrc.yml +++ b/.github/workflows/build_wamrc.yml @@ -56,8 +56,16 @@ jobs: cmake --build build --config Release --parallel 4 working-directory: wamr-compiler - - name: compress the binary - if: inputs.release + - name: Compress the binary on Windows + if: inputs.runner == 'windows-latest' && 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 + mv wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../ + working-directory: wamr-compiler/build/Release + + - name: compress the binary on non-Windows + if: inputs.runner != 'windows-latest' && inputs.release run: | tar czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc zip wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc diff --git a/.github/workflows/release_process.yml b/.github/workflows/release_process.yml index 2dce1b55c..b9d27d07a 100644 --- a/.github/workflows/release_process.yml +++ b/.github/workflows/release_process.yml @@ -72,6 +72,13 @@ jobs: os: "macos-13" arch: "AArch64 ARM Mips RISCV X86" + build_llvm_libraries_on_windows: + needs: [create_tag, create_release] + uses: ./.github/workflows/build_llvm_libraries.yml + with: + os: "windows-latest" + arch: "AArch64 ARM Mips RISCV X86" + # # WAMRC release_wamrc_on_ubuntu_2004: @@ -103,6 +110,16 @@ jobs: runner: macos-13 upload_url: ${{ needs.create_release.outputs.upload_url }} ver_num: ${{ needs.create_tag.outputs.new_ver }} + + release_wamrc_on_windows: + needs: [create_tag, create_release, build_llvm_libraries_on_windows] + uses: ./.github/workflows/build_wamrc.yml + with: + llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }} + release: true + runner: windows-latest + upload_url: ${{ needs.create_release.outputs.upload_url }} + ver_num: ${{ needs.create_tag.outputs.new_ver }} # # IWASM @@ -136,6 +153,16 @@ jobs: upload_url: ${{ needs.create_release.outputs.upload_url }} ver_num: ${{ needs.create_tag.outputs.new_ver}} + release_iwasm_on_windows: + needs: [create_tag, create_release, build_llvm_libraries_on_windows] + uses: ./.github/workflows/build_iwasm_release.yml + with: + cwd: product-mini/platforms/windows + llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }} + runner: windows-latest + upload_url: ${{ needs.create_release.outputs.upload_url }} + ver_num: ${{ needs.create_tag.outputs.new_ver}} + # # WAMR_SDK release_wamr_sdk_on_ubuntu_2004: diff --git a/build-scripts/build_llvm.py b/build-scripts/build_llvm.py index 40765d0fe..7de55b6a0 100755 --- a/build-scripts/build_llvm.py +++ b/build-scripts/build_llvm.py @@ -125,9 +125,7 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl if not llvm_dir.exists(): raise Exception(f"{llvm_dir} doesn't exist") - build_dir = llvm_dir.joinpath( - "win32build" if "windows" == platform else "build" - ).resolve() + build_dir = llvm_dir.joinpath("build").resolve() build_dir.mkdir(exist_ok=True) lib_llvm_core_library = build_dir.joinpath("lib/libLLVMCore.a").resolve() @@ -178,6 +176,7 @@ def repackage_llvm(llvm_dir): raise Exception("Find more than one LLVM-*.tar.gz") if not packs: + raise Exception("Didn't find any LLVM-* package") return llvm_package = packs[0].name @@ -193,6 +192,31 @@ def repackage_llvm(llvm_dir): # rm ./LLVM-1*.gz os.remove(llvm_dir.joinpath(llvm_package).resolve()) +def repackage_llvm_windows(llvm_dir): + build_dir = llvm_dir.joinpath("./build").resolve() + + packs_path = [f for f in build_dir.glob("./_CPack_Packages/win64/NSIS/LLVM-*-win64")] + if len(packs_path) > 1: + raise Exception("Find more than one LLVM-* package") + + if not packs_path: + raise Exception("Didn't find any LLVM-* package") + return + + llvm_package_path = f"_CPack_Packages/win64/NSIS/{packs_path[0].name}" + windows_package_dir = build_dir.joinpath(llvm_package_path).resolve() + + # mv package dir outside of build + shutil.move(str(windows_package_dir), str(llvm_dir)) + # rm -r build + shutil.rmtree(str(build_dir)) + # mkdir build + build_dir.mkdir() + # move back all the subdiretories under cpack directory(bin/include/lib) to build dir + moved_package_dir = llvm_dir.joinpath(packs_path[0].name) + for sub_dir in moved_package_dir.iterdir(): + shutil.move(str(sub_dir), str(build_dir)) + moved_package_dir.rmdir() def main(): parser = argparse.ArgumentParser(description="build necessary LLVM libraries") @@ -304,7 +328,11 @@ def main(): ) is not None ): - repackage_llvm(llvm_dir) + # TODO: repackage process may change in the future, this work for LLVM 15.x + if "windows" == platform: + repackage_llvm_windows(llvm_dir) + else: + repackage_llvm(llvm_dir) return True except subprocess.CalledProcessError: diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index f91fbcdb0..48c5f7be4 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -102,9 +102,6 @@ if (WAMR_BUILD_JIT EQUAL 1) if (NOT DEFINED LLVM_DIR) set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build") - if (WAMR_BUILD_PLATFORM STREQUAL "windows") - set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/win32build") - endif () if (NOT EXISTS "${LLVM_BUILD_ROOT}") message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}") endif () diff --git a/build-scripts/runtime_lib.cmake b/build-scripts/runtime_lib.cmake index a2aaf425b..c57cfc57a 100644 --- a/build-scripts/runtime_lib.cmake +++ b/build-scripts/runtime_lib.cmake @@ -59,7 +59,12 @@ if (WAMR_BUILD_INTERP EQUAL 1) endif () if (WAMR_BUILD_FAST_JIT EQUAL 1) - include (${IWASM_DIR}/fast-jit/iwasm_fast_jit.cmake) + if (WAMR_BUILD_PLATFORM STREQUAL "windows") + message ("Fast JIT currently not supported on Windows") + set (WAMR_BUILD_FAST_JIT 0) + else () + include (${IWASM_DIR}/fast-jit/iwasm_fast_jit.cmake) + endif () endif () if (WAMR_BUILD_JIT EQUAL 1) @@ -104,6 +109,10 @@ if (WAMR_BUILD_WASI_NN EQUAL 1) endif () if (WAMR_BUILD_LIB_PTHREAD EQUAL 1) + if (WAMR_BUILD_PLATFORM STREQUAL "windows") + set (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 0) + message ("Lib pthread semaphore currently not supported on Windows") + endif () include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake) # Enable the dependent feature if lib pthread is enabled set (WAMR_BUILD_THREAD_MGR 1) diff --git a/core/iwasm/libraries/lib-pthread/lib_pthread.cmake b/core/iwasm/libraries/lib-pthread/lib_pthread.cmake index 134edf0e8..a1d183ee1 100644 --- a/core/iwasm/libraries/lib-pthread/lib_pthread.cmake +++ b/core/iwasm/libraries/lib-pthread/lib_pthread.cmake @@ -6,7 +6,7 @@ set (LIB_PTHREAD_DIR ${CMAKE_CURRENT_LIST_DIR}) add_definitions (-DWASM_ENABLE_LIB_PTHREAD=1) if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1) -add_definitions (-DWASM_ENABLE_LIB_PTHREAD_SEMAPHORE=1) + add_definitions (-DWASM_ENABLE_LIB_PTHREAD_SEMAPHORE=1) endif() include_directories(${LIB_PTHREAD_DIR}) diff --git a/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index 34e920a3b..ab98b0382 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -163,17 +163,10 @@ endif() # Enable LLVM if (NOT WAMR_BUILD_WITH_CUSTOM_LLVM) set (LLVM_SRC_ROOT "${PROJECT_SOURCE_DIR}/../core/deps/llvm") - if (WAMR_BUILD_PLATFORM STREQUAL "windows") - if (NOT EXISTS "${LLVM_SRC_ROOT}/win32build") - message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/win32build") - endif () - set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/win32build;${CMAKE_PREFIX_PATH}") - else() - if (NOT EXISTS "${LLVM_SRC_ROOT}/build") - message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") - endif () - set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${LLVM_SRC_ROOT}/build") + message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") endif () + set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") endif () find_package(LLVM REQUIRED CONFIG) From 7e625a06249a34e69653d1d8cefa2d722246f2cc Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:50:54 +0800 Subject: [PATCH 023/105] Fix syntax error in codeql_buildscript.sh (#3864) --- .github/scripts/codeql_buildscript.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/codeql_buildscript.sh b/.github/scripts/codeql_buildscript.sh index f1c412a82..388f3680d 100755 --- a/.github/scripts/codeql_buildscript.sh +++ b/.github/scripts/codeql_buildscript.sh @@ -306,7 +306,7 @@ cd ${WAMR_DIR}/product-mini/platforms/linux rm -rf build && mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_DYNAMIC_AOT_DEBUG=1 make -j -if [[ $? != 0 ]]; +if [[ $? != 0 ]]; then echo "Failed to build iwasm dynamic aot debug enabled!" exit 1; fi From 74d2427fdc29961a28c1f94a4cdfc57bfe6829b0 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Fri, 18 Oct 2024 12:49:57 +0800 Subject: [PATCH 024/105] Allow to set native stack boundary to exec_env (#3862) Add runtime API wasm_runtime_set_native_stack_boundary. p.s. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3816 --- core/iwasm/common/wasm_exec_env.c | 9 +++++++-- core/iwasm/common/wasm_exec_env.h | 4 ++++ core/iwasm/common/wasm_runtime_common.c | 7 +++++++ core/iwasm/common/wasm_runtime_common.h | 5 +++++ core/iwasm/include/wasm_export.h | 20 ++++++++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/core/iwasm/common/wasm_exec_env.c b/core/iwasm/common/wasm_exec_env.c index 7128b4c63..48465fc94 100644 --- a/core/iwasm/common/wasm_exec_env.c +++ b/core/iwasm/common/wasm_exec_env.c @@ -282,8 +282,13 @@ wasm_exec_env_set_thread_info(WASMExecEnv *exec_env) os_mutex_lock(&exec_env->wait_lock); #endif exec_env->handle = os_self_thread(); - exec_env->native_stack_boundary = - stack_boundary ? stack_boundary + WASM_STACK_GUARD_SIZE : NULL; + if (exec_env->user_native_stack_boundary) + /* WASM_STACK_GUARD_SIZE isn't added for flexibility to developer, + he must ensure that enough guard bytes are kept. */ + exec_env->native_stack_boundary = exec_env->user_native_stack_boundary; + else + exec_env->native_stack_boundary = + stack_boundary ? stack_boundary + WASM_STACK_GUARD_SIZE : NULL; exec_env->native_stack_top_min = (void *)UINTPTR_MAX; #if WASM_ENABLE_THREAD_MGR != 0 os_mutex_unlock(&exec_env->wait_lock); diff --git a/core/iwasm/common/wasm_exec_env.h b/core/iwasm/common/wasm_exec_env.h index 53d248755..ce0c1fa7f 100644 --- a/core/iwasm/common/wasm_exec_env.h +++ b/core/iwasm/common/wasm_exec_env.h @@ -136,6 +136,10 @@ typedef struct WASMExecEnv { void *user_data; + /* The boundary of native stack set by host embedder. It is used + if it is not NULL when calling wasm functions. */ + uint8 *user_native_stack_boundary; + /* The native thread handle of current thread */ korp_tid handle; diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index cc3b4bb95..1c77b2e4d 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -2225,6 +2225,13 @@ wasm_runtime_get_user_data(WASMExecEnv *exec_env) return exec_env->user_data; } +void +wasm_runtime_set_native_stack_boundary(WASMExecEnv *exec_env, + uint8 *native_stack_boundary) +{ + exec_env->user_native_stack_boundary = native_stack_boundary; +} + #ifdef OS_ENABLE_HW_BOUND_CHECK void wasm_runtime_access_exce_check_guard_page() diff --git a/core/iwasm/common/wasm_runtime_common.h b/core/iwasm/common/wasm_runtime_common.h index fb2c79408..4c7dfed4f 100644 --- a/core/iwasm/common/wasm_runtime_common.h +++ b/core/iwasm/common/wasm_runtime_common.h @@ -673,6 +673,11 @@ wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data); WASM_RUNTIME_API_EXTERN void * wasm_runtime_get_user_data(WASMExecEnv *exec_env); +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_native_stack_boundary(WASMExecEnv *exec_env, + uint8 *native_stack_boundary); + #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 /* See wasm_export.h for description */ WASM_RUNTIME_API_EXTERN void diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index dfb6b8023..aa6cfaae7 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1755,6 +1755,26 @@ wasm_runtime_set_user_data(wasm_exec_env_t exec_env, void *user_data); WASM_RUNTIME_API_EXTERN void * wasm_runtime_get_user_data(wasm_exec_env_t exec_env); +/** + * Set native stack boundary to execution environment, if it is set, + * it will be used instead of getting the boundary with the platform + * layer API when calling wasm functions. This is useful for some + * fiber cases. + * + * Note: unlike setting the boundary by runtime, this API doesn't add + * the WASM_STACK_GUARD_SIZE(see comments in core/config.h) to the + * exec_env's native_stack_boundary to reserve bytes to the native + * thread stack boundary, which is used to throw native stack overflow + * exception if the guard boundary is reached. Developer should ensure + * that enough guard bytes are kept. + * + * @param exec_env the execution environment + * @param native_stack_boundary the user data to be set + */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_native_stack_boundary(wasm_exec_env_t exec_env, + uint8_t *native_stack_boundary); + /** * Dump runtime memory consumption, including: * Exec env memory consumption From 48eaa2286abfd02565175bc77866362023c0c93c Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Fri, 18 Oct 2024 15:15:33 +0800 Subject: [PATCH 025/105] Refine wasm/aot function instance lookup (#3865) Sort the module instance's export functions with the function name, and use binary search to lookup the wasm/aot function. --- core/iwasm/aot/aot_runtime.c | 20 +++++++++--- core/iwasm/common/wasm_c_api.c | 3 +- core/iwasm/common/wasm_runtime_common.c | 41 ++++++++++--------------- core/iwasm/interpreter/wasm_runtime.c | 30 +++++++++++++++--- 4 files changed, 57 insertions(+), 37 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 48b3b4b73..81e6aa1e8 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1379,6 +1379,15 @@ init_func_type_indexes(AOTModuleInstance *module_inst, AOTModule *module, return true; } +static int +cmp_func_inst(const void *a, const void *b) +{ + const AOTFunctionInstance *func_inst1 = (const AOTFunctionInstance *)a; + const AOTFunctionInstance *func_inst2 = (const AOTFunctionInstance *)b; + + return strcmp(func_inst1->func_name, func_inst2->func_name); +} + static bool create_export_funcs(AOTModuleInstance *module_inst, AOTModule *module, char *error_buf, uint32 error_buf_size) @@ -1419,6 +1428,9 @@ create_export_funcs(AOTModuleInstance *module_inst, AOTModule *module, export_func++; } } + + qsort(module_inst->export_functions, module_inst->export_func_count, + sizeof(AOTFunctionInstance), cmp_func_inst); } return true; @@ -2206,14 +2218,12 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst) AOTFunctionInstance * aot_lookup_function(const AOTModuleInstance *module_inst, const char *name) { - uint32 i; AOTFunctionInstance *export_funcs = (AOTFunctionInstance *)module_inst->export_functions; + AOTFunctionInstance key = { .func_name = (char *)name }; - for (i = 0; i < module_inst->export_func_count; i++) - if (!strcmp(export_funcs[i].func_name, name)) - return &export_funcs[i]; - return NULL; + return bsearch(&key, export_funcs, module_inst->export_func_count, + sizeof(AOTFunctionInstance), cmp_func_inst); } #ifdef OS_ENABLE_HW_BOUND_CHECK diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 01109658f..5c1e9efd3 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -3391,8 +3391,7 @@ wasm_func_call(const wasm_func_t *func, const wasm_val_vec_t *params, if (export->kind == EXPORT_KIND_FUNC) { if (export->index == func->func_idx_rt) { func_comm_rt = - (AOTFunctionInstance *)inst_aot->export_functions - + export_func_j; + aot_lookup_function(inst_aot, export->name); ((wasm_func_t *)func)->func_comm_rt = func_comm_rt; break; } diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 1c77b2e4d..fb16aa0f3 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3908,23 +3908,18 @@ wasm_runtime_is_wasi_mode(WASMModuleInstanceCommon *module_inst) WASMFunctionInstanceCommon * wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst) { - uint32 i; - #if WASM_ENABLE_INTERP != 0 if (module_inst->module_type == Wasm_Module_Bytecode) { WASMModuleInstance *wasm_inst = (WASMModuleInstance *)module_inst; - WASMFunctionInstance *func; - for (i = 0; i < wasm_inst->export_func_count; i++) { - if (!strcmp(wasm_inst->export_functions[i].name, "_start")) { - func = wasm_inst->export_functions[i].function; - if (func->u.func->func_type->param_count != 0 - || func->u.func->func_type->result_count != 0) { - LOG_ERROR("Lookup wasi _start function failed: " - "invalid function type.\n"); - return NULL; - } - return (WASMFunctionInstanceCommon *)func; + WASMFunctionInstance *func = wasm_lookup_function(wasm_inst, "_start"); + if (func) { + if (func->u.func->func_type->param_count != 0 + || func->u.func->func_type->result_count != 0) { + LOG_ERROR("Lookup wasi _start function failed: " + "invalid function type.\n"); + return NULL; } + return (WASMFunctionInstanceCommon *)func; } return NULL; } @@ -3933,19 +3928,15 @@ wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst) #if WASM_ENABLE_AOT != 0 if (module_inst->module_type == Wasm_Module_AoT) { AOTModuleInstance *aot_inst = (AOTModuleInstance *)module_inst; - AOTFunctionInstance *export_funcs = - (AOTFunctionInstance *)aot_inst->export_functions; - for (i = 0; i < aot_inst->export_func_count; i++) { - if (!strcmp(export_funcs[i].func_name, "_start")) { - AOTFuncType *func_type = export_funcs[i].u.func.func_type; - if (func_type->param_count != 0 - || func_type->result_count != 0) { - LOG_ERROR("Lookup wasi _start function failed: " - "invalid function type.\n"); - return NULL; - } - return (WASMFunctionInstanceCommon *)&export_funcs[i]; + AOTFunctionInstance *func = aot_lookup_function(aot_inst, "_start"); + if (func) { + AOTFuncType *func_type = func->u.func.func_type; + if (func_type->param_count != 0 || func_type->result_count != 0) { + LOG_ERROR("Lookup wasi _start function failed: " + "invalid function type.\n"); + return NULL; } + return func; } return NULL; } diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index f6d5e1034..78900cb8a 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1367,6 +1367,17 @@ export_functions_deinstantiate(WASMExportFuncInstance *functions) wasm_runtime_free(functions); } +static int +cmp_export_func_inst(const void *a, const void *b) +{ + const WASMExportFuncInstance *export_func1 = + (const WASMExportFuncInstance *)a; + const WASMExportFuncInstance *export_func2 = + (const WASMExportFuncInstance *)b; + + return strcmp(export_func1->name, export_func2->name); +} + /** * Instantiate export functions in a module. */ @@ -1395,6 +1406,9 @@ export_functions_instantiate(const WASMModule *module, } bh_assert((uint32)(export_func - export_funcs) == export_func_count); + + qsort(export_funcs, export_func_count, sizeof(WASMExportFuncInstance), + cmp_export_func_inst); return export_funcs; } @@ -3420,11 +3434,17 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst) WASMFunctionInstance * wasm_lookup_function(const WASMModuleInstance *module_inst, const char *name) { - uint32 i; - for (i = 0; i < module_inst->export_func_count; i++) - if (!strcmp(module_inst->export_functions[i].name, name)) - return module_inst->export_functions[i].function; - return NULL; + WASMExportFuncInstance key = { .name = (char *)name }; + WASMExportFuncInstance *export_func_inst; + + export_func_inst = bsearch( + &key, module_inst->export_functions, module_inst->export_func_count, + sizeof(WASMExportFuncInstance), cmp_export_func_inst); + + if (!export_func_inst) + return NULL; + + return export_func_inst->function; } WASMMemoryInstance * From bb3f8d9198c22ad99b0a152cfa5c551c31aa468b Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Mon, 21 Oct 2024 08:43:33 +0800 Subject: [PATCH 026/105] release CI: Add another iwasm binary that supports Garbage Collection and Exception Handling (#3866) As suggested in #3829, in release CI, we add zip/tar.gz artifacts named iwasm-gc-eh-{version}-{platform} for `iwasm` which supports features garbage collection and exception handling(classic interpreter only). Also, add a command line option to control GC heap size for `iwasm` on the Windows platform. --- .github/workflows/build_iwasm_release.yml | 108 +++++++++++++++------- product-mini/platforms/windows/main.c | 18 ++++ 2 files changed, 91 insertions(+), 35 deletions(-) diff --git a/.github/workflows/build_iwasm_release.yml b/.github/workflows/build_iwasm_release.yml index f0f25ab3f..c0a6f68bd 100644 --- a/.github/workflows/build_iwasm_release.yml +++ b/.github/workflows/build_iwasm_release.yml @@ -31,9 +31,72 @@ on: type: string required: false +env: + DEFAULT_BUILD_OPTIONS: + "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \ + -DWAMR_BUILD_CUSTOM_NAME_SECTION=0 \ + -DWAMR_BUILD_DEBUG_INTERP=0 \ + -DWAMR_BUILD_DEBUG_AOT=0 \ + -DWAMR_BUILD_DUMP_CALL_STACK=0 \ + -DWAMR_BUILD_LIBC_UVWASI=0 \ + -DWAMR_BUILD_LIBC_EMCC=0 \ + -DWAMR_BUILD_LIB_RATS=0 \ + -DWAMR_BUILD_LOAD_CUSTOM_SECTION=0 \ + -DWAMR_BUILD_MEMORY_PROFILING=0 \ + -DWAMR_BUILD_MINI_LOADER=0 \ + -DWAMR_BUILD_MULTI_MODULE=0 \ + -DWAMR_BUILD_PERF_PROFILING=0 \ + -DWAMR_BUILD_SPEC_TEST=0 \ + -DWAMR_BUILD_BULK_MEMORY=1 \ + -DWAMR_BUILD_LIB_PTHREAD=1 \ + -DWAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1 \ + -DWAMR_BUILD_LIB_WASI_THREADS=1 \ + -DWAMR_BUILD_LIBC_BUILTIN=1 \ + -DWAMR_BUILD_LIBC_WASI=1 \ + -DWAMR_BUILD_REF_TYPES=1 \ + -DWAMR_BUILD_SIMD=1 \ + -DWAMR_BUILD_SHARED_MEMORY=1 \ + -DWAMR_BUILD_TAIL_CALL=1 \ + -DWAMR_BUILD_THREAD_MGR=1" + GC_EH_BUILD_OPTIONS: + "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 \ + -DWAMR_BUILD_CUSTOM_NAME_SECTION=0 \ + -DWAMR_BUILD_DEBUG_INTERP=0 \ + -DWAMR_BUILD_DEBUG_AOT=0 \ + -DWAMR_BUILD_DUMP_CALL_STACK=0 \ + -DWAMR_BUILD_LIBC_UVWASI=0 \ + -DWAMR_BUILD_LIBC_EMCC=0 \ + -DWAMR_BUILD_LIB_RATS=0 \ + -DWAMR_BUILD_LOAD_CUSTOM_SECTION=0 \ + -DWAMR_BUILD_MEMORY_PROFILING=0 \ + -DWAMR_BUILD_MINI_LOADER=0 \ + -DWAMR_BUILD_MULTI_MODULE=0 \ + -DWAMR_BUILD_PERF_PROFILING=0 \ + -DWAMR_BUILD_SPEC_TEST=0 \ + -DWAMR_BUILD_BULK_MEMORY=1 \ + -DWAMR_BUILD_LIB_PTHREAD=1 \ + -DWAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1 \ + -DWAMR_BUILD_LIB_WASI_THREADS=1 \ + -DWAMR_BUILD_LIBC_BUILTIN=1 \ + -DWAMR_BUILD_LIBC_WASI=1 \ + -DWAMR_BUILD_REF_TYPES=1 \ + -DWAMR_BUILD_SIMD=1 \ + -DWAMR_BUILD_SHARED_MEMORY=1 \ + -DWAMR_BUILD_TAIL_CALL=1 \ + -DWAMR_BUILD_THREAD_MGR=1 \ + -DWAMR_BUILD_EXCE_HANDLING=1 \ + -DWAMR_BUILD_GC=1" + jobs: build: runs-on: ${{ inputs.runner }} + strategy: + matrix: + include: + - build_options: $DEFAULT_BUILD_OPTIONS + suffix: '' + - build_options: $GC_EH_BUILD_OPTIONS + suffix: '-gc-eh' steps: - uses: actions/checkout@v4 @@ -53,48 +116,23 @@ jobs: - name: generate iwasm binary release shell: bash run: | - cmake -S . -B build \ - -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \ - -DWAMR_BUILD_CUSTOM_NAME_SECTION=0 \ - -DWAMR_BUILD_DEBUG_INTERP=0 \ - -DWAMR_BUILD_DEBUG_AOT=0 \ - -DWAMR_BUILD_DUMP_CALL_STACK=0 \ - -DWAMR_BUILD_LIBC_UVWASI=0 \ - -DWAMR_BUILD_LIBC_EMCC=0 \ - -DWAMR_BUILD_LIB_RATS=0 \ - -DWAMR_BUILD_LOAD_CUSTOM_SECTION=0 \ - -DWAMR_BUILD_MEMORY_PROFILING=0 \ - -DWAMR_BUILD_MINI_LOADER=0 \ - -DWAMR_BUILD_MULTI_MODULE=0 \ - -DWAMR_BUILD_PERF_PROFILING=0 \ - -DWAMR_BUILD_SPEC_TEST=0 \ - -DWAMR_BUILD_BULK_MEMORY=1 \ - -DWAMR_BUILD_LIB_PTHREAD=1 \ - -DWAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1 \ - -DWAMR_BUILD_LIB_WASI_THREADS=1 \ - -DWAMR_BUILD_LIBC_BUILTIN=1 \ - -DWAMR_BUILD_LIBC_WASI=1 \ - -DWAMR_BUILD_REF_TYPES=1 \ - -DWAMR_BUILD_SIMD=1 \ - -DWAMR_BUILD_SHARED_MEMORY=1 \ - -DWAMR_BUILD_TAIL_CALL=1 \ - -DWAMR_BUILD_THREAD_MGR=1 + cmake -S . -B build ${{ matrix.build_options }} cmake --build build --config Release --parallel 4 working-directory: ${{ inputs.cwd }} - name: Compress the binary on Windows if: inputs.runner == 'windows-latest' run: | - tar -czf iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm.exe - Compress-Archive -Path iwasm.exe -DestinationPath iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip - mv iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../ + 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 + mv iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../ working-directory: ${{ inputs.cwd }}/build/Release - name: compress the binary on non-Windows if: inputs.runner != 'windows-latest' run: | - tar czf iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm - zip iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip iwasm + tar czf iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm + zip iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip iwasm working-directory: ${{ inputs.cwd }}/build - name: upload release tar.gz @@ -103,8 +141,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ inputs.upload_url }} - asset_path: ${{ inputs.cwd }}/build/iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz - asset_name: iwasm-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz + asset_path: ${{ inputs.cwd }}/build/iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz + asset_name: iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz asset_content_type: application/x-gzip - name: upload release zip @@ -113,6 +151,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ inputs.upload_url }} - asset_path: ${{ inputs.cwd }}/build/iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip - asset_name: iwasm-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip + asset_path: ${{ inputs.cwd }}/build/iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip + asset_name: iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip asset_content_type: application/zip diff --git a/product-mini/platforms/windows/main.c b/product-mini/platforms/windows/main.c index f51c9dcc5..e85e869c2 100644 --- a/product-mini/platforms/windows/main.c +++ b/product-mini/platforms/windows/main.c @@ -45,6 +45,10 @@ print_help() #endif printf(" --stack-size=n Set maximum stack size in bytes, default is 64 KB\n"); printf(" --heap-size=n Set maximum heap size in bytes, default is 16 KB\n"); +#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"); @@ -271,6 +275,9 @@ main(int argc, char *argv[]) #else uint32 heap_size = 16 * 1024; #endif +#if WASM_ENABLE_GC != 0 + uint32 gc_heap_size = GC_HEAP_SIZE_DEFAULT; +#endif #if WASM_ENABLE_JIT != 0 uint32 llvm_jit_size_level = 3; uint32 llvm_jit_opt_level = 3; @@ -346,6 +353,13 @@ 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_JIT != 0 else if (!strncmp(argv[0], "--llvm-jit-size-level=", 22)) { if (argv[0][22] == '\0') @@ -456,6 +470,10 @@ main(int argc, char *argv[]) init_args.mem_alloc_option.allocator.free_func = free_func; #endif +#if WASM_ENABLE_GC != 0 + init_args.gc_heap_size = gc_heap_size; +#endif + #if WASM_ENABLE_JIT != 0 init_args.llvm_jit_size_level = llvm_jit_size_level; init_args.llvm_jit_opt_level = llvm_jit_opt_level; From 87588caa7f204fd0d9fce80f76c318f58817b585 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 21 Oct 2024 09:57:42 +0800 Subject: [PATCH 027/105] Fix lookup function issue reported in nightly run (#3868) --- core/iwasm/aot/aot_runtime.c | 3 +++ core/iwasm/interpreter/wasm_runtime.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 81e6aa1e8..7e6d6360c 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -2222,6 +2222,9 @@ aot_lookup_function(const AOTModuleInstance *module_inst, const char *name) (AOTFunctionInstance *)module_inst->export_functions; AOTFunctionInstance key = { .func_name = (char *)name }; + if (!export_funcs) + return NULL; + return bsearch(&key, export_funcs, module_inst->export_func_count, sizeof(AOTFunctionInstance), cmp_func_inst); } diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 78900cb8a..accb40319 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -3437,6 +3437,9 @@ wasm_lookup_function(const WASMModuleInstance *module_inst, const char *name) WASMExportFuncInstance key = { .name = (char *)name }; WASMExportFuncInstance *export_func_inst; + if (!module_inst->export_functions) + return NULL; + export_func_inst = bsearch( &key, module_inst->export_functions, module_inst->export_func_count, sizeof(WASMExportFuncInstance), cmp_export_func_inst); From 3ad95303d66a6ae61335a2dcf714ebadc99b4be5 Mon Sep 17 00:00:00 2001 From: James Ring Date: Sun, 20 Oct 2024 20:02:30 -0700 Subject: [PATCH 028/105] Fix quadratic runtime for duplicate export name detection (#3861) Previously, the loader would check the name of a new export against all existing exports, leading to a quadratic running time. This change makes the loader parse the entire export section. The exports are then sorted by name, then adjacent exports are checked for uniqueness. --- core/iwasm/aot/aot_loader.c | 61 ++++++++++++++++++++++----- core/iwasm/interpreter/wasm_loader.c | 62 ++++++++++++++++++++++------ 2 files changed, 99 insertions(+), 24 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index df06e8706..01e246aa3 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -4,9 +4,8 @@ */ #include "aot_runtime.h" -#include "bh_common.h" -#include "bh_log.h" #include "aot_reloc.h" +#include "bh_platform.h" #include "../common/wasm_runtime_common.h" #include "../common/wasm_native.h" #include "../common/wasm_loader_common.h" @@ -2753,6 +2752,48 @@ destroy_exports(AOTExport *exports) wasm_runtime_free(exports); } +static int +cmp_export_name(const void *a, const void *b) +{ + return strcmp(*(char **)a, *(char **)b); +} + +static bool +check_duplicate_exports(AOTModule *module, char *error_buf, + uint32 error_buf_size) +{ + uint32 i; + bool result = false; + char *names_buf[32], **names = names_buf; + if (module->export_count > 32) { + names = loader_malloc(module->export_count * sizeof(char *), error_buf, + error_buf_size); + if (!names) { + return result; + } + } + + for (i = 0; i < module->export_count; i++) { + names[i] = module->exports[i].name; + } + + qsort(names, module->export_count, sizeof(char *), cmp_export_name); + + for (i = 1; i < module->export_count; i++) { + if (!strcmp(names[i], names[i - 1])) { + set_error_buf(error_buf, error_buf_size, "duplicate export name"); + goto cleanup; + } + } + + result = true; +cleanup: + if (module->export_count > 32) { + wasm_runtime_free(names); + } + return result; +} + static bool load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, bool is_load_from_file_buf, char *error_buf, uint32 error_buf_size) @@ -2760,7 +2801,7 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, const uint8 *buf = *p_buf; AOTExport *exports; uint64 size; - uint32 i, j; + uint32 i; /* Allocate memory */ size = sizeof(AOTExport) * (uint64)module->export_count; @@ -2775,14 +2816,6 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, read_uint8(buf, buf_end, exports[i].kind); read_string(buf, buf_end, exports[i].name); - for (j = 0; j < i; j++) { - if (!strcmp(exports[i].name, exports[j].name)) { - set_error_buf(error_buf, error_buf_size, - "duplicate export name"); - return false; - } - } - /* Check export kind and index */ switch (exports[i].kind) { case EXPORT_KIND_FUNC: @@ -2830,6 +2863,12 @@ load_exports(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, } } + if (module->export_count > 0) { + if (!check_duplicate_exports(module, error_buf, error_buf_size)) { + return false; + } + } + *p_buf = buf; return true; fail: diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 306f108a0..ae823d7be 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -4,8 +4,7 @@ */ #include "wasm_loader.h" -#include "bh_common.h" -#include "bh_log.h" +#include "bh_platform.h" #include "wasm.h" #include "wasm_opcode.h" #include "wasm_runtime.h" @@ -3184,6 +3183,12 @@ fail: return false; } +static int +cmp_export_name(const void *a, const void *b) +{ + return strcmp(*(char **)a, *(char **)b); +} + static bool load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, bool is_load_from_file_buf, bool no_resolve, @@ -4054,17 +4059,53 @@ fail: return false; } +static bool +check_duplicate_exports(WASMModule *module, char *error_buf, + uint32 error_buf_size) +{ + uint32 i; + bool result = false; + char *names_buf[32], **names = names_buf; + + if (module->export_count > 32) { + names = loader_malloc(module->export_count * sizeof(char *), error_buf, + error_buf_size); + if (!names) { + return result; + } + } + + for (i = 0; i < module->export_count; i++) { + names[i] = module->exports[i].name; + } + + qsort(names, module->export_count, sizeof(char *), cmp_export_name); + + for (i = 1; i < module->export_count; i++) { + if (!strcmp(names[i], names[i - 1])) { + set_error_buf(error_buf, error_buf_size, "duplicate export name"); + goto cleanup; + } + } + + result = true; +cleanup: + if (module->export_count > 32) { + wasm_runtime_free(names); + } + return result; +} + static bool load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, bool is_load_from_file_buf, char *error_buf, uint32 error_buf_size) { const uint8 *p = buf, *p_end = buf_end; - uint32 export_count, i, j, index; + uint32 export_count, i, index; uint64 total_size; uint32 str_len; WASMExport *export; - const char *name; read_leb_uint32(p, p_end, export_count); @@ -4090,15 +4131,6 @@ load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, read_leb_uint32(p, p_end, str_len); CHECK_BUF(p, p_end, str_len); - for (j = 0; j < i; j++) { - name = module->exports[j].name; - if (strlen(name) == str_len && memcmp(name, p, str_len) == 0) { - set_error_buf(error_buf, error_buf_size, - "duplicate export name"); - return false; - } - } - if (!(export->name = wasm_const_str_list_insert( p, str_len, module, is_load_from_file_buf, error_buf, error_buf_size))) { @@ -4171,6 +4203,10 @@ load_export_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, return false; } } + + if (!check_duplicate_exports(module, error_buf, error_buf_size)) { + return false; + } } if (p != p_end) { From b34b2c8e266b1474a7e70a029ab28f4939193519 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:13:55 +0800 Subject: [PATCH 029/105] Add token permissions for CIs to fix issues reported by scorecard (#3867) --- .github/workflows/build_docker_images.yml | 5 ++ .github/workflows/build_iwasm_release.yml | 6 +++ .github/workflows/build_llvm_libraries.yml | 6 +++ .github/workflows/build_wamr_lldb.yml | 8 +++ .github/workflows/build_wamr_sdk.yml | 6 +++ .github/workflows/build_wamr_vscode_ext.yml | 6 +++ .github/workflows/build_wamrc.yml | 6 +++ .github/workflows/codeql.yml | 12 +++-- .github/workflows/coding_guidelines.yml | 3 ++ .../compilation_on_android_ubuntu.yml | 6 +++ .github/workflows/compilation_on_macos.yml | 9 ++++ .github/workflows/compilation_on_nuttx.yml | 3 ++ .github/workflows/compilation_on_sgx.yml | 6 +++ .github/workflows/compilation_on_windows.yml | 3 ++ .github/workflows/create_tag.yml | 5 ++ .github/workflows/hadolint_dockerfiles.yml | 3 ++ .github/workflows/nightly_run.yml | 9 ++++ .github/workflows/release_process.yml | 51 +++++++++++++++++++ .../reuse_latest_release_binaries.yml | 6 +++ .github/workflows/spec_test_on_nuttx.yml | 9 ++++ 20 files changed, 164 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_docker_images.yml b/.github/workflows/build_docker_images.yml index d5bf682c4..f7643af3f 100644 --- a/.github/workflows/build_docker_images.yml +++ b/.github/workflows/build_docker_images.yml @@ -15,9 +15,14 @@ on: type: string required: true +permissions: + contents: read + jobs: build-and-push-images: runs-on: ubuntu-22.04 + permissions: + contents: write # for uploading release artifacts steps: - name: Checkout repository diff --git a/.github/workflows/build_iwasm_release.yml b/.github/workflows/build_iwasm_release.yml index c0a6f68bd..74c2340af 100644 --- a/.github/workflows/build_iwasm_release.yml +++ b/.github/workflows/build_iwasm_release.yml @@ -87,6 +87,9 @@ env: -DWAMR_BUILD_EXCE_HANDLING=1 \ -DWAMR_BUILD_GC=1" +permissions: + contents: read + jobs: build: runs-on: ${{ inputs.runner }} @@ -97,6 +100,9 @@ jobs: suffix: '' - build_options: $GC_EH_BUILD_OPTIONS suffix: '-gc-eh' + permissions: + contents: write # for uploading release artifacts + steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/build_llvm_libraries.yml b/.github/workflows/build_llvm_libraries.yml index 80a2bf672..bdfd4fcb2 100644 --- a/.github/workflows/build_llvm_libraries.yml +++ b/.github/workflows/build_llvm_libraries.yml @@ -27,6 +27,9 @@ on: description: "A cached key of LLVM libraries" value: ${{ jobs.build_llvm_libraries.outputs.key}} +permissions: + contents: read + jobs: build_llvm_libraries: runs-on: ${{ inputs.os }} @@ -36,6 +39,9 @@ jobs: image: ${{ inputs.container_image }} outputs: key: ${{ steps.create_lib_cache_key.outputs.key}} + permissions: + contents: read + actions: write # for uploading cached artifact steps: - name: checkout diff --git a/.github/workflows/build_wamr_lldb.yml b/.github/workflows/build_wamr_lldb.yml index 03474c53e..b5cf53a4c 100644 --- a/.github/workflows/build_wamr_lldb.yml +++ b/.github/workflows/build_wamr_lldb.yml @@ -28,8 +28,13 @@ on: required: false default: "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz" +permissions: + contents: read + jobs: try_reuse: + permissions: + contents: write # for uploading release artifacts uses: ./.github/workflows/reuse_latest_release_binaries.yml with: binary_name_stem: "wamr-lldb-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}" @@ -46,6 +51,9 @@ jobs: PYTHON_VERSION: '3.10' PYTHON_UBUNTU_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-unknown-linux-gnu-install_only.tar.gz PYTHON_MACOS_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-apple-darwin-install_only.tar.gz + permissions: + contents: write # for uploading release artifacts + steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/build_wamr_sdk.yml b/.github/workflows/build_wamr_sdk.yml index 519bf9636..266c3a646 100644 --- a/.github/workflows/build_wamr_sdk.yml +++ b/.github/workflows/build_wamr_sdk.yml @@ -35,9 +35,15 @@ on: type: string required: true +permissions: + contents: read + jobs: build: runs-on: ${{ inputs.runner }} + permissions: + contents: write # for uploading release artifacts + steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/build_wamr_vscode_ext.yml b/.github/workflows/build_wamr_vscode_ext.yml index 756215e60..d0fa3b18e 100644 --- a/.github/workflows/build_wamr_vscode_ext.yml +++ b/.github/workflows/build_wamr_vscode_ext.yml @@ -14,9 +14,15 @@ on: type: string required: true +permissions: + contents: read + jobs: build: runs-on: ubuntu-22.04 + permissions: + contents: write # for uploading release artifacts + steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/build_wamrc.yml b/.github/workflows/build_wamrc.yml index e88a04a9e..6b687c749 100644 --- a/.github/workflows/build_wamrc.yml +++ b/.github/workflows/build_wamrc.yml @@ -31,9 +31,15 @@ on: type: string required: false +permissions: + contents: read + jobs: build: runs-on: ${{ inputs.runner }} + permissions: + contents: write # for uploading release artifacts + steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 965a27aa6..ada492a88 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -19,6 +19,9 @@ on: # allow to be triggered manually workflow_dispatch: +permissions: + contents: read + jobs: analyze: if: github.repository == 'bytecodealliance/wasm-micro-runtime' @@ -30,10 +33,6 @@ jobs: # Consider using larger runners for possible analysis time improvements. runs-on: ${{ (matrix.language == 'swift' && 'macos-13') || 'ubuntu-22.04' }} timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} - permissions: - actions: read - contents: read - security-events: write strategy: fail-fast: false @@ -41,6 +40,11 @@ jobs: language: [ 'cpp' ] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] + permissions: + contents: read + actions: read + security-events: write + steps: - name: Checkout repository uses: actions/checkout@v3 diff --git a/.github/workflows/coding_guidelines.yml b/.github/workflows/coding_guidelines.yml index b0aa0a2b8..569237778 100644 --- a/.github/workflows/coding_guidelines.yml +++ b/.github/workflows/coding_guidelines.yml @@ -14,6 +14,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + jobs: compliance_job: runs-on: ubuntu-20.04 diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 6be445944..8ba6e0e80 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -70,8 +70,14 @@ env: MEMORY64_TEST_OPTIONS: "-s spec -W -b -P" MULTI_MEMORY_TEST_OPTIONS: "-s spec -E -b -P" +permissions: + contents: read + jobs: build_llvm_libraries_on_ubuntu_2204: + permissions: + contents: read + actions: write uses: ./.github/workflows/build_llvm_libraries.yml with: os: "ubuntu-22.04" diff --git a/.github/workflows/compilation_on_macos.yml b/.github/workflows/compilation_on_macos.yml index 5b1edac85..66938905c 100644 --- a/.github/workflows/compilation_on_macos.yml +++ b/.github/workflows/compilation_on_macos.yml @@ -52,13 +52,22 @@ env: LLVM_LAZY_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1" LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0" +permissions: + contents: read + jobs: build_llvm_libraries_on_intel_macos: + permissions: + contents: read + actions: write uses: ./.github/workflows/build_llvm_libraries.yml with: os: "macos-13" arch: "X86" build_llvm_libraries_on_arm_macos: + permissions: + contents: read + actions: write uses: ./.github/workflows/build_llvm_libraries.yml with: os: "macos-14" diff --git a/.github/workflows/compilation_on_nuttx.yml b/.github/workflows/compilation_on_nuttx.yml index e10784fe2..ef0799b42 100644 --- a/.github/workflows/compilation_on_nuttx.yml +++ b/.github/workflows/compilation_on_nuttx.yml @@ -46,6 +46,9 @@ concurrency: env: WASI_SDK_PATH: "/opt/wasi-sdk" +permissions: + contents: read + jobs: build_iwasm_on_nuttx: runs-on: ubuntu-latest diff --git a/.github/workflows/compilation_on_sgx.yml b/.github/workflows/compilation_on_sgx.yml index b7bc216eb..70597c366 100644 --- a/.github/workflows/compilation_on_sgx.yml +++ b/.github/workflows/compilation_on_sgx.yml @@ -54,8 +54,14 @@ env: LLVM_LAZY_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1" LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0" +permissions: + contents: read + jobs: build_llvm_libraries: + permissions: + contents: read + actions: write uses: ./.github/workflows/build_llvm_libraries.yml with: os: "ubuntu-20.04" diff --git a/.github/workflows/compilation_on_windows.yml b/.github/workflows/compilation_on_windows.yml index 8c5db4fdf..369980ba9 100644 --- a/.github/workflows/compilation_on_windows.yml +++ b/.github/workflows/compilation_on_windows.yml @@ -53,6 +53,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + jobs: build: runs-on: windows-latest diff --git a/.github/workflows/create_tag.yml b/.github/workflows/create_tag.yml index 5480592a9..7a90ea5f7 100644 --- a/.github/workflows/create_tag.yml +++ b/.github/workflows/create_tag.yml @@ -15,6 +15,9 @@ on: description: "the new tag just created" value: ${{ jobs.create_tag.outputs.new_tag}} +permissions: + contents: read + jobs: create_tag: runs-on: ubuntu-latest @@ -22,6 +25,8 @@ jobs: minor_version: ${{ steps.preparation.outputs.minor_version }} new_ver: ${{ steps.preparation.outputs.new_ver }} new_tag: ${{ steps.preparation.outputs.new_tag }} + permissions: + contents: write # create and push tags steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/hadolint_dockerfiles.yml b/.github/workflows/hadolint_dockerfiles.yml index c540649c8..f9d8c3893 100644 --- a/.github/workflows/hadolint_dockerfiles.yml +++ b/.github/workflows/hadolint_dockerfiles.yml @@ -28,6 +28,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + jobs: run-hadolint-on-dockerfiles: runs-on: ubuntu-22.04 diff --git a/.github/workflows/nightly_run.yml b/.github/workflows/nightly_run.yml index 5149c830f..5e9b4a4f2 100644 --- a/.github/workflows/nightly_run.yml +++ b/.github/workflows/nightly_run.yml @@ -44,13 +44,22 @@ env: X86_32_TARGET_TEST_OPTIONS: "-m x86_32 -P" WASI_TEST_OPTIONS: "-s wasi_certification -w" +permissions: + contents: read + jobs: build_llvm_libraries_on_ubuntu_2004: + permissions: + contents: read + actions: write uses: ./.github/workflows/build_llvm_libraries.yml with: os: "ubuntu-20.04" arch: "X86" build_llvm_libraries_on_ubuntu_2204: + permissions: + contents: read + actions: write uses: ./.github/workflows/build_llvm_libraries.yml with: os: "ubuntu-22.04" diff --git a/.github/workflows/release_process.yml b/.github/workflows/release_process.yml index b9d27d07a..031d57884 100644 --- a/.github/workflows/release_process.yml +++ b/.github/workflows/release_process.yml @@ -18,11 +18,18 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + jobs: create_tag: + permissions: + contents: write # create and push tags uses: ./.github/workflows/create_tag.yml create_release: + permissions: + contents: write # create release needs: [create_tag] runs-on: ubuntu-latest outputs: @@ -52,6 +59,9 @@ jobs: # # LLVM_LIBRARIES build_llvm_libraries_on_ubuntu_2004: + permissions: + contents: read + actions: write needs: [create_tag, create_release] uses: ./.github/workflows/build_llvm_libraries.yml with: @@ -59,6 +69,9 @@ jobs: arch: "AArch64 ARM Mips RISCV X86" build_llvm_libraries_on_ubuntu_2204: + permissions: + contents: read + actions: write needs: [create_tag, create_release] uses: ./.github/workflows/build_llvm_libraries.yml with: @@ -66,6 +79,9 @@ jobs: arch: "AArch64 ARM Mips RISCV X86" build_llvm_libraries_on_macos: + permissions: + contents: read + actions: write needs: [create_tag, create_release] uses: ./.github/workflows/build_llvm_libraries.yml with: @@ -73,6 +89,9 @@ jobs: arch: "AArch64 ARM Mips RISCV X86" build_llvm_libraries_on_windows: + permissions: + contents: read + actions: write needs: [create_tag, create_release] uses: ./.github/workflows/build_llvm_libraries.yml with: @@ -82,6 +101,8 @@ jobs: # # WAMRC release_wamrc_on_ubuntu_2004: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release, build_llvm_libraries_on_ubuntu_2004] uses: ./.github/workflows/build_wamrc.yml with: @@ -92,6 +113,8 @@ jobs: ver_num: ${{ needs.create_tag.outputs.new_ver}} release_wamrc_on_ubuntu_2204: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release, build_llvm_libraries_on_ubuntu_2204 ] uses: ./.github/workflows/build_wamrc.yml with: @@ -102,6 +125,8 @@ jobs: ver_num: ${{ needs.create_tag.outputs.new_ver }} release_wamrc_on_ubuntu_macos: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release, build_llvm_libraries_on_macos] uses: ./.github/workflows/build_wamrc.yml with: @@ -112,6 +137,8 @@ jobs: ver_num: ${{ needs.create_tag.outputs.new_ver }} release_wamrc_on_windows: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release, build_llvm_libraries_on_windows] uses: ./.github/workflows/build_wamrc.yml with: @@ -124,6 +151,8 @@ jobs: # # IWASM release_iwasm_on_ubuntu_2004: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release, build_llvm_libraries_on_ubuntu_2004] uses: ./.github/workflows/build_iwasm_release.yml with: @@ -134,6 +163,8 @@ jobs: ver_num: ${{ needs.create_tag.outputs.new_ver}} release_iwasm_on_ubuntu_2204: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release, build_llvm_libraries_on_ubuntu_2204] uses: ./.github/workflows/build_iwasm_release.yml with: @@ -144,6 +175,8 @@ jobs: ver_num: ${{ needs.create_tag.outputs.new_ver}} release_iwasm_on_macos: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release, build_llvm_libraries_on_macos] uses: ./.github/workflows/build_iwasm_release.yml with: @@ -154,6 +187,8 @@ jobs: ver_num: ${{ needs.create_tag.outputs.new_ver}} release_iwasm_on_windows: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release, build_llvm_libraries_on_windows] uses: ./.github/workflows/build_iwasm_release.yml with: @@ -166,6 +201,8 @@ jobs: # # WAMR_SDK release_wamr_sdk_on_ubuntu_2004: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release] uses: ./.github/workflows/build_wamr_sdk.yml with: @@ -177,6 +214,8 @@ jobs: wamr_app_framework_url: https://github.com/bytecodealliance/wamr-app-framework.git release_wamr_sdk_on_ubuntu_2204: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release] uses: ./.github/workflows/build_wamr_sdk.yml with: @@ -188,6 +227,8 @@ jobs: wamr_app_framework_url: https://github.com/bytecodealliance/wamr-app-framework.git release_wamr_sdk_on_macos: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release] uses: ./.github/workflows/build_wamr_sdk.yml with: @@ -201,6 +242,8 @@ jobs: # # vscode extension cross-platform release_wamr_ide_vscode_ext: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release] uses: ./.github/workflows/build_wamr_vscode_ext.yml secrets: inherit @@ -211,6 +254,8 @@ jobs: # # vscode extension docker images package release_wamr_ide_docker_images_package: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release] uses: ./.github/workflows/build_docker_images.yml with: @@ -220,6 +265,8 @@ jobs: # # WAMR_LLDB release_wamr_lldb_on_ubuntu_2004: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release] uses: ./.github/workflows/build_wamr_lldb.yml with: @@ -228,6 +275,8 @@ jobs: ver_num: ${{ needs.create_tag.outputs.new_ver}} release_wamr_lldb_on_ubuntu_2204: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release] uses: ./.github/workflows/build_wamr_lldb.yml with: @@ -236,6 +285,8 @@ jobs: ver_num: ${{ needs.create_tag.outputs.new_ver}} release_wamr_lldb_on_macos_universal: + permissions: + contents: write # upload release artifact needs: [create_tag, create_release] uses: ./.github/workflows/build_wamr_lldb.yml with: diff --git a/.github/workflows/reuse_latest_release_binaries.yml b/.github/workflows/reuse_latest_release_binaries.yml index c9832cec9..77fe7329f 100644 --- a/.github/workflows/reuse_latest_release_binaries.yml +++ b/.github/workflows/reuse_latest_release_binaries.yml @@ -22,11 +22,17 @@ on: result: value: ${{ jobs.build.outputs.result }} +permissions: + contents: read + jobs: reuse: runs-on: ubuntu-latest outputs: result: ${{ steps.try_reuse.outputs.result }} + permissions: + contents: write # for creating realease and uploading release artifacts + steps: - uses: actions/checkout@v4 # Full git history is needed to get a proper list of commits and tags diff --git a/.github/workflows/spec_test_on_nuttx.yml b/.github/workflows/spec_test_on_nuttx.yml index 3b63deac8..31427d43f 100644 --- a/.github/workflows/spec_test_on_nuttx.yml +++ b/.github/workflows/spec_test_on_nuttx.yml @@ -29,8 +29,14 @@ env: LLVM_CACHE_SUFFIX: "build-llvm_libraries_ex" WASI_SDK_PATH: "/opt/wasi-sdk" +permissions: + contents: read + jobs: build_llvm_libraries: + permissions: + contents: read + actions: write uses: ./.github/workflows/build_llvm_libraries.yml with: os: "ubuntu-22.04" @@ -38,6 +44,9 @@ jobs: container_image: ghcr.io/no1wudi/nuttx/apache-nuttx-ci-linux@sha256:8c4e00b607d4d6d66ba8f51c4544819a616eac69d3a2ac669e2af2150e2eb0f9 build_llvm_libraries_xtensa: + permissions: + contents: read + actions: write uses: ./.github/workflows/build_llvm_libraries.yml with: os: "ubuntu-22.04" From fe13f6de250790d9e198b85810bfae23ec4266a1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:33:02 +0800 Subject: [PATCH 030/105] build(deps): bump github/codeql-action from 3.26.12 to 3.26.13 (#3869) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.12 to 3.26.13. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.26.12...v3.26.13) --- updated-dependencies: - dependency-name: github/codeql-action 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 ada492a88..b458606c0 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.26.12 + uses: github/codeql-action/init@v3.26.13 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.26.12 + uses: github/codeql-action/analyze@v3.26.13 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.26.12 + uses: github/codeql-action/upload-sarif@v3.26.13 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 0b14397ba..26ad7d33e 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@ea2cd92c21b192add69983116b8b3222b09da33b # v2.2.4 + uses: github/codeql-action/upload-sarif@af56b044b5d41c317aef5d19920b3183cb4fbbec # v2.2.4 with: sarif_file: results.sarif From 217ba3b10c41036f0e9727aa93c2a164dba35e5c Mon Sep 17 00:00:00 2001 From: Maks Litskevich Date: Tue, 22 Oct 2024 02:34:03 +0100 Subject: [PATCH 031/105] Update release notes and update version to 2.2.0 (#3863) --- RELEASE_NOTES.md | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ core/version.h | 4 +-- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e296cdf9e..e0bb032cf 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,85 @@ +## WAMR-2.2.0 + +### Breaking changes + +### New features +- Add support for multi-memory proposal in classic interpreter (#3742) +- wasi-nn: Add a new target for llama.cpp as a wasi-nn backend (#3709) +- Add memory instance support apis (#3786) +- Implement a first version of shared heap feature (#3789) +- Support dynamic aot debug (#3788) +- Implement shared heap for AOT (#3815) +- Support table64 extension in classic-interp and AOT running modes (#3811) + + +### Bug fixes +- Enable merged os_mmap for aot data sections (#3681) +- Fix arm64 issues on mac (#3688) +- aot loader: Call os_mmap with MMAP_MAP_32BIT only when target is x86-64 or riscv64 (#3755) +- Fix building iwasm_shared and iwasm_static libs on win32 (#3762) +- Fix compile error when multi-module and tags are enabled (#3781) +- Fix aot multi export memory support (#3791) +- Fix Windows compile error when uvwasi is enabled (#3810) +- Fix missing symbols when using aot mode on riscv platforms (#3812) +- Fix mac build of libc_emcc_wrapper.c (#3836) +- aot_comp_option.h: Add missing stdint.h header (#3834) +- Fix compilation error found in tflite test (#3820) +- Fix exec_env_tls assertion in module instantiation (#3844) +- Fix issues of destroy_shared_heaps (#3847) + +### Enhancements +- aot loader: Refine os_mmap related code (#3711) +- Enable merged os_mmap for aot data sections and aot text (#3743) +- Improve posix mmap retry logic (#3714) +- Remove unnecessary code duplication in aot runtime (#3767) +- Add wamrc parameter to configure stack frame features (#3763) +- refactoring: Re-use commit IP functionality between exception handling and other cases (#3768) +- AOT call stack optimizations (#3773) +- Appease GCC strict prototypes warning (#3775) +- Appease GCC -Wformat (#3783) +- Fix compiler warnings (#3784) +- Implement option for skipping function index in the callstack (#3785) +- Fix a compile warning in aot_emit_function.c (#3793) +- Restore cmake hidden compile symbol visibility (#3796) +- Refactor shared heap feature for interpreter mode (#3794) +- Add no_resolve to LoadArgs and wasm_runtime_resolve_symbols (#3790) +- shared heap: Fix some issues and add basic unit test case (#3801) +- Add shared heap sample (#3806) +- Fix unused param warning when GC is enabled (#3814) +- Add scoreboard CI for supply-chain security (#3819) +- Emit load_addr and load_size if WAMR_ENABLE_COMPILER is set (#3835) +- libc-emcc: Use alternate method to check getrandom support (#3848) +- Enable libc-wasi for windows msvc build (#3852) +- Remove unused folder samples/gui and samples/littlevgl (#3853) +- Fix some compile warnings and typos (#3854) +- Allow to set native stack boundary to exec_env (#3862) +- Refine wasm/aot function instance lookup (#3865) +- Fix quadratic runtime for duplicate export name detection (#3861) + + +### Others +- Add a comment on AOT_SECTION_TYPE_SIGNATURE (#3746) +- CI: Freeze version of bloaty for NuttX compilation (#3756) +- aot compiler: Allow to control stack boundary check when boundary check is enabled (#3754) +- Update ref to the multi-memory tests (#3764) +- compilation_on_nuttx.yml: Update checkout action to suppress warnings (#3765) +- CI: Disable parallel test in spectest for NuttX (#3780) +- spec_test_on_nuttx.yml: Disable riscv32_ilp32f for now (#3777) +- Ignore temporary file from aider (#3787) +- Add CODEOWNERS (#3822) +- build(deps): bump github/codeql-action from 2.2.4 to 3.26.9 (#3826) +- build(deps): bump actions/upload-artifact from 3.1.0 to 4.4.0 (#3827) +- build(deps): bump ossf/scorecard-action from 2.3.1 to 2.4.0 (#3828) +- build(deps): bump github/codeql-action from 3.26.9 to 3.26.11 (#3843) +- build(deps): bump actions/upload-artifact from 4.4.0 to 4.4.3 (#3855) +- build(deps): bump github/codeql-action from 3.26.11 to 3.26.12 (#3856) +- Add Windows wamrc and iwasm build in release CI (#3857) +- Fix syntax error in codeql_buildscript.sh (#3864) +- release CI: Add another iwasm binary that supports Garbage Collection and Exception Handling (#3866) +- Fix lookup function issue reported in nightly run (#3868) + +--- + ## WAMR-2.1.2 ### Breaking Changes diff --git a/core/version.h b/core/version.h index 4e2cbaefc..4fe37e2d7 100644 --- a/core/version.h +++ b/core/version.h @@ -6,6 +6,6 @@ #ifndef _WAMR_VERSION_H_ #define _WAMR_VERSION_H_ #define WAMR_VERSION_MAJOR 2 -#define WAMR_VERSION_MINOR 1 -#define WAMR_VERSION_PATCH 2 +#define WAMR_VERSION_MINOR 2 +#define WAMR_VERSION_PATCH 0 #endif From 7d56289fab7900331726cea1b5614ec9f98b230a Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:48:15 +0800 Subject: [PATCH 032/105] Exclude fuzz test python and npm packages in scoreboard scan (#3871) * exclude fuzz test for scoreboard scan * ci ignore osv-scanner.toml file name inconsistency --- ci/coding_guidelines_check.py | 1 + .../wasm-mutator-fuzz/portal/osv-scanner.toml | 52 +++++++++++++++++++ .../wasm-mutator-fuzz/server/osv-scanner.toml | 32 ++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tests/fuzz/wasm-mutator-fuzz/portal/osv-scanner.toml create mode 100644 tests/fuzz/wasm-mutator-fuzz/server/osv-scanner.toml diff --git a/ci/coding_guidelines_check.py b/ci/coding_guidelines_check.py index d96446266..a0b4535f9 100644 --- a/ci/coding_guidelines_check.py +++ b/ci/coding_guidelines_check.py @@ -180,6 +180,7 @@ def check_file_name(path: Path) -> bool: "docker-compose", "package-lock", "vite-env.d", + "osv-scanner", ]: return True diff --git a/tests/fuzz/wasm-mutator-fuzz/portal/osv-scanner.toml b/tests/fuzz/wasm-mutator-fuzz/portal/osv-scanner.toml new file mode 100644 index 000000000..1eb55cd8d --- /dev/null +++ b/tests/fuzz/wasm-mutator-fuzz/portal/osv-scanner.toml @@ -0,0 +1,52 @@ +# GHSA-67hx-6x53-jw92 +[[PackageOverrides]] +name = "@babel/traverse" +ecosystem = "npm" +ignore = true +reason = "Accepted known vulnerabilities for testing purposes" + +# GHSA-67hx-6x53-jw92 +[[PackageOverrides]] +name = "babel-traverse" +ecosystem = "npm" +ignore = true +reason = "Accepted known vulnerabilities for testing purposes" + +# GHSA-9c47-m6qq-7p4h +[[PackageOverrides]] +name = "json5" +ecosystem = "npm" +ignore = true +reason = "Dependency not critical for security" + +# GHSA-7fh5-64p2-3v2j +[[PackageOverrides]] +name = "postcss" +ecosystem = "npm" +ignore = true +reason = "Vulnerabilities do not affect current use case" + +# GHSA-gcx4-mw62-g8wm +[[PackageOverrides]] +name = "rollup" +ecosystem = "npm" +ignore = true +reason = "Legacy build tool under controlled environment" + +# GHSA-c2qf-rxjj-qqgw +[[PackageOverrides]] +name = "semver" +ecosystem = "npm" +ignore = true +reason = "Version parsing is managed securely" + +# GHSA-353f-5xf4-qw67 +# GHSA-c24v-8rfc-w8vw +# GHSA-8jhw-289h-jh2g +# GHSA-64vr-g452-qvp3 +# GHSA-9cwx-2883-4wfx +[[PackageOverrides]] +name = "vite" +ecosystem = "npm" +ignore = true +reason = "Development server not exposed to untrusted networks" diff --git a/tests/fuzz/wasm-mutator-fuzz/server/osv-scanner.toml b/tests/fuzz/wasm-mutator-fuzz/server/osv-scanner.toml new file mode 100644 index 000000000..430d8ca8c --- /dev/null +++ b/tests/fuzz/wasm-mutator-fuzz/server/osv-scanner.toml @@ -0,0 +1,32 @@ +# GHSA-m2qf-hxjv-5gpq / PYSEC-2023-62 +[[PackageOverrides]] +name = "Flask" +ecosystem = "PyPI" +ignore = true +reason = "Accepted known vulnerabilities for testing purposes" + +# GHSA-m2qf-hxjv-5gpq / PYSEC-2023-62 +[[PackageOverrides]] +name = "flask" +ecosystem = "PyPI" +ignore = true +reason = "Accepted known vulnerabilities for testing purposes" + +# GHSA-84pr-m4jr-85g5 +# GHSA-hxwh-jpp2-84pm / PYSEC-2024-71 +[[PackageOverrides]] +name = "flask-cors" +ecosystem = "PyPI" +ignore = true +reason = "Accepted known vulnerabilities for testing purposes" + +# GHSA-2g68-c3qc-8985 +# GHSA-hrfv-mqp8-q5rw / PYSEC-2023-221 +# GHSA-px8h-6qxv-m22q / PYSEC-2023-57 +# GHSA-xg9f-g7g7-2323 / PYSEC-2023-58 +# PYSEC-2022-203 +[[PackageOverrides]] +name = "werkzeug" +ecosystem = "PyPI" +ignore = true +reason = "Accepted known vulnerabilities for testing purposes" From 6426fc4993478288f05a04827118cb27551a1b1e Mon Sep 17 00:00:00 2001 From: Maks Litskevich Date: Wed, 23 Oct 2024 07:48:40 +0100 Subject: [PATCH 033/105] Fix out of bounds issues after memory.grow on non-aot non-threads builds (#3872) Co-authored-by: Deniz Sokmen --- core/iwasm/interpreter/wasm_interp_classic.c | 2 +- core/iwasm/interpreter/wasm_interp_fast.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 41bfbe26d..7041fd89c 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -6727,7 +6727,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ || WASM_ENABLE_BULK_MEMORY != 0 if (memory) - linear_mem_size = get_linear_mem_size(); + linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory); #endif if (wasm_copy_exception(module, NULL)) { #if WASM_ENABLE_EXCE_HANDLING != 0 diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 82b6ff71b..531468282 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -5994,7 +5994,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ || WASM_ENABLE_BULK_MEMORY != 0 if (memory) - linear_mem_size = get_linear_mem_size(); + linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory); #endif if (wasm_copy_exception(module, NULL)) goto got_exception; From a713ba1110de6269473ce620dd5cf352f113b47f Mon Sep 17 00:00:00 2001 From: edoardo <48774736+xdoardo@users.noreply.github.com> Date: Tue, 29 Oct 2024 03:20:05 +0100 Subject: [PATCH 034/105] fix(ios): Remove `float-abi` flag (#3889) --- product-mini/platforms/ios/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/product-mini/platforms/ios/CMakeLists.txt b/product-mini/platforms/ios/CMakeLists.txt index 4bbff4cff..ea5a4f4b9 100644 --- a/product-mini/platforms/ios/CMakeLists.txt +++ b/product-mini/platforms/ios/CMakeLists.txt @@ -3,8 +3,6 @@ cmake_minimum_required (VERSION 3.21) -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard") - project (iwasm) set (WAMR_BUILD_PLATFORM "darwin") From 483c57de9fad9f7c2978d260bd55030e8a079a21 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:20:33 +0800 Subject: [PATCH 035/105] build(deps): bump github/codeql-action from 3.26.13 to 3.27.0 (#3888) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.13 to 3.27.0. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.26.13...v3.27.0) --- updated-dependencies: - dependency-name: github/codeql-action 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 b458606c0..62bcd0c31 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.26.13 + uses: github/codeql-action/init@v3.27.0 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.26.13 + uses: github/codeql-action/analyze@v3.27.0 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.26.13 + uses: github/codeql-action/upload-sarif@v3.27.0 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 26ad7d33e..5e331c08c 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@af56b044b5d41c317aef5d19920b3183cb4fbbec # v2.2.4 + uses: github/codeql-action/upload-sarif@3aa71356c75a8edd8430d54dff2982203a28be45 # v2.2.4 with: sarif_file: results.sarif From a3960c834d7e95061f85a9d7a2f9e0ab716ef4c4 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 29 Oct 2024 10:58:11 +0800 Subject: [PATCH 036/105] Refine looking up aot function with index (#3882) * Refine looking up aot function with index * refine the code --- core/iwasm/aot/aot_runtime.c | 82 ++++++++++++++++++++++++++++----- core/iwasm/aot/aot_runtime.h | 25 +++++++++- core/iwasm/common/wasm_c_api.c | 17 +------ core/iwasm/common/wasm_memory.c | 3 +- 4 files changed, 97 insertions(+), 30 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 7e6d6360c..01e04a3ec 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1096,11 +1096,11 @@ aot_get_default_memory(AOTModuleInstance *module_inst) } AOTMemoryInstance * -aot_get_memory_with_index(AOTModuleInstance *module_inst, uint32 index) +aot_get_memory_with_idx(AOTModuleInstance *module_inst, uint32 mem_idx) { - if ((index >= module_inst->memory_count) || !module_inst->memories) + if ((mem_idx >= module_inst->memory_count) || !module_inst->memories) return NULL; - return module_inst->memories[index]; + return module_inst->memories[mem_idx]; } static bool @@ -1282,20 +1282,77 @@ init_func_ptrs(AOTModuleInstance *module_inst, AOTModule *module, return true; } +static int +cmp_export_func_map(const void *a, const void *b) +{ + uint32 func_idx1 = ((const ExportFuncMap *)a)->func_idx; + uint32 func_idx2 = ((const ExportFuncMap *)b)->func_idx; + return func_idx1 < func_idx2 ? -1 : (func_idx1 > func_idx2 ? 1 : 0); +} + +AOTFunctionInstance * +aot_lookup_function_with_idx(AOTModuleInstance *module_inst, uint32 func_idx) +{ + AOTModuleInstanceExtra *extra = (AOTModuleInstanceExtra *)module_inst->e; + AOTFunctionInstance *export_funcs = + (AOTFunctionInstance *)module_inst->export_functions; + AOTFunctionInstance *func_inst = NULL; + ExportFuncMap *export_func_maps, *export_func_map, key; + uint64 size; + uint32 i; + + if (module_inst->export_func_count == 0) + return NULL; + + exception_lock(module_inst); + + /* create the func_idx to export_idx maps if it hasn't been created */ + if (!extra->export_func_maps) { + size = sizeof(ExportFuncMap) * (uint64)module_inst->export_func_count; + if (!(export_func_maps = extra->export_func_maps = + runtime_malloc(size, NULL, 0))) { + /* allocate memory failed, lookup the export function one by one */ + for (i = 0; i < module_inst->export_func_count; i++) { + if (export_funcs[i].func_index == func_idx) { + func_inst = &export_funcs[i]; + break; + } + } + goto unlock_and_return; + } + + for (i = 0; i < module_inst->export_func_count; i++) { + export_func_maps[i].func_idx = export_funcs[i].func_index; + export_func_maps[i].export_idx = i; + } + + qsort(export_func_maps, module_inst->export_func_count, + sizeof(ExportFuncMap), cmp_export_func_map); + } + + /* lookup the map to get the export_idx of the func_idx */ + key.func_idx = func_idx; + export_func_map = + bsearch(&key, extra->export_func_maps, module_inst->export_func_count, + sizeof(ExportFuncMap), cmp_export_func_map); + if (export_func_map) + func_inst = &export_funcs[export_func_map->export_idx]; + +unlock_and_return: + exception_unlock(module_inst); + return func_inst; +} + AOTFunctionInstance * aot_get_function_instance(AOTModuleInstance *module_inst, uint32 func_idx) { AOTModule *module = (AOTModule *)module_inst->module; AOTModuleInstanceExtra *extra = (AOTModuleInstanceExtra *)module_inst->e; - AOTFunctionInstance *export_funcs = - (AOTFunctionInstance *)module_inst->export_functions; - uint32 i; + AOTFunctionInstance *func_inst; - /* export functions are pre-instantiated */ - for (i = 0; i < module_inst->export_func_count; i++) { - if (export_funcs[i].func_index == func_idx) - return &export_funcs[i]; - } + /* lookup from export functions first */ + if ((func_inst = aot_lookup_function_with_idx(module_inst, func_idx))) + return func_inst; exception_lock(module_inst); @@ -2168,6 +2225,9 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst) if (module_inst->export_functions) wasm_runtime_free(module_inst->export_functions); + if (extra->export_func_maps) + wasm_runtime_free(extra->export_func_maps); + #if WASM_ENABLE_MULTI_MEMORY != 0 if (module_inst->export_memories) wasm_runtime_free(module_inst->export_memories); diff --git a/core/iwasm/aot/aot_runtime.h b/core/iwasm/aot/aot_runtime.h index bf5e4366c..297b2a5b5 100644 --- a/core/iwasm/aot/aot_runtime.h +++ b/core/iwasm/aot/aot_runtime.h @@ -109,6 +109,13 @@ typedef struct AOTFunctionInstance { } u; } AOTFunctionInstance; +/* Map of a function index to the element ith in + the export functions array */ +typedef struct ExportFuncMap { + uint32 func_idx; + uint32 export_idx; +} ExportFuncMap; + typedef struct AOTModuleInstanceExtra { DefPointer(const uint32 *, stack_sizes); /* @@ -120,6 +127,13 @@ typedef struct AOTModuleInstanceExtra { MemBound shared_heap_start_off; WASMModuleInstanceExtraCommon common; + + /** + * maps of func indexes to export func indexes, which + * is sorted by func index for a quick lookup and is + * created only when first time used. + */ + ExportFuncMap *export_func_maps; AOTFunctionInstance **functions; uint32 function_count; #if WASM_ENABLE_MULTI_MODULE != 0 @@ -556,6 +570,13 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst); AOTFunctionInstance * aot_lookup_function(const AOTModuleInstance *module_inst, const char *name); +/** + * Lookup an exported function in the AOT module instance with + * the function index. + */ +AOTFunctionInstance * +aot_lookup_function_with_idx(AOTModuleInstance *module_inst, uint32 func_idx); + AOTMemoryInstance * aot_lookup_memory(AOTModuleInstance *module_inst, char const *name); @@ -563,7 +584,7 @@ AOTMemoryInstance * aot_get_default_memory(AOTModuleInstance *module_inst); AOTMemoryInstance * -aot_get_memory_with_index(AOTModuleInstance *module_inst, uint32 index); +aot_get_memory_with_idx(AOTModuleInstance *module_inst, uint32 mem_idx); /** * Get a function in the AOT module instance. @@ -574,7 +595,7 @@ aot_get_memory_with_index(AOTModuleInstance *module_inst, uint32 index); * @return the function instance found */ AOTFunctionInstance * -aot_get_function_instance(AOTModuleInstance *module_inst, uint32_t func_idx); +aot_get_function_instance(AOTModuleInstance *module_inst, uint32 func_idx); /** * Call the given AOT function of a AOT module instance with diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 5c1e9efd3..0c5e37eab 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -3383,21 +3383,8 @@ wasm_func_call(const wasm_func_t *func, const wasm_val_vec_t *params, if (!(func_comm_rt = func->func_comm_rt)) { AOTModuleInstance *inst_aot = (AOTModuleInstance *)func->inst_comm_rt; - AOTModule *module_aot = (AOTModule *)inst_aot->module; - uint32 export_i = 0, export_func_j = 0; - - for (; export_i < module_aot->export_count; ++export_i) { - AOTExport *export = module_aot->exports + export_i; - if (export->kind == EXPORT_KIND_FUNC) { - if (export->index == func->func_idx_rt) { - func_comm_rt = - aot_lookup_function(inst_aot, export->name); - ((wasm_func_t *)func)->func_comm_rt = func_comm_rt; - break; - } - export_func_j++; - } - } + func_comm_rt = ((wasm_func_t *)func)->func_comm_rt = + aot_lookup_function_with_idx(inst_aot, func->func_idx_rt); } #endif } diff --git a/core/iwasm/common/wasm_memory.c b/core/iwasm/common/wasm_memory.c index 5f5a1be90..ff85d9f6c 100644 --- a/core/iwasm/common/wasm_memory.c +++ b/core/iwasm/common/wasm_memory.c @@ -1579,8 +1579,7 @@ wasm_runtime_get_memory(WASMModuleInstanceCommon *module_inst, uint32 index) #if WASM_ENABLE_AOT != 0 if (module_inst->module_type == Wasm_Module_AoT) - return aot_get_memory_with_index((AOTModuleInstance *)module_inst, - index); + return aot_get_memory_with_idx((AOTModuleInstance *)module_inst, index); #endif return NULL; From 95edef31857fc694bcf0d306829f53587a497b44 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 29 Oct 2024 12:26:06 +0900 Subject: [PATCH 037/105] Bump AOT_CURRENT_VERSION for WAMR 2.x (gc, memory64) (#3880) * Bump AOT_CURRENT_VERSION for WAMR 2.x (gc, memory64) Maybe it's too late because we have already made a few releases since then. But this might still help users who haven't upgraded to WAMR 2.x yet. Also, for the purpose of the versioning, it's safer to bump needlessly than missing necessary bumps. Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3837 * test-tools/aot-analyzer/include/config.h: bump AOT_CURRENT_VERSION --- core/config.h | 2 +- test-tools/aot-analyzer/include/config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/config.h b/core/config.h index 6bab4da90..f08d828d2 100644 --- a/core/config.h +++ b/core/config.h @@ -84,7 +84,7 @@ #endif #define AOT_MAGIC_NUMBER 0x746f6100 -#define AOT_CURRENT_VERSION 3 +#define AOT_CURRENT_VERSION 4 #ifndef WASM_ENABLE_JIT #define WASM_ENABLE_JIT 0 diff --git a/test-tools/aot-analyzer/include/config.h b/test-tools/aot-analyzer/include/config.h index 546b5b167..970d7e2cc 100644 --- a/test-tools/aot-analyzer/include/config.h +++ b/test-tools/aot-analyzer/include/config.h @@ -15,7 +15,7 @@ #define WASM_CURRENT_VERSION 1 #define AOT_MAGIC_NUMBER 0x746f6100 -#define AOT_CURRENT_VERSION 3 +#define AOT_CURRENT_VERSION 4 /* Legal values for bin_type */ #define BIN_TYPE_ELF32L 0 /* 32-bit little endian */ From 1138435455a7d149c793032b65c4a8117ce29c9f Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Wed, 30 Oct 2024 13:18:54 +0800 Subject: [PATCH 038/105] Fix mmap flags for AOT loader on non-Linux SGX platforms (#3890) --- core/iwasm/aot/aot_loader.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 01e246aa3..c53503be2 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -304,12 +304,13 @@ loader_mmap(uint32 size, bool prot_exec, char *error_buf, uint32 error_buf_size) #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \ || defined(BUILD_TARGET_RISCV64_LP64D) \ || defined(BUILD_TARGET_RISCV64_LP64) -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) /* The mmapped AOT data and code in 64-bit targets had better be in range 0 to 2G, or aot loader may fail to apply some relocations, e.g., R_X86_64_32/R_X86_64_32S/R_X86_64_PC32/R_RISCV_32. We try to mmap with MMAP_MAP_32BIT flag first, and if fails, mmap again without the flag. */ + /* sgx_tprotect_rsrv_mem() and sgx_alloc_rsrv_mem() will ignore flags */ map_flags = MMAP_MAP_32BIT; if ((mem = os_mmap(NULL, size, map_prot, map_flags, os_get_invalid_handle()))) { From c7b2683f17b42911e5cbd2b22502f483d882047d Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 31 Oct 2024 12:44:55 +0800 Subject: [PATCH 039/105] Fix out of bounds issue in is_native_addr_in_shared_heap function (#3886) When checking for integer overflow, you may often write tests like p + i < p. This works fine if p and i are unsigned integers, since any overflow in the addition will cause the value to simply "wrap around." However, using this pattern when p is a pointer is problematic because pointer overflow has undefined behavior according to the C and C++ standards. If the addition overflows and has an undefined result, the comparison will likewise be undefined; it may produce an unintended result, or may be deleted entirely by an optimizing compiler. --- core/iwasm/common/wasm_memory.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/core/iwasm/common/wasm_memory.c b/core/iwasm/common/wasm_memory.c index ff85d9f6c..74df84e56 100644 --- a/core/iwasm/common/wasm_memory.c +++ b/core/iwasm/common/wasm_memory.c @@ -420,13 +420,31 @@ is_native_addr_in_shared_heap(WASMModuleInstanceCommon *module_inst, uint8 *addr, uint32 bytes) { WASMSharedHeap *heap = get_shared_heap(module_inst); + uintptr_t base_addr; + uintptr_t addr_int; + uintptr_t end_addr; - if (heap && addr >= heap->base_addr - && addr + bytes <= heap->base_addr + heap->size - && addr + bytes > addr) { - return true; + if (!heap) { + return false; } - return false; + + base_addr = (uintptr_t)heap->base_addr; + addr_int = (uintptr_t)addr; + if (addr_int < base_addr) { + return false; + } + + end_addr = addr_int + bytes; + /* Check for overflow */ + if (end_addr <= addr_int) { + return false; + } + + if (end_addr > base_addr + heap->size) { + return false; + } + + return true; } uint64 From e352f0ab101116c46a5a615d5139b70e8e9a3d47 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Fri, 1 Nov 2024 10:16:24 +0800 Subject: [PATCH 040/105] Refactor AOT loader to support compatible versions (#3891) This commit refactors the AOT loader in `aot_loader.c` to support compatible versions of the AOT_CURRENT_VERSION constant. Previously, the loader only accepted the exact AOT_CURRENT_VERSION value, but now it also accepts version 3. This change ensures that the runtime can load modules AoT-compiled with different versions of wamrc as long as they have compatible AOT_CURRENT_VERSION values. Related to #3880. --- core/iwasm/aot/aot_loader.c | 12 +++++++++++- doc/build_wasm_app.md | 14 +++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index c53503be2..dd26bbee5 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -4236,6 +4236,16 @@ fail: return false; } +static bool +aot_compatible_version(uint32 version) +{ + /* + * refer to "AoT-compiled module compatibility among WAMR versions" in + * ./doc/biuld_wasm_app.md + */ + return version == 4 || version == 3; +} + static bool load(const uint8 *buf, uint32 size, AOTModule *module, bool wasm_binary_freeable, bool no_resolve, char *error_buf, @@ -4254,7 +4264,7 @@ load(const uint8 *buf, uint32 size, AOTModule *module, } read_uint32(p, p_end, version); - if (version != AOT_CURRENT_VERSION) { + if (!aot_compatible_version(version)) { set_error_buf(error_buf, error_buf_size, "unknown binary version"); return false; } diff --git a/doc/build_wasm_app.md b/doc/build_wasm_app.md index 7747d9ac3..9536d1a8d 100644 --- a/doc/build_wasm_app.md +++ b/doc/build_wasm_app.md @@ -377,15 +377,23 @@ Examples: wamrc -o test.aot test.wasm When making major ABI changes for AoT-compiled modules, we bump `AOT_CURRENT_VERSION` constant in `core/config.h` header. The runtime rejects to load a module AoT-compiled with wamrc with -a different `AOT_CURRENT_VERSION`. +a non-compatible`AOT_CURRENT_VERSION`. We try our best to maintain our runtime ABI for AoT-compiled modules -compatible among WAMR versions with the same `AOT_CURRENT_VERSION` +compatible among WAMR versions with compatible `AOT_CURRENT_VERSION` so that combinations of older wamrc and newer runtime usually work. However, there might be minor incompatibilities time to time. -For productions, we recommend to use the exactly same version of +For productions, we recommend to use compatible versions of wamrc and the runtime. +| WAMR version | AOT_CURRENT_VERSION | Compatible AOT version | +| ------------ | ------------------- | ---------------------- | +| 1.x | 3 | 3 | +| 2.0.0 | 3 | 3 | +| 2.1.x | 3 | 3 | +| 2.2.0 | 3 | 3 | +| next | 4 | 3,4 | + ## AoT compilation with 3rd-party toolchains `wamrc` uses LLVM to compile wasm bytecode to AoT file, this works for most of the architectures, but there may be circumstances where you want to use 3rd-party toolchains to take over some steps of the compilation pipeline, e.g. From bf78863c5611de857caae3a998cbbf441dbd90cd Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:38:42 +0800 Subject: [PATCH 041/105] Wasm loader enhancement: check code size in code entry (#3892) add wasm loader check: in code entry, the code size should match the size of vec(locals) + expr, and expr should end with opcode end --- core/iwasm/interpreter/wasm_loader.c | 26 +++++++++++++++-------- core/iwasm/interpreter/wasm_mini_loader.c | 2 ++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index ae823d7be..04fa2473e 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -3610,6 +3610,17 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, #endif } + /* Code size in code entry can't be smaller than size of vec(locals) + * + expr(at least 1 for opcode end). And expressions are encoded by + * their instruction sequence terminated with an explicit 0x0B + * opcode for end. */ + if (p_code_end <= p_code || *(p_code_end - 1) != WASM_OP_END) { + set_error_buf( + error_buf, error_buf_size, + "section size mismatch: function body END opcode expected"); + return false; + } + /* Alloc memory, layout: function structure + local types */ code_size = (uint32)(p_code_end - p_code); @@ -15837,15 +15848,12 @@ re_scan: } if (loader_ctx->csp_num > 0) { - if (cur_func_idx < module->function_count - 1) - /* Function with missing end marker (between two functions) */ - set_error_buf(error_buf, error_buf_size, "END opcode expected"); - else - /* Function with missing end marker - (at EOF or end of code sections) */ - set_error_buf(error_buf, error_buf_size, - "unexpected end of section or function, " - "or section size mismatch"); + /* unmatched end opcodes result from unbalanced control flow structures, + * for example, br_table with inconsistent target count (1 declared, 2 + * given), or simply superfluous end opcodes */ + set_error_buf( + error_buf, error_buf_size, + "unexpected end opcodes from unbalanced control flow structures"); goto fail; } diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 0d1f83704..006a38c1c 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -1183,6 +1183,8 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, local_count += sub_local_count; } + bh_assert(p_code_end > p_code && *(p_code_end - 1) == WASM_OP_END); + /* Alloc memory, layout: function structure + local types */ code_size = (uint32)(p_code_end - p_code); From 397f6633491052a3d4607039f6a87834b9a8524e Mon Sep 17 00:00:00 2001 From: Fadumina Barre Date: Fri, 8 Nov 2024 08:26:37 +0000 Subject: [PATCH 042/105] fix(uwp): Gate NTSTATUS definition behind WINAPI_PARTITION_DESKTOP for UWP builds --- core/shared/platform/windows/win_clock.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/shared/platform/windows/win_clock.c b/core/shared/platform/windows/win_clock.c index ec0bc8566..c402330aa 100644 --- a/core/shared/platform/windows/win_clock.c +++ b/core/shared/platform/windows/win_clock.c @@ -10,9 +10,11 @@ #define NANOSECONDS_PER_SECOND 1000000000ULL #define NANOSECONDS_PER_TICK 100 +#if WINAPI_PARTITION_DESKTOP extern NTSTATUS NtQueryTimerResolution(PULONG MinimumResolution, PULONG MaximumResolution, PULONG CurrentResolution); +#endif static __wasi_errno_t calculate_monotonic_clock_frequency(uint64 *out_frequency) From fdda259d362b418f1f2a624c10d5a44bcdf81d51 Mon Sep 17 00:00:00 2001 From: James Ring Date: Tue, 12 Nov 2024 22:52:27 -0800 Subject: [PATCH 043/105] Fix linked global initialization in multimodule (#3905) While resolving linked globals in multi-module mode, WAMR tries to copy the linked global's initial value into the destination global in the current module. However, a bug in the implementation causes the copy to be done from the InitializerExpression struct, not from its WASMValue field. This did not come up in WAMR's spec test runner because those are built with WASM_ENABLE_SPEC_TEST, which means these globals are resolved as builtins, not linked globals, which goes through a different (presumably not faulty) path. --- core/iwasm/interpreter/wasm_runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index accb40319..0f1ccd937 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1209,7 +1209,7 @@ globals_instantiate(WASMModule *module, WASMModuleInstance *module_inst, /* The linked global instance has been initialized, we just need to copy the value. */ bh_memcpy_s(&(global->initial_value), sizeof(WASMValue), - &(global_import->import_global_linked->init_expr), + &(global_import->import_global_linked->init_expr.u), sizeof(WASMValue)); } else From 75f5fa46ab7064951b7f1fa4487c67f01a9762b5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:11:11 +0800 Subject: [PATCH 044/105] build(deps): bump github/codeql-action from 3.27.0 to 3.27.1 (#3902) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.0 to 3.27.1. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.27.0...v3.27.1) --- updated-dependencies: - dependency-name: github/codeql-action 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 62bcd0c31..a3228e20d 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.27.0 + uses: github/codeql-action/init@v3.27.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.27.0 + uses: github/codeql-action/analyze@v3.27.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.27.0 + uses: github/codeql-action/upload-sarif@v3.27.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 5e331c08c..28efecc47 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@3aa71356c75a8edd8430d54dff2982203a28be45 # v2.2.4 + uses: github/codeql-action/upload-sarif@acb9cb18eec7e3a113ef83cff0be91e75cfd9526 # v2.2.4 with: sarif_file: results.sarif From 226bf22f9e61c33345d831c16e756ec40a90b689 Mon Sep 17 00:00:00 2001 From: James Ring Date: Tue, 12 Nov 2024 23:11:33 -0800 Subject: [PATCH 045/105] GlobalValueSet was moved to IRPartitionLayer recently, but we have a local definition anyway (#3899) --- core/iwasm/compilation/aot_orc_extra.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/compilation/aot_orc_extra.cpp b/core/iwasm/compilation/aot_orc_extra.cpp index dad9e04c0..d9cf3e711 100644 --- a/core/iwasm/compilation/aot_orc_extra.cpp +++ b/core/iwasm/compilation/aot_orc_extra.cpp @@ -177,7 +177,7 @@ LLVMOrcLLLazyJITBuilderSetJITTargetMachineBuilder( LLVMOrcDisposeJITTargetMachineBuilder(JTMP); } -static Optional +static Optional PartitionFunction(GlobalValueSet Requested) { std::vector GVsToAdd; From 0e4dffc47922bb6fcdcaed7de2a6edfe8c48a7cd Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:16:13 +0800 Subject: [PATCH 046/105] Fix a leak in wasm_loader_emit_br_info (#3900) Reference Info: 377955855 wamr:wasm_mutator_fuzz_loader: Direct-leak in wasm_loader_emit_br_info https://issues.oss-fuzz.com/issues/377955855 --- core/iwasm/common/wasm_application.c | 3 ++- core/iwasm/interpreter/wasm_loader.c | 22 +++++++++++++--------- core/iwasm/interpreter/wasm_mini_loader.c | 18 +++++++++--------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/core/iwasm/common/wasm_application.c b/core/iwasm/common/wasm_application.c index 3b3be16c0..b5928d95c 100644 --- a/core/iwasm/common/wasm_application.c +++ b/core/iwasm/common/wasm_application.c @@ -105,7 +105,8 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[]) bool ret, is_import_func = true, is_memory64 = false; #if WASM_ENABLE_MEMORY64 != 0 WASMModuleInstance *wasm_module_inst = (WASMModuleInstance *)module_inst; - is_memory64 = wasm_module_inst->memories[0]->is_memory64; + if (wasm_module_inst->memory_count > 0) + is_memory64 = wasm_module_inst->memories[0]->is_memory64; #endif exec_env = wasm_runtime_get_exec_env_singleton(module_inst); diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 04fa2473e..418456210 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -9885,13 +9885,6 @@ fail: } #endif /* WASM_ENABLE_FAST_INTERP */ -#define RESERVE_BLOCK_RET() \ - do { \ - if (!reserve_block_ret(loader_ctx, opcode, disable_emit, error_buf, \ - error_buf_size)) \ - goto fail; \ - } while (0) - #define PUSH_TYPE(type) \ do { \ if (!(wasm_loader_push_frame_ref(loader_ctx, type, error_buf, \ @@ -11612,7 +11605,10 @@ re_scan: #if WASM_ENABLE_FAST_INTERP != 0 /* if the result of if branch is in local or const area, add a * copy op */ - RESERVE_BLOCK_RET(); + if (!reserve_block_ret(loader_ctx, opcode, disable_emit, + error_buf, error_buf_size)) { + goto fail; + } emit_empty_label_addr_and_frame_ip(PATCH_END); apply_label_patch(loader_ctx, 1, PATCH_ELSE); @@ -11672,7 +11668,15 @@ re_scan: #if WASM_ENABLE_FAST_INTERP != 0 skip_label(); /* copy the result to the block return address */ - RESERVE_BLOCK_RET(); + if (!reserve_block_ret(loader_ctx, opcode, disable_emit, + error_buf, error_buf_size)) { + /* it could be tmp frame_csp allocated from opcode like + * OP_BR and not counted in loader_ctx->csp_num, it won't + * be freed in wasm_loader_ctx_destroy(loader_ctx) so need + * to free the loader_ctx->frame_csp if fails */ + free_label_patch_list(loader_ctx->frame_csp); + goto fail; + } apply_label_patch(loader_ctx, 0, PATCH_END); free_label_patch_list(loader_ctx->frame_csp); diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 006a38c1c..a1fb3102f 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -5592,13 +5592,6 @@ fail: #endif /* WASM_ENABLE_FAST_INTERP */ -#define RESERVE_BLOCK_RET() \ - do { \ - if (!reserve_block_ret(loader_ctx, opcode, disable_emit, error_buf, \ - error_buf_size)) \ - goto fail; \ - } while (0) - #define PUSH_TYPE(type) \ do { \ if (!(wasm_loader_push_frame_ref(loader_ctx, type, error_buf, \ @@ -6366,7 +6359,10 @@ re_scan: #if WASM_ENABLE_FAST_INTERP != 0 /* if the result of if branch is in local or const area, add a * copy op */ - RESERVE_BLOCK_RET(); + if (!reserve_block_ret(loader_ctx, opcode, disable_emit, + error_buf, error_buf_size)) { + goto fail; + } emit_empty_label_addr_and_frame_ip(PATCH_END); apply_label_patch(loader_ctx, 1, PATCH_ELSE); @@ -6426,7 +6422,11 @@ re_scan: #if WASM_ENABLE_FAST_INTERP != 0 skip_label(); /* copy the result to the block return address */ - RESERVE_BLOCK_RET(); + if (!reserve_block_ret(loader_ctx, opcode, disable_emit, + error_buf, error_buf_size)) { + free_label_patch_list(loader_ctx->frame_csp); + goto fail; + } apply_label_patch(loader_ctx, 0, PATCH_END); free_label_patch_list(loader_ctx->frame_csp); From 0119b17526ae447c5c57784d9deb90c04af51fe5 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Mon, 18 Nov 2024 20:01:00 +0800 Subject: [PATCH 047/105] Correct the table index calculation in aot_instantiation (#3903) `module_inst->table_count = module->import_table_count + module->table_count`, using it as an index will go through `module->import_tables` and `module->tables`, but aot init data is only available for non-import tables. --- core/iwasm/aot/aot_runtime.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 01e04a3ec..5d50f255c 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1785,7 +1785,7 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent, bool ret = false; #endif - /* Check heap size */ + /* Align and validate heap size */ heap_size = align_uint(heap_size, 8); if (heap_size > APP_HEAP_SIZE_MAX) heap_size = APP_HEAP_SIZE_MAX; @@ -2001,7 +2001,11 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent, AOTTableInstance *table_inst; table_elem_type_t *table_data; - table = &module->tables[i]; + /* bypass imported table since AOTImportTable doesn't have init_expr */ + if (i < module->import_table_count) + continue; + + table = &module->tables[i - module->import_table_count]; bh_assert(table); if (table->init_expr.init_expr_type == INIT_EXPR_NONE) { From 2975e2ffb8e83691c1dbaa685253c2d4bf63b03b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:45:50 +0800 Subject: [PATCH 048/105] build(deps): bump github/codeql-action from 3.27.1 to 3.27.4 (#3912) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.1 to 3.27.4. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.27.1...v3.27.4) --- updated-dependencies: - dependency-name: github/codeql-action 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 a3228e20d..c71f305aa 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.27.1 + uses: github/codeql-action/init@v3.27.4 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.27.1 + uses: github/codeql-action/analyze@v3.27.4 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.27.1 + uses: github/codeql-action/upload-sarif@v3.27.4 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 28efecc47..1d5baa6b1 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@acb9cb18eec7e3a113ef83cff0be91e75cfd9526 # v2.2.4 + uses: github/codeql-action/upload-sarif@a1695c562bbfa68dc5ab58c9b5e9f616b52bf5be # v2.2.4 with: sarif_file: results.sarif From f2b87d773e88790fd2eac89d828f78836c219900 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:47:05 +0800 Subject: [PATCH 049/105] Support external toolchain on Windows for aot compiler (#3911) allowing custom ARC toolchain on Windows --- build-scripts/build_llvm.py | 20 ++++++++- core/iwasm/compilation/aot_compiler.c | 43 ++----------------- core/iwasm/compilation/aot_emit_aot_file.c | 20 ++------- core/iwasm/compilation/aot_llvm.c | 10 ----- core/iwasm/compilation/aot_llvm.h | 12 ++++++ core/shared/utils/bh_common.c | 50 ++++++++++++++++++++++ core/shared/utils/bh_common.h | 10 +++++ 7 files changed, 97 insertions(+), 68 deletions(-) diff --git a/build-scripts/build_llvm.py b/build-scripts/build_llvm.py index 7de55b6a0..ec6bb3954 100755 --- a/build-scripts/build_llvm.py +++ b/build-scripts/build_llvm.py @@ -102,12 +102,27 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl "default": [], } + experimental_backends = ["ARC", "Xtensa"] + normal_backends = [s for s in backends if s not in experimental_backends] + LLVM_TARGETS_TO_BUILD = [ - '-DLLVM_TARGETS_TO_BUILD:STRING="' + ";".join(backends) + '"' - if backends + '-DLLVM_TARGETS_TO_BUILD:STRING="' + ";".join(normal_backends) + '"' + if normal_backends else '-DLLVM_TARGETS_TO_BUILD:STRING="AArch64;ARM;Mips;RISCV;X86"' ] + # if not on ARC platform, but want to add expeirmental backend ARC as target + if platform != "ARC" and "ARC" in backends: + LLVM_TARGETS_TO_BUILD.extend( + LLVM_EXTRA_COMPILE_OPTIONS["arc"] + ) + + if platform != "Xtensa" and "Xtensa" in backends: + print( + "Currently it's not supported to build Xtensa backend on non-Xtensa platform" + ) + return None + LLVM_PROJECTS_TO_BUILD = [ '-DLLVM_ENABLE_PROJECTS:STRING="' + ";".join(projects) + '"' if projects else "" ] @@ -240,6 +255,7 @@ def main(): "X86", "Xtensa", ], + default=[], help="identify LLVM supported backends, separate by space, like '--arch ARM Mips X86'", ) parser.add_argument( diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index 07734b3b4..82f70ca3d 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -4093,39 +4093,6 @@ aot_compile_wasm(AOTCompContext *comp_ctx) return true; } -#if !(defined(_WIN32) || defined(_WIN32_)) -char * -aot_generate_tempfile_name(const char *prefix, const char *extension, - char *buffer, uint32 len) -{ - int fd, name_len; - - name_len = snprintf(buffer, len, "%s-XXXXXX", prefix); - - if ((fd = mkstemp(buffer)) <= 0) { - aot_set_last_error("make temp file failed."); - return NULL; - } - - /* close and remove temp file */ - close(fd); - unlink(buffer); - - /* Check if buffer length is enough */ - /* name_len + '.' + extension + '\0' */ - if (name_len + 1 + strlen(extension) + 1 > len) { - aot_set_last_error("temp file name too long."); - return NULL; - } - - snprintf(buffer + name_len, len - name_len, ".%s", extension); - return buffer; -} -#else - -errno_t -_mktemp_s(char *nameTemplate, size_t sizeInChars); - char * aot_generate_tempfile_name(const char *prefix, const char *extension, char *buffer, uint32 len) @@ -4134,7 +4101,8 @@ aot_generate_tempfile_name(const char *prefix, const char *extension, name_len = snprintf(buffer, len, "%s-XXXXXX", prefix); - if (_mktemp_s(buffer, name_len + 1) != 0) { + if (!bh_mkstemp(buffer, name_len + 1)) { + aot_set_last_error("make temp file failed."); return NULL; } @@ -4148,7 +4116,6 @@ aot_generate_tempfile_name(const char *prefix, const char *extension, snprintf(buffer + name_len, len - name_len, ".%s", extension); return buffer; } -#endif /* end of !(defined(_WIN32) || defined(_WIN32_)) */ bool aot_emit_llvm_file(AOTCompContext *comp_ctx, const char *file_name) @@ -4227,7 +4194,6 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) bh_print_time("Begin to emit object file"); -#if !(defined(_WIN32) || defined(_WIN32_)) if (comp_ctx->external_llc_compiler || comp_ctx->external_asm_compiler) { char cmd[1024]; int ret; @@ -4270,7 +4236,7 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) file_name, bc_file_name); LOG_VERBOSE("invoking external LLC compiler:\n\t%s", cmd); - ret = system(cmd); + ret = bh_system(cmd); /* remove temp bitcode file */ unlink(bc_file_name); @@ -4323,7 +4289,7 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) file_name, asm_file_name); LOG_VERBOSE("invoking external ASM compiler:\n\t%s", cmd); - ret = system(cmd); + ret = bh_system(cmd); /* remove temp assembly file */ unlink(asm_file_name); @@ -4336,7 +4302,6 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) return true; } -#endif /* end of !(defined(_WIN32) || defined(_WIN32_)) */ if (!strncmp(LLVMGetTargetName(target), "arc", 3)) /* Emit to assembly file instead for arc target diff --git a/core/iwasm/compilation/aot_emit_aot_file.c b/core/iwasm/compilation/aot_emit_aot_file.c index 8fa205308..9b2436a2b 100644 --- a/core/iwasm/compilation/aot_emit_aot_file.c +++ b/core/iwasm/compilation/aot_emit_aot_file.c @@ -4292,10 +4292,6 @@ aot_obj_data_create(AOTCompContext *comp_ctx) bh_print_time("Begin to emit object file"); if (comp_ctx->external_llc_compiler || comp_ctx->external_asm_compiler) { -#if defined(_WIN32) || defined(_WIN32_) - aot_set_last_error("external toolchain not supported on Windows"); - goto fail; -#else /* Generate a temp file name */ int ret; char obj_file_name[64]; @@ -4323,27 +4319,18 @@ aot_obj_data_create(AOTCompContext *comp_ctx) aot_set_last_error("create mem buffer with file failed."); goto fail; } -#endif /* end of defined(_WIN32) || defined(_WIN32_) */ } else if (!strncmp(LLVMGetTargetName(target), "arc", 3)) { -#if defined(_WIN32) || defined(_WIN32_) - aot_set_last_error("emit object file on Windows is unsupported."); - goto fail; -#else /* Emit to assembly file instead for arc target as it cannot emit to object file */ char file_name[] = "wasm-XXXXXX", buf[128]; - int fd, ret; + int ret; - if ((fd = mkstemp(file_name)) <= 0) { + if (!bh_mkstemp(file_name, sizeof(file_name))) { aot_set_last_error("make temp file failed."); goto fail; } - /* close and remove temp file */ - close(fd); - unlink(file_name); - snprintf(buf, sizeof(buf), "%s%s", file_name, ".s"); if (LLVMTargetMachineEmitToFile(comp_ctx->target_machine, comp_ctx->module, buf, LLVMAssemblyFile, @@ -4364,7 +4351,7 @@ aot_obj_data_create(AOTCompContext *comp_ctx) "/opt/zephyr-sdk/arc-zephyr-elf/bin/arc-zephyr-elf-gcc ", "-mcpu=arcem -o ", file_name, ".o -c ", file_name, ".s"); /* TODO: use try..catch to handle possible exceptions */ - ret = system(buf); + ret = bh_system(buf); /* remove temp assembly file */ snprintf(buf, sizeof(buf), "%s%s", file_name, ".s"); unlink(buf); @@ -4391,7 +4378,6 @@ aot_obj_data_create(AOTCompContext *comp_ctx) aot_set_last_error("create mem buffer with file failed."); goto fail; } -#endif /* end of defined(_WIN32) || defined(_WIN32_) */ } else { if (LLVMTargetMachineEmitToMemoryBuffer( diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index fb1c4308b..14ee4dd2b 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -2746,10 +2746,6 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) /* verify external llc compiler */ comp_ctx->external_llc_compiler = getenv("WAMRC_LLC_COMPILER"); if (comp_ctx->external_llc_compiler) { -#if defined(_WIN32) || defined(_WIN32_) - comp_ctx->external_llc_compiler = NULL; - LOG_WARNING("External LLC compiler not supported on Windows."); -#else if (access(comp_ctx->external_llc_compiler, X_OK) != 0) { LOG_WARNING("WAMRC_LLC_COMPILER [%s] not found, fallback to " "default pipeline", @@ -2761,17 +2757,12 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) LOG_VERBOSE("Using external LLC compiler [%s]", comp_ctx->external_llc_compiler); } -#endif } /* verify external asm compiler */ if (!comp_ctx->external_llc_compiler) { comp_ctx->external_asm_compiler = getenv("WAMRC_ASM_COMPILER"); if (comp_ctx->external_asm_compiler) { -#if defined(_WIN32) || defined(_WIN32_) - comp_ctx->external_asm_compiler = NULL; - LOG_WARNING("External ASM compiler not supported on Windows."); -#else if (access(comp_ctx->external_asm_compiler, X_OK) != 0) { LOG_WARNING( "WAMRC_ASM_COMPILER [%s] not found, fallback to " @@ -2784,7 +2775,6 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) LOG_VERBOSE("Using external ASM compiler [%s]", comp_ctx->external_asm_compiler); } -#endif } } diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index 0dce988bc..9c608d301 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -37,6 +37,18 @@ #include "aot_orc_extra.h" #include "aot_comp_option.h" +#if defined(_WIN32) || defined(_WIN32_) +#include +#define access _access +/* On windows there is no X_OK flag to check for executablity, only check for + * existence */ +#ifdef X_OK +#undef X_OK +#endif +#define X_OK 00 +#define unlink _unlink +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/core/shared/utils/bh_common.c b/core/shared/utils/bh_common.c index 7fe123c91..62f36caf1 100644 --- a/core/shared/utils/bh_common.c +++ b/core/shared/utils/bh_common.c @@ -165,3 +165,53 @@ wa_strdup(const char *s) } return s1; } + +#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0 +int +bh_system(const char *cmd) +{ + int ret; + +#if !(defined(_WIN32) || defined(_WIN32_)) + ret = system(cmd); +#else + ret = _spawnlp(_P_WAIT, "cmd.exe", "/c", cmd, NULL); +#endif + + return ret; +} + +#if defined(_WIN32) || defined(_WIN32_) +errno_t +_mktemp_s(char *nameTemplate, size_t sizeInChars); +#endif + +bool +bh_mkstemp(char *file_name, size_t name_len) +{ + int fd; + +#if !(defined(_WIN32) || defined(_WIN32_)) + (void)name_len; + /* On Linux, it generates a unique temporary filename from template, creates + * and opens the file, and returns an open file descriptor for the file. */ + if ((fd = mkstemp(file_name)) <= 0) { + goto fail; + } + + /* close and remove temp file */ + close(fd); + unlink(file_name); +#else + /* On Windows, it generates a unique temporary file name but does not create + * or open the file */ + if (_mktemp_s(file_name, name_len) != 0) { + goto fail; + } +#endif + + return true; +fail: + return false; +} +#endif /* End of WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0 */ diff --git a/core/shared/utils/bh_common.h b/core/shared/utils/bh_common.h index adae722bb..093e62208 100644 --- a/core/shared/utils/bh_common.h +++ b/core/shared/utils/bh_common.h @@ -66,6 +66,16 @@ bh_strdup(const char *s); char * wa_strdup(const char *s); +#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0 +/* Executes a system command in bash/cmd.exe */ +int +bh_system(const char *cmd); + +/* Tests whether can create a temporary file with the given name */ +bool +bh_mkstemp(char *filename, size_t name_len); +#endif + #ifdef __cplusplus } #endif From f1d03db8e58a268e1745ece954b44772c9522349 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:22:36 +0800 Subject: [PATCH 050/105] Fix CI wamr-ide error (#3913) The recent version of the rust toolchain will emit ref types opcodes, which needs to enable this feature in the `iwasm` build. The vector format parsing logic has some errors in the current version. I disabled the check for now and am waiting for further investigation. --- .github/workflows/compilation_on_android_ubuntu.yml | 2 +- .../src/test/suite/extension.test.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 8ba6e0e80..1ea36418e 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -828,7 +828,7 @@ jobs: run: | mkdir build cd build - cmake .. -DWAMR_BUILD_DEBUG_INTERP=1 + cmake .. -DWAMR_BUILD_DEBUG_INTERP=1 -DWAMR_BUILD_REF_TYPES=1 make working-directory: product-mini/platforms/linux diff --git a/test-tools/wamr-ide/VSCode-Extension/src/test/suite/extension.test.ts b/test-tools/wamr-ide/VSCode-Extension/src/test/suite/extension.test.ts index d1420dfa5..91d54853e 100644 --- a/test-tools/wamr-ide/VSCode-Extension/src/test/suite/extension.test.ts +++ b/test-tools/wamr-ide/VSCode-Extension/src/test/suite/extension.test.ts @@ -196,11 +196,14 @@ suite('Inegration Tests', function () { ); // Vector - assert.equal( - namesToVariables['vector'].value, - ' (5) vec![1, 2, 3, 4, 12]', - 'The Vector summary string looks different than expected' - ); + // TODO: The vector format conversion have some problem now, can't see the actual value + // - (5) vec![{...}, {...}, {...}, {...}, {...}, ...] + // + (5) vec![1, 2, 3, 4, 12] + // assert.equal( + // namesToVariables['vector'].value, + // ' (5) vec![1, 2, 3, 4, 12]', + // 'The Vector summary string looks different than expected' + // ); // Map assert.equal( From 62aca1727908848c194dfe52c7d62397f5df8441 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:01:24 +0800 Subject: [PATCH 051/105] Check possible integer overflow in aot memory boundary check (#3920) Check possible integer overflow in aot memory boundary check when the wasm memory is 64-bit. --- core/iwasm/compilation/aot_emit_memory.c | 38 ++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index 869a1dbb2..9adf96ac5 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -273,10 +273,24 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } /* offset1 = offset + addr; */ - /* TODO: check whether integer overflow occurs when memory is 64-bit - and boundary check is enabled */ BUILD_OP(Add, offset_const, addr, offset1, "offset1"); + if (is_memory64 && comp_ctx->enable_bound_check) { + /* Check whether integer overflow occurs in offset + addr */ + LLVMBasicBlockRef check_integer_overflow_end; + ADD_BASIC_BLOCK(check_integer_overflow_end, + "check_integer_overflow_end"); + LLVMMoveBasicBlockAfter(check_integer_overflow_end, block_curr); + + BUILD_ICMP(LLVMIntULT, offset1, offset_const, cmp1, "cmp1"); + if (!aot_emit_exception(comp_ctx, func_ctx, + EXCE_OUT_OF_BOUNDS_MEMORY_ACCESS, true, cmp1, + check_integer_overflow_end)) { + goto fail; + } + SET_BUILD_POS(check_integer_overflow_end); + } + if (comp_ctx->enable_shared_heap /* TODO: && mem_idx == 0 */) { LLVMBasicBlockRef app_addr_in_shared_heap, app_addr_in_linear_mem; LLVMValueRef is_in_shared_heap, shared_heap_check_bound = NULL; @@ -303,7 +317,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr); if (!is_target_64bit) { - /* Check whether interger overflow occurs in addr + offset */ + /* Check whether integer overflow occurs in addr + offset */ LLVMBasicBlockRef check_integer_overflow_end; ADD_BASIC_BLOCK(check_integer_overflow_end, "check_integer_overflow_end"); @@ -1215,10 +1229,24 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; } - /* TODO: check whether integer overflow occurs when memory is 64-bit - and boundary check is enabled */ BUILD_OP(Add, offset, bytes, max_addr, "max_addr"); + if (is_memory64 && comp_ctx->enable_bound_check) { + /* Check whether integer overflow occurs in offset + addr */ + LLVMBasicBlockRef check_integer_overflow_end; + ADD_BASIC_BLOCK(check_integer_overflow_end, + "check_integer_overflow_end"); + LLVMMoveBasicBlockAfter(check_integer_overflow_end, block_curr); + + BUILD_ICMP(LLVMIntULT, max_addr, offset, cmp, "cmp"); + if (!aot_emit_exception(comp_ctx, func_ctx, + EXCE_OUT_OF_BOUNDS_MEMORY_ACCESS, true, cmp, + check_integer_overflow_end)) { + goto fail; + } + SET_BUILD_POS(check_integer_overflow_end); + } + if (comp_ctx->enable_shared_heap /* TODO: && mem_idx == 0 */) { LLVMBasicBlockRef app_addr_in_shared_heap, app_addr_in_linear_mem; LLVMValueRef shared_heap_start_off, shared_heap_check_bound; From 00c2aa10a8428aa38a0197c97455a8bc3a24937d Mon Sep 17 00:00:00 2001 From: James Ring Date: Sat, 23 Nov 2024 19:30:00 -0800 Subject: [PATCH 052/105] Drop declarative elements on module instantiation (#3922) --- core/iwasm/aot/aot_runtime.c | 4 +++- core/iwasm/interpreter/wasm_runtime.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 5d50f255c..8a33a7271 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1905,7 +1905,9 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent, goto fail; } for (i = 0; i < module->table_init_data_count; i++) { - if (wasm_elem_is_active(module->table_init_data_list[i]->mode)) + if (wasm_elem_is_active(module->table_init_data_list[i]->mode) + || wasm_elem_is_declarative( + module->table_init_data_list[i]->mode)) bh_bitmap_set_bit(common->elem_dropped, i); } } diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 0f1ccd937..f9378aac9 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -2467,7 +2467,8 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent, goto fail; } for (i = 0; i < module->table_seg_count; i++) { - if (wasm_elem_is_active(module->table_segments[i].mode)) + if (wasm_elem_is_active(module->table_segments[i].mode) + || wasm_elem_is_declarative(module->table_segments[i].mode)) bh_bitmap_set_bit(module_inst->e->common.elem_dropped, i); } } From 9d8150efaee35240638a756ddd35b23f1376a4a1 Mon Sep 17 00:00:00 2001 From: Dylan Johnston <18252447+dpjohnst@users.noreply.github.com> Date: Sun, 24 Nov 2024 14:31:55 +1100 Subject: [PATCH 053/105] Fix WASI Path Mapping Processing (#3923) Filesystem paths can be mapped from the host path to a guest path using the format `::`. Previously `strtok` was used to find the `::` delimiter. Unfortunately `strtok` processes each delimiter character individually. This meant that the code was ~equivalent to `strtok(mapping_copy, ":")` which breaks with Windows-style paths (E.g. `C:\my_path\`). To fix this `strstr` is used to search for the exact delimiter. --- core/iwasm/common/wasm_runtime_common.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index fb16aa0f3..26aab9664 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3631,8 +3631,14 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, bh_memcpy_s(mapping_copy, max_len, map_dir_list[i], (uint32)(strlen(map_dir_list[i]) + 1)); - map_mapped = strtok(mapping_copy, "::"); - map_host = strtok(NULL, "::"); + + const char *delim = "::"; + char *delim_pos = strstr(mapping_copy, delim); + if (delim_pos) { + *delim_pos = '\0'; + map_mapped = mapping_copy; + map_host = delim_pos + strlen(delim); + } if (!map_mapped || !map_host) { if (error_buf) From dbdf3df60b8bc4fc81b46f7d53335e986b2cfb15 Mon Sep 17 00:00:00 2001 From: James Ring Date: Sat, 23 Nov 2024 19:32:34 -0800 Subject: [PATCH 054/105] Use plain assignment rather than bh_memcpy_s (#3924) --- core/iwasm/interpreter/wasm_runtime.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index f9378aac9..c3f35916c 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1208,9 +1208,8 @@ globals_instantiate(WASMModule *module, WASMModuleInstance *module_inst, /* The linked global instance has been initialized, we just need to copy the value. */ - bh_memcpy_s(&(global->initial_value), sizeof(WASMValue), - &(global_import->import_global_linked->init_expr.u), - sizeof(WASMValue)); + global->initial_value = + global_import->import_global_linked->init_expr.u; } else #endif From b0c6d5c23a243cb51f2672f552882de24305f42b Mon Sep 17 00:00:00 2001 From: WenLY1 <130950131+WenLY1@users.noreply.github.com> Date: Sun, 24 Nov 2024 11:34:38 +0800 Subject: [PATCH 055/105] add testcases for shared heap and fix POP_MEM_OFFSET of memory64 (#3916) - add testcases for shared_heap - fix POP_MEM_OFFSET and POP_TBL_ELEM_IDX of memory64 Signed-off-by: wenlingyun1 --- core/iwasm/interpreter/wasm_interp_classic.c | 4 +- tests/unit/shared-heap/CMakeLists.txt | 2 +- tests/unit/shared-heap/shared_heap_test.cc | 132 +++++++++++++++--- .../unit/shared-heap/wasm-apps/CMakeLists.txt | 35 ++++- tests/unit/shared-heap/wasm-apps/test.c | 14 +- .../shared-heap/wasm-apps/test_addr_conv.c | 32 +++++ 6 files changed, 197 insertions(+), 22 deletions(-) create mode 100644 tests/unit/shared-heap/wasm-apps/test_addr_conv.c diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 7041fd89c..834311f7e 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -593,8 +593,8 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame) #endif #if WASM_ENABLE_MEMORY64 != 0 -#define POP_MEM_OFFSET() (is_memory64 ? POP_I64() : POP_I32()) -#define POP_TBL_ELEM_IDX() (is_table64 ? POP_I64() : POP_I32()) +#define POP_MEM_OFFSET() (is_memory64 ? POP_I64() : (uint32)POP_I32()) +#define POP_TBL_ELEM_IDX() (is_table64 ? POP_I64() : (uint32)POP_I32()) #else #define POP_MEM_OFFSET() POP_I32() #define POP_TBL_ELEM_IDX() POP_I32() diff --git a/tests/unit/shared-heap/CMakeLists.txt b/tests/unit/shared-heap/CMakeLists.txt index 6baf420f8..2b06c537f 100644 --- a/tests/unit/shared-heap/CMakeLists.txt +++ b/tests/unit/shared-heap/CMakeLists.txt @@ -8,7 +8,7 @@ project(test-shared-heap) add_definitions(-DRUN_ON_LINUX) set(WAMR_BUILD_APP_FRAMEWORK 0) -set(WAMR_BUILD_AOT 0) +set(WAMR_BUILD_AOT 1) set(WAMR_BUILD_INTERP 1) set(WAMR_BUILD_FAST_INTERP 1) set(WAMR_BUILD_JIT 0) diff --git a/tests/unit/shared-heap/shared_heap_test.cc b/tests/unit/shared-heap/shared_heap_test.cc index 5e45d3111..deb4bbb38 100644 --- a/tests/unit/shared-heap/shared_heap_test.cc +++ b/tests/unit/shared-heap/shared_heap_test.cc @@ -92,37 +92,28 @@ destroy_module_env(struct ret_env module_env) } } -TEST_F(shared_heap_test, test_shared_heap) +static void test_shared_heap(WASMSharedHeap *shared_heap, const char *file, const char *func_name, uint32 argc, uint32 argv[]) { struct ret_env tmp_module_env; WASMFunctionInstanceCommon *func_test = nullptr; bool ret = false; - uint32 argv[1] = { 65535 }; const char *exception = nullptr; - SharedHeapInitArgs args; - WASMSharedHeap *shared_heap = nullptr; - args.size = 1024; - shared_heap = wasm_runtime_create_shared_heap(&args); - tmp_module_env = load_wasm((char *)"test.wasm", 0); + tmp_module_env = load_wasm((char *)file, 0); - if (!shared_heap) { - printf("Failed to create shared heap\n"); - goto test_failed; - } if (!wasm_runtime_attach_shared_heap(tmp_module_env.wasm_module_inst, shared_heap)) { printf("Failed to attach shared heap\n"); goto test_failed; } - func_test = wasm_runtime_lookup_function( - tmp_module_env.wasm_module_inst, "test"); + func_test = wasm_runtime_lookup_function(tmp_module_env.wasm_module_inst, + func_name); if (!func_test) { printf("\nFailed to wasm_runtime_lookup_function!\n"); goto test_failed; } ret = - wasm_runtime_call_wasm(tmp_module_env.exec_env, func_test, 1, argv); + wasm_runtime_call_wasm(tmp_module_env.exec_env, func_test, argc, argv); if (!ret) { printf("\nFailed to wasm_runtime_call_wasm!\n"); const char *s = wasm_runtime_get_exception(tmp_module_env.wasm_module_inst); @@ -131,12 +122,119 @@ TEST_F(shared_heap_test, test_shared_heap) } wasm_runtime_detach_shared_heap(tmp_module_env.wasm_module_inst); - - EXPECT_EQ(10, argv[0]); - destroy_module_env(tmp_module_env); return; test_failed: destroy_module_env(tmp_module_env); EXPECT_EQ(1, 0); } + +TEST_F(shared_heap_test, test_shared_heap_basic) +{ + SharedHeapInitArgs args; + WASMSharedHeap *shared_heap = nullptr; + uint32 argv[1] = { 0 }; + + args.size = 1024; + shared_heap = wasm_runtime_create_shared_heap(&args); + + if (!shared_heap) { + printf("Failed to create shared heap\n"); + EXPECT_EQ(1, 0); + } + + // test wasm + test_shared_heap(shared_heap, "test.wasm", "test", 1, argv); + EXPECT_EQ(10, argv[0]); + + // test aot + test_shared_heap(shared_heap, "test.aot", "test", 1, argv); + EXPECT_EQ(10, argv[0]); + +} + +TEST_F(shared_heap_test, test_shared_heap_malloc_fail) +{ + SharedHeapInitArgs args; + WASMSharedHeap *shared_heap = nullptr; + uint32 argv[1] = { 0 }; + + args.size = 1024; + shared_heap = wasm_runtime_create_shared_heap(&args); + + if (!shared_heap) { + printf("Failed to create shared heap\n"); + EXPECT_EQ(1, 0); + } + + // test wasm + test_shared_heap(shared_heap, "test.wasm", "test_malloc_fail", 1, argv); + EXPECT_EQ(1, argv[0]); + + // test aot + test_shared_heap(shared_heap, "test.aot", "test_malloc_fail", 1, argv); + EXPECT_EQ(1, argv[0]); +} + +#ifndef native_function +#define native_function(func_name, signature) \ + { #func_name, (void *)glue_##func_name, signature, NULL } + +#endif +#ifndef nitems +#define nitems(_a) (sizeof(_a) / sizeof(0 [(_a)])) +#endif /* nitems */ +uintptr_t glue_test_addr_conv(wasm_exec_env_t env, uintptr_t addr) +{ + wasm_module_inst_t module_inst = get_module_inst(env); + uintptr_t ret; + void *native_addr = (void *)addr; + uintptr_t app_addr = addr_native_to_app(native_addr); + + native_addr = addr_app_to_native(app_addr); + if (native_addr != (void *)addr) + { + EXPECT_EQ(1, 0); + } + return app_addr; +} + +static NativeSymbol g_test_native_symbols[] = +{ + native_function(test_addr_conv,"(*)i"), +}; + +TEST_F(shared_heap_test, test_addr_conv) +{ + SharedHeapInitArgs args; + WASMSharedHeap *shared_heap = nullptr; + uint32 argv[1] = { 0 }; + struct ret_env tmp_module_env; + WASMFunctionInstanceCommon *func_test = nullptr; + bool ret = false; + const char *exception = nullptr; + wasm_module_inst_t module_inst = tmp_module_env.wasm_module_inst; + + ret = wasm_native_register_natives("env", g_test_native_symbols, + nitems(g_test_native_symbols)); + if (!ret) + { + EXPECT_EQ(1, 0); + return; + } + + args.size = 1024; + shared_heap = wasm_runtime_create_shared_heap(&args); + if (!shared_heap) { + printf("Failed to create shared heap\n"); + EXPECT_EQ(1, 0); + } + + // test wasm + test_shared_heap(shared_heap, "test_addr_conv.wasm", "test", 1, argv); + EXPECT_EQ(1, argv[0]); + + // test aot + test_shared_heap(shared_heap, "test_addr_conv.aot", "test", 1, argv); + EXPECT_EQ(1, argv[0]); +} diff --git a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt index 3627a2c14..097f66ae5 100644 --- a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt @@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 3.14) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) +set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler/build) set(CMAKE_SYSTEM_PROCESSOR wasm32) set(CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot) @@ -36,4 +37,36 @@ add_custom_command(TARGET test.wasm POST_BUILD ${CMAKE_CURRENT_BINARY_DIR}/test.wasm ${CMAKE_CURRENT_BINARY_DIR}/../ COMMENT "Copy test.wasm to the same directory of google test" - ) \ No newline at end of file + ) + +add_custom_command(TARGET test.wasm POST_BUILD + COMMAND ${WAMRC_ROOT_DIR}/wamrc --opt-level=0 --enable-shared-heap --bounds-checks=1 + -o + test.aot + test.wasm + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_BINARY_DIR}/test.aot + ${CMAKE_CURRENT_BINARY_DIR}/../ + COMMENT "Copy test.aot to the same directory of google test" + ) + +add_executable(test_addr_conv.wasm test_addr_conv.c) +target_link_libraries(test.wasm) + +add_custom_command(TARGET test_addr_conv.wasm POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv.wasm + ${CMAKE_CURRENT_BINARY_DIR}/../ + COMMENT "Copy test_addr_conv.wasm to the same directory of google test" + ) + +add_custom_command(TARGET test_addr_conv.wasm POST_BUILD + COMMAND ${WAMRC_ROOT_DIR}/wamrc --opt-level=0 --enable-shared-heap --bounds-checks=1 + -o + test_addr_conv.aot + test_addr_conv.wasm + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv.aot + ${CMAKE_CURRENT_BINARY_DIR}/../ + COMMENT "Copy test_addr_conv.aot to the same directory of google test" + ) diff --git a/tests/unit/shared-heap/wasm-apps/test.c b/tests/unit/shared-heap/wasm-apps/test.c index b83ee64ff..bd0df19c2 100644 --- a/tests/unit/shared-heap/wasm-apps/test.c +++ b/tests/unit/shared-heap/wasm-apps/test.c @@ -13,10 +13,22 @@ shared_heap_free(void *offset); int test() { - int *ptr = (int *)shared_heap_malloc(10); + int *ptr = (int *)shared_heap_malloc(4); *ptr = 10; int a = *ptr; shared_heap_free(ptr); return a; } + +int +test_malloc_fail() +{ + int *ptr = (int *)shared_heap_malloc(8192); + + if (ptr == NULL) { + return 1; + } + shared_heap_free(ptr); + return 0; +} diff --git a/tests/unit/shared-heap/wasm-apps/test_addr_conv.c b/tests/unit/shared-heap/wasm-apps/test_addr_conv.c new file mode 100644 index 000000000..f91764c84 --- /dev/null +++ b/tests/unit/shared-heap/wasm-apps/test_addr_conv.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 Xiaomi Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include + +extern void * +shared_heap_malloc(int size); +extern void +shared_heap_free(void *offset); +extern void * +test_addr_conv(void *ptr); + +int +test() +{ + int *ptr = NULL; + int *ptr2 = NULL; + + ptr = (int *)shared_heap_malloc(4); + + if (ptr == NULL) { + return 0; + } + ptr2 = test_addr_conv(ptr); + if (ptr2 != ptr) { + return 0; + } + shared_heap_free(ptr); + return 1; +} From 1d111a38d68abf71f1fa513ee21927e764aeec38 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:08:51 +0800 Subject: [PATCH 056/105] Fix loader small bug (#3928) --- core/iwasm/interpreter/wasm_loader.c | 7 ++++++- core/iwasm/interpreter/wasm_mini_loader.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 418456210..79ed996d8 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -9855,7 +9855,12 @@ reserve_block_ret(WASMLoaderContext *loader_ctx, uint8 opcode, else { loader_ctx->frame_offset = frame_offset; loader_ctx->dynamic_offset = dynamic_offset; - PUSH_OFFSET_TYPE(return_types[i]); + if (!(wasm_loader_push_frame_offset( + loader_ctx, return_types[i], disable_emit, + operand_offset, error_buf, error_buf_size))) { + wasm_runtime_free(emit_data); + goto fail; + } wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); loader_ctx->frame_offset = frame_offset_org; loader_ctx->dynamic_offset = dynamic_offset_org; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index a1fb3102f..4dad55523 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -5561,7 +5561,12 @@ reserve_block_ret(WASMLoaderContext *loader_ctx, uint8 opcode, else { loader_ctx->frame_offset = frame_offset; loader_ctx->dynamic_offset = dynamic_offset; - PUSH_OFFSET_TYPE(return_types[i]); + if (!(wasm_loader_push_frame_offset( + loader_ctx, return_types[i], disable_emit, + operand_offset, error_buf, error_buf_size))) { + wasm_runtime_free(emit_data); + goto fail; + } wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); loader_ctx->frame_offset = frame_offset_org; loader_ctx->dynamic_offset = dynamic_offset_org; From 7b553cd420e9cd1f93817d054345f8733a681295 Mon Sep 17 00:00:00 2001 From: Maks Litskevich Date: Wed, 27 Nov 2024 14:06:07 +0300 Subject: [PATCH 057/105] Enable ref types by default (#3894) --- CMakeLists.txt | 4 ++-- doc/build_wamr.md | 2 +- product-mini/platforms/linux/CMakeLists.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40658e9ac..3efd6aa82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,8 +113,8 @@ if (NOT DEFINED WAMR_BUILD_SIMD) endif () if (NOT DEFINED WAMR_BUILD_REF_TYPES) - # Disable reference types by default - set (WAMR_BUILD_REF_TYPES 0) + # Enable reference types by default + set (WAMR_BUILD_REF_TYPES 1) endif () set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/doc/build_wamr.md b/doc/build_wamr.md index 4537ee084..abf663177 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -223,7 +223,7 @@ Currently we only profile the memory consumption of module, module_instance and > See [basic sample](../samples/basic/src/main.c) for a usage example. #### **Enable reference types feature** -- **WAMR_BUILD_REF_TYPES**=1/0, default to disable if not set +- **WAMR_BUILD_REF_TYPES**=1/0, default to enable if not set #### **Exclude WAMR application entry functions** - **WAMR_DISABLE_APP_ENTRY**=1/0, default to disable if not set diff --git a/product-mini/platforms/linux/CMakeLists.txt b/product-mini/platforms/linux/CMakeLists.txt index 2e37b75f9..321c4a955 100644 --- a/product-mini/platforms/linux/CMakeLists.txt +++ b/product-mini/platforms/linux/CMakeLists.txt @@ -108,8 +108,8 @@ if (NOT DEFINED WAMR_BUILD_SIMD) endif () if (NOT DEFINED WAMR_BUILD_REF_TYPES) - # Disable reference types by default - set (WAMR_BUILD_REF_TYPES 0) + # Enable reference types by default + set (WAMR_BUILD_REF_TYPES 1) endif () if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP) From 27d96aac02abad895793b7a0d1aa20707ad54566 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Wed, 27 Nov 2024 19:06:22 +0800 Subject: [PATCH 058/105] Update README.md to clarify Windows toolchain support and ESP-IDF reference (#3917) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d89d0cd17..05368b929 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ The WAMR VMcore supports the following architectures: - XTENSA, MIPS, ARC The following platforms are supported, click each link below for how to build iwasm on that platform. Refer to [WAMR porting guide](./doc/port_wamr.md) for how to port WAMR to a new platform. -- [Linux](./product-mini/README.md#linux), [Linux SGX (Intel Software Guard Extension)](./doc/linux_sgx.md), [MacOS](./product-mini/README.md#macos), [Android](./product-mini/README.md#android), [Windows](./product-mini/README.md#windows), [Windows (MinGW)](./product-mini/README.md#mingw) -- [Zephyr](./product-mini/README.md#zephyr), [AliOS-Things](./product-mini/README.md#alios-things), [VxWorks](./product-mini/README.md#vxworks), [NuttX](./product-mini/README.md#nuttx), [RT-Thread](./product-mini/README.md#RT-Thread), [ESP-IDF](./product-mini/README.md#esp-idf) +- [Linux](./product-mini/README.md#linux), [Linux SGX (Intel Software Guard Extension)](./doc/linux_sgx.md), [MacOS](./product-mini/README.md#macos), [Android](./product-mini/README.md#android), [Windows](./product-mini/README.md#windows), [Windows (MinGW, MSVC)](./product-mini/README.md#mingw) +- [Zephyr](./product-mini/README.md#zephyr), [AliOS-Things](./product-mini/README.md#alios-things), [VxWorks](./product-mini/README.md#vxworks), [NuttX](./product-mini/README.md#nuttx), [RT-Thread](./product-mini/README.md#RT-Thread), [ESP-IDF(FreeRTOS)](./product-mini/README.md#esp-idf) ## Getting started From fd91b51cfb36345b7a3c4fd66771171dc865385d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:49:23 +0800 Subject: [PATCH 059/105] build(deps): bump github/codeql-action from 3.27.4 to 3.27.5 (#3931) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.4 to 3.27.5. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.27.4...v3.27.5) --- updated-dependencies: - dependency-name: github/codeql-action 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 c71f305aa..9ed8919c7 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.27.4 + uses: github/codeql-action/init@v3.27.5 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.27.4 + uses: github/codeql-action/analyze@v3.27.5 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.27.4 + uses: github/codeql-action/upload-sarif@v3.27.5 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 1d5baa6b1..f2aa485ea 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@a1695c562bbfa68dc5ab58c9b5e9f616b52bf5be # v2.2.4 + uses: github/codeql-action/upload-sarif@3d3d628990a5f99229dd9fa1821cc5a4f31b613b # v2.2.4 with: sarif_file: results.sarif From 8698d22e6738a278eb9639ba9c8860456550771f Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:49:55 +0800 Subject: [PATCH 060/105] add thread cpu time for zephyr (#3937) --- core/shared/platform/zephyr/zephyr_time.c | 15 +++++++++++++-- product-mini/platforms/zephyr/simple/prj.conf | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/shared/platform/zephyr/zephyr_time.c b/core/shared/platform/zephyr/zephyr_time.c index 78bc3e076..59b720e41 100644 --- a/core/shared/platform/zephyr/zephyr_time.c +++ b/core/shared/platform/zephyr/zephyr_time.c @@ -14,6 +14,17 @@ os_time_get_boot_us() uint64 os_time_thread_cputime_us(void) { - /* FIXME if u know the right api */ - return os_time_get_boot_us(); + k_tid_t tid; + struct k_thread_runtime_stats stats; + uint32 clock_freq; + uint64 cpu_cycles, time_in_us = 0; + + tid = k_current_get(); + if (k_thread_runtime_stats_get(tid, &stats) == 0) { + cpu_cycles = stats.execution_cycles; + clock_freq = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC; + time_in_us = (cpu_cycles * 1000000) / clock_freq; + } + + return time_in_us; } diff --git a/product-mini/platforms/zephyr/simple/prj.conf b/product-mini/platforms/zephyr/simple/prj.conf index c269b8ab4..8ab3c52f8 100644 --- a/product-mini/platforms/zephyr/simple/prj.conf +++ b/product-mini/platforms/zephyr/simple/prj.conf @@ -5,3 +5,4 @@ CONFIG_STACK_SENTINEL=y CONFIG_PRINTK=y CONFIG_LOG=y CONFIG_LOG_BUFFER_SIZE=4096 +CONFIG_THREAD_RUNTIME_STATS=y From e09613c722ca45b2f2d659024d109786f212182b Mon Sep 17 00:00:00 2001 From: James Ring Date: Wed, 27 Nov 2024 19:50:16 -0800 Subject: [PATCH 061/105] support WASM_FUNCREF return type in argv_to_results (#3936) --- core/iwasm/common/wasm_c_api.c | 1 + 1 file changed, 1 insertion(+) diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 0c5e37eab..500f99dc8 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -3330,6 +3330,7 @@ argv_to_results(const uint32 *argv, const wasm_valtype_vec_t *result_defs, break; #if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0 case WASM_EXTERNREF: + case WASM_FUNCREF: result->of.ref = (struct wasm_ref_t *)(*(uintptr_t *)argv); argv += sizeof(uintptr_t) / sizeof(uint32); break; From 838dd81e682249fbd2d7ee16d6999dafb87481b9 Mon Sep 17 00:00:00 2001 From: James Ring Date: Wed, 27 Nov 2024 19:50:44 -0800 Subject: [PATCH 062/105] don't return an uninitialized trap if argv_to_results fails (#3935) Currently, if argv_to_results fails (e.g. because an unsupported type is encountered), an non-null trap with an uninitialized message is returned. --- core/iwasm/common/wasm_c_api.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 500f99dc8..d5c45a441 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -3442,6 +3442,8 @@ wasm_func_call(const wasm_func_t *func, const wasm_val_vec_t *params, if (result_count) { if (!argv_to_results(argv, wasm_functype_results(func->type), results)) { + wasm_runtime_set_exception(func->inst_comm_rt, + "argv_to_results failed"); goto failed; } results->num_elems = result_count; From 739efd78e9bd601b59a3688506396bc7968fbbf2 Mon Sep 17 00:00:00 2001 From: Dylan Johnston <18252447+dpjohnst@users.noreply.github.com> Date: Sun, 1 Dec 2024 23:40:43 +1100 Subject: [PATCH 063/105] Fix incorrect assignment in win_file.c (#3939) win_error should be compared to ERROR_INVALID_HANDLE but was instead being assigned the value. --- core/shared/platform/windows/win_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shared/platform/windows/win_file.c b/core/shared/platform/windows/win_file.c index 408d0d00c..770c5c741 100644 --- a/core/shared/platform/windows/win_file.c +++ b/core/shared/platform/windows/win_file.c @@ -1758,7 +1758,7 @@ os_closedir(os_dir_stream dir_stream) if (!success) { DWORD win_error = GetLastError(); - if (win_error = ERROR_INVALID_HANDLE) + if (win_error == ERROR_INVALID_HANDLE) BH_FREE(dir_stream); return convert_windows_error_code(win_error); } From aabe83074ebfce6be5332765ed71d093975d8a24 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:39:53 +0800 Subject: [PATCH 064/105] Improvements for platform thread APIs on Windows and Zephyr (#3941) * improvements for os_thread_join on Windows and Zephyr --- core/shared/platform/windows/win_thread.c | 72 +++++++++++++++++++-- core/shared/platform/zephyr/zephyr_thread.c | 14 ++-- core/shared/utils/bh_atomic.h | 3 +- 3 files changed, 78 insertions(+), 11 deletions(-) diff --git a/core/shared/platform/windows/win_thread.c b/core/shared/platform/windows/win_thread.c index f37250fa4..438e16040 100644 --- a/core/shared/platform/windows/win_thread.c +++ b/core/shared/platform/windows/win_thread.c @@ -60,6 +60,63 @@ static DWORD thread_data_key; static void(WINAPI *GetCurrentThreadStackLimits_Kernel32)(PULONG_PTR, PULONG_PTR) = NULL; +static void +thread_data_list_add(os_thread_data *thread_data) +{ + os_mutex_lock(&thread_data_list_lock); + /* If already in list, just return */ + os_thread_data *p = &supervisor_thread_data; + while (p) { + if (p == thread_data) { + os_mutex_unlock(&thread_data_list_lock); + return; + } + p = p->next; + } + thread_data->next = supervisor_thread_data.next; + supervisor_thread_data.next = thread_data; + os_mutex_unlock(&thread_data_list_lock); +} + +static void +thread_data_list_remove(os_thread_data *thread_data) +{ + os_mutex_lock(&thread_data_list_lock); + /* Search and remove it from list */ + os_thread_data *p = &supervisor_thread_data; + while (p && p->next != thread_data) + p = p->next; + + if (p && p->next) { + bh_assert(p->next == thread_data); + p->next = p->next->next; + /* Release the resources in thread_data */ + os_cond_destroy(&thread_data->wait_cond); + os_mutex_destroy(&thread_data->wait_lock); + os_sem_destroy(&thread_data->wait_node.sem); + BH_FREE(thread_data); + } + os_mutex_unlock(&thread_data_list_lock); +} + +static os_thread_data * +thread_data_list_lookup(korp_tid tid) +{ + os_thread_data *thread_data = (os_thread_data *)tid; + os_mutex_lock(&thread_data_list_lock); + os_thread_data *p = supervisor_thread_data.next; + while (p) { + if (p == thread_data) { + /* Found */ + os_mutex_unlock(&thread_data_list_lock); + return p; + } + p = p->next; + } + os_mutex_unlock(&thread_data_list_lock); + return NULL; +} + int os_sem_init(korp_sem *sem); int @@ -254,10 +311,7 @@ os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start, } /* Add thread data into thread data list */ - os_mutex_lock(&thread_data_list_lock); - thread_data->next = supervisor_thread_data.next; - supervisor_thread_data.next = thread_data; - os_mutex_unlock(&thread_data_list_lock); + thread_data_list_add(thread_data); /* Wait for the thread routine to set thread_data's tid and add thread_data to thread data list */ @@ -302,8 +356,12 @@ os_thread_join(korp_tid thread, void **p_retval) curr_thread_data->wait_node.next = NULL; /* Get thread data of thread to join */ - thread_data = (os_thread_data *)thread; - bh_assert(thread_data); + thread_data = thread_data_list_lookup(thread); + + if (thread_data == NULL) { + os_printf("Can't join thread %p, it does not exist", thread); + return BHT_ERROR; + } os_mutex_lock(&thread_data->wait_lock); @@ -312,6 +370,7 @@ os_thread_join(korp_tid thread, void **p_retval) if (p_retval) *p_retval = thread_data->thread_retval; os_mutex_unlock(&thread_data->wait_lock); + thread_data_list_remove(thread_data); return BHT_OK; } @@ -332,6 +391,7 @@ os_thread_join(korp_tid thread, void **p_retval) os_sem_wait(&curr_thread_data->wait_node.sem); if (p_retval) *p_retval = curr_thread_data->wait_node.retval; + thread_data_list_remove(thread_data); return BHT_OK; } diff --git a/core/shared/platform/zephyr/zephyr_thread.c b/core/shared/platform/zephyr/zephyr_thread.c index 628a842d6..31aaad7a9 100644 --- a/core/shared/platform/zephyr/zephyr_thread.c +++ b/core/shared/platform/zephyr/zephyr_thread.c @@ -393,6 +393,16 @@ os_thread_join(korp_tid thread, void **value_ptr) os_thread_data *thread_data; os_thread_wait_node *node; + /* Get thread data */ + thread_data = thread_data_list_lookup(thread); + + if (thread_data == NULL) { + os_printf( + "Can't join thread %p, probably already exited or does not exist", + thread); + return BHT_OK; + } + /* Create wait node and append it to wait list */ if (!(node = BH_MALLOC(sizeof(os_thread_wait_node)))) return BHT_ERROR; @@ -400,10 +410,6 @@ os_thread_join(korp_tid thread, void **value_ptr) sem_init(&node->sem, 0, 1); node->next = NULL; - /* Get thread data */ - thread_data = thread_data_list_lookup(thread); - bh_assert(thread_data != NULL); - mutex_lock(&thread_data->wait_list_lock, K_FOREVER); if (!thread_data->thread_wait_list) thread_data->thread_wait_list = node; diff --git a/core/shared/utils/bh_atomic.h b/core/shared/utils/bh_atomic.h index 5148497f8..57cb4d1c9 100644 --- a/core/shared/utils/bh_atomic.h +++ b/core/shared/utils/bh_atomic.h @@ -114,7 +114,8 @@ typedef uint16 bh_atomic_16_t; #endif /* On some 32-bit platform, disable 64-bit atomic operations, otherwise - * undefined reference to `__atomic_load_8' */ + * undefined reference to `__atomic_load_8', if on Zephyr, can add board related + * macro in autoconf.h to control */ #ifndef WASM_UINT64_IS_ATOMIC #if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) \ && !defined(__OpenBSD__) && (defined(__riscv) || defined(__arm__)) \ From c32a6ceae1114d177b493ecaf949213ac29db910 Mon Sep 17 00:00:00 2001 From: kk Date: Fri, 6 Dec 2024 14:54:37 +0800 Subject: [PATCH 065/105] Refactor SConscript and add file checks in iwasm.c (#3945) --- core/iwasm/common/SConscript | 11 ++++------- product-mini/platforms/rt-thread/iwasm.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/core/iwasm/common/SConscript b/core/iwasm/common/SConscript index 0a55f244b..eb69744e9 100644 --- a/core/iwasm/common/SConscript +++ b/core/iwasm/common/SConscript @@ -13,13 +13,10 @@ cwd = GetCurrentDir() src = Glob('*.c') -if rtconfig.ARCH == 'arm': - if re.match('^cortex-m.*', rtconfig.CPU): - src += ['arch/invokeNative_thumb.s'] - elif re.match('^cortex-a.*', rtconfig.CPU): - src += ['arch/invokeNative_arm.s'] -elif rtconfig.ARCH == 'ia32': - src += ['arch/invokeNative_ia32.s'] +if rtconfig.ARCH == 'arm' and re.match('^cortex-m.*', rtconfig.CPU): + src += ['arch/invokeNative_thumb.s'] +else: + src.append(f"arch/invokeNative_{rtconfig.ARCH}.s") CPPPATH = [cwd, cwd + '/../include'] diff --git a/product-mini/platforms/rt-thread/iwasm.c b/product-mini/platforms/rt-thread/iwasm.c index 7d15a041d..f8932bdec 100644 --- a/product-mini/platforms/rt-thread/iwasm.c +++ b/product-mini/platforms/rt-thread/iwasm.c @@ -192,6 +192,21 @@ my_read_file_to_buffer(char *filename, rt_uint32_t *size) { struct stat f_stat; + if (!filename || !size) { + rt_set_errno(-EINVAL); + return RT_NULL; + } + + if (stat(filename, &f_stat) != 0) { + rt_set_errno(errno); + return RT_NULL; + } + + if (f_stat.st_size <= 0) { + rt_set_errno(-EINVAL); + return RT_NULL; + } + rt_uint8_t *buff = rt_malloc(f_stat.st_size); *size = 0; if (!buff) { From f665e7b739c83506bc44d7a08a26561a3f93a6ff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:39:04 +0000 Subject: [PATCH 066/105] build(deps): bump github/codeql-action from 3.27.5 to 3.27.6 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.5 to 3.27.6. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.27.5...v3.27.6) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .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 9ed8919c7..88f13cc8b 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.27.5 + uses: github/codeql-action/init@v3.27.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.27.5 + uses: github/codeql-action/analyze@v3.27.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.27.5 + uses: github/codeql-action/upload-sarif@v3.27.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 f2aa485ea..2d605f6c9 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@3d3d628990a5f99229dd9fa1821cc5a4f31b613b # v2.2.4 + uses: github/codeql-action/upload-sarif@6f9e628e6f9a18c785dd746325ba455111df1b67 # v2.2.4 with: sarif_file: results.sarif From 591b74057101fbb8ae91dc9ecc14a41684c2f325 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Tue, 10 Dec 2024 20:26:14 +0800 Subject: [PATCH 067/105] Consume the placeholders that were put when emitting table info (#3940) --- core/iwasm/aot/aot_loader.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index dd26bbee5..239e328bd 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -1333,7 +1333,12 @@ load_import_table_list(const uint8 **p_buf, const uint8 *buf_end, if (wasm_is_type_multi_byte_type(import_table->table_type.elem_type)) { read_uint8(buf, buf_end, ref_type.ref_ht_common.nullable); } + else #endif + { + /* Skip 1 byte */ + buf += 1; + } read_uint32(buf, buf_end, import_table->table_type.init_size); read_uint32(buf, buf_end, import_table->table_type.max_size); #if WASM_ENABLE_GC != 0 @@ -1393,7 +1398,12 @@ load_table_list(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, if (wasm_is_type_multi_byte_type(table->table_type.elem_type)) { read_uint8(buf, buf_end, ref_type.ref_ht_common.nullable); } + else #endif + { + /* Skip 1 byte */ + buf += 1; + } read_uint32(buf, buf_end, table->table_type.init_size); read_uint32(buf, buf_end, table->table_type.max_size); #if WASM_ENABLE_GC != 0 @@ -1481,7 +1491,7 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end, else #endif { - /* Skip 8 byte for ref type info */ + /* Skip 8 byte(2+2+4) for ref type info */ buf += 8; } From bebdd4ad174a49005b62e4074e71cd32b05640e8 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 10 Dec 2024 20:26:32 +0800 Subject: [PATCH 068/105] Fix aot table instantiate (#3946) --- core/iwasm/aot/aot_runtime.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 8a33a7271..0f7b5d3d9 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -689,20 +689,23 @@ tables_instantiate(AOTModuleInstance *module_inst, AOTModule *module, tbl_inst->cur_size = import_table->table_type.init_size; tbl_inst->max_size = aot_get_imp_tbl_data_slots(import_table, false); - tbl_inst->elem_type = module->tables[i].table_type.elem_type; + tbl_inst->elem_type = import_table->table_type.elem_type; + tbl_inst->is_table64 = + import_table->table_type.flags & TABLE64_FLAG; #if WASM_ENABLE_GC != 0 tbl_inst->elem_ref_type.elem_ref_type = - module->tables[i].table_type.elem_ref_type; + import_table->table_type.elem_ref_type; #endif } else { AOTTable *table = module->tables + (i - module->import_table_count); tbl_inst->cur_size = table->table_type.init_size; tbl_inst->max_size = aot_get_tbl_data_slots(table, false); - tbl_inst->elem_type = module->tables[i].table_type.elem_type; + tbl_inst->elem_type = table->table_type.elem_type; + tbl_inst->is_table64 = table->table_type.flags & TABLE64_FLAG; #if WASM_ENABLE_GC != 0 tbl_inst->elem_ref_type.elem_ref_type = - module->tables[i].table_type.elem_ref_type; + table->table_type.elem_ref_type; #endif } From 9563909d6c104906f4a8ad4f3be08a4241d781a6 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:33:46 +0800 Subject: [PATCH 069/105] set alignment 4 when loading multi return value (#3955) set alignment 4 when loading multi return value for all call opcodes --- core/iwasm/compilation/aot_emit_function.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/iwasm/compilation/aot_emit_function.c b/core/iwasm/compilation/aot_emit_function.c index 49b1ac1cb..d22c1d5dd 100644 --- a/core/iwasm/compilation/aot_emit_function.c +++ b/core/iwasm/compilation/aot_emit_function.c @@ -1832,6 +1832,7 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, aot_set_last_error("llvm build load failed."); goto fail; } + LLVMSetAlignment(ext_ret, 4); PUSH(ext_ret, ext_ret_types[i]); } } @@ -2068,6 +2069,7 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, aot_set_last_error("llvm build load failed."); return false; } + LLVMSetAlignment(value_rets[i], 4); cell_num += wasm_value_type_cell_num_internal(wasm_ret_types[i], comp_ctx->pointer_size); } @@ -2699,6 +2701,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, aot_set_last_error("llvm build load failed."); goto fail; } + LLVMSetAlignment(ext_ret, 4); LLVMAddIncoming(result_phis[i], &ext_ret, &block_curr, 1); } } @@ -3130,6 +3133,7 @@ aot_compile_op_call_ref(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, aot_set_last_error("llvm build load failed."); goto fail; } + LLVMSetAlignment(ext_ret, 4); LLVMAddIncoming(result_phis[i], &ext_ret, &block_curr, 1); } } @@ -3205,6 +3209,7 @@ aot_compile_op_call_ref(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, aot_set_last_error("llvm build load failed."); goto fail; } + LLVMSetAlignment(ext_ret, 4); LLVMAddIncoming(result_phis[i], &ext_ret, &block_curr, 1); } } From 296c3cc69ddf5afe21e3a8cb7cb6407f93064212 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo <90845888+midokura-xavi92@users.noreply.github.com> Date: Thu, 19 Dec 2024 01:49:13 +0100 Subject: [PATCH 070/105] wasm_export.h: Use "default" visibility for gcc and clang (#3957) Since the top-level CMakelists.txt is appending `-fvisibility=hidden` to the compile options, no public symbols are exported by default. This forbids users from linking against the shared library. Using `gcc/clang` attributes [1], it is possible to override the definition for `WASM_RUNTIME_API_EXTERN` so that only required symbols are correctly exported. [1]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes --- core/iwasm/include/wasm_export.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index aa6cfaae7..273657246 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -23,6 +23,8 @@ #else #define WASM_RUNTIME_API_EXTERN __declspec(dllimport) #endif +#elif defined(__GNUC__) || defined(__clang__) +#define WASM_RUNTIME_API_EXTERN __attribute__((visibility("default"))) #else #define WASM_RUNTIME_API_EXTERN #endif From 09c2abde4aa2398eab024459ddc9ec58fbfefa9e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:05:44 +0800 Subject: [PATCH 071/105] build(deps): Bump github/codeql-action from 3.27.6 to 3.27.9 (#3960) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.6 to 3.27.9. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.27.6...v3.27.9) --- updated-dependencies: - dependency-name: github/codeql-action 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 88f13cc8b..697aba4b0 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.27.6 + uses: github/codeql-action/init@v3.27.9 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.27.6 + uses: github/codeql-action/analyze@v3.27.9 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.27.6 + uses: github/codeql-action/upload-sarif@v3.27.9 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 2d605f6c9..3fa318292 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@6f9e628e6f9a18c785dd746325ba455111df1b67 # v2.2.4 + uses: github/codeql-action/upload-sarif@dd7559424621a6dd0b32ababe9e4b271a87f78d2 # v2.2.4 with: sarif_file: results.sarif From 932eb5d9e5be01e812d8783d60ce6984f39014be Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:26:34 +0800 Subject: [PATCH 072/105] Only access Zephyr thread stats info when it's available (#3962) --- core/shared/platform/zephyr/zephyr_time.c | 6 ++++++ product-mini/platforms/zephyr/simple/build_and_run.sh | 2 +- tests/fuzz/wasm-mutator-fuzz/portal/osv-scanner.toml | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/shared/platform/zephyr/zephyr_time.c b/core/shared/platform/zephyr/zephyr_time.c index 59b720e41..5b8405737 100644 --- a/core/shared/platform/zephyr/zephyr_time.c +++ b/core/shared/platform/zephyr/zephyr_time.c @@ -14,6 +14,9 @@ os_time_get_boot_us() uint64 os_time_thread_cputime_us(void) { + /* On certain boards, enabling userspace could impact the collection of + * thread runtime statistics */ +#ifdef CONFIG_THREAD_RUNTIME_STATS k_tid_t tid; struct k_thread_runtime_stats stats; uint32 clock_freq; @@ -27,4 +30,7 @@ os_time_thread_cputime_us(void) } return time_in_us; +#else + return os_time_get_boot_us(); +#endif } diff --git a/product-mini/platforms/zephyr/simple/build_and_run.sh b/product-mini/platforms/zephyr/simple/build_and_run.sh index 6b8fb4f87..bd89906d4 100755 --- a/product-mini/platforms/zephyr/simple/build_and_run.sh +++ b/product-mini/platforms/zephyr/simple/build_and_run.sh @@ -38,7 +38,7 @@ TARGET=$1 case $TARGET in $X86_TARGET) - west build -b qemu_x86_nommu \ + west build -b qemu_x86_tiny \ . -p always -- \ -DWAMR_BUILD_TARGET=X86_32 west build -t run diff --git a/tests/fuzz/wasm-mutator-fuzz/portal/osv-scanner.toml b/tests/fuzz/wasm-mutator-fuzz/portal/osv-scanner.toml index 1eb55cd8d..b1b7145de 100644 --- a/tests/fuzz/wasm-mutator-fuzz/portal/osv-scanner.toml +++ b/tests/fuzz/wasm-mutator-fuzz/portal/osv-scanner.toml @@ -50,3 +50,10 @@ name = "vite" ecosystem = "npm" ignore = true reason = "Development server not exposed to untrusted networks" + +# GHSA-mwcw-c2x4-8c55 +[[PackageOverrides]] +name = "nanoid" +ecosystem = "npm" +ignore = true +reason = "Accepted known vulnerabilities for testing purposes" From 9916813a342baba08965b79519938c54e85a9cf1 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 19 Dec 2024 17:49:25 +0900 Subject: [PATCH 073/105] top-level cmakefile: fix macOS build (#3968) At least fast-jit seems to require a bit new C++ standard. C++17 was chosen to match product-mini/platforms/darwin. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3efd6aa82..e5a1bf1c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ endif() project (iwasm) +set(CMAKE_CXX_STANDARD 17) + set (CMAKE_VERBOSE_MAKEFILE OFF) if (NOT DEFINED WAMR_BUILD_PLATFORM) From 8d51a3c7a82405c76df26154b321465fa4c6cb07 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 19 Dec 2024 16:49:44 +0800 Subject: [PATCH 074/105] use a random secret key (#3971) --- tests/fuzz/wasm-mutator-fuzz/server/app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fuzz/wasm-mutator-fuzz/server/app/main.py b/tests/fuzz/wasm-mutator-fuzz/server/app/main.py index d8a0955e2..620625dd3 100644 --- a/tests/fuzz/wasm-mutator-fuzz/server/app/main.py +++ b/tests/fuzz/wasm-mutator-fuzz/server/app/main.py @@ -56,7 +56,7 @@ app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv( app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False -app.secret_key = "hwhefsewljfejrlesjfl" +app.secret_key = os.urandom(12).hex() db = SQLAlchemy(app) From f8f37c8ebbcd618f28d7373c21d76bfecd44a8e3 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 19 Dec 2024 16:51:20 +0800 Subject: [PATCH 075/105] [fuzzing] Enable instantiation (#3958) - Increase input seed size for wasm-tools to generate larger WebAssembly modules - Add instantiation in wasm mutator fuzz tests --- tests/fuzz/wasm-mutator-fuzz/README.md | 1 + tests/fuzz/wasm-mutator-fuzz/smith_wasm.sh | 38 ++++++++--------- .../wasm-mutator-fuzz/wasm_mutator_fuzz.cc | 42 ++++++++++++------- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/tests/fuzz/wasm-mutator-fuzz/README.md b/tests/fuzz/wasm-mutator-fuzz/README.md index 0d21519a1..acf210ae4 100644 --- a/tests/fuzz/wasm-mutator-fuzz/README.md +++ b/tests/fuzz/wasm-mutator-fuzz/README.md @@ -19,6 +19,7 @@ $ wasm-tools help mkdir build && cd build # Without custom mutator (libfuzzer modify the buffer randomly) cmake .. +# TODO: TBC. `wasm-tools mutate` is not supported yet # With custom mutator (wasm-tools mutate) cmake .. -DCUSTOM_MUTATOR=1 make -j$(nproc) diff --git a/tests/fuzz/wasm-mutator-fuzz/smith_wasm.sh b/tests/fuzz/wasm-mutator-fuzz/smith_wasm.sh index 29d24dbd0..02ac83174 100755 --- a/tests/fuzz/wasm-mutator-fuzz/smith_wasm.sh +++ b/tests/fuzz/wasm-mutator-fuzz/smith_wasm.sh @@ -33,36 +33,36 @@ function try_generate_wasm() local try_i=0 until [[ -f $GENERATED_WASM_NAME ]]; do - head -c 100 /dev/urandom | wasm-tools smith $SMITH_OPTIONS -o $GENERATED_WASM_NAME >/dev/null 2>&1 + # Larger input seeds tend to generate larger WebAssembly modules. (256KB) + head -c 262144 /dev/urandom | wasm-tools smith $SMITH_OPTIONS -o $GENERATED_WASM_NAME >/dev/null 2>&1 try_i=$((try_i+1)) done printf -- "-- output ${GENERATED_WASM_NAME} in %d retries\n" $try_i } -# try_generate_wasm "--min-memories=1 --min-tables=1" "test_min.wasm" +WASM_SHAPE=" --allow-invalid-funcs true \ +--generate-custom-sections true \ +--min-funcs 5 \ +--max-instructions 1024 \ +--min-globals 10" + +WASM_MVP_FEATURES=" --bulk-memory-enabled true \ +--multi-value-enabled true \ +--reference-types-enabled true \ +--simd-enabled true \ +--tail-call-enabled true" for i in $(seq 1 $EXPECTED_NUM) do - # by default - try_generate_wasm "" test_$i.wasm - - # with different features # mvp - try_generate_wasm "--min-memories=1 --min-tables=1" test_min_$i.wasm - try_generate_wasm "--min-memories=1 --min-tables=1 --bulk-memory-enabled true" test_bulk_$i.wasm - try_generate_wasm "--min-memories=1 --min-tables=1 --reference-types-enabled true" test_ref_$i.wasm - try_generate_wasm "--min-memories=1 --min-tables=1 --multi-value-enabled true" test_multi_$i.wasm - try_generate_wasm "--min-memories=1 --min-tables=1 --simd-enabled true" test_simd_$i.wasm - try_generate_wasm "--min-memories=1 --min-tables=1 --tail-call-enabled true " test_tail_$i.wasm + try_generate_wasm "${WASM_SHAPE} ${WASM_MVP_FEATURES}" test_mvp_$i.wasm - # enable me when compiling iwasm with those features - #try_generate_wasm "--min-memories=1 --min-tables=1 --threads-enabled true" test_thread_$i.wasm - #try_generate_wasm "--min-memories=1 --min-tables=1 --memory64-enabled true" test_memory64_$i.wasm - #try_generate_wasm "--min-memories=1 --min-tables=1 --exceptions-enabled true" test_exception_$i.wasm - #try_generate_wasm "--min-memories=1 --min-tables=1 --gc-enabled true" test_gc_$i.wasm - # with custom-section - try_generate_wasm "--min-memories=1 --min-tables=1 --generate-custom-sections true" test_custom_$i.wasm + # other proposals + try_generate_wasm "${WASM_SHAPE} --exceptions-enabled true" test_exception_$i.wasm + try_generate_wasm "${WASM_SHAPE} --gc-enabled true" test_gc_$i.wasm + try_generate_wasm "${WASM_SHAPE} --memory64-enabled true" test_memory64_$i.wasm + try_generate_wasm "${WASM_SHAPE} --threads-enabled true" test_threads_$i.wasm done printf "Done\n" diff --git a/tests/fuzz/wasm-mutator-fuzz/wasm_mutator_fuzz.cc b/tests/fuzz/wasm-mutator-fuzz/wasm_mutator_fuzz.cc index 0817e5bdd..2d5a66703 100644 --- a/tests/fuzz/wasm-mutator-fuzz/wasm_mutator_fuzz.cc +++ b/tests/fuzz/wasm-mutator-fuzz/wasm_mutator_fuzz.cc @@ -13,31 +13,41 @@ using namespace std; -extern "C" WASMModuleCommon * -wasm_runtime_load(uint8 *buf, uint32 size, char *error_buf, - uint32 error_buf_size); - -extern "C" WASMModuleInstanceCommon * -wasm_runtime_instantiate(WASMModuleCommon *module, uint32 stack_size, - uint32 heap_size, char *error_buf, - uint32 error_buf_size); - extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { /* libfuzzer don't allow us to modify the given Data, so we copy the data * here */ std::vector myData(Data, Data + Size); + /* init runtime environment */ wasm_runtime_init(); - wasm_module_t module = - wasm_runtime_load((uint8_t *)myData.data(), Size, nullptr, 0); - if (module) { - wasm_runtime_unload(module); - } - /* destroy runtime environment */ - wasm_runtime_destroy(); + char error_buf[128] = { 0 }; + wasm_module_t module = + wasm_runtime_load((uint8_t *)myData.data(), Size, error_buf, 120); + if (!module) { + std::cout << "[LOADING] " << error_buf << std::endl; + wasm_runtime_destroy(); + /* return SUCCESS because the failure has been handled */ + return 0; + } + + wasm_module_inst_t inst = wasm_runtime_instantiate( + module, 8 * 1024 * 1024, 16 * 1024 * 1024, error_buf, 120); + if (!inst) { + std::cout << "[INSTANTIATE] " << error_buf << std::endl; + wasm_runtime_unload(module); + wasm_runtime_destroy(); + /* return SUCCESS because the failure has been handled */ + return 0; + } + + std::cout << "PASS" << std::endl; + + wasm_runtime_deinstantiate(inst); + wasm_runtime_unload(module); + wasm_runtime_destroy(); return 0; /* Values other than 0 and -1 are reserved for future use. */ } From 9598611e3565094008137c027ccbac69c5f6d020 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo <90845888+midokura-xavi92@users.noreply.github.com> Date: Fri, 20 Dec 2024 06:05:50 +0100 Subject: [PATCH 076/105] CMakeLists.txt: Do not require C++ (#3956) By default, the project() CMake command defaults to C and C++. [1] Therefore, CMake might perform tests for both C and C++ compilers as part of the configuration phase. However, this has the consequence of the configuration phase to fail if the system does not have a C++ toolchain installed, even if C++ is not really used by the top-level project under the default settings. Some configurations might still require a C++ toolchain, so enable_language is selectively called under such circumstances. [1]: https://cmake.org/cmake/help/latest/command/project.html --- CMakeLists.txt | 2 +- core/iwasm/compilation/iwasm_compl.cmake | 1 + core/iwasm/fast-jit/iwasm_fast_jit.cmake | 1 + core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake | 1 + core/shared/platform/windows/shared_platform.cmake | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5a1bf1c5..2bd82fc83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ if(ESP_PLATFORM) return() endif() -project (iwasm) +project (iwasm LANGUAGES C) set(CMAKE_CXX_STANDARD 17) diff --git a/core/iwasm/compilation/iwasm_compl.cmake b/core/iwasm/compilation/iwasm_compl.cmake index 4ec460304..77925d62d 100644 --- a/core/iwasm/compilation/iwasm_compl.cmake +++ b/core/iwasm/compilation/iwasm_compl.cmake @@ -1,6 +1,7 @@ set (IWASM_COMPL_DIR ${CMAKE_CURRENT_LIST_DIR}) include_directories(${IWASM_COMPL_DIR}) +enable_language(CXX) if (WAMR_BUILD_DEBUG_AOT EQUAL 1) file (GLOB_RECURSE source_all diff --git a/core/iwasm/fast-jit/iwasm_fast_jit.cmake b/core/iwasm/fast-jit/iwasm_fast_jit.cmake index cd880a34b..c5012bd36 100644 --- a/core/iwasm/fast-jit/iwasm_fast_jit.cmake +++ b/core/iwasm/fast-jit/iwasm_fast_jit.cmake @@ -9,6 +9,7 @@ if (WAMR_BUILD_FAST_JIT_DUMP EQUAL 1) endif () include_directories (${IWASM_FAST_JIT_DIR}) +enable_language(CXX) if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") include(FetchContent) diff --git a/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake b/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake index a903f0af1..c6deab6fc 100644 --- a/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake +++ b/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake @@ -22,6 +22,7 @@ add_compile_definitions( # - tflite if(WAMR_BUILD_WASI_NN_TFLITE EQUAL 1) find_package(tensorflow_lite REQUIRED) + enable_language(CXX) add_library( wasi_nn_tflite diff --git a/core/shared/platform/windows/shared_platform.cmake b/core/shared/platform/windows/shared_platform.cmake index c2d74463f..7a3331eff 100644 --- a/core/shared/platform/windows/shared_platform.cmake +++ b/core/shared/platform/windows/shared_platform.cmake @@ -6,6 +6,7 @@ set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR}) add_definitions(-DBH_PLATFORM_WINDOWS) add_definitions(-DHAVE_STRUCT_TIMESPEC) add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS) +enable_language(CXX) include_directories(${PLATFORM_SHARED_DIR}) include_directories(${PLATFORM_SHARED_DIR}/../include) From 4cda74ad85e9f18dce0790e86ec8aaef1f76ba5c Mon Sep 17 00:00:00 2001 From: Chris Woods <6069113+woodsmc@users.noreply.github.com> Date: Sun, 22 Dec 2024 05:48:43 -0500 Subject: [PATCH 077/105] add reference type support by default for darwin to support WASI-SDK-25 (#3978) --- product-mini/platforms/darwin/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/product-mini/platforms/darwin/CMakeLists.txt b/product-mini/platforms/darwin/CMakeLists.txt index 865e516fc..12ed8052f 100644 --- a/product-mini/platforms/darwin/CMakeLists.txt +++ b/product-mini/platforms/darwin/CMakeLists.txt @@ -91,6 +91,11 @@ if (NOT DEFINED WAMR_BUILD_SIMD) set (WAMR_BUILD_SIMD 1) endif () +if (NOT DEFINED WAMR_BUILD_REF_TYPES) + # Enable reference types by default + set (WAMR_BUILD_REF_TYPES 1) +endif () + if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP) # Disable Debug feature by default set (WAMR_BUILD_DEBUG_INTERP 0) From 040e776162688c20fdd0dd2fea2491c5cdc26bf9 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 23 Dec 2024 14:38:48 +0900 Subject: [PATCH 078/105] top-level cmake: link llvm libraries to our shared library (#3973) This fixes link errors seen on my environment. (macOS 15.2, x86-64, Xcode 16.2) Tested as: ``` mkdir b cd b cmake -D WAMR_BUILD_JIT=1 -D LLVM_DIR=/usr/local/opt/llvm@19/lib/cmake/llvm .. make ``` --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bd82fc83..a637c3643 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,7 +182,7 @@ if (WAMR_BUILD_SHARED) add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE}) set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm) target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include) - target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries (iwasm_shared PUBLIC ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT}) if (WAMR_BUILD_WASM_CACHE EQUAL 1) target_link_libraries(iwasm_shared INTERFACE boringssl_crypto) endif () From 8ac06490db10cea20fdc07784555f93e60130805 Mon Sep 17 00:00:00 2001 From: James Ring Date: Mon, 23 Dec 2024 15:25:52 -0800 Subject: [PATCH 079/105] Set thread information earlier in exec_env creation (#3967) For boundary checking, WAMR calls `pthread_attr_np`, which is unfortunately quite slow on Linux when not called on the main thread (see https://github.com/bytecodealliance/wasm-micro-runtime/issues/3966 for discussion). This change moves the cost of stack bounds checking earlier in the wasm_exec_env creation process. The idea is that it's perhaps better to pay the price when creating the execution environment rather than in the first function call. The original code is left in place inside `call_wasm_with_hw_bound_check` in case the `wasm_exec_env` is created via `wasm_runtime_spawn_exec_env`. --- core/shared/platform/common/posix/posix_thread.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/shared/platform/common/posix/posix_thread.c b/core/shared/platform/common/posix/posix_thread.c index 5ec957e52..1d1024606 100644 --- a/core/shared/platform/common/posix/posix_thread.c +++ b/core/shared/platform/common/posix/posix_thread.c @@ -712,6 +712,13 @@ os_thread_signal_init(os_signal_handler handler) #if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 sigalt_stack_base_addr = map_addr; #endif + +#if defined(os_thread_local_attribute) + // calculate and cache the new stack boundary. + // see https://github.com/bytecodealliance/wasm-micro-runtime/issues/3966 + (void)os_thread_get_stack_boundary(); +#endif + signal_handler = handler; thread_signal_inited = true; return 0; From 70bec1407056dd2ed8db992713189e2d018a3f36 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Tue, 24 Dec 2024 20:19:40 +0800 Subject: [PATCH 080/105] Add Tianlong into code owners (#3970) --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index d8ec4c1b3..990dcfce2 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -22,7 +22,7 @@ # If none of the later patterns match, assign to anyone. This team is the # parent of all the other teams and automatically includes everyone on those # teams. -* @loganek @lum1n0us @no1wudi @wenyongh @xujuntwt95329 @yamt +* @loganek @lum1n0us @no1wudi @TianlongLiang @wenyongh @xujuntwt95329 @yamt # Some parts of the project require more specialized knowledge. In those areas # we designate smaller groups who are more likely to be aware of who's working From bf2f36619bc82b37279001d8b66a1eefc3dff704 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Dec 2024 13:31:17 +0800 Subject: [PATCH 081/105] build(deps): Bump github/codeql-action from 3.27.9 to 3.28.0 (#3982) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.9 to 3.28.0. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.27.9...v3.28.0) --- updated-dependencies: - dependency-name: github/codeql-action 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 697aba4b0..0df082bab 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.27.9 + uses: github/codeql-action/init@v3.28.0 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.27.9 + uses: github/codeql-action/analyze@v3.28.0 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.27.9 + uses: github/codeql-action/upload-sarif@v3.28.0 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 3fa318292..5ac94278d 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@dd7559424621a6dd0b32ababe9e4b271a87f78d2 # v2.2.4 + uses: github/codeql-action/upload-sarif@78760076e3f08852c2c3aeb5334f70d074e28c59 # v2.2.4 with: sarif_file: results.sarif From 04f1071f1c08b47d734acf0e74511bfeef7c5568 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Dec 2024 13:31:37 +0800 Subject: [PATCH 082/105] build(deps): Bump actions/upload-artifact from 4.4.3 to 4.5.0 (#3981) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.4.3 to 4.5.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4.4.3...v4.5.0) --- updated-dependencies: - dependency-name: actions/upload-artifact 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 | 2 +- .github/workflows/spec_test_on_nuttx.yml | 2 +- .github/workflows/supply_chain.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 0df082bab..1da37a4c3 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -106,7 +106,7 @@ jobs: - name: Upload CodeQL results as an artifact if: success() || failure() - uses: actions/upload-artifact@v4.4.3 + uses: actions/upload-artifact@v4.5.0 with: name: codeql-results path: ${{ steps.step1.outputs.sarif-output }} diff --git a/.github/workflows/spec_test_on_nuttx.yml b/.github/workflows/spec_test_on_nuttx.yml index 31427d43f..b6ca914fb 100644 --- a/.github/workflows/spec_test_on_nuttx.yml +++ b/.github/workflows/spec_test_on_nuttx.yml @@ -350,7 +350,7 @@ jobs: - name: upload the log if: always() - uses: actions/upload-artifact@v4.4.3 + uses: actions/upload-artifact@v4.5.0 with: name: spec-test-log-${{ github.run_id }}-${{ strategy.job-index }}-${{ matrix.target_config.target }} path: log diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index 5ac94278d..425eda532 100644 --- a/.github/workflows/supply_chain.yml +++ b/.github/workflows/supply_chain.yml @@ -52,7 +52,7 @@ jobs: # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # format to the repository Actions tab. - name: "Upload artifact" - uses: actions/upload-artifact@184d73b71b93c222403b2e7f1ffebe4508014249 # v3.1.0 + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v3.1.0 with: name: SARIF file path: results.sarif From 9b807660d55fe3ff901714a52ffc804508618bfa Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Wed, 25 Dec 2024 21:46:48 +0800 Subject: [PATCH 083/105] Break aot_create_comp_data into small functions Signed-off-by: Huang Qi --- core/iwasm/compilation/aot.c | 299 ++++++++++++++++++++++++++--------- 1 file changed, 220 insertions(+), 79 deletions(-) diff --git a/core/iwasm/compilation/aot.c b/core/iwasm/compilation/aot.c index 0a2cae1f0..c35a9782c 100644 --- a/core/iwasm/compilation/aot.c +++ b/core/iwasm/compilation/aot.c @@ -487,60 +487,70 @@ calculate_struct_field_sizes_offsets(AOTCompData *comp_data, bool is_target_x86, } #endif -AOTCompData * -aot_create_comp_data(WASMModule *module, const char *target_arch, - bool gc_enabled) +/** + * Checks if target architecture is 64-bit based on target_arch string. + * + * @param target_arch The target architecture string (e.g. "x86_64", "aarch64") + * @return true if target is 64-bit architecture, false otherwise + * + * If target_arch is NULL, detection is based on UINTPTR_MAX. + * Otherwise looks for "64" in target_arch string. + */ +static bool +arch_is_64bit(const char *target_arch) { - AOTCompData *comp_data; - uint32 import_global_data_size_64bit = 0, global_data_size_64bit = 0, i, j; - uint32 import_global_data_size_32bit = 0, global_data_size_32bit = 0; - uint64 size; - bool is_64bit_target = false; -#if WASM_ENABLE_GC != 0 - bool is_target_x86 = false; + if (!target_arch) { +#if UINTPTR_MAX == UINT64_MAX + return true; +#else + return false; #endif + } + /* All 64bit targets contains "64" string in their target name */ + return strstr(target_arch, "64") != NULL; +} -#if WASM_ENABLE_GC != 0 +/** + * Checks if target architecture is x86/x64 based on target_arch string. + * + * @param target_arch The target architecture string (e.g. "x86_64", "i386") + * @return true if target is x86/x64 architecture, false otherwise + * + * If target_arch is NULL, detection is based on build-time definitions. + * Otherwise checks for x86_64 or i386 in target_arch string. + */ +static bool +arch_is_x86(const char *target_arch) +{ if (!target_arch) { #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \ || defined(BUILD_TARGET_X86_32) - is_target_x86 = true; + return true; +#else + return false; #endif } - else { - if (!strncmp(target_arch, "x86_64", 6) - || !strncmp(target_arch, "i386", 4)) - is_target_x86 = true; - } -#endif + return !strncmp(target_arch, "x86_64", 6) + || !strncmp(target_arch, "i386", 4); +} - if (!target_arch) { -#if UINTPTR_MAX == UINT64_MAX - is_64bit_target = true; -#endif - } - else { - /* All 64bit targets contains "64" string in their target name */ - if (strstr(target_arch, "64") != NULL) { - is_64bit_target = true; - } - } - - /* Allocate memory */ - if (!(comp_data = wasm_runtime_malloc(sizeof(AOTCompData)))) { - aot_set_last_error("create compile data failed.\n"); - return NULL; - } - - memset(comp_data, 0, sizeof(AOTCompData)); +/** + * Initialize memory information in AOT compilation data from WASM module. + * + * @param comp_data the AOT compilation data structure to initialize + * @param module the source WASM module containing memory information + * @return true if initialization succeeded, false otherwise + */ +static bool +aot_init_memories(AOTCompData *comp_data, WASMModule *module) +{ + uint32 i, j; + uint64 size; comp_data->memory_count = module->import_memory_count + module->memory_count; - /* TODO: create import memories */ - /* Allocate memory for memory array, reserve one AOTMemory space at least */ - /* TODO: multi-memory */ if (!comp_data->memory_count) comp_data->memory_count = 1; @@ -548,7 +558,7 @@ aot_create_comp_data(WASMModule *module, const char *target_arch, if (size >= UINT32_MAX || !(comp_data->memories = wasm_runtime_malloc((uint32)size))) { aot_set_last_error("create memories array failed.\n"); - goto fail; + return false; } memset(comp_data->memories, 0, size); @@ -580,22 +590,30 @@ aot_create_comp_data(WASMModule *module, const char *target_arch, } } - /* Create memory data segments */ - comp_data->mem_init_data_count = module->data_seg_count; - if (comp_data->mem_init_data_count > 0 - && !(comp_data->mem_init_data_list = - aot_create_mem_init_data_list(module))) - goto fail; + return true; +} + +/** + * Initialize table information in AOT compilation data from WASM module. + * + * @param comp_data the AOT compilation data structure to initialize + * @param module the source WASM module containing table information + * @return true if initialization succeeded, false otherwise + */ +static bool +aot_init_tables(AOTCompData *comp_data, WASMModule *module) +{ + uint32 i, j; + uint64 size; - /* Create tables */ comp_data->table_count = module->import_table_count + module->table_count; if (comp_data->table_count > 0) { size = sizeof(AOTTable) * (uint64)comp_data->table_count; if (size >= UINT32_MAX || !(comp_data->tables = wasm_runtime_malloc((uint32)size))) { - aot_set_last_error("create memories array failed.\n"); - goto fail; + aot_set_last_error("create tables array failed.\n"); + return false; } memset(comp_data->tables, 0, size); for (i = 0; i < comp_data->table_count; i++) { @@ -641,64 +659,150 @@ aot_create_comp_data(WASMModule *module, const char *target_arch, } } - /* Create table data segments */ + return true; +} + +/** + * Initialize memory segment information in AOT compilation data. + * + * @param comp_data the AOT compilation data structure to initialize + * @param module the source WASM module containing memory segments + * @return true if initialization succeeded, false otherwise + */ +static bool +aot_init_memory_segments(AOTCompData *comp_data, WASMModule *module) +{ + comp_data->mem_init_data_count = module->data_seg_count; + if (comp_data->mem_init_data_count > 0 + && !(comp_data->mem_init_data_list = + aot_create_mem_init_data_list(module))) { + return false; + } + return true; +} + +/** + * Initialize table segment information in AOT compilation data. + * + * @param comp_data the AOT compilation data structure to initialize + * @param module the source WASM module containing table segments + * @return true if initialization succeeded, false otherwise + */ +static bool +aot_init_table_segments(AOTCompData *comp_data, WASMModule *module) +{ comp_data->table_init_data_count = module->table_seg_count; if (comp_data->table_init_data_count > 0 && !(comp_data->table_init_data_list = - aot_create_table_init_data_list(module))) - goto fail; + aot_create_table_init_data_list(module))) { + return false; + } + return true; +} - /* Create import globals */ +/** + * Initialize global variable information in AOT compilation data. + * + * @param comp_data the AOT compilation data structure to initialize + * @param module the source WASM module containing global information + * @param gc_enabled whether garbage collection is enabled + * @param import_global_data_size_64bit [out] size of imported global data for + * 64-bit + * @param import_global_data_size_32bit [out] size of imported global data for + * 32-bit + * @param global_data_size_64bit [out] size of global data for 64-bit + * @param global_data_size_32bit [out] size of global data for 32-bit + * @return true if initialization succeeded, false otherwise + */ +static bool +aot_init_globals(AOTCompData *comp_data, WASMModule *module, bool gc_enabled, + uint32 *import_global_data_size_64bit, + uint32 *import_global_data_size_32bit, + uint32 *global_data_size_64bit, uint32 *global_data_size_32bit) +{ comp_data->import_global_count = module->import_global_count; if (comp_data->import_global_count > 0 && !(comp_data->import_globals = aot_create_import_globals( - module, gc_enabled, &import_global_data_size_64bit, - &import_global_data_size_32bit))) - goto fail; + module, gc_enabled, import_global_data_size_64bit, + import_global_data_size_32bit))) { + return false; + } - /* Create globals */ comp_data->global_count = module->global_count; if (comp_data->global_count && !(comp_data->globals = aot_create_globals( - module, gc_enabled, import_global_data_size_64bit, - import_global_data_size_32bit, &global_data_size_64bit, - &global_data_size_32bit))) - goto fail; + module, gc_enabled, *import_global_data_size_64bit, + *import_global_data_size_32bit, global_data_size_64bit, + global_data_size_32bit))) { + return false; + } comp_data->global_data_size_64bit = - import_global_data_size_64bit + global_data_size_64bit; + *import_global_data_size_64bit + *global_data_size_64bit; comp_data->global_data_size_32bit = - import_global_data_size_32bit + global_data_size_32bit; + *import_global_data_size_32bit + *global_data_size_32bit; - /* Create types, they are checked by wasm loader */ + return true; +} + +/** + * Initialize type information in AOT compilation data. + * + * @param comp_data the AOT compilation data structure to initialize + * @param module the source WASM module containing type information + * @param is_target_x86 whether the target architecture is x86 + * @param gc_enabled whether garbage collection is enabled + * @return true if initialization succeeded, false otherwise + */ +static bool +aot_init_types(AOTCompData *comp_data, WASMModule *module, bool is_target_x86, + bool gc_enabled) +{ comp_data->type_count = module->type_count; comp_data->types = module->types; #if WASM_ENABLE_GC != 0 - /* Calculate the field sizes and field offsets for 64-bit and 32-bit - targets since they may vary in 32-bit target and 64-bit target */ calculate_struct_field_sizes_offsets(comp_data, is_target_x86, gc_enabled); #endif + return true; +} - /* Create import functions */ +/** + * Initialize function information in AOT compilation data. + * + * @param comp_data the AOT compilation data structure to initialize + * @param module the source WASM module containing function information + * @param is_64bit_target whether the target architecture is 64-bit + * @return true if initialization succeeded, false otherwise + */ +static bool +aot_init_functions(AOTCompData *comp_data, WASMModule *module, + bool is_64bit_target) +{ comp_data->import_func_count = module->import_function_count; if (comp_data->import_func_count - && !(comp_data->import_funcs = aot_create_import_funcs(module))) - goto fail; + && !(comp_data->import_funcs = aot_create_import_funcs(module))) { + return false; + } - /* Create functions */ comp_data->func_count = module->function_count; if (comp_data->func_count && !(comp_data->funcs = - aot_create_funcs(module, is_64bit_target ? 8 : 4))) - goto fail; + aot_create_funcs(module, is_64bit_target ? 8 : 4))) { + return false; + } -#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0 - /* Create custom name section */ - comp_data->name_section_buf = module->name_section_buf; - comp_data->name_section_buf_end = module->name_section_buf_end; -#endif + return true; +} - /* Create aux data/heap/stack information */ +/** + * Initialize auxiliary data in AOT compilation data. + * + * @param comp_data the AOT compilation data structure to initialize + * @param module the source WASM module containing auxiliary data + */ +static void +aot_init_aux_data(AOTCompData *comp_data, WASMModule *module) +{ comp_data->aux_data_end_global_index = module->aux_data_end_global_index; comp_data->aux_data_end = module->aux_data_end; comp_data->aux_heap_base_global_index = module->aux_heap_base_global_index; @@ -717,6 +821,43 @@ aot_create_comp_data(WASMModule *module, const char *target_arch, comp_data->string_literal_ptrs_wp = module->string_literal_ptrs; comp_data->string_literal_lengths_wp = module->string_literal_lengths; #endif +} + +AOTCompData * +aot_create_comp_data(WASMModule *module, const char *target_arch, + bool gc_enabled) +{ + AOTCompData *comp_data; + uint32 import_global_data_size_64bit = 0, global_data_size_64bit = 0; + uint32 import_global_data_size_32bit = 0, global_data_size_32bit = 0; + bool is_64bit_target = arch_is_64bit(target_arch); + bool is_target_x86 = arch_is_x86(target_arch); + + if (!(comp_data = wasm_runtime_malloc(sizeof(AOTCompData)))) { + aot_set_last_error("create compile data failed.\n"); + return NULL; + } + memset(comp_data, 0, sizeof(AOTCompData)); + + if (!aot_init_memories(comp_data, module) + || !aot_init_memory_segments(comp_data, module) + || !aot_init_tables(comp_data, module) + || !aot_init_table_segments(comp_data, module) + || !aot_init_globals(comp_data, module, gc_enabled, + &import_global_data_size_64bit, + &import_global_data_size_32bit, + &global_data_size_64bit, &global_data_size_32bit) + || !aot_init_types(comp_data, module, is_target_x86, gc_enabled) + || !aot_init_functions(comp_data, module, is_64bit_target)) { + goto fail; + } + +#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0 + comp_data->name_section_buf = module->name_section_buf; + comp_data->name_section_buf_end = module->name_section_buf_end; +#endif + + aot_init_aux_data(comp_data, module); comp_data->wasm_module = module; From 38cf2742924d4e82593d3b27e27d29f1f5f61359 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Thu, 26 Dec 2024 15:15:25 +0800 Subject: [PATCH 084/105] Optimize memory initialization handling in AOT loader (#3983) Save memory if the file buffer is always exist before exit. Signed-off-by: Huang Qi --- core/iwasm/aot/aot_loader.c | 75 ++++++++++++++++++++++++++++++++---- core/iwasm/compilation/aot.c | 25 +++++++++--- core/iwasm/compilation/aot.h | 2 +- 3 files changed, 89 insertions(+), 13 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 239e328bd..bde3ee034 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -967,13 +967,29 @@ destroy_import_memories(AOTImportMemory *import_memories) wasm_runtime_free(import_memories); } +/** + * Free memory initialization data segments. + * + * @param module the AOT module containing the data + * @param data_list array of memory initialization data segments to free + * @param count number of segments in the data_list array + */ + static void -destroy_mem_init_data_list(AOTMemInitData **data_list, uint32 count) +destroy_mem_init_data_list(AOTModule *module, AOTMemInitData **data_list, + uint32 count) { uint32 i; + /* Free each memory initialization data segment */ for (i = 0; i < count; i++) - if (data_list[i]) + if (data_list[i]) { + /* If the module owns the binary data, free the bytes buffer */ + if (module->is_binary_freeable && data_list[i]->bytes) + wasm_runtime_free(data_list[i]->bytes); + /* Free the data segment structure itself */ wasm_runtime_free(data_list[i]); + } + /* Free the array of data segment pointers */ wasm_runtime_free(data_list); } @@ -982,6 +998,22 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, InitializerExpression *expr, char *error_buf, uint32 error_buf_size); +/** + * Load memory initialization data segments from the AOT module. + * + * This function reads memory initialization data segments from the buffer and + * creates AOTMemInitData structures for each segment. The data can either be + * cloned into new memory or referenced directly from the buffer. + * + * @param p_buf pointer to buffer containing memory init data + * @param buf_end end of buffer + * @param module the AOT module being loaded + * @param error_buf buffer for error messages + * @param error_buf_size size of error buffer + * + * @return true if successful, false if error occurred + */ + static bool load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, char *error_buf, @@ -1013,8 +1045,8 @@ load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end, return false; } read_uint32(buf, buf_end, byte_count); - size = offsetof(AOTMemInitData, bytes) + (uint64)byte_count; - if (!(data_list[i] = loader_malloc(size, error_buf, error_buf_size))) { + if (!(data_list[i] = loader_malloc(sizeof(AOTMemInitData), error_buf, + error_buf_size))) { return false; } @@ -1026,8 +1058,22 @@ load_mem_init_data_list(const uint8 **p_buf, const uint8 *buf_end, data_list[i]->offset.init_expr_type = init_value.init_expr_type; data_list[i]->offset.u = init_value.u; data_list[i]->byte_count = byte_count; - read_byte_array(buf, buf_end, data_list[i]->bytes, - data_list[i]->byte_count); + data_list[i]->bytes = NULL; + /* If the module owns the binary data, clone the bytes buffer */ + if (module->is_binary_freeable) { + if (byte_count > 0) { + if (!(data_list[i]->bytes = loader_malloc(byte_count, error_buf, + error_buf_size))) { + return false; + } + read_byte_array(buf, buf_end, data_list[i]->bytes, + data_list[i]->byte_count); + } + } + else { + data_list[i]->bytes = (uint8 *)buf; + buf += byte_count; + } } *p_buf = buf; @@ -1036,6 +1082,21 @@ fail: return false; } +/** + * Load memory information from the AOT module. + * + * This function reads memory-related data including import memory count, + * memory count, memory flags, page sizes, and memory initialization data. + * + * @param p_buf pointer to buffer containing memory info + * @param buf_end end of buffer + * @param module the AOT module being loaded + * @param error_buf buffer for error messages + * @param error_buf_size size of error buffer + * + * @return true if successful, false if error occurred + */ + static bool load_memory_info(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, char *error_buf, uint32 error_buf_size) @@ -4356,7 +4417,7 @@ aot_unload(AOTModule *module) wasm_runtime_free(module->memories); if (module->mem_init_data_list) - destroy_mem_init_data_list(module->mem_init_data_list, + destroy_mem_init_data_list(module, module->mem_init_data_list, module->mem_init_data_count); if (module->native_symbol_list) diff --git a/core/iwasm/compilation/aot.c b/core/iwasm/compilation/aot.c index 0a2cae1f0..699f3c875 100644 --- a/core/iwasm/compilation/aot.c +++ b/core/iwasm/compilation/aot.c @@ -36,8 +36,11 @@ aot_destroy_mem_init_data_list(AOTMemInitData **data_list, uint32 count) { uint32 i; for (i = 0; i < count; i++) - if (data_list[i]) + if (data_list[i]) { + if (data_list[i]->bytes) + wasm_runtime_free(data_list[i]->bytes); wasm_runtime_free(data_list[i]); + } wasm_runtime_free(data_list); } @@ -60,8 +63,7 @@ aot_create_mem_init_data_list(const WASMModule *module) /* Create each memory data segment */ for (i = 0; i < module->data_seg_count; i++) { - size = offsetof(AOTMemInitData, bytes) - + (uint64)module->data_segments[i]->data_length; + size = sizeof(AOTMemInitData); if (size >= UINT32_MAX || !(data_list[i] = wasm_runtime_malloc((uint32)size))) { aot_set_last_error("allocate memory failed."); @@ -69,18 +71,31 @@ aot_create_mem_init_data_list(const WASMModule *module) } #if WASM_ENABLE_BULK_MEMORY != 0 + /* Set bulk memory specific properties if enabled */ data_list[i]->is_passive = module->data_segments[i]->is_passive; data_list[i]->memory_index = module->data_segments[i]->memory_index; #endif data_list[i]->offset = module->data_segments[i]->base_offset; data_list[i]->byte_count = module->data_segments[i]->data_length; - memcpy(data_list[i]->bytes, module->data_segments[i]->data, - module->data_segments[i]->data_length); + data_list[i]->bytes = NULL; + /* Allocate memory for AOT compiler is OK, because the data segment + * is small and the host memory is enough */ + if (data_list[i]->byte_count > 0) { + data_list[i]->bytes = wasm_runtime_malloc(data_list[i]->byte_count); + if (!data_list[i]->bytes) { + aot_set_last_error("allocate memory failed."); + goto fail; + } + /* Copy the actual data bytes from the WASM module */ + memcpy(data_list[i]->bytes, module->data_segments[i]->data, + module->data_segments[i]->data_length); + } } return data_list; fail: + /* Clean up allocated memory in case of failure */ aot_destroy_mem_init_data_list(data_list, module->data_seg_count); return NULL; } diff --git a/core/iwasm/compilation/aot.h b/core/iwasm/compilation/aot.h index 98d2cc6cc..973d198ca 100644 --- a/core/iwasm/compilation/aot.h +++ b/core/iwasm/compilation/aot.h @@ -103,7 +103,7 @@ typedef struct AOTMemInitData { /* Byte count */ uint32 byte_count; /* Byte array */ - uint8 bytes[1]; + uint8 *bytes; } AOTMemInitData; /** From 7f3e0df21c7c8ff6f999597d14e83eacbd0a378f Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Sun, 29 Dec 2024 15:52:12 +0800 Subject: [PATCH 085/105] Handle a new scenario where an item is both exported and imported. (#3984) --- core/iwasm/common/wasm_runtime_common.c | 154 ++++++++++++++++++------ 1 file changed, 118 insertions(+), 36 deletions(-) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 26aab9664..5517fe60f 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -4266,31 +4266,68 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index, export_type->kind = aot_export->kind; switch (export_type->kind) { case WASM_IMPORT_EXPORT_KIND_FUNC: - export_type->u.func_type = - (AOTFuncType *)aot_module - ->types[aot_module->func_type_indexes - [aot_export->index - - aot_module->import_func_count]]; + { + if (aot_export->index < aot_module->import_func_count) { + export_type->u.func_type = + (AOTFuncType *)aot_module + ->import_funcs[aot_export->index] + .func_type; + } + else { + export_type->u.func_type = + (AOTFuncType *)aot_module + ->types[aot_module->func_type_indexes + [aot_export->index + - aot_module->import_func_count]]; + } break; + } case WASM_IMPORT_EXPORT_KIND_GLOBAL: - export_type->u.global_type = - &aot_module - ->globals[aot_export->index - - aot_module->import_global_count] - .type; + { + if (aot_export->index < aot_module->import_global_count) { + export_type->u.global_type = + &aot_module->import_globals[aot_export->index].type; + } + else { + export_type->u.global_type = + &aot_module + ->globals[aot_export->index + - aot_module->import_global_count] + .type; + } break; + } case WASM_IMPORT_EXPORT_KIND_TABLE: - export_type->u.table_type = - &aot_module - ->tables[aot_export->index - - aot_module->import_table_count] - .table_type; + { + if (aot_export->index < aot_module->import_table_count) { + export_type->u.table_type = + &aot_module->import_tables[aot_export->index] + .table_type; + } + else { + export_type->u.table_type = + &aot_module + ->tables[aot_export->index + - aot_module->import_table_count] + .table_type; + } break; + } case WASM_IMPORT_EXPORT_KIND_MEMORY: - export_type->u.memory_type = - &aot_module->memories[aot_export->index - - aot_module->import_memory_count]; + { + if (aot_export->index < aot_module->import_memory_count) { + export_type->u.memory_type = + &aot_module->import_memories[aot_export->index] + .mem_type; + } + else { + export_type->u.memory_type = + &aot_module + ->memories[aot_export->index + - aot_module->import_memory_count]; + } break; + } default: bh_assert(0); break; @@ -4312,31 +4349,76 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index, export_type->kind = wasm_export->kind; switch (export_type->kind) { case WASM_IMPORT_EXPORT_KIND_FUNC: - export_type->u.func_type = - wasm_module - ->functions[wasm_export->index - - wasm_module->import_function_count] - ->func_type; + { + if (wasm_export->index < wasm_module->import_function_count) { + export_type->u.func_type = + (WASMFuncType *)wasm_module + ->import_functions[wasm_export->index] + .u.function.func_type; + } + else { + export_type->u.func_type = + wasm_module + ->functions[wasm_export->index + - wasm_module->import_function_count] + ->func_type; + } + break; + } case WASM_IMPORT_EXPORT_KIND_GLOBAL: - export_type->u.global_type = - &wasm_module - ->globals[wasm_export->index - - wasm_module->import_global_count] - .type; + { + if (wasm_export->index < wasm_module->import_global_count) { + export_type->u.global_type = + (WASMGlobalType *)&wasm_module + ->import_globals[wasm_export->index] + .u.global.type; + } + else { + export_type->u.global_type = + &wasm_module + ->globals[wasm_export->index + - wasm_module->import_global_count] + .type; + } + break; + } case WASM_IMPORT_EXPORT_KIND_TABLE: - export_type->u.table_type = - &wasm_module - ->tables[wasm_export->index - - wasm_module->import_table_count] - .table_type; + { + if (wasm_export->index < wasm_module->import_table_count) { + export_type->u.table_type = + (WASMTableType *)&wasm_module + ->import_tables[wasm_export->index] + .u.table.table_type; + } + else { + export_type->u.table_type = + &wasm_module + ->tables[wasm_export->index + - wasm_module->import_table_count] + .table_type; + } + break; + } case WASM_IMPORT_EXPORT_KIND_MEMORY: - export_type->u.memory_type = - &wasm_module->memories[wasm_export->index - - wasm_module->import_memory_count]; + { + if (wasm_export->index < wasm_module->import_memory_count) { + export_type->u.memory_type = + (WASMMemoryType *)&wasm_module + ->import_memories[wasm_export->index] + .u.memory.mem_type; + } + else { + export_type->u.memory_type = + &wasm_module + ->memories[wasm_export->index + - wasm_module->import_memory_count]; + } + break; + } default: bh_assert(0); break; From 31ff576edfa01f5f928069deab9cf75a9eef512d Mon Sep 17 00:00:00 2001 From: Marcin Kolny Date: Fri, 3 Jan 2025 02:44:25 +0000 Subject: [PATCH 086/105] Error message improvement (#4000) Improve error message in the scenario where the runtime was built with ref types disabled but the module uses reference types feature. --- core/iwasm/interpreter/wasm_loader.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 79ed996d8..91237c007 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -4237,7 +4237,10 @@ check_table_index(const WASMModule *module, uint32 table_index, char *error_buf, { #if WASM_ENABLE_REF_TYPES == 0 && WASM_ENABLE_GC == 0 if (table_index != 0) { - set_error_buf(error_buf, error_buf_size, "zero byte expected"); + set_error_buf( + error_buf, error_buf_size, + "zero byte expected. The module uses reference types feature " + "which is disabled in the runtime."); return false; } #endif From 099056b076626c0f9df5664f1484f76e1c4d5ee5 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Fri, 3 Jan 2025 14:37:09 +0800 Subject: [PATCH 087/105] Ensure __heap_base and __data_end global indices are validated against import count (#3996) --- core/iwasm/interpreter/wasm_loader.c | 14 ++++++++++++++ core/iwasm/interpreter/wasm_mini_loader.c | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 91237c007..e01e17fe9 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -5927,6 +5927,13 @@ load_from_sections(WASMModule *module, WASMSection *sections, for (i = 0; i < module->export_count; i++, export ++) { if (export->kind == EXPORT_KIND_GLOBAL) { if (!strcmp(export->name, "__heap_base")) { + if (export->index < module->import_global_count) { + LOG_DEBUG("Skip the process if __heap_base is imported " + "instead of being a local global"); + continue; + } + + /* only process linker-generated symbols */ global_index = export->index - module->import_global_count; global = module->globals + global_index; if (global->type.val_type == VALUE_TYPE_I32 @@ -5941,6 +5948,13 @@ load_from_sections(WASMModule *module, WASMSection *sections, } } else if (!strcmp(export->name, "__data_end")) { + if (export->index < module->import_global_count) { + LOG_DEBUG("Skip the process if __data_end is imported " + "instead of being a local global"); + continue; + } + + /* only process linker-generated symbols */ global_index = export->index - module->import_global_count; global = module->globals + global_index; if (global->type.val_type == VALUE_TYPE_I32 diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 4dad55523..de9e22018 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -2736,6 +2736,12 @@ load_from_sections(WASMModule *module, WASMSection *sections, for (i = 0; i < module->export_count; i++, export ++) { if (export->kind == EXPORT_KIND_GLOBAL) { if (!strcmp(export->name, "__heap_base")) { + if (export->index < module->import_global_count) { + LOG_DEBUG("Skip the process if __heap_base is imported " + "instead of being a local global"); + continue; + } + global_index = export->index - module->import_global_count; global = module->globals + global_index; if (global->type.val_type == VALUE_TYPE_I32 @@ -2750,6 +2756,12 @@ load_from_sections(WASMModule *module, WASMSection *sections, } } else if (!strcmp(export->name, "__data_end")) { + if (export->index < module->import_global_count) { + LOG_DEBUG("Skip the process if __data_end is imported " + "instead of being a local global"); + continue; + } + global_index = export->index - module->import_global_count; global = module->globals + global_index; if (global->type.val_type == VALUE_TYPE_I32 From 1958808a2485e14a179dd57563dbb628c4268c84 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Sun, 5 Jan 2025 15:27:40 +0800 Subject: [PATCH 088/105] Fix table index calculations in wasm_loader and wasm_mini_loader (#4004) --- core/iwasm/interpreter/wasm_loader.c | 11 +++++++---- core/iwasm/interpreter/wasm_mini_loader.c | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index e01e17fe9..533538adc 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -58,7 +58,9 @@ is_table_64bit(WASMModule *module, uint32 table_idx) return !!(module->import_tables[table_idx].u.table.table_type.flags & TABLE64_FLAG); else - return !!(module->tables[table_idx].table_type.flags & TABLE64_FLAG); + return !!(module->tables[table_idx - module->import_table_count] + .table_type.flags + & TABLE64_FLAG); return false; } @@ -4285,7 +4287,8 @@ check_table_elem_type(WASMModule *module, uint32 table_index, module->import_tables[table_index].u.table.table_type.elem_type; else table_declared_elem_type = - (module->tables + table_index)->table_type.elem_type; + module->tables[table_index - module->import_table_count] + .table_type.elem_type; if (table_declared_elem_type == type_from_elem_seg) return true; @@ -10854,12 +10857,12 @@ get_table_elem_type(const WASMModule *module, uint32 table_idx, else { if (p_elem_type) *p_elem_type = - module->tables[module->import_table_count + table_idx] + module->tables[table_idx - module->import_table_count] .table_type.elem_type; #if WASM_ENABLE_GC != 0 if (p_ref_type) *((WASMRefType **)p_ref_type) = - module->tables[module->import_table_count + table_idx] + module->tables[table_idx - module->import_table_count] .table_type.elem_ref_type; #endif } diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index de9e22018..e83a20045 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -48,7 +48,9 @@ is_table_64bit(WASMModule *module, uint32 table_idx) return !!(module->import_tables[table_idx].u.table.table_type.flags & TABLE64_FLAG); else - return !!(module->tables[table_idx].table_type.flags & TABLE64_FLAG); + return !!(module->tables[table_idx - module->import_table_count] + .table_type.flags + & TABLE64_FLAG); return false; } @@ -2566,7 +2568,7 @@ get_table_elem_type(const WASMModule *module, uint32 table_idx, module->import_tables[table_idx].u.table.table_type.elem_type; else *p_elem_type = - module->tables[module->import_table_count + table_idx] + module->tables[table_idx - module->import_table_count] .table_type.elem_type; } return true; From 1807eec9d2d38b88545c2fc7208959113750a342 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Sun, 5 Jan 2025 15:34:17 +0800 Subject: [PATCH 089/105] Add an example of how to embed WAMR in Zephyr user mode (#3998) --- .../platforms/zephyr/simple/CMakeLists.txt | 3 +- .../platforms/zephyr/user-mode/CMakeLists.txt | 15 ++ .../platforms/zephyr/user-mode/README.md | 60 ++++++ .../user-mode/lib-wamr-zephyr/CMakeLists.txt | 63 +++++++ .../user-mode/lib-wamr-zephyr/test_wasm.h | 46 +++++ .../lib-wamr-zephyr/test_wasm_riscv64.h | 41 +++++ .../user-mode/lib-wamr-zephyr/wamr_lib.c | 172 ++++++++++++++++++ .../platforms/zephyr/user-mode/prj.conf | 9 + .../platforms/zephyr/user-mode/src/main.c | 78 ++++++++ 9 files changed, 486 insertions(+), 1 deletion(-) create mode 100644 product-mini/platforms/zephyr/user-mode/CMakeLists.txt create mode 100644 product-mini/platforms/zephyr/user-mode/README.md create mode 100644 product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/CMakeLists.txt create mode 100644 product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/test_wasm.h create mode 100644 product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/test_wasm_riscv64.h create mode 100644 product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/wamr_lib.c create mode 100644 product-mini/platforms/zephyr/user-mode/prj.conf create mode 100644 product-mini/platforms/zephyr/user-mode/src/main.c diff --git a/product-mini/platforms/zephyr/simple/CMakeLists.txt b/product-mini/platforms/zephyr/simple/CMakeLists.txt index 8b2af15eb..78dd32285 100644 --- a/product-mini/platforms/zephyr/simple/CMakeLists.txt +++ b/product-mini/platforms/zephyr/simple/CMakeLists.txt @@ -32,7 +32,8 @@ if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) endif () if (NOT DEFINED WAMR_BUILD_LIBC_WASI) - # Disable libc wasi support by default + # Disable libc wasi support by default, in the future, + # it can be enabled if libc wasi file/socket/lock support is ready on Zephyr platform set (WAMR_BUILD_LIBC_WASI 0) endif () diff --git a/product-mini/platforms/zephyr/user-mode/CMakeLists.txt b/product-mini/platforms/zephyr/user-mode/CMakeLists.txt new file mode 100644 index 000000000..16c9b26dc --- /dev/null +++ b/product-mini/platforms/zephyr/user-mode/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required(VERSION 3.13.1) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(wamr_user_mode LANGUAGES C) + +# Add the wamr-lib directory +add_subdirectory(lib-wamr-zephyr) + +# Link the wamr library to the app target +target_link_libraries(app PRIVATE wamr_lib) + +target_sources(app PRIVATE src/main.c) diff --git a/product-mini/platforms/zephyr/user-mode/README.md b/product-mini/platforms/zephyr/user-mode/README.md new file mode 100644 index 000000000..b15746732 --- /dev/null +++ b/product-mini/platforms/zephyr/user-mode/README.md @@ -0,0 +1,60 @@ +# How to use WAMR with Zephyr in user mode + +This example demonstrates how to build and run a WebAssembly application in user mode on Zephyr. + +> Note: The user mode is not supported on all Zephyr boards. Please refer to the Zephyr documentation for more information. + +## Setup + +Please refer to the [previous WAMR Zephyr README.md](../simple/README.md) for general Zephyr setup instructions. + +And refer to [official documentation of Zephyr user mode](https://docs.zephyrproject.org/latest/kernel/usermode/index.html) for more information about Zephyr user mode. + +### Enable user mode + +To enable Zephyr user mode, set the `CONFIG_USERSPACE` option to yes in the Zephyr configuration. + +```conf +CONFIG_USERSPACE=y +``` + +And link the WAMR runtime as a separate library in CMakelists.txt. + +```cmake +...WAMR CMake set up... + +zephyr_library_named (wamr_lib) + +zephyr_library_sources ( + ${WAMR_RUNTIME_LIB_SOURCE} + wamr_lib.c +) + +zephyr_library_app_memory (wamr_partition) +``` + +The `wamr_partition` is a memory partition that will be granted to the WAMR runtime. It is defined in the Zephyr application code. + +```C +K_APPMEM_PARTITION_DEFINE(wamr_partition); +``` + +When creating a Zephyr thread, set the thread option to `K_USER` and the timeout to `K_FOREVER`. This can ensure that the `wamr_partition` is granted access to the thread before starting it with `k_thread_start`. + +### Advantage of using WAMR runtime in Zephyr user mode thread + +In a user-mode Zephyr thread, the application can only access a restricted partition of memory it granted to. It creates a sandbox for the WAMR runtime to run in, and the WAMR runtime can only access that memory space, meaning that all global variables in the WAMR runtime and both runtime and wasm app heap memory will be allocated from it. In this way, an extra layer of security is added to the wasm application on top of the wasm sandbox provided by WAMR. + +### Example Targets + +x86_64 QEMU (x86_64) is a 64-bit x86 target for emulating the x86_64 platform. + +```shell +west build -b qemu_x86_tiny . -p always -- -DWAMR_BUILD_TARGET=X86_32 +``` + +Use qemu to run the image. + +```shell +qemu-system-i386 -m 32 -cpu qemu32,+nx,+pae -machine pc -device isa-debug-exit,iobase=0xf4,iosize=0x04 -no-reboot -nographic -net none -pidfile qemu.pid -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -icount shift=5,align=off,sleep=off -rtc clock=vm -kernel ./build/zephyr/zephyr.elf +``` diff --git a/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/CMakeLists.txt b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/CMakeLists.txt new file mode 100644 index 000000000..7c68a71ac --- /dev/null +++ b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/CMakeLists.txt @@ -0,0 +1,63 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required(VERSION 3.8.2) + +set (WAMR_BUILD_PLATFORM "zephyr") + +# Build as X86_32 by default, change to "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS" or "XTENSA" +# if we want to support arm, thumb, mips or xtensa +if (NOT DEFINED WAMR_BUILD_TARGET) + set (WAMR_BUILD_TARGET "X86_32") +endif () + +if (NOT DEFINED WAMR_BUILD_INTERP) + # Enable Interpreter by default + set (WAMR_BUILD_INTERP 1) +endif () + +if (NOT DEFINED WAMR_BUILD_AOT) + # Enable AOT by default. + set (WAMR_BUILD_AOT 1) +endif () + +if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) + # Enable libc builtin support by default + set (WAMR_BUILD_LIBC_BUILTIN 1) +endif () + +if (NOT DEFINED WAMR_BUILD_LIBC_WASI) + # Disable libc wasi support by default, in the future, + # it can be enabled if libc wasi file/socket/lock support is ready on Zephyr platform + set (WAMR_BUILD_LIBC_WASI 0) +endif () + +if (WAMR_BUILD_TARGET STREQUAL "RISCV64_LP64" OR WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32") + set (WAMR_BUILD_FAST_INTERP 1) +endif () + +# Limited to global heap usage in Zephyr user mode +set (WAMR_BUILD_GLOBAL_HEAP_POOL 1) + +# Override the global heap size for small devices +if (NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_SIZE) + set (WAMR_BUILD_GLOBAL_HEAP_SIZE 40960) # 40 KB +endif () + +set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) + +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +# Embed WAMR as a Zephyr library +zephyr_library_named (wamr_lib) + +# Add source files to the library +zephyr_library_sources ( + ${WAMR_RUNTIME_LIB_SOURCE} + wamr_lib.c +) + +# Specify the memory partition where all globals(including the WAMR global heap buffer) +# in the library should be placed. This partition will be defined in the app source code +# and added to the use-mode thread that uses the WAMR library. +zephyr_library_app_memory (wamr_partition) diff --git a/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/test_wasm.h b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/test_wasm.h new file mode 100644 index 000000000..a729cadef --- /dev/null +++ b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/test_wasm.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +/** + * The byte array buffer is the file content of a test wasm binary file, + * which is compiled by wasi-sdk toolchain from C source file of: + * product-mini/app-samples/hello-world/main.c. + */ +unsigned char __aligned(4) wasm_test_file[] = { + 0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x03, 0x60, + 0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01, + 0x7F, 0x00, 0x02, 0x31, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75, + 0x74, 0x73, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C, + 0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x70, 0x72, + 0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66, + 0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01, + 0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x13, 0x03, + 0x7F, 0x01, 0x41, 0xC0, 0x28, 0x0B, 0x7F, 0x00, 0x41, 0xBA, 0x08, 0x0B, + 0x7F, 0x00, 0x41, 0xC0, 0x28, 0x0B, 0x07, 0x2C, 0x04, 0x06, 0x6D, 0x65, + 0x6D, 0x6F, 0x72, 0x79, 0x02, 0x00, 0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74, + 0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03, 0x01, 0x0B, 0x5F, 0x5F, 0x68, 0x65, + 0x61, 0x70, 0x5F, 0x62, 0x61, 0x73, 0x65, 0x03, 0x02, 0x04, 0x6D, 0x61, + 0x69, 0x6E, 0x00, 0x04, 0x0A, 0xB2, 0x01, 0x01, 0xAF, 0x01, 0x01, 0x03, + 0x7F, 0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x20, 0x6B, 0x22, 0x02, + 0x24, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x9B, 0x88, 0x80, 0x80, 0x00, + 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x02, 0x40, 0x02, 0x40, 0x41, + 0x80, 0x08, 0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x22, 0x03, 0x0D, 0x00, + 0x41, 0xA8, 0x88, 0x80, 0x80, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, + 0x1A, 0x41, 0x7F, 0x21, 0x04, 0x0C, 0x01, 0x0B, 0x20, 0x02, 0x20, 0x03, + 0x36, 0x02, 0x10, 0x41, 0x80, 0x88, 0x80, 0x80, 0x00, 0x20, 0x02, 0x41, + 0x10, 0x6A, 0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, 0x00, 0x21, + 0x04, 0x20, 0x03, 0x41, 0x04, 0x6A, 0x41, 0x00, 0x2F, 0x00, 0x91, 0x88, + 0x80, 0x80, 0x00, 0x3B, 0x00, 0x00, 0x20, 0x03, 0x41, 0x00, 0x28, 0x00, + 0x8D, 0x88, 0x80, 0x80, 0x00, 0x36, 0x00, 0x00, 0x20, 0x02, 0x20, 0x03, + 0x36, 0x02, 0x00, 0x41, 0x93, 0x88, 0x80, 0x80, 0x00, 0x20, 0x02, 0x10, + 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x20, 0x03, 0x10, 0x83, 0x80, 0x80, + 0x80, 0x00, 0x0B, 0x20, 0x02, 0x41, 0x20, 0x6A, 0x24, 0x80, 0x80, 0x80, + 0x80, 0x00, 0x20, 0x04, 0x0B, 0x0B, 0x41, 0x01, 0x00, 0x41, 0x80, 0x08, + 0x0B, 0x3A, 0x62, 0x75, 0x66, 0x20, 0x70, 0x74, 0x72, 0x3A, 0x20, 0x25, + 0x70, 0x0A, 0x00, 0x31, 0x32, 0x33, 0x34, 0x0A, 0x00, 0x62, 0x75, 0x66, + 0x3A, 0x20, 0x25, 0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, + 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, + 0x20, 0x62, 0x75, 0x66, 0x20, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64, 0x00 +}; diff --git a/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/test_wasm_riscv64.h b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/test_wasm_riscv64.h new file mode 100644 index 000000000..1b45211d7 --- /dev/null +++ b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/test_wasm_riscv64.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +unsigned char __aligned(4) wasm_test_file[] = { + 0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x03, 0x60, + 0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01, + 0x7F, 0x00, 0x02, 0x31, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75, + 0x74, 0x73, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C, + 0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x70, 0x72, + 0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66, + 0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01, + 0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x12, 0x03, + 0x7F, 0x01, 0x41, 0xC0, 0x01, 0x0B, 0x7F, 0x00, 0x41, 0x3A, 0x0B, 0x7F, + 0x00, 0x41, 0xC0, 0x01, 0x0B, 0x07, 0x2C, 0x04, 0x06, 0x6D, 0x65, 0x6D, + 0x6F, 0x72, 0x79, 0x02, 0x00, 0x04, 0x6D, 0x61, 0x69, 0x6E, 0x00, 0x04, + 0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74, 0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03, + 0x01, 0x0B, 0x5F, 0x5F, 0x68, 0x65, 0x61, 0x70, 0x5F, 0x62, 0x61, 0x73, + 0x65, 0x03, 0x02, 0x0A, 0xB1, 0x01, 0x01, 0xAE, 0x01, 0x01, 0x03, 0x7F, + 0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x20, 0x6B, 0x22, 0x02, 0x24, + 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x9B, 0x80, 0x80, 0x80, 0x00, 0x10, + 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x02, 0x40, 0x02, 0x40, 0x41, 0x10, + 0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x22, 0x03, 0x0D, 0x00, 0x41, 0xA8, + 0x80, 0x80, 0x80, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, + 0x7F, 0x21, 0x04, 0x0C, 0x01, 0x0B, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02, + 0x10, 0x41, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x41, 0x10, 0x6A, + 0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, 0x00, 0x21, 0x04, 0x20, + 0x03, 0x41, 0x04, 0x6A, 0x41, 0x00, 0x2F, 0x00, 0x91, 0x80, 0x80, 0x80, + 0x00, 0x3B, 0x00, 0x00, 0x20, 0x03, 0x41, 0x00, 0x28, 0x00, 0x8D, 0x80, + 0x80, 0x80, 0x00, 0x36, 0x00, 0x00, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02, + 0x00, 0x41, 0x93, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x10, 0x82, 0x80, + 0x80, 0x80, 0x00, 0x1A, 0x20, 0x03, 0x10, 0x83, 0x80, 0x80, 0x80, 0x00, + 0x0B, 0x20, 0x02, 0x41, 0x20, 0x6A, 0x24, 0x80, 0x80, 0x80, 0x80, 0x00, + 0x20, 0x04, 0x0B, 0x0B, 0x40, 0x01, 0x00, 0x41, 0x00, 0x0B, 0x3A, 0x62, + 0x75, 0x66, 0x20, 0x70, 0x74, 0x72, 0x3A, 0x20, 0x25, 0x70, 0x0A, 0x00, + 0x31, 0x32, 0x33, 0x34, 0x0A, 0x00, 0x62, 0x75, 0x66, 0x3A, 0x20, 0x25, + 0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, + 0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x20, 0x62, 0x75, + 0x66, 0x20, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64, 0x00 +}; diff --git a/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/wamr_lib.c b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/wamr_lib.c new file mode 100644 index 000000000..a2c639e80 --- /dev/null +++ b/product-mini/platforms/zephyr/user-mode/lib-wamr-zephyr/wamr_lib.c @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include +#include "bh_platform.h" +#include "bh_assert.h" +#include "bh_log.h" +#include "bh_queue.h" +#include "wasm_export.h" +#if defined(BUILD_TARGET_RISCV64_LP64) || defined(BUILD_TARGET_RISCV32_ILP32) +#include "test_wasm_riscv64.h" +#else +#include "test_wasm.h" +#endif /* end of BUILD_TARGET_RISCV64_LP64 || BUILD_TARGET_RISCV32_ILP32 */ + +#if defined(BUILD_TARGET_RISCV64_LP64) || defined(BUILD_TARGET_RISCV32_ILP32) +#define CONFIG_GLOBAL_HEAP_BUF_SIZE 5120 +#define CONFIG_APP_STACK_SIZE 512 +#define CONFIG_APP_HEAP_SIZE 512 +#else /* else of BUILD_TARGET_RISCV64_LP64 || BUILD_TARGET_RISCV32_ILP32 */ +#define CONFIG_GLOBAL_HEAP_BUF_SIZE WASM_GLOBAL_HEAP_SIZE +#define CONFIG_APP_STACK_SIZE 8192 +#define CONFIG_APP_HEAP_SIZE 8192 +#endif /* end of BUILD_TARGET_RISCV64_LP64 || BUILD_TARGET_RISCV32_ILP32 */ + +static int app_argc; +static char **app_argv; + +/** + * Find the unique main function from a WASM module instance + * and execute that function. + * + * @param module_inst the WASM module instance + * @param argc the number of arguments + * @param argv the arguments array + * + * @return true if the main function is called, false otherwise. + */ +bool +wasm_application_execute_main(wasm_module_inst_t module_inst, int argc, + char *argv[]); + +static void * +app_instance_main(wasm_module_inst_t module_inst) +{ + const char *exception; + wasm_function_inst_t func; + wasm_exec_env_t exec_env; + unsigned argv[2] = { 0 }; + + if (wasm_runtime_lookup_function(module_inst, "main") + || wasm_runtime_lookup_function(module_inst, "__main_argc_argv")) { + LOG_VERBOSE("Calling main function\n"); + wasm_application_execute_main(module_inst, app_argc, app_argv); + } + else if ((func = wasm_runtime_lookup_function(module_inst, "app_main"))) { + exec_env = + wasm_runtime_create_exec_env(module_inst, CONFIG_APP_HEAP_SIZE); + if (!exec_env) { + os_printf("Create exec env failed\n"); + return NULL; + } + + LOG_VERBOSE("Calling app_main function\n"); + wasm_runtime_call_wasm(exec_env, func, 0, argv); + + if (!wasm_runtime_get_exception(module_inst)) { + os_printf("result: 0x%x\n", argv[0]); + } + + wasm_runtime_destroy_exec_env(exec_env); + } + else { + os_printf("Failed to lookup function main or app_main to call\n"); + return NULL; + } + + if ((exception = wasm_runtime_get_exception(module_inst))) + os_printf("%s\n", exception); + + return NULL; +} + +#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0 +static char global_heap_buf[CONFIG_GLOBAL_HEAP_BUF_SIZE] = { 0 }; +#endif + +void +iwasm_main(void *arg1, void *arg2, void *arg3) +{ + int start, end; + start = k_uptime_get_32(); + uint8 *wasm_file_buf = NULL; + uint32 wasm_file_size; + wasm_module_t wasm_module = NULL; + wasm_module_inst_t wasm_module_inst = NULL; + RuntimeInitArgs init_args; + char error_buf[128]; +#if WASM_ENABLE_LOG != 0 + int log_verbose_level = 2; +#endif + + (void)arg1; + (void)arg2; + (void)arg3; + + os_printf("User mode thread: start\n"); + + memset(&init_args, 0, sizeof(RuntimeInitArgs)); + +#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0 + 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); +#elif (defined(CONFIG_COMMON_LIBC_MALLOC) \ + && CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE != 0) \ + || defined(CONFIG_NEWLIB_LIBC) + init_args.mem_alloc_type = Alloc_With_System_Allocator; +#else +#error "memory allocation scheme is not defined." +#endif + + /* initialize runtime environment */ + if (!wasm_runtime_full_init(&init_args)) { + printf("Init runtime environment failed.\n"); + return; + } + +#if WASM_ENABLE_LOG != 0 + bh_log_set_verbose_level(log_verbose_level); +#endif + + /* load WASM byte buffer from byte buffer of include file */ + wasm_file_buf = (uint8 *)wasm_test_file; + wasm_file_size = sizeof(wasm_test_file); + + /* load WASM module */ + if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, + error_buf, sizeof(error_buf)))) { + printf("%s\n", error_buf); + goto fail1; + } + + /* instantiate the module */ + if (!(wasm_module_inst = wasm_runtime_instantiate( + wasm_module, CONFIG_APP_STACK_SIZE, CONFIG_APP_HEAP_SIZE, + error_buf, sizeof(error_buf)))) { + printf("%s\n", error_buf); + goto fail2; + } + + /* invoke the main function */ + app_instance_main(wasm_module_inst); + + /* destroy the module instance */ + wasm_runtime_deinstantiate(wasm_module_inst); + +fail2: + /* unload the module */ + wasm_runtime_unload(wasm_module); + +fail1: + /* destroy runtime environment */ + wasm_runtime_destroy(); + + end = k_uptime_get_32(); + + os_printf("User mode thread: elapsed %d\n", (end - start)); +} diff --git a/product-mini/platforms/zephyr/user-mode/prj.conf b/product-mini/platforms/zephyr/user-mode/prj.conf new file mode 100644 index 000000000..023a3caa2 --- /dev/null +++ b/product-mini/platforms/zephyr/user-mode/prj.conf @@ -0,0 +1,9 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +CONFIG_USERSPACE=y +CONFIG_STACK_SENTINEL=y +CONFIG_PRINTK=y +CONFIG_LOG=y +CONFIG_LOG_BUFFER_SIZE=8096 +CONFIG_THREAD_RUNTIME_STATS=y diff --git a/product-mini/platforms/zephyr/user-mode/src/main.c b/product-mini/platforms/zephyr/user-mode/src/main.c new file mode 100644 index 000000000..4f51e10d3 --- /dev/null +++ b/product-mini/platforms/zephyr/user-mode/src/main.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include + +#include +#include + +#define MAIN_THREAD_STACK_SIZE 2048 +#define MAIN_THREAD_PRIORITY 5 + +static struct k_thread iwasm_user_mode_thread; +K_THREAD_STACK_DEFINE(iwasm_user_mode_thread_stack, MAIN_THREAD_STACK_SIZE); + +extern struct k_mem_partition z_libc_partition; +K_APPMEM_PARTITION_DEFINE(wamr_partition); + +/* WAMR memory domain */ +struct k_mem_domain wamr_domain; + +extern void +iwasm_main(void *arg1, void *arg2, void *arg3); + +bool +iwasm_user_mode(void) +{ + struct k_mem_partition *wamr_domain_parts[] = { &wamr_partition, + &z_libc_partition }; + + printk("wamr_partition start addr: %ld, size: %zu\n", wamr_partition.start, + wamr_partition.size); + + /* Initialize the memory domain with single WAMR partition */ + if (k_mem_domain_init(&wamr_domain, 2, wamr_domain_parts) != 0) { + printk("Failed to initialize memory domain.\n"); + return false; + } + + k_tid_t tid = + k_thread_create(&iwasm_user_mode_thread, iwasm_user_mode_thread_stack, + MAIN_THREAD_STACK_SIZE, iwasm_main, NULL, NULL, NULL, + MAIN_THREAD_PRIORITY, K_USER, K_FOREVER); + + /* Grant WAMR memory domain access to user mode thread */ + if (k_mem_domain_add_thread(&wamr_domain, tid) != 0) { + printk("Failed to add memory domain to thread.\n"); + return false; + } + +#if KERNEL_VERSION_NUMBER < 0x040000 /* version 4.0.0 */ + /* k_thread_start is a legacy API for compatibility. Modern Zephyr threads + * are initialized in the "sleeping" state and do not need special handling + * for "start".*/ + k_thread_start(tid); +#else + /* wakes up thread from sleeping */ + k_wakeup(tid); +#endif + + return tid ? true : false; +} + +#if KERNEL_VERSION_NUMBER < 0x030400 /* version 3.4.0 */ +void +main(void) +{ + iwasm_user_mode(); +} +#else +int +main(void) +{ + iwasm_user_mode(); + return 0; +} +#endif From 9989b1cc1bdfec48bfc114174ef62d997590661a Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Mon, 6 Jan 2025 11:36:11 +0800 Subject: [PATCH 090/105] [fuzzing] Use software bound-check during fuzzing (#4003) * Update CMakeLists.txt of fuzzing - enable software bound-check - enable wasi - disable libc builtin and multiple modules * Fix off-by-one error in result offset calculation for function calls --- core/iwasm/interpreter/wasm_interp_fast.c | 7 ++++--- tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 531468282..f44644e45 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -1670,7 +1670,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, { uint32 ret_idx; WASMFuncType *func_type; - uint32 off, ret_offset; + int32 off; + uint32 ret_offset; uint8 *ret_types; if (cur_func->is_import_func) func_type = cur_func->u.func_import->func_type; @@ -1682,9 +1683,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, ret_offset = prev_frame->ret_offset; for (ret_idx = 0, - off = sizeof(int16) * (func_type->result_count - 1); + off = (int32)sizeof(int16) * (func_type->result_count - 1); ret_idx < func_type->result_count; - ret_idx++, off -= sizeof(int16)) { + ret_idx++, off -= (int32)sizeof(int16)) { if (ret_types[ret_idx] == VALUE_TYPE_I64 || ret_types[ret_idx] == VALUE_TYPE_F64) { PUT_I64_TO_ADDR(prev_frame->lp + ret_offset, diff --git a/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt b/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt index 356869d17..6177d27e7 100644 --- a/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt +++ b/tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt @@ -66,7 +66,7 @@ if (NOT DEFINED WAMR_BUILD_JIT) endif () if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) - # Enable libc builtin support by default + # Disable libc builtin support by default set (WAMR_BUILD_LIBC_BUILTIN 0) endif () @@ -81,7 +81,7 @@ if (NOT DEFINED WAMR_BUILD_FAST_INTERP) endif () if (NOT DEFINED WAMR_BUILD_MULTI_MODULE) - # Enable multiple modules + # Disable multiple modules set (WAMR_BUILD_MULTI_MODULE 0) endif () @@ -116,6 +116,10 @@ if (WAMR_BUILD_DEBUG_INTERP EQUAL 1) set (WAMR_BUILD_SIMD 0) endif () +# sanitizer may use kHandleSignalExclusive to handle SIGSEGV +# like `UBSAN_OPTIONS=handle_segv=2:...` +set (WAMR_DISABLE_HW_BOUND_CHECK 1) + set (REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..) message([ceith]:REPO_ROOT_DIR, ${REPO_ROOT_DIR}) From a653746b7bea358251805b98e3ea824152659608 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:55:43 +0800 Subject: [PATCH 091/105] Check whether related table has funcref elem in opcode call_indirect (#3999) * check whether table has funcref elem in call_indirect * check whether table has funcref elem in call_indirect when gc is enabled --- core/iwasm/interpreter/wasm_loader.c | 41 +++++++++++++++++++++++ core/iwasm/interpreter/wasm_mini_loader.c | 9 +++++ 2 files changed, 50 insertions(+) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 533538adc..8065173a4 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -12103,6 +12103,10 @@ re_scan: { int32 idx; WASMFuncType *func_type; + uint32 tbl_elem_type; +#if WASM_ENABLE_GC != 0 + WASMRefType *elem_ref_type = NULL; +#endif read_leb_uint32(p, p_end, type_idx); #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 @@ -12125,6 +12129,43 @@ re_scan: error_buf_size)) { goto fail; } + tbl_elem_type = + table_idx < module->import_table_count + ? module->import_tables[table_idx] + .u.table.table_type.elem_type + : module->tables[table_idx - module->import_table_count] + .table_type.elem_type; + +#if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0 + if (tbl_elem_type != VALUE_TYPE_FUNCREF) { + set_error_buf_v(error_buf, error_buf_size, + "type mismatch: instruction requires table " + "of functions but table %u has externref", + table_idx); + goto fail; + } +#elif WASM_ENABLE_GC != 0 + /* Table element must match type ref null func */ + elem_ref_type = + table_idx < module->import_table_count + ? module->import_tables[table_idx] + .u.table.table_type.elem_ref_type + : module->tables[table_idx - module->import_table_count] + .table_type.elem_ref_type; + + if (!wasm_reftype_is_subtype_of( + tbl_elem_type, elem_ref_type, REF_TYPE_FUNCREF, NULL, + module->types, module->type_count)) { + set_error_buf_v(error_buf, error_buf_size, + "type mismatch: instruction requires " + "reference type t match type ref null func" + "in table %u", + table_idx); + goto fail; + } +#else + (void)tbl_elem_type; +#endif #if WASM_ENABLE_FAST_INTERP != 0 /* we need to emit before arguments */ diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index e83a20045..f994f0def 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -6700,6 +6700,15 @@ re_scan: goto fail; } + bh_assert( + (table_idx < module->import_table_count + ? module->import_tables[table_idx] + .u.table.table_type.elem_type + : module + ->tables[table_idx - module->import_table_count] + .table_type.elem_type) + == VALUE_TYPE_FUNCREF); + #if WASM_ENABLE_FAST_INTERP != 0 /* we need to emit before arguments */ emit_uint32(loader_ctx, type_idx); From 02683d2eed275e4207bcd7fd964bc62c93806a15 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 9 Jan 2025 13:11:25 +0800 Subject: [PATCH 092/105] Improve stack consistency by ensuring sufficient space for dummy offsets (#4011) One more corner case: if the `frame_offset` increases and becomes equal to the `frame_offset_boundary` after the last assignment within the for loop. --- core/iwasm/interpreter/wasm_loader.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 8065173a4..bb34e29f0 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -11228,21 +11228,23 @@ re_scan: uint32 cell_num = wasm_value_type_cell_num(func_type->types[i]); if (i >= available_params) { + /* make sure enough space */ + if (loader_ctx->p_code_compiled == NULL) { + loader_ctx->frame_offset += cell_num; + if (!check_offset_push(loader_ctx, error_buf, + error_buf_size)) + goto fail; + /* for following dummy value assignemnt */ + loader_ctx->frame_offset -= cell_num; + } + /* If there isn't enough data on stack, push a dummy * offset to keep the stack consistent with * frame_ref. * Since the stack is already in polymorphic state, * the opcode will not be executed, so the dummy * offset won't cause any error */ - uint32 n; - - for (n = 0; n < cell_num; n++) { - if (loader_ctx->p_code_compiled == NULL) { - if (!check_offset_push(loader_ctx, - error_buf, - error_buf_size)) - goto fail; - } + for (uint32 n = 0; n < cell_num; n++) { *loader_ctx->frame_offset++ = 0; } } From 902f7d26310b2b2832dddb3a3ca64141fcfc86f7 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 9 Jan 2025 13:13:30 +0800 Subject: [PATCH 093/105] Add documentation regarding security issues and the status of Wasm proposals (#3972) Add documentation regarding security issues and the status of Wasm proposals. --- doc/security_need_to_know.md | 33 +++++++++++++ doc/stability_wasm_proposals.md | 82 +++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 doc/security_need_to_know.md create mode 100644 doc/stability_wasm_proposals.md diff --git a/doc/security_need_to_know.md b/doc/security_need_to_know.md new file mode 100644 index 000000000..b2b358983 --- /dev/null +++ b/doc/security_need_to_know.md @@ -0,0 +1,33 @@ +# About security issues + +This document aims to explain the process of identifying a security issue and the steps for managing a security issue. + +## identifying a security issue + +It is commonly stated that a security issue is an issue that: + +- Exposes sensitive information to unauthorized parties. +- Allows unauthorized modification of data or system state. +- Affects the availability of the system or its services. +- Permits unauthorized access to the system. +- Enables users to perform actions they should not be able to. +- Allows users to deny actions they have performed. + +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). + +> [!NOTE] +> keep updating this document as the project evolves. + +## reporting a security issue + +Follow the [same guidelines](https://bytecodealliance.org/security) as other projects within the Bytecode Alliance. + +## 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](https://github.com/bytecodealliance/rfcs/blob/main/accepted/vulnerability-response-runbook.md) for the subsequent steps to take. diff --git a/doc/stability_wasm_proposals.md b/doc/stability_wasm_proposals.md new file mode 100644 index 000000000..98617d15b --- /dev/null +++ b/doc/stability_wasm_proposals.md @@ -0,0 +1,82 @@ +# Wasm Proposals + +This document is intended to describe the current status of WebAssembly proposals and WASI proposals in WAMR. + +Only track proposals that are followed in the [WebAssembly proposals](https://github.com/WebAssembly/proposals) and [WASI proposals](https://github.com/WebAssembly/WASI/blob/main/Proposals.md). + +Normally, the document tracks proposals that are in phase 4. However, if a proposal in an earlier phase receives support, it will be added to the list below. + +The _status_ represents the configuration _product-mini/platforms/linux/CMakeLists.txt_. There may be minor differences between the top-level CMakeLists and platform-specific CMakeLists. + +Users can turn those features on or off by using compilation options. If a relevant compilation option is not available(`N/A`), it indicates that the feature is permanently enabled. + +## On-by-default Wasm Proposals + +| Proposal | >= Phase 4 | Compilation Option | +| ------------------------------------- | ---------- | ------------------------ | +| Bulk memory operations | Yes | `WAMR_BUILD_BULK_MEMORY` | +| Extended Constant Expressions | Yes | N/A | +| Fixed-width SIMD[^1] | Yes | `WAMR_BUILD_SIMD` | +| 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 | + +[^1]: llvm-jit and aot only. + +## Off-by-default Wasm Proposals + +| Proposal | >= Phase 4 | Compilation Option | +| ----------------------------- | ---------- | -------------------------- | +| Garbage collection | Yes | `WAMR_BUILD_GC` | +| Legacy Exception handling[^2] | No | `WAMR_BUILD_EXCE_HANDLING` | +| Memory64 | Yes | `WAMR_BUILD_MEMORY64` | +| Multiple memories[^3] | Yes | `WAMR_BUILD_MULTI_MEMORY` | +| Reference-Typed Strings | No | `WAMR_BUILD_STRINGREF` | +| Tail call | Yes | `WAMR_BUILD_TAIL_CALL` | +| Thread[^4] | Yes | `WAMR_BUILD_SHARED_MEMORY` | +| Typed Function References | Yes | `WAMR_BUILD_GC` | + +[^2]: + interpreter only. [a legacy version](https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/legacy/Exceptions.md). + This proposal is currently also known as the "legacy proposal" and still + supported in the web, but can be deprecated in future and the use of + this proposal is discouraged. + +[^3]: interpreter only +[^4]: `WAMR_BUILD_LIB_PTHREAD` can also be used to enable + +## Unimplemented Wasm Proposals + +| Proposal | >= Phase 4 | +| ------------------------------------------- | ---------- | +| Branch Hinting | Yes | +| Custom Annotation Syntax in the Text Format | Yes | +| Exception handling[^5] | Yes | +| Import/Export of Mutable Globals | Yes | +| JS String Builtins | Yes | +| Relaxed SIMD | Yes | + +[^5]: [up-to-date version](https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md) + +## On-by-default WASI Proposals + +| Proposal | >= Phase 4 | Compilation Option | +| -------- | ---------- | ------------------ | + +## Off-by-default WASI Proposals + +| Proposal | >= Phase 4 | Compilation Option | +| -------------------------- | ---------- | ----------------------------- | +| Machine Learning (wasi-nn) | No | `WAMR_BUILD_WASI_NN` | +| Threads | No | `WAMR_BUILD_LIB_WASI_THREADS` | + +## Unimplemented WASI Proposals + +| Proposal | >= Phase 4 | +| -------- | ---------- | + +## WAMR features + +WAMR offers a variety of customizable features to create a highly efficient runtime. For more details, please refer to [build_wamr](./build_wamr.md). From 53da420c414e6c7b2a871b72c58b1f645b8bc0ee Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Mon, 13 Jan 2025 07:09:04 +0800 Subject: [PATCH 094/105] Enable shrunk memory by default and add related configurations (#4008) - Enable shrunk memory by default and add related configurations - Improve error messages for memory access alignment checks - Add documentation for WAMR shrunk memory build option - Update NuttX workflow to disable shrunk memory build option --- .github/workflows/spec_test_on_nuttx.yml | 2 +- build-scripts/config_common.cmake | 12 + core/config.h | 4 + core/iwasm/interpreter/wasm_loader.c | 21 +- core/iwasm/interpreter/wasm_mini_loader.c | 15 +- doc/build_wamr.md | 106 +++++---- doc/memory_tune.md | 1 + .../spec-test-script/ignore_cases.patch | 225 ++++++++---------- .../multi_module_ignore_cases.patch | 53 ----- .../spec-test-script/runtest.py | 3 +- tests/wamr-test-suites/test_wamr.sh | 41 ++-- wamr-compiler/CMakeLists.txt | 6 + 12 files changed, 216 insertions(+), 273 deletions(-) diff --git a/.github/workflows/spec_test_on_nuttx.yml b/.github/workflows/spec_test_on_nuttx.yml index b6ca914fb..7f1169583 100644 --- a/.github/workflows/spec_test_on_nuttx.yml +++ b/.github/workflows/spec_test_on_nuttx.yml @@ -208,7 +208,7 @@ jobs: if: contains(matrix.wamr_test_option.mode, 'aot') working-directory: apps/interpreters/wamr/wamr/wamr-compiler run: | - cmake -Bbuild . + cmake -B build -DWAMR_BUILD_SHRUNK_MEMORY=0 -S . cmake --build build # the nuttx version we use for xtensa requires esptool.py newer than diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index 48c5f7be4..6a30bfb7b 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -162,6 +162,11 @@ if (WAMR_BUILD_LINUX_PERF EQUAL 1) endif () endif () +if (NOT DEFINED WAMR_BUILD_SHRUNK_MEMORY) + # Enable shrunk memory by default + set (WAMR_BUILD_SHRUNK_MEMORY 1) +endif () + ######################################## message ("-- Build Configurations:") @@ -599,3 +604,10 @@ endif() if (NOT WAMR_BUILD_SANITIZER STREQUAL "") message (" Sanitizer ${WAMR_BUILD_SANITIZER} enabled") endif () +if (WAMR_BUILD_SHRUNK_MEMORY EQUAL 1) + add_definitions (-DWASM_ENABLE_SHRUNK_MEMORY=1) + message (" Shrunk memory enabled") +else () + add_definitions (-DWASM_ENABLE_SHRUNK_MEMORY=0) + message (" Shrunk memory disabled") +endif () diff --git a/core/config.h b/core/config.h index f08d828d2..27d26f093 100644 --- a/core/config.h +++ b/core/config.h @@ -698,4 +698,8 @@ #define WASM_ENABLE_SHARED_HEAP 0 #endif +#ifndef WASM_ENABLE_SHRUNK_MEMORY +#define WASM_ENABLE_SHRUNK_MEMORY 1 +#endif + #endif /* end of _CONFIG_H_ */ diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index bb34e29f0..12f4aff75 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -6156,9 +6156,7 @@ load_from_sections(WASMModule *module, WASMSection *sections, } if (!module->possible_memory_grow) { - WASMMemoryImport *memory_import; - WASMMemory *memory; - +#if WASM_ENABLE_SHRUNK_MEMORY != 0 if (aux_data_end_global && aux_heap_base_global && aux_stack_top_global) { uint64 init_memory_size; @@ -6168,7 +6166,8 @@ load_from_sections(WASMModule *module, WASMSection *sections, * valid range of uint32 */ if (shrunk_memory_size <= UINT32_MAX) { if (module->import_memory_count) { - memory_import = &module->import_memories[0].u.memory; + WASMMemoryImport *memory_import = + &module->import_memories[0].u.memory; init_memory_size = (uint64)memory_import->mem_type.num_bytes_per_page * memory_import->mem_type.init_page_count; @@ -6183,7 +6182,7 @@ load_from_sections(WASMModule *module, WASMSection *sections, } if (module->memory_count) { - memory = &module->memories[0]; + WASMMemory *memory = &module->memories[0]; init_memory_size = (uint64)memory->num_bytes_per_page * memory->init_page_count; if (shrunk_memory_size <= init_memory_size) { @@ -6196,10 +6195,12 @@ load_from_sections(WASMModule *module, WASMSection *sections, } } } +#endif /* WASM_ENABLE_SHRUNK_MEMORY != 0 */ #if WASM_ENABLE_MULTI_MODULE == 0 if (module->import_memory_count) { - memory_import = &module->import_memories[0].u.memory; + WASMMemoryImport *memory_import = + &module->import_memories[0].u.memory; /* Only resize the memory to one big page if num_bytes_per_page is * in valid range of uint32 */ if (memory_import->mem_type.init_page_count < DEFAULT_MAX_PAGES) { @@ -6215,7 +6216,7 @@ load_from_sections(WASMModule *module, WASMSection *sections, } } if (module->memory_count) { - memory = &module->memories[0]; + WASMMemory *memory = &module->memories[0]; /* Only resize(shrunk) the memory size if num_bytes_per_page is in * valid range of uint32 */ if (memory->init_page_count < DEFAULT_MAX_PAGES) { @@ -10021,7 +10022,8 @@ check_memory_access_align(uint8 opcode, uint32 align, char *error_buf, bh_assert(opcode >= WASM_OP_I32_LOAD && opcode <= WASM_OP_I64_STORE32); if (align > mem_access_aligns[opcode - WASM_OP_I32_LOAD]) { set_error_buf(error_buf, error_buf_size, - "alignment must not be larger than natural"); + "invalid memop flags: alignment must not be larger " + "than natural"); return false; } return true; @@ -10060,7 +10062,8 @@ check_simd_memory_access_align(uint8 opcode, uint32 align, char *error_buf, && align > mem_access_aligns_load_lane[opcode - SIMD_v128_load8_lane])) { set_error_buf(error_buf, error_buf_size, - "alignment must not be larger than natural"); + "invalid memop flags: alignment must not be larger " + "than natural"); return false; } diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index f994f0def..df4d818a3 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -2958,9 +2958,7 @@ load_from_sections(WASMModule *module, WASMSection *sections, } if (!module->possible_memory_grow) { - WASMMemoryImport *memory_import; - WASMMemory *memory; - +#if WASM_ENABLE_SHRUNK_MEMORY != 0 if (aux_data_end_global && aux_heap_base_global && aux_stack_top_global) { uint64 init_memory_size; @@ -2970,7 +2968,8 @@ load_from_sections(WASMModule *module, WASMSection *sections, * valid range of uint32 */ if (shrunk_memory_size <= UINT32_MAX) { if (module->import_memory_count) { - memory_import = &module->import_memories[0].u.memory; + WASMMemoryImport *memory_import = + &module->import_memories[0].u.memory; init_memory_size = (uint64)memory_import->mem_type.num_bytes_per_page * memory_import->mem_type.init_page_count; @@ -2985,7 +2984,7 @@ load_from_sections(WASMModule *module, WASMSection *sections, } if (module->memory_count) { - memory = &module->memories[0]; + WASMMemory *memory = &module->memories[0]; init_memory_size = (uint64)memory->num_bytes_per_page * memory->init_page_count; if (shrunk_memory_size <= init_memory_size) { @@ -2998,9 +2997,11 @@ load_from_sections(WASMModule *module, WASMSection *sections, } } } +#endif /* WASM_ENABLE_SHRUNK_MEMORY != 0 */ if (module->import_memory_count) { - memory_import = &module->import_memories[0].u.memory; + WASMMemoryImport *memory_import = + &module->import_memories[0].u.memory; if (memory_import->mem_type.init_page_count < DEFAULT_MAX_PAGES) { memory_import->mem_type.num_bytes_per_page *= memory_import->mem_type.init_page_count; @@ -3014,7 +3015,7 @@ load_from_sections(WASMModule *module, WASMSection *sections, } if (module->memory_count) { - memory = &module->memories[0]; + WASMMemory *memory = &module->memories[0]; if (memory->init_page_count < DEFAULT_MAX_PAGES) { memory->num_bytes_per_page *= memory->init_page_count; if (memory->init_page_count > 0) diff --git a/doc/build_wamr.md b/doc/build_wamr.md index abf663177..cde884457 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -20,7 +20,7 @@ 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. -#### **Configure platform and architecture** +### **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). @@ -34,7 +34,7 @@ The script `runtime_lib.cmake` defines a number of variables for configuring the cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM ``` -#### **Configure interpreters** +### **Configure interpreters** - **WAMR_BUILD_INTERP**=1/0: enable or disable WASM interpreter @@ -42,14 +42,14 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM NOTE: the fast interpreter runs ~2X faster than classic interpreter, but consumes about 2X memory to hold the pre-compiled code. -#### **Configure AOT and JITs** +### **Configure AOT and JITs** - **WAMR_BUILD_AOT**=1/0, enable AOT or not, default to enable if not set - **WAMR_BUILD_JIT**=1/0, enable LLVM JIT or not, default to disable if not set - **WAMR_BUILD_FAST_JIT**=1/0, enable Fast JIT or not, default to disable if not set - **WAMR_BUILD_FAST_JIT**=1 and **WAMR_BUILD_JIT**=1, enable Multi-tier JIT, default to disable if not set -#### **Configure LIBC** +### **Configure LIBC** - **WAMR_BUILD_LIBC_BUILTIN**=1/0, build the built-in libc subset for WASM app, default to enable if not set @@ -59,98 +59,98 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM > Note: for platform which doesn't support **WAMR_BUILD_LIBC_WASI**, e.g. Windows, developer can try using **WAMR_BUILD_LIBC_UVWASI**. -#### **Enable Multi-Module feature** +### **Enable Multi-Module feature** - **WAMR_BUILD_MULTI_MODULE**=1/0, default to disable if not set > Note: See [Multiple Modules as Dependencies](./multi_module.md) for more details. -#### **Enable WASM mini loader** +### **Enable WASM mini loader** - **WAMR_BUILD_MINI_LOADER**=1/0, default to disable if not set > Note: the mini loader doesn't check the integrity of the WASM binary file, developer must ensure that the WASM file is well-formed. -#### **Enable shared memory feature** +### **Enable shared memory feature** - **WAMR_BUILD_SHARED_MEMORY**=1/0, default to disable if not set -#### **Enable bulk memory feature** +### **Enable bulk memory feature** - **WAMR_BUILD_BULK_MEMORY**=1/0, default to disable if not set -#### **Enable memory64 feature** +### **Enable memory64 feature** - **WAMR_BUILD_MEMORY64**=1/0, default to disable if not set > Note: Currently, the memory64 feature is only supported in classic interpreter running mode and AOT mode. -#### **Enable thread manager** +### **Enable thread manager** - **WAMR_BUILD_THREAD_MGR**=1/0, default to disable if not set -#### **Enable lib-pthread** +### **Enable lib-pthread** - **WAMR_BUILD_LIB_PTHREAD**=1/0, default to disable if not set > Note: The dependent feature of lib pthread such as the `shared memory` and `thread manager` will be enabled automatically. > See [WAMR pthread library](./pthread_library.md) for more details. -#### **Enable lib-pthread-semaphore** +### **Enable lib-pthread-semaphore** - **WAMR_BUILD_LIB_PTHREAD_SEMAPHORE**=1/0, default to disable if not set > Note: This feature depends on `lib-pthread`, it will be enabled automatically if this feature is enabled. -#### **Enable lib wasi-threads** +### **Enable lib wasi-threads** - **WAMR_BUILD_LIB_WASI_THREADS**=1/0, default to disable if not set > Note: The dependent feature of lib wasi-threads such as the `shared memory` and `thread manager` will be enabled automatically. > See [wasi-threads](./pthread_impls.md#wasi-threads-new) and [Introduction to WAMR WASI threads](https://bytecodealliance.github.io/wamr.dev/blog/introduction-to-wamr-wasi-threads) for more details. -#### **Enable lib wasi-nn** +### **Enable lib wasi-nn** - **WAMR_BUILD_WASI_NN**=1/0, default to disable if not set > Note: See [WASI-NN](../core/iwasm/libraries/wasi-nn) for more details. -#### **Enable lib wasi-nn GPU mode** +### **Enable lib wasi-nn GPU mode** - **WAMR_BUILD_WASI_NN_ENABLE_GPU**=1/0, default to disable if not set -#### **Enable lib wasi-nn external delegate mode** +### **Enable lib wasi-nn external delegate mode** - **WAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE**=1/0, default to disable if not set - **WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH**=Path to the external delegate shared library (e.g. `libedgetpu.so.1.0` for Coral USB) -#### **Enable lib wasi-nn with `wasi_ephemeral_nn` module support** +### **Enable lib wasi-nn with `wasi_ephemeral_nn` module support** - **WAMR_BUILD_WASI_EPHEMERAL_NN**=1/0, default to disable if not set -#### **Disable boundary check with hardware trap** +### **Disable boundary check with hardware trap** - **WAMR_DISABLE_HW_BOUND_CHECK**=1/0, default to enable if not set and supported by platform > Note: by default only platform [linux/darwin/android/windows/vxworks 64-bit](https://github.com/bytecodealliance/wasm-micro-runtime/blob/5fb5119239220b0803e7045ca49b0a29fe65e70e/core/shared/platform/linux/platform_internal.h#L81) will enable the boundary check with hardware trap feature, for 32-bit platforms it's automatically disabled even when the flag is set to 0, and the wamrc tool will generate AOT code without boundary check instructions in all 64-bit targets except SGX to improve performance. The boundary check includes linear memory access boundary and native stack access boundary, if `WAMR_DISABLE_STACK_HW_BOUND_CHECK` below isn't set. -#### **Disable native stack boundary check with hardware trap** +### **Disable native stack boundary check with hardware trap** - **WAMR_DISABLE_STACK_HW_BOUND_CHECK**=1/0, default to enable if not set and supported by platform, same as `WAMR_DISABLE_HW_BOUND_CHECK`. > Note: When boundary check with hardware trap is disabled, or `WAMR_DISABLE_HW_BOUND_CHECK` is set to 1, the native stack boundary check with hardware trap will be disabled too, no matter what value is set to `WAMR_DISABLE_STACK_HW_BOUND_CHECK`. And when boundary check with hardware trap is enabled, the status of this feature is set according to the value of `WAMR_DISABLE_STACK_HW_BOUND_CHECK`. -#### **Disable async wakeup of blocking operation** +### **Disable async wakeup of blocking operation** - **WAMR_DISABLE_WAKEUP_BLOCKING_OP**=1/0, default to enable if supported by the platform > Note: The feature helps async termination of blocking threads. If you disable it, the runtime can wait for termination of blocking threads possibly forever. -#### **Enable tail call feature** +### **Enable tail call feature** - **WAMR_BUILD_TAIL_CALL**=1/0, default to disable if not set -#### **Enable 128-bit SIMD feature** +### **Enable 128-bit SIMD feature** - **WAMR_BUILD_SIMD**=1/0, default to enable if not set > Note: only supported in AOT mode x86-64 target. -#### **Enable Exception Handling** +### **Enable Exception Handling** - **WAMR_BUILD_EXCE_HANDLING**=1/0, default to disable if not set > Note: Currently, the exception handling feature is only supported in classic interpreter running mode. -#### **Enable Garbage Collection** +### **Enable Garbage Collection** - **WAMR_BUILD_GC**=1/0, default to disable if not set -#### **Configure Debug** +### **Configure Debug** - **WAMR_BUILD_CUSTOM_NAME_SECTION**=1/0, load the function name from custom name section, default to disable if not set -#### **Enable AOT stack frame feature** +### **Enable AOT stack frame feature** - **WAMR_BUILD_AOT_STACK_FRAME**=1/0, default to disable if not set > Note: if it is enabled, the AOT or JIT stack frames (like stack frame of classic interpreter but only necessary data is committed) will be created for AOT or JIT mode in function calls. And please add `--enable-dump-call-stack` option to wamrc during compiling AOT module. -#### **Enable dump call stack feature** +### **Enable dump call stack feature** - **WAMR_BUILD_DUMP_CALL_STACK**=1/0, default to disable if not set > Note: if it is enabled, the call stack will be dumped when exception occurs. @@ -158,14 +158,14 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM > - For interpreter mode, the function names are firstly extracted from *custom name section*, if this section doesn't exist or the feature is not enabled, then the name will be extracted from the import/export sections > - For AOT/JIT mode, the function names are extracted from import/export section, please export as many functions as possible (for `wasi-sdk` you can use `-Wl,--export-all`) when compiling wasm module, and add `--enable-dump-call-stack --emit-custom-sections=name` option to wamrc during compiling AOT module. -#### **Enable memory profiling (Experiment)** +### **Enable memory profiling (Experiment)** - **WAMR_BUILD_MEMORY_PROFILING**=1/0, default to disable if not set > Note: if it is enabled, developer can use API `void wasm_runtime_dump_mem_consumption(wasm_exec_env_t exec_env)` to dump the memory consumption info. Currently we only profile the memory consumption of module, module_instance and exec_env, the memory consumed by other components such as `wasi-ctx`, `multi-module` and `thread-manager` are not included. > Also refer to [Memory usage estimation for a module](./memory_usage.md). -#### **Enable performance profiling (Experiment)** +### **Enable performance profiling (Experiment)** - **WAMR_BUILD_PERF_PROFILING**=1/0, default to disable if not set > Note: if it is enabled, developer can use API `void wasm_runtime_dump_perf_profiling(wasm_module_inst_t module_inst)` to dump the performance consumption info. Currently we only profile the performance consumption of each WASM function. @@ -173,24 +173,24 @@ Currently we only profile the memory consumption of module, module_instance and > Also refer to [Tune the performance of running wasm/aot file](./perf_tune.md). -#### **Enable the global heap** +### **Enable the global heap** - **WAMR_BUILD_GLOBAL_HEAP_POOL**=1/0, default to disable if not set for all *iwasm* applications, except for the platforms Alios and Zephyr. > **WAMR_BUILD_GLOBAL_HEAP_POOL** is used in the *iwasm* applications provided in the directory `product-mini`. When writing your own host application using WAMR, if you want to use a global heap and allocate memory from it, you must set the initialization argument `mem_alloc_type` to `Alloc_With_Pool`. > The global heap is defined in the documentation [Memory model and memory usage tunning](memory_tune.md). -#### **Set the global heap size** +### **Set the global heap size** - **WAMR_BUILD_GLOBAL_HEAP_SIZE**=n, default to 10 MB (10485760) if not set for all *iwasm* applications, except for the platforms Alios (256 kB), Riot (256 kB) and Zephyr (128 kB). > **WAMR_BUILD_GLOBAL_HEAP_SIZE** is used in the *iwasm* applications provided in the directory `product-mini`. When writing your own host application using WAMR, if you want to set the amount of memory dedicated to the global heap pool, you must set the initialization argument `mem_alloc_option.pool` with the appropriate values. > The global heap is defined in the documentation [Memory model and memory usage tunning](memory_tune.md). > Note: if `WAMR_BUILD_GLOBAL_HEAP_SIZE` is not set and the flag `WAMR_BUILD_SPEC_TEST` is set, the global heap size is equal to 300 MB (314572800), or 100 MB (104857600) when compiled for Intel SGX (Linux). -#### **Set maximum app thread stack size** +### **Set maximum app thread stack size** - **WAMR_APP_THREAD_STACK_SIZE_MAX**=n, default to 8 MB (8388608) if not set > Note: the AOT boundary check with hardware trap mechanism might consume large stack since the OS may lazily grow the stack mapping as a guard page is hit, we may use this configuration to reduce the total stack usage, e.g. -DWAMR_APP_THREAD_STACK_SIZE_MAX=131072 (128 KB). -#### **Set vprintf callback** +### **Set vprintf callback** - **WAMR_BH_VPRINTF**=, default to disable if not set > Note: if the vprintf_callback function is provided by developer, the os_printf() and os_vprintf() in Linux, Darwin, Windows, VxWorks, Android and esp-idf platforms, besides WASI Libc output will call the callback function instead of libc vprintf() function to redirect the stdout output. For example, developer can define the callback function like below outside runtime lib: > @@ -212,7 +212,7 @@ Currently we only profile the memory consumption of module, module_instance and > > and then use `cmake -DWAMR_BH_VPRINTF=my_vprintf ..` to pass the callback function, or add `BH_VPRINTF=my_vprintf` macro for the compiler, e.g. add line `add_definitions(-DBH_VPRINTF=my_vprintf)` in CMakeLists.txt. See [basic sample](../samples/basic/src/main.c) for a usage example. -#### **WAMR_BH_LOG**=, default to disable if not set +### **WAMR_BH_LOG**=, default to disable if not set > Note: if the log_callback function is provided by the developer, WAMR logs are redirected to such callback. For example: > ```C > void my_log(uint32 log_level, const char *file, int line, const char *fmt, ...) @@ -222,20 +222,20 @@ Currently we only profile the memory consumption of module, module_instance and > ``` > See [basic sample](../samples/basic/src/main.c) for a usage example. -#### **Enable reference types feature** +### **Enable reference types feature** - **WAMR_BUILD_REF_TYPES**=1/0, default to enable if not set -#### **Exclude WAMR application entry functions** +### **Exclude WAMR application entry functions** - **WAMR_DISABLE_APP_ENTRY**=1/0, default to disable if not set > Note: The WAMR application entry (`core/iwasm/common/wasm_application.c`) encapsulate some common process to instantiate, execute the wasm functions and print the results. Some platform related APIs are used in these functions, so you can enable this flag to exclude this file if your platform doesn't support those APIs. > *Don't enable this flag if you are building `product-mini`* -#### **Enable source debugging features** +### **Enable source debugging features** - **WAMR_BUILD_DEBUG_INTERP**=1/0, default to 0 if not set > Note: There are some other setup required by source debugging, please refer to [source_debugging.md](./source_debugging.md) and [WAMR source debugging basic](https://bytecodealliance.github.io/wamr.dev/blog/wamr-source-debugging-basic) for more details. -#### **Enable load wasm custom sections** +### **Enable load wasm custom sections** - **WAMR_BUILD_LOAD_CUSTOM_SECTION**=1/0, default to disable if not set > Note: By default, the custom sections are ignored. If the embedder wants to get custom sections from `wasm_module_t`, then `WAMR_BUILD_LOAD_CUSTOM_SECTION` should be enabled, and then `wasm_runtime_get_custom_section` can be used to get a custom section by name. @@ -244,29 +244,29 @@ Currently we only profile the memory consumption of module, module_instance and > For AoT file, must use `--emit-custom-sections` to specify which sections need to be emitted into AoT file, otherwise all custom sections will be ignored. -#### **Stack guard size** +### **Stack guard size** - **WAMR_BUILD_STACK_GUARD_SIZE**=n, default to N/A if not set. > Note: By default, the stack guard size is 1K (1024) or 24K (if uvwasi enabled). -#### **Disable writing the linear memory base address to x86 GS segment register** +### **Disable writing the linear memory base address to x86 GS segment register** - **WAMR_DISABLE_WRITE_GS_BASE**=1/0, default to enable if not set and supported by platform > Note: by default only platform [linux x86-64](https://github.com/bytecodealliance/wasm-micro-runtime/blob/5fb5119239220b0803e7045ca49b0a29fe65e70e/core/shared/platform/linux/platform_internal.h#L67) will enable this feature, for 32-bit platforms it's automatically disabled even when the flag is set to 0. In linux x86-64, writing the linear memory base address to x86 GS segment register may be used to speedup the linear memory access for LLVM AOT/JIT, when `--enable-segue=[]` option is added for `wamrc` or `iwasm`. > See [Enable segue optimization for wamrc when generating the aot file](./perf_tune.md#3-enable-segue-optimization-for-wamrc-when-generating-the-aot-file) for more details. -#### **User defined linear memory allocator** +### **User defined linear memory allocator** - **WAMR_BUILD_ALLOC_WITH_USAGE**=1/0, default to disable if not set > Notes: by default, the linear memory is allocated by system. when it's set to 1 and Alloc_With_Allocator is selected, it will be allocated by customer. -#### **Enable running PGO(Profile-Guided Optimization) instrumented AOT file** +### **Enable running PGO(Profile-Guided Optimization) instrumented AOT file** - **WAMR_BUILD_STATIC_PGO**=1/0, default to disable if not set > Note: See [Use the AOT static PGO method](./perf_tune.md#5-use-the-aot-static-pgo-method) for more details. -#### **Enable linux perf support** +### **Enable linux perf support** - **WAMR_BUILD_LINUX_PERF**=1/0, enable linux perf support to generate the flamegraph to analyze the performance of a wasm application, default to disable if not set > Note: See [Use linux-perf](./perf_tune.md#7-use-linux-perf) for more details. -#### **Enable module instance context APIs** +### **Enable module instance context APIs** - **WAMR_BUILD_MODULE_INST_CONTEXT**=1/0, enable module instance context APIs which can set one or more contexts created by the embedder for a wasm module instance, default to enable if not set: ```C wasm_runtime_create_context_key @@ -277,19 +277,19 @@ Currently we only profile the memory consumption of module, module_instance and ``` > Note: See [wasm_export.h](../core/iwasm/include/wasm_export.h) for more details. -#### **Enable quick AOT/JTI entries** +### **Enable quick AOT/JTI entries** - **WAMR_BUILD_QUICK_AOT_ENTRY**=1/0, enable registering quick call entries to speedup the aot/jit func call process, default to enable if not set > Note: See [Refine callings to AOT/JIT functions from host native](./perf_tune.md#83-refine-callings-to-aotjit-functions-from-host-native) for more details. -#### **Enable AOT intrinsics** +### **Enable AOT intrinsics** - **WAMR_BUILD_AOT_INTRINSICS**=1/0, enable the AOT intrinsic functions, default to enable if not set. These functions can be called from the AOT code when `--disable-llvm-intrinsics` flag or `--enable-builtin-intrinsics=` flag is used by wamrc to generate the AOT file. > Note: See [Tuning the XIP intrinsic functions](./xip.md#tuning-the-xip-intrinsic-functions) for more details. -#### **Configurable memory access boundary check** +### **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. -#### **Module instance context APIs** +### **Module instance context APIs** - **WAMR_BUILD_MODULE_INST_CONTEXT**=1/0, default to disable if not set > Note: If it is enabled, allow to set one or more contexts created by embedder for a module instance, the below APIs are provided: ```C @@ -300,7 +300,7 @@ Currently we only profile the memory consumption of module, module_instance and wasm_runtime_get_context ``` -#### **Shared heap among wasm apps and host native** +### **Shared heap among wasm apps and host native** - **WAMR_BUILD_SHARED_HEAP**=1/0, default to disable if not set > Note: If it is enabled, allow to create one or more shared heaps, and attach one to a module instance, the belows APIs ared provided: ```C @@ -316,7 +316,11 @@ And the wasm app can calls below APIs to allocate/free memory from/to the shared void shared_heap_free(void *ptr); ``` -**Combination of configurations:** +### **Shrunk the memory usage** +- **WAMR_BUILD_SHRUNK_MEMORY**=1/0, default to enable if not set +> Note: When enabled, this feature will reduce memory usage by decreasing the size of the linear memory, particularly when the `memory.grow` opcode is not used and memory usage is somewhat predictable. + +## **Combination of configurations:** We can combine the configurations. For example, if we want to disable interpreter, enable AOT and WASI, we can run command: @@ -328,4 +332,4 @@ Or if we want to enable interpreter, disable AOT and WASI, and build as X86_32, ``` Bash cmake .. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_LIBC_WASI=0 -DWAMR_BUILD_TARGET=X86_32 -``` +``` \ No newline at end of file diff --git a/doc/memory_tune.md b/doc/memory_tune.md index 9bb4f6a10..77c7d433f 100644 --- a/doc/memory_tune.md +++ b/doc/memory_tune.md @@ -32,3 +32,4 @@ Normally there are some methods to tune the memory usage: - use XIP mode, refer to [WAMR XIP (Execution In Place) feature introduction](./xip.md) for more details - when using the Wasm C API in fast interpreter or AOT mode, set `clone_wasm_binary=false` in `LoadArgs` and free the wasm binary buffer (with `wasm_byte_vec_delete`) after module loading; `wasm_module_is_underlying_binary_freeable` can be queried to check if the wasm binary buffer can be safely freed (see [the example](../samples/basic/src/free_buffer_early.c)); after the buffer is freed, `wasm_runtime_get_custom_section` cannot be called anymore - when using the wasm/AOT loader in fast interpreter or AOT mode, set `wasm_binary_freeable=true` in `LoadArgs` and free the wasm binary buffer (with `wasm_byte_vec_delete`) after module loading; `wasm_runtime_is_underlying_binary_freeable` can be queried to check if the wasm binary buffer can be safely freed; after the buffer is freed, `wasm_runtime_get_custom_section` cannot be called anymore +- `WAMR_BUILD_SHRUNK_MEMORY` can be used to reduce the memory usage of WAMR, but it might affect the standard expected behavior of WAMR. \ No newline at end of file diff --git a/tests/wamr-test-suites/spec-test-script/ignore_cases.patch b/tests/wamr-test-suites/spec-test-script/ignore_cases.patch index 73f749737..e0bcf362e 100644 --- a/tests/wamr-test-suites/spec-test-script/ignore_cases.patch +++ b/tests/wamr-test-suites/spec-test-script/ignore_cases.patch @@ -1,136 +1,66 @@ -diff --git a/test/core/data.wast b/test/core/data.wast -index b1e1239..a0f6967 100644 ---- a/test/core/data.wast -+++ b/test/core/data.wast -@@ -312,7 +312,8 @@ - "\02\01\41\00\0b" ;; active data segment 0 for memory 1 - "\00" ;; empty vec(byte) - ) -- "unknown memory 1" -+ ;; TODO: restore after supporting multi memory" -+ "unknown memory" - ) - - ;; Data segment with memory index 0 (no memory section) -@@ -334,7 +335,8 @@ - "\02\01\41\00\0b" ;; active data segment 0 for memory 1 - "\00" ;; empty vec(byte) - ) -- "unknown memory 1" -+ ;; TODO: restore after supporting multi memory" -+ "unknown memory" - ) - - ;; Data segment with memory index 1 and vec(byte) as above, -@@ -354,7 +356,8 @@ - "\20\21\22\23\24\25\26\27\28\29\2a\2b\2c\2d\2e\2f" - "\30\31\32\33\34\35\36\37\38\39\3a\3b\3c\3d" - ) -- "unknown memory 1" -+ ;; TODO: restore after supporting multi memory" -+ "unknown memory" - ) - - ;; Data segment with memory index 1 and specially crafted vec(byte) after. -@@ -374,7 +377,8 @@ - "\20\21\22\23\24\25\26\27\28\29\2a\2b\2c\2d\2e\2f" - "\30\31\32\33\34\35\36\37\38\39\3a\3b\3c\3d" - ) -- "unknown memory 1" -+ ;; TODO: restore after supporting multi memory" -+ "unknown memory" - ) - - diff --git a/test/core/elem.wast b/test/core/elem.wast -index 33b3f67..a4c1a2d 100644 +index 68a244b..a42cbd4 100644 --- a/test/core/elem.wast +++ b/test/core/elem.wast -@@ -586,6 +586,7 @@ - (assert_return (invoke $module1 "call-8") (i32.const 65)) - (assert_return (invoke $module1 "call-9") (i32.const 66)) +@@ -560,6 +560,9 @@ + ) + (assert_return (invoke "call-overwritten-element") (i32.const 66)) -+(; - (module $module2 - (type $out-i32 (func (result i32))) - (import "module1" "shared-table" (table 10 funcref)) -@@ -598,7 +599,9 @@ - (assert_return (invoke $module1 "call-7") (i32.const 67)) - (assert_return (invoke $module1 "call-8") (i32.const 68)) - (assert_return (invoke $module1 "call-9") (i32.const 66)) -+;) ++(;; FIXME: enable the following cases after supporting the import of tables ++ ;; ++ + ;; Element sections across multiple modules change the same table -+(; - (module $module3 - (type $out-i32 (func (result i32))) - (import "module1" "shared-table" (table 10 funcref)) -@@ -611,6 +614,7 @@ - (assert_return (invoke $module1 "call-7") (i32.const 67)) - (assert_return (invoke $module1 "call-8") (i32.const 69)) - (assert_return (invoke $module1 "call-9") (i32.const 70)) -+;) - - ;; Element segments must match element type of table - -@@ -643,6 +647,7 @@ - - ;; Initializing a table with an externref-type element segment - -+(; - (module $m - (table $t (export "table") 2 externref) - (func (export "get") (param $i i32) (result externref) -@@ -667,9 +672,11 @@ - - (assert_return (invoke $m "get" (i32.const 0)) (ref.null extern)) - (assert_return (invoke $m "get" (i32.const 1)) (ref.extern 137)) -+;) - - ;; Initializing a table with imported funcref global - -+(; - (module $module4 - (func (result i32) - i32.const 42 -@@ -690,3 +697,4 @@ + (module $module1 +@@ -690,3 +693,5 @@ ) (assert_return (invoke "call_imported_elem") (i32.const 42)) -+;) -diff --git a/test/core/if.wast b/test/core/if.wast -index 2ea45f6..6f07304 100644 ---- a/test/core/if.wast -+++ b/test/core/if.wast -@@ -530,7 +530,10 @@ - (func (export "atypical-condition") - i32.const 0 - (if (then) (else)) -- (if (i32.const 1) (i32.eqz) (then) (else)) -+ ;; restore after wabt(> 1.34.0) supports it -+ (i32.const 1) -+ (i32.eqz) -+ (if (then) (else)) - ) - ) ++;; ++;;) +diff --git a/test/core/memory_grow.wast b/test/core/memory_grow.wast +index 882e4b5..d17a509 100644 +--- a/test/core/memory_grow.wast ++++ b/test/core/memory_grow.wast +@@ -308,7 +308,8 @@ + (assert_return (invoke "as-memory.grow-size") (i32.const 1)) + +- ++(;; FIXME: enable the following cases after supporting the import of memories ++ ;; + (module $Mgm + (memory (export "memory") 1) ;; initial size is 1 + (func (export "grow") (result i32) (memory.grow (i32.const 1))) +@@ -328,7 +329,8 @@ + (func (export "size") (result i32) (memory.size)) + ) + (assert_return (invoke $Mgim2 "size") (i32.const 3)) +- ++;; ++;;) + + (assert_invalid + (module diff --git a/test/core/ref_func.wast b/test/core/ref_func.wast -index adb5cb7..6396013 100644 +index adb5cb7..98e02cd 100644 --- a/test/core/ref_func.wast +++ b/test/core/ref_func.wast -@@ -4,7 +4,7 @@ +@@ -4,7 +4,8 @@ (register "M") (module - (func $f (import "M" "f") (param i32) (result i32)) ++ (;;FIXME: change it back after supporting the import by default ;;) + (func $f (param $x i32) (result i32) (local.get $x)) (func $g (param $x i32) (result i32) (i32.add (local.get $x) (i32.const 1)) ) diff --git a/test/core/table_copy.wast b/test/core/table_copy.wast -index 380e84e..59230cf 100644 +index 380e84e..2ac9fdc 100644 --- a/test/core/table_copy.wast +++ b/test/core/table_copy.wast -@@ -14,11 +14,11 @@ +@@ -14,11 +14,12 @@ (module (type (func (result i32))) ;; type #0 @@ -139,6 +69,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -147,7 +78,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -106,11 +106,11 @@ +@@ -106,11 +107,12 @@ (module (type (func (result i32))) ;; type #0 @@ -156,6 +87,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -164,7 +96,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -198,11 +198,11 @@ +@@ -198,11 +200,12 @@ (module (type (func (result i32))) ;; type #0 @@ -173,6 +105,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -181,7 +114,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -290,11 +290,11 @@ +@@ -290,11 +293,12 @@ (module (type (func (result i32))) ;; type #0 @@ -190,6 +123,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -198,7 +132,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -382,11 +382,11 @@ +@@ -382,11 +386,12 @@ (module (type (func (result i32))) ;; type #0 @@ -207,6 +141,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -215,7 +150,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -474,11 +474,11 @@ +@@ -474,11 +479,12 @@ (module (type (func (result i32))) ;; type #0 @@ -224,6 +159,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -232,7 +168,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -566,11 +566,11 @@ +@@ -566,11 +572,12 @@ (module (type (func (result i32))) ;; type #0 @@ -241,6 +177,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -249,7 +186,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -658,11 +658,11 @@ +@@ -658,11 +665,12 @@ (module (type (func (result i32))) ;; type #0 @@ -258,6 +195,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -266,7 +204,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -750,11 +750,11 @@ +@@ -750,11 +758,12 @@ (module (type (func (result i32))) ;; type #0 @@ -275,6 +213,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -283,7 +222,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -842,11 +842,11 @@ +@@ -842,11 +851,12 @@ (module (type (func (result i32))) ;; type #0 @@ -292,6 +231,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -300,7 +240,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -934,11 +934,11 @@ +@@ -934,11 +944,12 @@ (module (type (func (result i32))) ;; type #0 @@ -309,6 +249,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -317,7 +258,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1026,11 +1026,11 @@ +@@ -1026,11 +1037,12 @@ (module (type (func (result i32))) ;; type #0 @@ -326,6 +267,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -334,7 +276,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1118,11 +1118,11 @@ +@@ -1118,11 +1130,12 @@ (module (type (func (result i32))) ;; type #0 @@ -343,6 +285,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -351,7 +294,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1210,11 +1210,11 @@ +@@ -1210,11 +1223,12 @@ (module (type (func (result i32))) ;; type #0 @@ -360,6 +303,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -368,7 +312,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1302,11 +1302,11 @@ +@@ -1302,11 +1316,12 @@ (module (type (func (result i32))) ;; type #0 @@ -377,6 +321,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -385,7 +330,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1394,11 +1394,11 @@ +@@ -1394,11 +1409,12 @@ (module (type (func (result i32))) ;; type #0 @@ -394,6 +339,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -402,7 +348,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1486,11 +1486,11 @@ +@@ -1486,11 +1502,12 @@ (module (type (func (result i32))) ;; type #0 @@ -411,6 +357,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -419,7 +366,7 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1578,11 +1578,11 @@ +@@ -1578,11 +1595,12 @@ (module (type (func (result i32))) ;; type #0 @@ -428,6 +375,7 @@ index 380e84e..59230cf 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;;FIXME: change it back after supporting the import of tables ;;) + (func (result i32) (i32.const 0)) ;; index 0 + (func (result i32) (i32.const 1)) + (func (result i32) (i32.const 2)) @@ -436,6 +384,29 @@ index 380e84e..59230cf 100644 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) +diff --git a/test/core/table_grow.wast b/test/core/table_grow.wast +index 5345a80..0636f67 100644 +--- a/test/core/table_grow.wast ++++ b/test/core/table_grow.wast +@@ -108,6 +108,8 @@ + (assert_return (invoke "check-table-null" (i32.const 0) (i32.const 19)) (ref.null func)) + + ++(;; FIXME: enable the following cases after supporting the import of tables ++ ;; + (module $Tgt + (table (export "table") 1 funcref) ;; initial size is 1 + (func (export "grow") (result i32) (table.grow (ref.null func) (i32.const 1))) +@@ -127,7 +129,8 @@ + (func (export "size") (result i32) (table.size)) + ) + (assert_return (invoke $Tgit2 "size") (i32.const 3)) +- ++;; ++;;) + + ;; Type errors + diff --git a/test/core/table_init.wast b/test/core/table_init.wast index 0b2d26f..3c595e5 100644 --- a/test/core/table_init.wast diff --git a/tests/wamr-test-suites/spec-test-script/multi_module_ignore_cases.patch b/tests/wamr-test-suites/spec-test-script/multi_module_ignore_cases.patch index 9f908488e..3ff4966d1 100644 --- a/tests/wamr-test-suites/spec-test-script/multi_module_ignore_cases.patch +++ b/tests/wamr-test-suites/spec-test-script/multi_module_ignore_cases.patch @@ -1,56 +1,3 @@ -diff --git a/test/core/imports.wast b/test/core/imports.wast -index 0cc07cb..4e8367a 100644 ---- a/test/core/imports.wast -+++ b/test/core/imports.wast -@@ -86,7 +86,7 @@ - (assert_return (invoke "print64" (i64.const 24))) - - (assert_invalid -- (module -+ (module - (type (func (result i32))) - (import "test" "func" (func (type 1))) - ) -@@ -578,6 +578,7 @@ - (assert_return (invoke "grow" (i32.const 1)) (i32.const -1)) - (assert_return (invoke "grow" (i32.const 0)) (i32.const 2)) - -+(; - (module $Mgm - (memory (export "memory") 1) ;; initial size is 1 - (func (export "grow") (result i32) (memory.grow (i32.const 1))) -@@ -586,7 +587,7 @@ - (assert_return (invoke $Mgm "grow") (i32.const 1)) ;; now size is 2 - (module $Mgim1 - ;; imported memory limits should match, because external memory size is 2 now -- (memory (export "memory") (import "grown-memory" "memory") 2) -+ (memory (export "memory") (import "grown-memory" "memory") 2) - (func (export "grow") (result i32) (memory.grow (i32.const 1))) - ) - (register "grown-imported-memory" $Mgim1) -@@ -597,7 +598,7 @@ - (func (export "size") (result i32) (memory.size)) - ) - (assert_return (invoke $Mgim2 "size") (i32.const 3)) -- -+;) - - ;; Syntax errors - -@@ -669,6 +670,7 @@ - "import after memory" - ) - -+(; - ;; This module is required to validate, regardless of whether it can be - ;; linked. Overloading is not possible in wasm itself, but it is possible - ;; in modules from which wasm can import. -@@ -695,3 +697,4 @@ - ) - "unknown import" - ) -+;) -\ No newline at end of file diff --git a/test/core/linking.wast b/test/core/linking.wast index 994e0f4..8fbcc02 100644 --- a/test/core/linking.wast diff --git a/tests/wamr-test-suites/spec-test-script/runtest.py b/tests/wamr-test-suites/spec-test-script/runtest.py index 97820eaad..6e963bdc7 100755 --- a/tests/wamr-test-suites/spec-test-script/runtest.py +++ b/tests/wamr-test-suites/spec-test-script/runtest.py @@ -1103,7 +1103,8 @@ def compile_wast_to_wasm(form, wast_tempfile, wasm_tempfile, opts): elif opts.multi_memory: cmd = [opts.wast2wasm, "--enable-multi-memory", "--no-check", wast_tempfile, "-o", wasm_tempfile ] else: - cmd = [opts.wast2wasm, "--enable-threads", "--no-check", + # `--enable-multi-memory` for a case in memory.wast but doesn't require runtime support + cmd = [opts.wast2wasm, "--enable-multi-memory", "--enable-threads", "--no-check", wast_tempfile, "-o", wasm_tempfile ] # remove reference-type and bulk-memory enabling options since a WABT diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 70a8b687c..64abd9f35 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -269,16 +269,12 @@ readonly WAMRC_CMD_DEFAULT="${WAMR_DIR}/wamr-compiler/build/wamrc" readonly CLASSIC_INTERP_COMPILE_FLAGS="\ -DWAMR_BUILD_TARGET=${TARGET} \ -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 \ - -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0 \ - -DWAMR_BUILD_SPEC_TEST=1 \ - -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}" + -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0" readonly FAST_INTERP_COMPILE_FLAGS="\ -DWAMR_BUILD_TARGET=${TARGET} \ -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=1 \ - -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0 \ - -DWAMR_BUILD_SPEC_TEST=1 \ - -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}" + -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0" # jit: report linking error if set COLLECT_CODE_COVERAGE, # now we don't collect code coverage of jit type @@ -286,39 +282,29 @@ readonly ORC_EAGER_JIT_COMPILE_FLAGS="\ -DWAMR_BUILD_TARGET=${TARGET} \ -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \ -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_AOT=1 \ - -DWAMR_BUILD_LAZY_JIT=0 \ - -DWAMR_BUILD_SPEC_TEST=1 \ - -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}" + -DWAMR_BUILD_LAZY_JIT=0" readonly ORC_LAZY_JIT_COMPILE_FLAGS="\ -DWAMR_BUILD_TARGET=${TARGET} \ -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \ -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_AOT=1 \ - -DWAMR_BUILD_LAZY_JIT=1 \ - -DWAMR_BUILD_SPEC_TEST=1 \ - -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}" + -DWAMR_BUILD_LAZY_JIT=1" readonly AOT_COMPILE_FLAGS="\ -DWAMR_BUILD_TARGET=${TARGET} \ -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \ - -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=1 \ - -DWAMR_BUILD_SPEC_TEST=1 \ - -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}" + -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=1" readonly FAST_JIT_COMPILE_FLAGS="\ -DWAMR_BUILD_TARGET=${TARGET} \ -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 \ -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0 \ - -DWAMR_BUILD_FAST_JIT=1 \ - -DWAMR_BUILD_SPEC_TEST=1 \ - -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}" + -DWAMR_BUILD_FAST_JIT=1" readonly MULTI_TIER_JIT_COMPILE_FLAGS="\ -DWAMR_BUILD_TARGET=${TARGET} \ -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 \ - -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \ - -DWAMR_BUILD_SPEC_TEST=1 \ - -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}" + -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1" readonly COMPILE_FLAGS=( "${CLASSIC_INTERP_COMPILE_FLAGS}" @@ -525,8 +511,8 @@ function spec_test() git clone -b main --single-branch https://github.com/WebAssembly/spec pushd spec - # Apr 3, 2024 [js-api] Integrate with the ResizableArrayBuffer proposal (#1300) - git reset --hard bc76fd79cfe61033d7f4ad4a7e8fc4f996dc5ba8 + # Dec 20, 2024. Use WPT version of test harness for HTML core test conversion (#1859) + git reset --hard f3a0e06235d2d84bb0f3b5014da4370613886965 git apply ../../spec-test-script/ignore_cases.patch || exit 1 if [[ ${ENABLE_SIMD} == 1 ]]; then git apply ../../spec-test-script/simd_ignore_cases.patch || exit 1 @@ -833,7 +819,9 @@ function build_wamrc() && ./${BUILD_LLVM_SH} \ && if [ -d build ]; then rm -r build/*; else mkdir build; fi \ && cd build \ - && cmake .. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} \ + && cmake .. \ + -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} \ + -DWAMR_BUILD_SHRUNK_MEMORY=0 \ && make -j 4 } @@ -962,6 +950,11 @@ function trigger() fi local EXTRA_COMPILE_FLAGS="" + # for spec test + EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SPEC_TEST=1" + EXTRA_COMPILE_FLAGS+=" -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}" + EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SHRUNK_MEMORY=0" + # default enabled features EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1" EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1" diff --git a/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index ab98b0382..bc56f4030 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -238,6 +238,12 @@ if (NOT DEFINED WAMR_BUILD_LIB_WASI_THREADS) set (WAMR_BUILD_LIB_WASI_THREADS 1) endif () +# Enable by default +if (NOT DEFINED WAMR_BUILD_SHRUNK_MEMORY) + set (WAMR_BUILD_SHRUNK_MEMORY 1) +endif () +add_definitions (-DWASM_ENABLE_SHRUNK_MEMORY=${WAMR_BUILD_SHRUNK_MEMORY}) + if (WAMR_BUILD_LIBC_UVWASI EQUAL 1) message ("-- Libc WASI enabled with uvwasi implementation") endif () From 0d20521406c554e44f8bba7182477f14f7074461 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:30:28 +0800 Subject: [PATCH 095/105] build(deps): Bump actions/upload-artifact from 4.5.0 to 4.6.0 (#4021) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.5.0 to 4.6.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4.5.0...v4.6.0) --- updated-dependencies: - dependency-name: actions/upload-artifact 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 | 2 +- .github/workflows/spec_test_on_nuttx.yml | 2 +- .github/workflows/supply_chain.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 1da37a4c3..67022b510 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -106,7 +106,7 @@ jobs: - name: Upload CodeQL results as an artifact if: success() || failure() - uses: actions/upload-artifact@v4.5.0 + uses: actions/upload-artifact@v4.6.0 with: name: codeql-results path: ${{ steps.step1.outputs.sarif-output }} diff --git a/.github/workflows/spec_test_on_nuttx.yml b/.github/workflows/spec_test_on_nuttx.yml index 7f1169583..2cf80d743 100644 --- a/.github/workflows/spec_test_on_nuttx.yml +++ b/.github/workflows/spec_test_on_nuttx.yml @@ -350,7 +350,7 @@ jobs: - name: upload the log if: always() - uses: actions/upload-artifact@v4.5.0 + uses: actions/upload-artifact@v4.6.0 with: name: spec-test-log-${{ github.run_id }}-${{ strategy.job-index }}-${{ matrix.target_config.target }} path: log diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index 425eda532..e5f2be4af 100644 --- a/.github/workflows/supply_chain.yml +++ b/.github/workflows/supply_chain.yml @@ -52,7 +52,7 @@ jobs: # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # format to the repository Actions tab. - name: "Upload artifact" - uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v3.1.0 + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v3.1.0 with: name: SARIF file path: results.sarif From 946430f15e0f1182f493806e80ee3a14503628bb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:36:50 +0800 Subject: [PATCH 096/105] build(deps): Bump github/codeql-action from 3.28.0 to 3.28.1 (#4020) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.0 to 3.28.1. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.0...v3.28.1) --- updated-dependencies: - dependency-name: github/codeql-action 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 67022b510..753322fcc 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.28.0 + uses: github/codeql-action/init@v3.28.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.28.0 + uses: github/codeql-action/analyze@v3.28.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.28.0 + uses: github/codeql-action/upload-sarif@v3.28.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 e5f2be4af..39f2f9835 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@78760076e3f08852c2c3aeb5334f70d074e28c59 # v2.2.4 + uses: github/codeql-action/upload-sarif@db7177a1c66bea89f5e7ce32d0ea48bea4a0d460 # v2.2.4 with: sarif_file: results.sarif From 9c3807e124d6f7eb26d7a93dcc24d16e8ce0afce Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 14 Jan 2025 17:43:29 +0800 Subject: [PATCH 097/105] Refine read leb int wasm loader of fast interpreter (#4017) --- core/iwasm/interpreter/wasm_loader.c | 216 +++++++++++++++------- core/iwasm/interpreter/wasm_mini_loader.c | 148 +++++++++++---- 2 files changed, 262 insertions(+), 102 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 12f4aff75..4ee553e0b 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -197,7 +197,6 @@ check_buf1(const uint8 *buf, const uint8 *buf_end, uint32 length, res = (int32)res64; \ } while (0) -#define read_leb_memidx(p, p_end, res) read_leb_uint32(p, p_end, res) #if WASM_ENABLE_MULTI_MEMORY != 0 #define check_memidx(module, memidx) \ do { \ @@ -10924,6 +10923,83 @@ DEFINE_GOTO_TABLE(const char *, op_mnemonics); #undef HANDLE_OPCODE #endif +#if WASM_ENABLE_FAST_INTERP == 0 + +#define pb_read_leb_uint32 read_leb_uint32 +#define pb_read_leb_int32 read_leb_int32 +#define pb_read_leb_int64 read_leb_int64 +#define pb_read_leb_memarg read_leb_memarg +#define pb_read_leb_mem_offset read_leb_mem_offset + +#else + +/* Read leb without malformed format check */ +static uint64 +read_leb_quick(uint8 **p_buf, uint32 maxbits, bool sign) +{ + uint8 *buf = *p_buf; + uint64 result = 0, byte = 0; + uint32 shift = 0; + + do { + byte = *buf++; + result |= ((byte & 0x7f) << shift); + shift += 7; + } while (byte & 0x80); + + if (sign && (shift < maxbits) && (byte & 0x40)) { + /* Sign extend */ + result |= (~((uint64)0)) << shift; + } + + *p_buf = buf; + return result; +} + +#define pb_read_leb_uint32(p, p_end, res) \ + do { \ + if (!loader_ctx->p_code_compiled) \ + /* Enable format check in the first scan */ \ + read_leb_uint32(p, p_end, res); \ + else \ + /* Disable format check in the second scan */ \ + res = (uint32)read_leb_quick(&p, 32, false); \ + } while (0) + +#define pb_read_leb_int32(p, p_end, res) \ + do { \ + if (!loader_ctx->p_code_compiled) \ + /* Enable format check in the first scan */ \ + read_leb_int32(p, p_end, res); \ + else \ + /* Disable format check in the second scan */ \ + res = (int32)read_leb_quick(&p, 32, true); \ + } while (0) + +#define pb_read_leb_int64(p, p_end, res) \ + do { \ + if (!loader_ctx->p_code_compiled) \ + /* Enable format check in the first scan */ \ + read_leb_int64(p, p_end, res); \ + else \ + /* Disable format check in the second scan */ \ + res = (int64)read_leb_quick(&p, 64, true); \ + } while (0) + +#if WASM_ENABLE_MULTI_MEMORY != 0 +#define pb_read_leb_memarg read_leb_memarg +#else +#define pb_read_leb_memarg pb_read_leb_uint32 +#endif + +#if WASM_ENABLE_MEMORY64 != 0 +#define pb_read_leb_mem_offset read_leb_mem_offset +#else +#define pb_read_leb_mem_offset pb_read_leb_uint32 +#endif + +#endif /* end of WASM_ENABLE_FAST_INTERP != 0 */ + static bool wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, uint32 cur_func_idx, char *error_buf, @@ -11153,7 +11229,7 @@ re_scan: /* Resolve the leb128 encoded type index as block type */ p--; p_org = p - 1; - read_leb_int32(p, p_end, type_index); + pb_read_leb_int32(p, p_end, type_index); if ((uint32)type_index >= module->type_count) { set_error_buf(error_buf, error_buf_size, "unknown type"); @@ -11362,7 +11438,7 @@ re_scan: uint8 label_type = cur_block->label_type; uint32 tag_index = 0; - read_leb_int32(p, p_end, tag_index); + pb_read_leb_int32(p, p_end, tag_index); /* check validity of tag_index against module->tag_count */ /* check tag index is within the tag index space */ @@ -11506,7 +11582,7 @@ re_scan: uint8 label_type = cur_block->label_type; uint32 tag_index = 0; - read_leb_int32(p, p_end, tag_index); + pb_read_leb_int32(p, p_end, tag_index); /* check validity of tag_index against module->tag_count */ /* check tag index is within the tag index space */ @@ -11773,7 +11849,7 @@ re_scan: uint32 j; #endif - read_leb_uint32(p, p_end, count); + pb_read_leb_uint32(p, p_end, count); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, count); #endif @@ -11782,7 +11858,7 @@ re_scan: /* Get each depth and check it */ p_org = p; for (i = 0; i <= count; i++) { - read_leb_uint32(p, p_end, depth); + pb_read_leb_uint32(p, p_end, depth); bh_assert(loader_ctx->csp_num > 0); if (loader_ctx->csp_num - 1 < depth) { set_error_buf(error_buf, error_buf_size, @@ -11804,7 +11880,7 @@ re_scan: #endif for (i = 0; i <= count; i++) { p_org = p; - read_leb_uint32(p, p_end, depth); + pb_read_leb_uint32(p, p_end, depth); p = p_org; /* Get the target block's arity and check it */ @@ -11938,7 +12014,7 @@ re_scan: #if WASM_ENABLE_GC != 0 if (opcode == WASM_OP_CALL_REF || opcode == WASM_OP_RETURN_CALL_REF) { - read_leb_uint32(p, p_end, type_idx1); + pb_read_leb_uint32(p, p_end, type_idx1); if (!check_type_index(module, module->type_count, type_idx1, error_buf, error_buf_size)) { goto fail; @@ -11977,7 +12053,7 @@ re_scan: else #endif { - read_leb_uint32(p, p_end, func_idx); + pb_read_leb_uint32(p, p_end, func_idx); #if WASM_ENABLE_FAST_INTERP != 0 /* we need to emit func_idx before arguments */ emit_uint32(loader_ctx, func_idx); @@ -12113,7 +12189,7 @@ re_scan: WASMRefType *elem_ref_type = NULL; #endif - read_leb_uint32(p, p_end, type_idx); + pb_read_leb_uint32(p, p_end, type_idx); #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 #if WASM_ENABLE_WAMR_COMPILER != 0 if (p + 1 < p_end && *p != 0x00) { @@ -12125,7 +12201,7 @@ re_scan: module->is_ref_types_used = true; } #endif - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_idx); #else CHECK_BUF(p, p_end, 1); table_idx = read_uint8(p); @@ -12444,7 +12520,7 @@ re_scan: uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled; #endif - read_leb_uint32(p, p_end, vec_len); + pb_read_leb_uint32(p, p_end, vec_len); if (vec_len != 1) { /* typed select must have exactly one result */ set_error_buf(error_buf, error_buf_size, @@ -12574,7 +12650,7 @@ re_scan: WASMRefType *ref_type; #endif - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_idx); if (!get_table_elem_type(module, table_idx, &decl_ref_type, #if WASM_ENABLE_GC != 0 (void **)&ref_type, @@ -12635,7 +12711,7 @@ re_scan: goto fail; } #else - read_leb_int32(p, p_end, heap_type); + pb_read_leb_int32(p, p_end, heap_type); if (heap_type >= 0) { if (!check_type_index(module, module->type_count, heap_type, error_buf, error_buf_size)) { @@ -12722,7 +12798,7 @@ re_scan: } case WASM_OP_REF_FUNC: { - read_leb_uint32(p, p_end, func_idx); + pb_read_leb_uint32(p, p_end, func_idx); if (!check_function_index(module, func_idx, error_buf, error_buf_size)) { @@ -13118,7 +13194,7 @@ re_scan: #endif p_org = p - 1; - read_leb_uint32(p, p_end, global_idx); + pb_read_leb_uint32(p, p_end, global_idx); if (global_idx >= global_count) { set_error_buf(error_buf, error_buf_size, "unknown global"); goto fail; @@ -13178,7 +13254,7 @@ re_scan: #endif p_org = p - 1; - read_leb_uint32(p, p_end, global_idx); + pb_read_leb_uint32(p, p_end, global_idx); if (global_idx >= global_count) { set_error_buf(error_buf, error_buf_size, "unknown global"); goto fail; @@ -13313,8 +13389,8 @@ re_scan: } #endif CHECK_MEMORY(); - read_leb_memarg(p, p_end, align); /* align */ - read_leb_mem_offset(p, p_end, mem_offset); /* offset */ + pb_read_leb_memarg(p, p_end, align); /* align */ + pb_read_leb_mem_offset(p, p_end, mem_offset); /* offset */ if (!check_memory_access_align(opcode, align, error_buf, error_buf_size)) { goto fail; @@ -13379,7 +13455,7 @@ re_scan: case WASM_OP_MEMORY_SIZE: CHECK_MEMORY(); - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); check_memidx(module, memidx); PUSH_PAGE_COUNT(); @@ -13391,7 +13467,7 @@ re_scan: case WASM_OP_MEMORY_GROW: CHECK_MEMORY(); - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); check_memidx(module, memidx); POP_AND_PUSH(mem_offset_type, mem_offset_type); @@ -13406,7 +13482,7 @@ re_scan: break; case WASM_OP_I32_CONST: - read_leb_int32(p, p_end, i32_const); + pb_read_leb_int32(p, p_end, i32_const); #if WASM_ENABLE_FAST_INTERP != 0 skip_label(); disable_emit = true; @@ -13424,7 +13500,7 @@ re_scan: break; case WASM_OP_I64_CONST: - read_leb_int64(p, p_end, i64_const); + pb_read_leb_int64(p, p_end, i64_const); #if WASM_ENABLE_FAST_INTERP != 0 skip_label(); disable_emit = true; @@ -13707,7 +13783,7 @@ re_scan: { uint32 opcode1; - read_leb_uint32(p, p_end, opcode1); + pb_read_leb_uint32(p, p_end, opcode1); #if WASM_ENABLE_FAST_INTERP != 0 emit_byte(loader_ctx, ((uint8)opcode1)); #endif @@ -13716,7 +13792,7 @@ re_scan: case WASM_OP_STRUCT_NEW: case WASM_OP_STRUCT_NEW_DEFAULT: { - read_leb_uint32(p, p_end, type_idx); + pb_read_leb_uint32(p, p_end, type_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, type_idx); #endif @@ -13803,7 +13879,7 @@ re_scan: uint32 field_idx; uint8 field_type; - read_leb_uint32(p, p_end, type_idx); + pb_read_leb_uint32(p, p_end, type_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, type_idx); #endif @@ -13820,7 +13896,7 @@ re_scan: } struct_type = (WASMStructType *)module->types[type_idx]; - read_leb_uint32(p, p_end, field_idx); + pb_read_leb_uint32(p, p_end, field_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, field_idx); #endif @@ -13896,14 +13972,14 @@ re_scan: uint8 elem_type; uint32 u32 = 0; - read_leb_uint32(p, p_end, type_idx); + pb_read_leb_uint32(p, p_end, type_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, type_idx); #endif if (opcode1 == WASM_OP_ARRAY_NEW_FIXED || opcode1 == WASM_OP_ARRAY_NEW_DATA || opcode1 == WASM_OP_ARRAY_NEW_ELEM) { - read_leb_uint32(p, p_end, u32); + pb_read_leb_uint32(p, p_end, u32); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, u32); #endif @@ -14006,7 +14082,7 @@ re_scan: WASMArrayType *array_type; WASMRefType *ref_type = NULL; - read_leb_uint32(p, p_end, type_idx); + pb_read_leb_uint32(p, p_end, type_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, type_idx); #endif @@ -14078,7 +14154,7 @@ re_scan: WASMArrayType *array_type; uint8 elem_type; /* typeidx */ - read_leb_uint32(p, p_end, type_idx); + pb_read_leb_uint32(p, p_end, type_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, type_idx); #endif @@ -14124,12 +14200,12 @@ re_scan: WASMArrayType *array_type; /* typeidx1 */ - read_leb_uint32(p, p_end, type_idx); + pb_read_leb_uint32(p, p_end, type_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, type_idx); #endif /* typeidx2 */ - read_leb_uint32(p, p_end, src_type_idx); + pb_read_leb_uint32(p, p_end, src_type_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, src_type_idx); #endif @@ -14216,7 +14292,7 @@ re_scan: { uint8 type; - read_leb_int32(p, p_end, heap_type); + pb_read_leb_int32(p, p_end, heap_type); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, (uint32)heap_type); #endif @@ -14277,13 +14353,13 @@ re_scan: #endif p_org = p; - read_leb_uint32(p, p_end, depth); - read_leb_int32(p, p_end, heap_type); + pb_read_leb_uint32(p, p_end, depth); + pb_read_leb_int32(p, p_end, heap_type); #if WASM_ENABLE_FAST_INTERP != 0 /* Emit heap_type firstly */ emit_uint32(loader_ctx, (uint32)heap_type); #endif - read_leb_int32(p, p_end, heap_type_dst); + pb_read_leb_int32(p, p_end, heap_type_dst); #if WASM_ENABLE_FAST_INTERP != 0 /* Emit heap_type firstly */ emit_uint32(loader_ctx, (uint32)heap_type_dst); @@ -14485,7 +14561,7 @@ re_scan: func->has_memory_operations = true; #endif - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, (uint32)memidx); #endif @@ -14499,7 +14575,7 @@ re_scan: { uint32 contents; - read_leb_uint32(p, p_end, contents); + pb_read_leb_uint32(p, p_end, contents); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, (uint32)contents); #endif @@ -14526,7 +14602,7 @@ re_scan: func->has_memory_operations = true; #endif - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, (uint32)memidx); #endif @@ -14580,7 +14656,7 @@ re_scan: func->has_memory_operations = true; #endif - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, (uint32)memidx); #endif @@ -14628,7 +14704,7 @@ re_scan: func->has_memory_operations = true; #endif - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, (uint32)memidx); #endif @@ -14712,7 +14788,7 @@ re_scan: { uint32 opcode1; - read_leb_uint32(p, p_end, opcode1); + pb_read_leb_uint32(p, p_end, opcode1); #if WASM_ENABLE_FAST_INTERP != 0 emit_byte(loader_ctx, ((uint8)opcode1)); #endif @@ -14736,7 +14812,7 @@ re_scan: #if WASM_ENABLE_BULK_MEMORY != 0 case WASM_OP_MEMORY_INIT: { - read_leb_uint32(p, p_end, data_seg_idx); + pb_read_leb_uint32(p, p_end, data_seg_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, data_seg_idx); #endif @@ -14744,7 +14820,7 @@ re_scan: && module->memory_count == 0) goto fail_unknown_memory; - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); check_memidx(module, memidx); if (data_seg_idx >= module->data_seg_count) { @@ -14770,7 +14846,7 @@ re_scan: } case WASM_OP_DATA_DROP: { - read_leb_uint32(p, p_end, data_seg_idx); + pb_read_leb_uint32(p, p_end, data_seg_idx); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, data_seg_idx); #endif @@ -14795,9 +14871,9 @@ re_scan: { CHECK_BUF(p, p_end, sizeof(int16)); /* check both src and dst memory index */ - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); check_memidx(module, memidx); - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); check_memidx(module, memidx); if (module->import_memory_count == 0 @@ -14817,7 +14893,7 @@ re_scan: } case WASM_OP_MEMORY_FILL: { - read_leb_uint32(p, p_end, memidx); + pb_read_leb_uint32(p, p_end, memidx); check_memidx(module, memidx); if (module->import_memory_count == 0 && module->memory_count == 0) { @@ -14852,8 +14928,8 @@ re_scan: WASMRefType *seg_ref_type = NULL, *tbl_ref_type = NULL; #endif - read_leb_uint32(p, p_end, table_seg_idx); - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_seg_idx); + pb_read_leb_uint32(p, p_end, table_idx); if (!get_table_elem_type(module, table_idx, &tbl_type, #if WASM_ENABLE_GC != 0 @@ -14910,7 +14986,7 @@ re_scan: } case WASM_OP_ELEM_DROP: { - read_leb_uint32(p, p_end, table_seg_idx); + pb_read_leb_uint32(p, p_end, table_seg_idx); if (!get_table_seg_elem_type(module, table_seg_idx, NULL, NULL, error_buf, error_buf_size)) @@ -14933,7 +15009,7 @@ re_scan: #endif uint32 src_tbl_idx, dst_tbl_idx; - read_leb_uint32(p, p_end, dst_tbl_idx); + pb_read_leb_uint32(p, p_end, dst_tbl_idx); if (!get_table_elem_type(module, dst_tbl_idx, &dst_type, #if WASM_ENABLE_GC != 0 (void **)&dst_ref_type, @@ -14943,7 +15019,7 @@ re_scan: error_buf, error_buf_size)) goto fail; - read_leb_uint32(p, p_end, src_tbl_idx); + pb_read_leb_uint32(p, p_end, src_tbl_idx); if (!get_table_elem_type(module, src_tbl_idx, &src_type, #if WASM_ENABLE_GC != 0 (void **)&src_ref_type, @@ -15006,7 +15082,7 @@ re_scan: } case WASM_OP_TABLE_SIZE: { - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_idx); /* TODO: shall we create a new function to check table idx instead of using below function? */ if (!get_table_elem_type(module, table_idx, NULL, NULL, @@ -15037,7 +15113,7 @@ re_scan: WASMRefType *ref_type = NULL; #endif - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_idx); if (!get_table_elem_type(module, table_idx, &decl_type, #if WASM_ENABLE_GC != 0 (void **)&ref_type, @@ -15112,7 +15188,7 @@ re_scan: module->is_simd_used = true; #endif - read_leb_uint32(p, p_end, opcode1); + pb_read_leb_uint32(p, p_end, opcode1); /* follow the order of enum WASMSimdEXTOpcode in wasm_opcode.h */ @@ -15132,13 +15208,14 @@ re_scan: { CHECK_MEMORY(); - read_leb_uint32(p, p_end, align); /* align */ + pb_read_leb_uint32(p, p_end, align); /* align */ if (!check_simd_memory_access_align( opcode1, align, error_buf, error_buf_size)) { goto fail; } - read_leb_mem_offset(p, p_end, mem_offset); /* offset */ + pb_read_leb_mem_offset(p, p_end, + mem_offset); /* offset */ POP_AND_PUSH(mem_offset_type, VALUE_TYPE_V128); #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 @@ -15151,13 +15228,14 @@ re_scan: { CHECK_MEMORY(); - read_leb_uint32(p, p_end, align); /* align */ + pb_read_leb_uint32(p, p_end, align); /* align */ if (!check_simd_memory_access_align( opcode1, align, error_buf, error_buf_size)) { goto fail; } - read_leb_mem_offset(p, p_end, mem_offset); /* offset */ + pb_read_leb_mem_offset(p, p_end, + mem_offset); /* offset */ POP_V128(); POP_MEM_OFFSET(); @@ -15369,13 +15447,14 @@ re_scan: CHECK_MEMORY(); - read_leb_uint32(p, p_end, align); /* align */ + pb_read_leb_uint32(p, p_end, align); /* align */ if (!check_simd_memory_access_align( opcode1, align, error_buf, error_buf_size)) { goto fail; } - read_leb_mem_offset(p, p_end, mem_offset); /* offset */ + pb_read_leb_mem_offset(p, p_end, + mem_offset); /* offset */ CHECK_BUF(p, p_end, 1); lane = read_uint8(p); @@ -15400,13 +15479,14 @@ re_scan: { CHECK_MEMORY(); - read_leb_uint32(p, p_end, align); /* align */ + pb_read_leb_uint32(p, p_end, align); /* align */ if (!check_simd_memory_access_align( opcode1, align, error_buf, error_buf_size)) { goto fail; } - read_leb_mem_offset(p, p_end, mem_offset); /* offset */ + pb_read_leb_mem_offset(p, p_end, + mem_offset); /* offset */ POP_AND_PUSH(mem_offset_type, VALUE_TYPE_V128); #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 @@ -15764,15 +15844,15 @@ re_scan: { uint32 opcode1; - read_leb_uint32(p, p_end, opcode1); + pb_read_leb_uint32(p, p_end, opcode1); #if WASM_ENABLE_FAST_INTERP != 0 emit_byte(loader_ctx, opcode1); #endif if (opcode1 != WASM_OP_ATOMIC_FENCE) { CHECK_MEMORY(); - read_leb_uint32(p, p_end, align); /* align */ - read_leb_mem_offset(p, p_end, mem_offset); /* offset */ + pb_read_leb_uint32(p, p_end, align); /* align */ + pb_read_leb_mem_offset(p, p_end, mem_offset); /* offset */ if (!check_memory_align_equal(opcode1, align, error_buf, error_buf_size)) { goto fail; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index df4d818a3..fde969c94 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -6048,6 +6048,86 @@ fail: } \ } while (0) +#if WASM_ENABLE_FAST_INTERP == 0 + +#define pb_read_leb_uint32 read_leb_uint32 +#define pb_read_leb_int32 read_leb_int32 +#define pb_read_leb_int64 read_leb_int64 +#define pb_read_leb_memarg read_leb_memarg +#define pb_read_leb_mem_offset read_leb_mem_offset +#define pb_read_leb_memidx read_leb_memidx + +#else + +/* Read leb without malformed format check */ +static uint64 +read_leb_quick(uint8 **p_buf, uint32 maxbits, bool sign) +{ + uint8 *buf = *p_buf; + uint64 result = 0, byte = 0; + uint32 shift = 0; + + do { + byte = *buf++; + result |= ((byte & 0x7f) << shift); + shift += 7; + } while (byte & 0x80); + + if (sign && (shift < maxbits) && (byte & 0x40)) { + /* Sign extend */ + result |= (~((uint64)0)) << shift; + } + + *p_buf = buf; + return result; +} + +#define pb_read_leb_uint32(p, p_end, res) \ + do { \ + if (!loader_ctx->p_code_compiled) \ + /* Enable format check in the first scan */ \ + read_leb_uint32(p, p_end, res); \ + else \ + /* Disable format check in the second scan */ \ + res = (uint32)read_leb_quick(&p, 32, false); \ + } while (0) + +#define pb_read_leb_int32(p, p_end, res) \ + do { \ + if (!loader_ctx->p_code_compiled) \ + /* Enable format check in the first scan */ \ + read_leb_int32(p, p_end, res); \ + else \ + /* Disable format check in the second scan */ \ + res = (int32)read_leb_quick(&p, 32, true); \ + } while (0) + +#define pb_read_leb_int64(p, p_end, res) \ + do { \ + if (!loader_ctx->p_code_compiled) \ + /* Enable format check in the first scan */ \ + read_leb_int64(p, p_end, res); \ + else \ + /* Disable format check in the second scan */ \ + res = (int64)read_leb_quick(&p, 64, true); \ + } while (0) + +#if WASM_ENABLE_MULTI_MEMORY != 0 +#define pb_read_leb_memarg read_leb_memarg +#else +#define pb_read_leb_memarg pb_read_leb_uint32 +#endif + +#if WASM_ENABLE_MEMORY64 != 0 +#define pb_read_leb_mem_offset read_leb_mem_offset +#else +#define pb_read_leb_mem_offset pb_read_leb_uint32 +#endif + +#define pb_read_leb_memidx pb_read_leb_uint32 + +#endif /* end of WASM_ENABLE_FAST_INTERP != 0 */ + static bool wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, uint32 cur_func_idx, char *error_buf, @@ -6195,7 +6275,7 @@ re_scan: int32 type_index; /* Resolve the leb128 encoded type index as block type */ p--; - read_leb_int32(p, p_end, type_index); + pb_read_leb_int32(p, p_end, type_index); bh_assert((uint32)type_index < module->type_count); block_type.is_value_type = false; block_type.u.type = module->types[type_index]; @@ -6508,7 +6588,7 @@ re_scan: uint32 j; #endif - read_leb_uint32(p, p_end, count); + pb_read_leb_uint32(p, p_end, count); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, count); #endif @@ -6517,7 +6597,7 @@ re_scan: /* Get each depth and check it */ p_org = p; for (i = 0; i <= count; i++) { - read_leb_uint32(p, p_end, depth); + pb_read_leb_uint32(p, p_end, depth); bh_assert(loader_ctx->csp_num > 0); bh_assert(loader_ctx->csp_num - 1 >= depth); (void)depth; @@ -6615,7 +6695,7 @@ re_scan: uint32 func_idx; int32 idx; - read_leb_uint32(p, p_end, func_idx); + pb_read_leb_uint32(p, p_end, func_idx); #if WASM_ENABLE_FAST_INTERP != 0 /* we need to emit func_idx before arguments */ emit_uint32(loader_ctx, func_idx); @@ -6688,10 +6768,10 @@ re_scan: bh_assert(module->import_table_count + module->table_count > 0); - read_leb_uint32(p, p_end, type_idx); + pb_read_leb_uint32(p, p_end, type_idx); #if WASM_ENABLE_REF_TYPES != 0 - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_idx); #else CHECK_BUF(p, p_end, 1); table_idx = read_uint8(p); @@ -6931,7 +7011,7 @@ re_scan: uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled; #endif - read_leb_uint32(p, p_end, vec_len); + pb_read_leb_uint32(p, p_end, vec_len); if (vec_len != 1) { /* typed select must have exactly one result */ set_error_buf(error_buf, error_buf_size, @@ -7006,7 +7086,7 @@ re_scan: uint8 decl_ref_type; uint32 table_idx; - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_idx); if (!get_table_elem_type(module, table_idx, &decl_ref_type, error_buf, error_buf_size)) goto fail; @@ -7100,7 +7180,7 @@ re_scan: case WASM_OP_REF_FUNC: { uint32 func_idx = 0; - read_leb_uint32(p, p_end, func_idx); + pb_read_leb_uint32(p, p_end, func_idx); if (!check_function_index(module, func_idx, error_buf, error_buf_size)) { @@ -7317,7 +7397,7 @@ re_scan: case WASM_OP_GET_GLOBAL: { p_org = p - 1; - read_leb_uint32(p, p_end, global_idx); + pb_read_leb_uint32(p, p_end, global_idx); bh_assert(global_idx < global_count); global_type = global_idx < module->import_global_count @@ -7351,7 +7431,7 @@ re_scan: bool is_mutable = false; p_org = p - 1; - read_leb_uint32(p, p_end, global_idx); + pb_read_leb_uint32(p, p_end, global_idx); bh_assert(global_idx < global_count); is_mutable = global_idx < module->import_global_count @@ -7448,8 +7528,8 @@ re_scan: } #endif CHECK_MEMORY(); - read_leb_memarg(p, p_end, align); /* align */ - read_leb_mem_offset(p, p_end, mem_offset); /* offset */ + pb_read_leb_memarg(p, p_end, align); /* align */ + pb_read_leb_mem_offset(p, p_end, mem_offset); /* offset */ #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, mem_offset); #endif @@ -7510,7 +7590,7 @@ re_scan: case WASM_OP_MEMORY_SIZE: CHECK_MEMORY(); - read_leb_memidx(p, p_end, memidx); + pb_read_leb_memidx(p, p_end, memidx); check_memidx(module, memidx); PUSH_PAGE_COUNT(); @@ -7522,7 +7602,7 @@ re_scan: case WASM_OP_MEMORY_GROW: CHECK_MEMORY(); - read_leb_memidx(p, p_end, memidx); + pb_read_leb_memidx(p, p_end, memidx); check_memidx(module, memidx); POP_AND_PUSH(mem_offset_type, mem_offset_type); @@ -7537,7 +7617,7 @@ re_scan: break; case WASM_OP_I32_CONST: - read_leb_int32(p, p_end, i32_const); + pb_read_leb_int32(p, p_end, i32_const); #if WASM_ENABLE_FAST_INTERP != 0 skip_label(); disable_emit = true; @@ -7555,7 +7635,7 @@ re_scan: break; case WASM_OP_I64_CONST: - read_leb_int64(p, p_end, i64_const); + pb_read_leb_int64(p, p_end, i64_const); #if WASM_ENABLE_FAST_INTERP != 0 skip_label(); disable_emit = true; @@ -7837,7 +7917,7 @@ re_scan: { uint32 opcode1; - read_leb_uint32(p, p_end, opcode1); + pb_read_leb_uint32(p, p_end, opcode1); #if WASM_ENABLE_FAST_INTERP != 0 emit_byte(loader_ctx, ((uint8)opcode1)); #endif @@ -7862,11 +7942,11 @@ re_scan: case WASM_OP_MEMORY_INIT: { CHECK_MEMORY(); - read_leb_uint32(p, p_end, segment_index); + pb_read_leb_uint32(p, p_end, segment_index); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, segment_index); #endif - read_leb_memidx(p, p_end, memidx); + pb_read_leb_memidx(p, p_end, memidx); check_memidx(module, memidx); bh_assert(segment_index < module->data_seg_count); @@ -7882,7 +7962,7 @@ re_scan: } case WASM_OP_DATA_DROP: { - read_leb_uint32(p, p_end, segment_index); + pb_read_leb_uint32(p, p_end, segment_index); #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, segment_index); #endif @@ -7898,9 +7978,9 @@ re_scan: CHECK_MEMORY(); CHECK_BUF(p, p_end, sizeof(int16)); /* check both src and dst memory index */ - read_leb_memidx(p, p_end, memidx); + pb_read_leb_memidx(p, p_end, memidx); check_memidx(module, memidx); - read_leb_memidx(p, p_end, memidx); + pb_read_leb_memidx(p, p_end, memidx); check_memidx(module, memidx); POP_MEM_OFFSET(); @@ -7914,7 +7994,7 @@ re_scan: case WASM_OP_MEMORY_FILL: { CHECK_MEMORY(); - read_leb_memidx(p, p_end, memidx); + pb_read_leb_memidx(p, p_end, memidx); check_memidx(module, memidx); POP_MEM_OFFSET(); @@ -7932,8 +8012,8 @@ re_scan: uint8 seg_ref_type, tbl_ref_type; uint32 table_seg_idx, table_idx; - read_leb_uint32(p, p_end, table_seg_idx); - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_seg_idx); + pb_read_leb_uint32(p, p_end, table_idx); if (!get_table_elem_type(module, table_idx, &tbl_ref_type, error_buf, @@ -7968,7 +8048,7 @@ re_scan: case WASM_OP_ELEM_DROP: { uint32 table_seg_idx; - read_leb_uint32(p, p_end, table_seg_idx); + pb_read_leb_uint32(p, p_end, table_seg_idx); if (!get_table_seg_elem_type(module, table_seg_idx, NULL, error_buf, error_buf_size)) @@ -7984,13 +8064,13 @@ re_scan: uint32 src_tbl_idx, dst_tbl_idx, src_tbl_idx_type, dst_tbl_idx_type, min_tbl_idx_type; - read_leb_uint32(p, p_end, src_tbl_idx); + pb_read_leb_uint32(p, p_end, src_tbl_idx); if (!get_table_elem_type(module, src_tbl_idx, &src_ref_type, error_buf, error_buf_size)) goto fail; - read_leb_uint32(p, p_end, dst_tbl_idx); + pb_read_leb_uint32(p, p_end, dst_tbl_idx); if (!get_table_elem_type(module, dst_tbl_idx, &dst_ref_type, error_buf, error_buf_size)) @@ -8037,7 +8117,7 @@ re_scan: { uint32 table_idx; - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_idx); /* TODO: shall we create a new function to check table idx instead of using below function? */ if (!get_table_elem_type(module, table_idx, NULL, @@ -8062,7 +8142,7 @@ re_scan: uint8 decl_ref_type; uint32 table_idx; - read_leb_uint32(p, p_end, table_idx); + pb_read_leb_uint32(p, p_end, table_idx); if (!get_table_elem_type(module, table_idx, &decl_ref_type, error_buf, error_buf_size)) @@ -8114,15 +8194,15 @@ re_scan: { uint32 opcode1; - read_leb_uint32(p, p_end, opcode1); + pb_read_leb_uint32(p, p_end, opcode1); #if WASM_ENABLE_FAST_INTERP != 0 emit_byte(loader_ctx, opcode1); #endif if (opcode1 != WASM_OP_ATOMIC_FENCE) { CHECK_MEMORY(); - read_leb_uint32(p, p_end, align); /* align */ - read_leb_mem_offset(p, p_end, mem_offset); /* offset */ + pb_read_leb_uint32(p, p_end, align); /* align */ + pb_read_leb_mem_offset(p, p_end, mem_offset); /* offset */ #if WASM_ENABLE_FAST_INTERP != 0 emit_uint32(loader_ctx, mem_offset); #endif From 1ac62e1f22ab28789d8611dae9a51b1580cb3ad3 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo <90845888+midokura-xavi92@users.noreply.github.com> Date: Wed, 15 Jan 2025 08:14:22 +0100 Subject: [PATCH 098/105] .github: Add shared lib builds (#3975) So far, no workflows would attempt to build the shared version of the iwasm library (namely, vmlib). Note that, as opposed to GC_EH_BUILD_OPTIONS and DEFAULT_BUILD_OPTIONS, the actual default options defined by the build system are assumed, for the sake of simplicity and avoiding repeated code. --- .github/workflows/compilation_on_android_ubuntu.yml | 4 ++++ .github/workflows/nightly_run.yml | 1 + 2 files changed, 5 insertions(+) diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 1ea36418e..119c8b2d0 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -156,6 +156,7 @@ jobs: "-DWAMR_DISABLE_HW_BOUND_CHECK=1", "-DWAMR_BUILD_MEMORY64=1", "-DWAMR_BUILD_MULTI_MEMORY=1", + "-DWAMR_BUILD_SHARED=1", ] os: [ubuntu-22.04] platform: [android, linux] @@ -253,6 +254,9 @@ jobs: platform: android - make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS platform: android + # android does not support WAMR_BUILD_SHARED in its CMakeLists.txt. + - make_options_feature: "-DWAMR_BUILD_SHARED=1" + platform: android include: - os: ubuntu-22.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} diff --git a/.github/workflows/nightly_run.yml b/.github/workflows/nightly_run.yml index 5e9b4a4f2..dacdbc42d 100644 --- a/.github/workflows/nightly_run.yml +++ b/.github/workflows/nightly_run.yml @@ -142,6 +142,7 @@ jobs: "-DWAMR_DISABLE_HW_BOUND_CHECK=1", "-DWAMR_BUILD_MEMORY64=1", "-DWAMR_BUILD_MULTI_MEMORY=1", + "-DWAMR_BUILD_SHARED=1", ] os: [ubuntu-20.04] platform: [android, linux] From ba75b8fd563d041009fed4c910fc886dbb31c68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Mal=C3=BD?= Date: Fri, 17 Jan 2025 04:06:14 +0100 Subject: [PATCH 099/105] fixes for compiling on windows (#4026) --- core/shared/platform/windows/win_clock.c | 16 +++++++++++++--- core/shared/platform/windows/win_thread.c | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/core/shared/platform/windows/win_clock.c b/core/shared/platform/windows/win_clock.c index c402330aa..1d618c8b6 100644 --- a/core/shared/platform/windows/win_clock.c +++ b/core/shared/platform/windows/win_clock.c @@ -11,9 +11,19 @@ #define NANOSECONDS_PER_TICK 100 #if WINAPI_PARTITION_DESKTOP -extern NTSTATUS -NtQueryTimerResolution(PULONG MinimumResolution, PULONG MaximumResolution, - PULONG CurrentResolution); +#ifndef __kernel_entry +#define __kernel_entry +#endif +#ifndef NTAPI +#define NTAPI +#endif +#ifndef _Out_ +#define _Out_ +#endif +extern __kernel_entry NTSTATUS NTAPI +NtQueryTimerResolution(_Out_ PULONG MinimumResolution, + _Out_ PULONG MaximumResolution, + _Out_ PULONG CurrentResolution); #endif static __wasi_errno_t diff --git a/core/shared/platform/windows/win_thread.c b/core/shared/platform/windows/win_thread.c index 438e16040..1f6a57ebb 100644 --- a/core/shared/platform/windows/win_thread.c +++ b/core/shared/platform/windows/win_thread.c @@ -60,6 +60,17 @@ static DWORD thread_data_key; static void(WINAPI *GetCurrentThreadStackLimits_Kernel32)(PULONG_PTR, PULONG_PTR) = NULL; +int +os_sem_init(korp_sem *sem); +int +os_sem_destroy(korp_sem *sem); +int +os_sem_wait(korp_sem *sem); +int +os_sem_reltimed_wait(korp_sem *sem, uint64 useconds); +int +os_sem_signal(korp_sem *sem); + static void thread_data_list_add(os_thread_data *thread_data) { @@ -117,17 +128,6 @@ thread_data_list_lookup(korp_tid tid) return NULL; } -int -os_sem_init(korp_sem *sem); -int -os_sem_destroy(korp_sem *sem); -int -os_sem_wait(korp_sem *sem); -int -os_sem_reltimed_wait(korp_sem *sem, uint64 useconds); -int -os_sem_signal(korp_sem *sem); - int os_thread_sys_init() { From 831e4bbfd51323e10e47db1d5f7200341e87a6bb Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 20 Jan 2025 09:39:32 +0800 Subject: [PATCH 100/105] Refine getting const offsets in wasm loader of fast-interp (#4012) - Refine const offsets in loader for fast-interp - handle const cell num overflow - Use const array, remove list --- core/iwasm/interpreter/wasm_loader.c | 336 +++++++++++++--------- core/iwasm/interpreter/wasm_mini_loader.c | 336 +++++++++++++--------- 2 files changed, 412 insertions(+), 260 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 4ee553e0b..6cd1ece4f 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -355,9 +355,14 @@ memory_realloc(void *mem_old, uint32 size_old, uint32 size_new, char *error_buf, { uint8 *mem_new; bh_assert(size_new > size_old); + + if ((mem_new = wasm_runtime_realloc(mem_old, size_new))) { + memset(mem_new + size_old, 0, size_new - size_old); + return mem_new; + } + if ((mem_new = loader_malloc(size_new, error_buf, error_buf_size))) { bh_memcpy_s(mem_new, size_new, mem_old, size_old); - memset(mem_new + size_old, 0, size_new - size_old); wasm_runtime_free(mem_old); } return mem_new; @@ -7949,11 +7954,16 @@ typedef struct WASMLoaderContext { /* preserved local offset */ int16 preserved_local_offset; - /* const buffer */ - uint8 *const_buf; - uint16 num_const; - uint16 const_cell_num; - uint32 const_buf_size; + /* const buffer for i64 and f64 consts, note that the raw bytes + * of i64 and f64 are the same, so we read an i64 value from an + * f64 const with its raw bytes, something like `*(int64 *)&f64 */ + int64 *i64_consts; + uint32 i64_const_max_num; + uint32 i64_const_num; + /* const buffer for i32 and f32 consts */ + int32 *i32_consts; + uint32 i32_const_max_num; + uint32 i32_const_num; /* processed code */ uint8 *p_code_compiled; @@ -7966,12 +7976,6 @@ typedef struct WASMLoaderContext { #endif } WASMLoaderContext; -typedef struct Const { - WASMValue value; - uint16 slot_index; - uint8 value_type; -} Const; - #define CHECK_CSP_PUSH() \ do { \ if (ctx->frame_csp >= ctx->frame_csp_boundary) { \ @@ -8189,8 +8193,10 @@ wasm_loader_ctx_destroy(WASMLoaderContext *ctx) #if WASM_ENABLE_FAST_INTERP != 0 if (ctx->frame_offset_bottom) wasm_runtime_free(ctx->frame_offset_bottom); - if (ctx->const_buf) - wasm_runtime_free(ctx->const_buf); + if (ctx->i64_consts) + wasm_runtime_free(ctx->i64_consts); + if (ctx->i32_consts) + wasm_runtime_free(ctx->i32_consts); #endif wasm_runtime_free(ctx); } @@ -8238,10 +8244,15 @@ wasm_loader_ctx_init(WASMFunction *func, char *error_buf, uint32 error_buf_size) goto fail; loader_ctx->frame_offset_boundary = loader_ctx->frame_offset_bottom + 32; - loader_ctx->num_const = 0; - loader_ctx->const_buf_size = sizeof(Const) * 8; - if (!(loader_ctx->const_buf = loader_malloc(loader_ctx->const_buf_size, - error_buf, error_buf_size))) + loader_ctx->i64_const_max_num = 8; + if (!(loader_ctx->i64_consts = + loader_malloc(sizeof(int64) * loader_ctx->i64_const_max_num, + error_buf, error_buf_size))) + goto fail; + loader_ctx->i32_const_max_num = 8; + if (!(loader_ctx->i32_consts = + loader_malloc(sizeof(int32) * loader_ctx->i32_const_max_num, + error_buf, error_buf_size))) goto fail; if (func->param_cell_num >= (int32)INT16_MAX - func->local_cell_num) { @@ -9489,108 +9500,116 @@ wasm_loader_push_pop_frame_ref_offset(WASMLoaderContext *ctx, uint8 pop_cnt, return true; } +static int +cmp_i64_const(const void *p_i64_const1, const void *p_i64_const2) +{ + int64 i64_const1 = *(int64 *)p_i64_const1; + int64 i64_const2 = *(int64 *)p_i64_const2; + + return (i64_const1 < i64_const2) ? -1 : (i64_const1 > i64_const2) ? 1 : 0; +} + +static int +cmp_i32_const(const void *p_i32_const1, const void *p_i32_const2) +{ + int32 i32_const1 = *(int32 *)p_i32_const1; + int32 i32_const2 = *(int32 *)p_i32_const2; + + return (i32_const1 < i32_const2) ? -1 : (i32_const1 > i32_const2) ? 1 : 0; +} + static bool wasm_loader_get_const_offset(WASMLoaderContext *ctx, uint8 type, void *value, int16 *offset, char *error_buf, uint32 error_buf_size) { - int8 bytes_to_increase; - int16 operand_offset = 0; - Const *c; + if (!ctx->p_code_compiled) { + /* Treat i64 and f64 as the same by reading i64 value from + the raw bytes */ + if (type == VALUE_TYPE_I64 || type == VALUE_TYPE_F64) { + /* No slot left, emit const instead */ + if (ctx->i64_const_num * 2 + ctx->i32_const_num > INT16_MAX - 2) { + *offset = 0; + return true; + } - /* Search existing constant */ - for (c = (Const *)ctx->const_buf; - (uint8 *)c < ctx->const_buf + ctx->num_const * sizeof(Const); c++) { - /* TODO: handle v128 type? */ - if ((type == c->value_type) - && ((type == VALUE_TYPE_I64 && *(int64 *)value == c->value.i64) - || (type == VALUE_TYPE_I32 && *(int32 *)value == c->value.i32) -#if WASM_ENABLE_REF_TYPES != 0 && WASM_ENABLE_GC == 0 - || (type == VALUE_TYPE_FUNCREF - && *(int32 *)value == c->value.i32) - || (type == VALUE_TYPE_EXTERNREF - && *(int32 *)value == c->value.i32) -#endif - || (type == VALUE_TYPE_F64 - && (0 == memcmp(value, &(c->value.f64), sizeof(float64)))) - || (type == VALUE_TYPE_F32 - && (0 - == memcmp(value, &(c->value.f32), sizeof(float32)))))) { - operand_offset = c->slot_index; - break; - } - if (is_32bit_type(c->value_type)) - operand_offset += 1; - else - operand_offset += 2; - } + /* Traverse the list if the const num is small */ + if (ctx->i64_const_num < 10) { + for (uint32 i = 0; i < ctx->i64_const_num; i++) { + if (ctx->i64_consts[i] == *(int64 *)value) { + *offset = -1; + return true; + } + } + } - if ((uint8 *)c == ctx->const_buf + ctx->num_const * sizeof(Const)) { - /* New constant, append to the const buffer */ - if ((type == VALUE_TYPE_F64) || (type == VALUE_TYPE_I64)) { - bytes_to_increase = 2; + if (ctx->i64_const_num >= ctx->i64_const_max_num) { + MEM_REALLOC(ctx->i64_consts, + sizeof(int64) * ctx->i64_const_max_num, + sizeof(int64) * (ctx->i64_const_max_num * 2)); + ctx->i64_const_max_num *= 2; + } + ctx->i64_consts[ctx->i64_const_num++] = *(int64 *)value; } else { - bytes_to_increase = 1; + /* Treat i32 and f32 as the same by reading i32 value from + the raw bytes */ + bh_assert(type == VALUE_TYPE_I32 || type == VALUE_TYPE_F32); + + /* No slot left, emit const instead */ + if (ctx->i64_const_num * 2 + ctx->i32_const_num > INT16_MAX - 1) { + *offset = 0; + return true; + } + + /* Traverse the list if the const num is small */ + if (ctx->i32_const_num < 10) { + for (uint32 i = 0; i < ctx->i32_const_num; i++) { + if (ctx->i32_consts[i] == *(int32 *)value) { + *offset = -1; + return true; + } + } + } + + if (ctx->i32_const_num >= ctx->i32_const_max_num) { + MEM_REALLOC(ctx->i32_consts, + sizeof(int32) * ctx->i32_const_max_num, + sizeof(int32) * (ctx->i32_const_max_num * 2)); + ctx->i32_const_max_num *= 2; + } + ctx->i32_consts[ctx->i32_const_num++] = *(int32 *)value; } - /* The max cell num of const buffer is 32768 since the valid index range - * is -32768 ~ -1. Return an invalid index 0 to indicate the buffer is - * full */ - if (ctx->const_cell_num > INT16_MAX - bytes_to_increase + 1) { - *offset = 0; - return true; - } - - if ((uint8 *)c == ctx->const_buf + ctx->const_buf_size) { - MEM_REALLOC(ctx->const_buf, ctx->const_buf_size, - ctx->const_buf_size + 4 * sizeof(Const)); - ctx->const_buf_size += 4 * sizeof(Const); - c = (Const *)(ctx->const_buf + ctx->num_const * sizeof(Const)); - } - c->value_type = type; - switch (type) { - case VALUE_TYPE_F64: - bh_memcpy_s(&(c->value.f64), sizeof(WASMValue), value, - sizeof(float64)); - ctx->const_cell_num += 2; - /* The const buf will be reversed, we use the second cell */ - /* of the i64/f64 const so the final offset is correct */ - operand_offset++; - break; - case VALUE_TYPE_I64: - c->value.i64 = *(int64 *)value; - ctx->const_cell_num += 2; - operand_offset++; - break; - case VALUE_TYPE_F32: - bh_memcpy_s(&(c->value.f32), sizeof(WASMValue), value, - sizeof(float32)); - ctx->const_cell_num++; - break; - case VALUE_TYPE_I32: - c->value.i32 = *(int32 *)value; - ctx->const_cell_num++; - break; -#if WASM_ENABLE_REF_TYPES != 0 && WASM_ENABLE_GC == 0 - case VALUE_TYPE_EXTERNREF: - case VALUE_TYPE_FUNCREF: - c->value.i32 = *(int32 *)value; - ctx->const_cell_num++; - break; -#endif - default: - break; - } - c->slot_index = operand_offset; - ctx->num_const++; - LOG_OP("#### new const [%d]: %ld\n", ctx->num_const, - (int64)c->value.i64); + *offset = -1; + return true; + } + else { + if (type == VALUE_TYPE_I64 || type == VALUE_TYPE_F64) { + int64 key = *(int64 *)value, *i64_const; + i64_const = bsearch(&key, ctx->i64_consts, ctx->i64_const_num, + sizeof(int64), cmp_i64_const); + if (!i64_const) { /* not found, emit const instead */ + *offset = 0; + return true; + } + *offset = -(uint32)(ctx->i64_const_num * 2 + ctx->i32_const_num) + + (uint32)(i64_const - ctx->i64_consts) * 2; + } + else { + int32 key = *(int32 *)value, *i32_const; + i32_const = bsearch(&key, ctx->i32_consts, ctx->i32_const_num, + sizeof(int32), cmp_i32_const); + if (!i32_const) { /* not found, emit const instead */ + *offset = 0; + return true; + } + *offset = -(uint32)(ctx->i32_const_num) + + (uint32)(i32_const - ctx->i32_consts); + } + + return true; } - /* use negative index for const */ - operand_offset = -(operand_offset + 1); - *offset = operand_offset; - return true; fail: return false; } @@ -11028,7 +11047,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, bool need_ref_type_map; #endif #if WASM_ENABLE_FAST_INTERP != 0 - uint8 *func_const_end, *func_const = NULL; int16 operand_offset = 0; uint8 last_op = 0; bool disable_emit, preserve_local = false, if_condition_available = true; @@ -11095,6 +11113,68 @@ re_scan: p = func->code; func->code_compiled = loader_ctx->p_code_compiled; func->code_compiled_size = loader_ctx->code_compiled_size; + + if (loader_ctx->i64_const_num > 0) { + int64 *i64_consts_old = loader_ctx->i64_consts; + + /* Sort the i64 consts */ + qsort(i64_consts_old, loader_ctx->i64_const_num, sizeof(int64), + cmp_i64_const); + + /* Remove the duplicated i64 consts */ + uint32 k = 1; + for (i = 1; i < loader_ctx->i64_const_num; i++) { + if (i64_consts_old[i] != i64_consts_old[i - 1]) { + i64_consts_old[k++] = i64_consts_old[i]; + } + } + + if (k < loader_ctx->i64_const_num) { + int64 *i64_consts_new; + /* Try to reallocate memory with a smaller size */ + if ((i64_consts_new = + wasm_runtime_malloc((uint32)sizeof(int64) * k))) { + bh_memcpy_s(i64_consts_new, (uint32)sizeof(int64) * k, + i64_consts_old, (uint32)sizeof(int64) * k); + /* Free the old memory */ + wasm_runtime_free(i64_consts_old); + loader_ctx->i64_consts = i64_consts_new; + loader_ctx->i64_const_max_num = k; + } + loader_ctx->i64_const_num = k; + } + } + + if (loader_ctx->i32_const_num > 0) { + int32 *i32_consts_old = loader_ctx->i32_consts; + + /* Sort the i32 consts */ + qsort(i32_consts_old, loader_ctx->i32_const_num, sizeof(int32), + cmp_i32_const); + + /* Remove the duplicated i32 consts */ + uint32 k = 1; + for (i = 1; i < loader_ctx->i32_const_num; i++) { + if (i32_consts_old[i] != i32_consts_old[i - 1]) { + i32_consts_old[k++] = i32_consts_old[i]; + } + } + + if (k < loader_ctx->i32_const_num) { + int32 *i32_consts_new; + /* Try to reallocate memory with a smaller size */ + if ((i32_consts_new = + wasm_runtime_malloc((uint32)sizeof(int32) * k))) { + bh_memcpy_s(i32_consts_new, (uint32)sizeof(int32) * k, + i32_consts_old, (uint32)sizeof(int32) * k); + /* Free the old memory */ + wasm_runtime_free(i32_consts_old); + loader_ctx->i32_consts = i32_consts_new; + loader_ctx->i32_const_max_num = k; + } + loader_ctx->i32_const_num = k; + } + } } #endif @@ -16016,29 +16096,25 @@ re_scan: if (loader_ctx->p_code_compiled == NULL) goto re_scan; - func->const_cell_num = loader_ctx->const_cell_num; + func->const_cell_num = + loader_ctx->i64_const_num * 2 + loader_ctx->i32_const_num; if (func->const_cell_num > 0) { - int32 j; - - if (!(func->consts = func_const = loader_malloc( - func->const_cell_num * 4, error_buf, error_buf_size))) + if (!(func->consts = + loader_malloc((uint64)sizeof(uint32) * func->const_cell_num, + error_buf, error_buf_size))) goto fail; - - func_const_end = func->consts + func->const_cell_num * 4; - /* reverse the const buf */ - for (j = loader_ctx->num_const - 1; j >= 0; j--) { - Const *c = (Const *)(loader_ctx->const_buf + j * sizeof(Const)); - if (c->value_type == VALUE_TYPE_F64 - || c->value_type == VALUE_TYPE_I64) { - bh_memcpy_s(func_const, (uint32)(func_const_end - func_const), - &(c->value.f64), (uint32)sizeof(int64)); - func_const += sizeof(int64); - } - else { - bh_memcpy_s(func_const, (uint32)(func_const_end - func_const), - &(c->value.f32), (uint32)sizeof(int32)); - func_const += sizeof(int32); - } + if (loader_ctx->i64_const_num > 0) { + bh_memcpy_s(func->consts, + (uint32)sizeof(int64) * loader_ctx->i64_const_num, + loader_ctx->i64_consts, + (uint32)sizeof(int64) * loader_ctx->i64_const_num); + } + if (loader_ctx->i32_const_num > 0) { + bh_memcpy_s(func->consts + + sizeof(int64) * loader_ctx->i64_const_num, + (uint32)sizeof(int32) * loader_ctx->i32_const_num, + loader_ctx->i32_consts, + (uint32)sizeof(int32) * loader_ctx->i32_const_num); } } diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index fde969c94..1638459a5 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -208,9 +208,14 @@ memory_realloc(void *mem_old, uint32 size_old, uint32 size_new, char *error_buf, { uint8 *mem_new; bh_assert(size_new > size_old); + + if ((mem_new = wasm_runtime_realloc(mem_old, size_new))) { + memset(mem_new + size_old, 0, size_new - size_old); + return mem_new; + } + if ((mem_new = loader_malloc(size_new, error_buf, error_buf_size))) { bh_memcpy_s(mem_new, size_new, mem_old, size_old); - memset(mem_new + size_old, 0, size_new - size_old); wasm_runtime_free(mem_old); } return mem_new; @@ -4047,11 +4052,16 @@ typedef struct WASMLoaderContext { /* preserved local offset */ int16 preserved_local_offset; - /* const buffer */ - uint8 *const_buf; - uint16 num_const; - uint16 const_cell_num; - uint32 const_buf_size; + /* const buffer for i64 and f64 consts, note that the raw bytes + * of i64 and f64 are the same, so we read an i64 value from an + * f64 const with its raw bytes, something like `*(int64 *)&f64 */ + int64 *i64_consts; + uint32 i64_const_max_num; + uint32 i64_const_num; + /* const buffer for i32 and f32 consts */ + int32 *i32_consts; + uint32 i32_const_max_num; + uint32 i32_const_num; /* processed code */ uint8 *p_code_compiled; @@ -4064,12 +4074,6 @@ typedef struct WASMLoaderContext { #endif } WASMLoaderContext; -typedef struct Const { - WASMValue value; - uint16 slot_index; - uint8 value_type; -} Const; - #define CHECK_CSP_PUSH() \ do { \ if (ctx->frame_csp >= ctx->frame_csp_boundary) { \ @@ -4224,8 +4228,10 @@ wasm_loader_ctx_destroy(WASMLoaderContext *ctx) #if WASM_ENABLE_FAST_INTERP != 0 if (ctx->frame_offset_bottom) wasm_runtime_free(ctx->frame_offset_bottom); - if (ctx->const_buf) - wasm_runtime_free(ctx->const_buf); + if (ctx->i64_consts) + wasm_runtime_free(ctx->i64_consts); + if (ctx->i32_consts) + wasm_runtime_free(ctx->i32_consts); #endif wasm_runtime_free(ctx); } @@ -4259,10 +4265,15 @@ wasm_loader_ctx_init(WASMFunction *func, char *error_buf, uint32 error_buf_size) goto fail; loader_ctx->frame_offset_boundary = loader_ctx->frame_offset_bottom + 32; - loader_ctx->num_const = 0; - loader_ctx->const_buf_size = sizeof(Const) * 8; - if (!(loader_ctx->const_buf = loader_malloc(loader_ctx->const_buf_size, - error_buf, error_buf_size))) + loader_ctx->i64_const_max_num = 8; + if (!(loader_ctx->i64_consts = + loader_malloc(sizeof(int64) * loader_ctx->i64_const_max_num, + error_buf, error_buf_size))) + goto fail; + loader_ctx->i32_const_max_num = 8; + if (!(loader_ctx->i32_consts = + loader_malloc(sizeof(int32) * loader_ctx->i32_const_max_num, + error_buf, error_buf_size))) goto fail; if (func->param_cell_num >= (int32)INT16_MAX - func->local_cell_num) { @@ -5085,107 +5096,116 @@ wasm_loader_push_pop_frame_ref_offset(WASMLoaderContext *ctx, uint8 pop_cnt, return true; } +static int +cmp_i64_const(const void *p_i64_const1, const void *p_i64_const2) +{ + int64 i64_const1 = *(int64 *)p_i64_const1; + int64 i64_const2 = *(int64 *)p_i64_const2; + + return (i64_const1 < i64_const2) ? -1 : (i64_const1 > i64_const2) ? 1 : 0; +} + +static int +cmp_i32_const(const void *p_i32_const1, const void *p_i32_const2) +{ + int32 i32_const1 = *(int32 *)p_i32_const1; + int32 i32_const2 = *(int32 *)p_i32_const2; + + return (i32_const1 < i32_const2) ? -1 : (i32_const1 > i32_const2) ? 1 : 0; +} + static bool wasm_loader_get_const_offset(WASMLoaderContext *ctx, uint8 type, void *value, int16 *offset, char *error_buf, uint32 error_buf_size) { - int8 bytes_to_increase; - int16 operand_offset = 0; - Const *c; + if (!ctx->p_code_compiled) { + /* Treat i64 and f64 as the same by reading i64 value from + the raw bytes */ + if (type == VALUE_TYPE_I64 || type == VALUE_TYPE_F64) { + /* No slot left, emit const instead */ + if (ctx->i64_const_num * 2 + ctx->i32_const_num > INT16_MAX - 2) { + *offset = 0; + return true; + } - /* Search existing constant */ - for (c = (Const *)ctx->const_buf; - (uint8 *)c < ctx->const_buf + ctx->num_const * sizeof(Const); c++) { - if ((type == c->value_type) - && ((type == VALUE_TYPE_I64 && *(int64 *)value == c->value.i64) - || (type == VALUE_TYPE_I32 && *(int32 *)value == c->value.i32) -#if WASM_ENABLE_REF_TYPES != 0 - || (type == VALUE_TYPE_FUNCREF - && *(int32 *)value == c->value.i32) - || (type == VALUE_TYPE_EXTERNREF - && *(int32 *)value == c->value.i32) -#endif - || (type == VALUE_TYPE_F64 - && (0 == memcmp(value, &(c->value.f64), sizeof(float64)))) - || (type == VALUE_TYPE_F32 - && (0 - == memcmp(value, &(c->value.f32), sizeof(float32)))))) { - operand_offset = c->slot_index; - break; - } - if (c->value_type == VALUE_TYPE_I64 || c->value_type == VALUE_TYPE_F64) - operand_offset += 2; - else - operand_offset += 1; - } + /* Traverse the list if the const num is small */ + if (ctx->i64_const_num < 10) { + for (uint32 i = 0; i < ctx->i64_const_num; i++) { + if (ctx->i64_consts[i] == *(int64 *)value) { + *offset = -1; + return true; + } + } + } - if ((uint8 *)c == ctx->const_buf + ctx->num_const * sizeof(Const)) { - /* New constant, append to the const buffer */ - if ((type == VALUE_TYPE_F64) || (type == VALUE_TYPE_I64)) { - bytes_to_increase = 2; + if (ctx->i64_const_num >= ctx->i64_const_max_num) { + MEM_REALLOC(ctx->i64_consts, + sizeof(int64) * ctx->i64_const_max_num, + sizeof(int64) * (ctx->i64_const_max_num * 2)); + ctx->i64_const_max_num *= 2; + } + ctx->i64_consts[ctx->i64_const_num++] = *(int64 *)value; } else { - bytes_to_increase = 1; + /* Treat i32 and f32 as the same by reading i32 value from + the raw bytes */ + bh_assert(type == VALUE_TYPE_I32 || type == VALUE_TYPE_F32); + + /* No slot left, emit const instead */ + if (ctx->i64_const_num * 2 + ctx->i32_const_num > INT16_MAX - 1) { + *offset = 0; + return true; + } + + /* Traverse the list if the const num is small */ + if (ctx->i32_const_num < 10) { + for (uint32 i = 0; i < ctx->i32_const_num; i++) { + if (ctx->i32_consts[i] == *(int32 *)value) { + *offset = -1; + return true; + } + } + } + + if (ctx->i32_const_num >= ctx->i32_const_max_num) { + MEM_REALLOC(ctx->i32_consts, + sizeof(int32) * ctx->i32_const_max_num, + sizeof(int32) * (ctx->i32_const_max_num * 2)); + ctx->i32_const_max_num *= 2; + } + ctx->i32_consts[ctx->i32_const_num++] = *(int32 *)value; } - /* The max cell num of const buffer is 32768 since the valid index range - * is -32768 ~ -1. Return an invalid index 0 to indicate the buffer is - * full */ - if (ctx->const_cell_num > INT16_MAX - bytes_to_increase + 1) { - *offset = 0; - return true; - } - - if ((uint8 *)c == ctx->const_buf + ctx->const_buf_size) { - MEM_REALLOC(ctx->const_buf, ctx->const_buf_size, - ctx->const_buf_size + 4 * sizeof(Const)); - ctx->const_buf_size += 4 * sizeof(Const); - c = (Const *)(ctx->const_buf + ctx->num_const * sizeof(Const)); - } - c->value_type = type; - switch (type) { - case VALUE_TYPE_F64: - bh_memcpy_s(&(c->value.f64), sizeof(WASMValue), value, - sizeof(float64)); - ctx->const_cell_num += 2; - /* The const buf will be reversed, we use the second cell */ - /* of the i64/f64 const so the finnal offset is corrent */ - operand_offset++; - break; - case VALUE_TYPE_I64: - c->value.i64 = *(int64 *)value; - ctx->const_cell_num += 2; - operand_offset++; - break; - case VALUE_TYPE_F32: - bh_memcpy_s(&(c->value.f32), sizeof(WASMValue), value, - sizeof(float32)); - ctx->const_cell_num++; - break; - case VALUE_TYPE_I32: - c->value.i32 = *(int32 *)value; - ctx->const_cell_num++; - break; -#if WASM_ENABLE_REF_TYPES != 0 - case VALUE_TYPE_EXTERNREF: - case VALUE_TYPE_FUNCREF: - c->value.i32 = *(int32 *)value; - ctx->const_cell_num++; - break; -#endif - default: - break; - } - c->slot_index = operand_offset; - ctx->num_const++; - LOG_OP("#### new const [%d]: %ld\n", ctx->num_const, - (int64)c->value.i64); + *offset = -1; + return true; + } + else { + if (type == VALUE_TYPE_I64 || type == VALUE_TYPE_F64) { + int64 key = *(int64 *)value, *i64_const; + i64_const = bsearch(&key, ctx->i64_consts, ctx->i64_const_num, + sizeof(int64), cmp_i64_const); + if (!i64_const) { /* not found, emit const instead */ + *offset = 0; + return true; + } + *offset = -(uint32)(ctx->i64_const_num * 2 + ctx->i32_const_num) + + (uint32)(i64_const - ctx->i64_consts) * 2; + } + else { + int32 key = *(int32 *)value, *i32_const; + i32_const = bsearch(&key, ctx->i32_consts, ctx->i32_const_num, + sizeof(int32), cmp_i32_const); + if (!i32_const) { /* not found, emit const instead */ + *offset = 0; + return true; + } + *offset = -(uint32)(ctx->i32_const_num) + + (uint32)(i32_const - ctx->i32_consts); + } + + return true; } - /* use negetive index for const */ - operand_offset = -(operand_offset + 1); - *offset = operand_offset; - return true; fail: return false; } @@ -6151,11 +6171,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, uint32 segment_index; #endif #if WASM_ENABLE_FAST_INTERP != 0 - uint8 *func_const_end, *func_const = NULL; int16 operand_offset = 0; uint8 last_op = 0; bool disable_emit, preserve_local = false, if_condition_available = true; - ; float32 f32_const; float64 f64_const; @@ -6206,6 +6224,68 @@ re_scan: p = func->code; func->code_compiled = loader_ctx->p_code_compiled; func->code_compiled_size = loader_ctx->code_compiled_size; + + if (loader_ctx->i64_const_num > 0) { + int64 *i64_consts_old = loader_ctx->i64_consts; + + /* Sort the i64 consts */ + qsort(i64_consts_old, loader_ctx->i64_const_num, sizeof(int64), + cmp_i64_const); + + /* Remove the duplicated i64 consts */ + uint32 k = 1; + for (i = 1; i < loader_ctx->i64_const_num; i++) { + if (i64_consts_old[i] != i64_consts_old[i - 1]) { + i64_consts_old[k++] = i64_consts_old[i]; + } + } + + if (k < loader_ctx->i64_const_num) { + int64 *i64_consts_new; + /* Try to reallocate memory with a smaller size */ + if ((i64_consts_new = + wasm_runtime_malloc((uint32)sizeof(int64) * k))) { + bh_memcpy_s(i64_consts_new, (uint32)sizeof(int64) * k, + i64_consts_old, (uint32)sizeof(int64) * k); + /* Free the old memory */ + wasm_runtime_free(i64_consts_old); + loader_ctx->i64_consts = i64_consts_new; + loader_ctx->i64_const_max_num = k; + } + loader_ctx->i64_const_num = k; + } + } + + if (loader_ctx->i32_const_num > 0) { + int32 *i32_consts_old = loader_ctx->i32_consts; + + /* Sort the i32 consts */ + qsort(i32_consts_old, loader_ctx->i32_const_num, sizeof(int32), + cmp_i32_const); + + /* Remove the duplicated i32 consts */ + uint32 k = 1; + for (i = 1; i < loader_ctx->i32_const_num; i++) { + if (i32_consts_old[i] != i32_consts_old[i - 1]) { + i32_consts_old[k++] = i32_consts_old[i]; + } + } + + if (k < loader_ctx->i32_const_num) { + int32 *i32_consts_new; + /* Try to reallocate memory with a smaller size */ + if ((i32_consts_new = + wasm_runtime_malloc((uint32)sizeof(int32) * k))) { + bh_memcpy_s(i32_consts_new, (uint32)sizeof(int32) * k, + i32_consts_old, (uint32)sizeof(int32) * k); + /* Free the old memory */ + wasm_runtime_free(i32_consts_old); + loader_ctx->i32_consts = i32_consts_new; + loader_ctx->i32_const_max_num = k; + } + loader_ctx->i32_const_num = k; + } + } } #endif @@ -8352,29 +8432,25 @@ re_scan: if (loader_ctx->p_code_compiled == NULL) goto re_scan; - func->const_cell_num = loader_ctx->const_cell_num; + func->const_cell_num = + loader_ctx->i64_const_num * 2 + loader_ctx->i32_const_num; if (func->const_cell_num > 0) { - int32 j; - - if (!(func->consts = func_const = loader_malloc( - func->const_cell_num * 4, error_buf, error_buf_size))) + if (!(func->consts = + loader_malloc((uint64)sizeof(uint32) * func->const_cell_num, + error_buf, error_buf_size))) goto fail; - - func_const_end = func->consts + func->const_cell_num * 4; - /* reverse the const buf */ - for (j = loader_ctx->num_const - 1; j >= 0; j--) { - Const *c = (Const *)(loader_ctx->const_buf + j * sizeof(Const)); - if (c->value_type == VALUE_TYPE_F64 - || c->value_type == VALUE_TYPE_I64) { - bh_memcpy_s(func_const, (uint32)(func_const_end - func_const), - &(c->value.f64), (uint32)sizeof(int64)); - func_const += sizeof(int64); - } - else { - bh_memcpy_s(func_const, (uint32)(func_const_end - func_const), - &(c->value.f32), (uint32)sizeof(int32)); - func_const += sizeof(int32); - } + if (loader_ctx->i64_const_num > 0) { + bh_memcpy_s(func->consts, + (uint32)sizeof(int64) * loader_ctx->i64_const_num, + loader_ctx->i64_consts, + (uint32)sizeof(int64) * loader_ctx->i64_const_num); + } + if (loader_ctx->i32_const_num > 0) { + bh_memcpy_s(func->consts + + sizeof(int64) * loader_ctx->i64_const_num, + (uint32)sizeof(int32) * loader_ctx->i32_const_num, + loader_ctx->i32_consts, + (uint32)sizeof(int32) * loader_ctx->i32_const_num); } } From e3ddbd58f7d35e3ee367679b1b6b61ea8e7839af Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Mon, 20 Jan 2025 09:41:47 +0800 Subject: [PATCH 101/105] Synchronize the GC spec tests to the commit from December 9. 2024. (#4022) - Synchronize the GC spec tests to the commit from December 9. 2024. - Revise the error messages to be consistent with the spec test cases. - bypass gc spec test on the nuttx platform as a workaround --- .github/workflows/spec_test_on_nuttx.yml | 3 +- core/iwasm/common/wasm_runtime_common.c | 8 +- core/iwasm/interpreter/wasm_interp_classic.c | 10 +- core/iwasm/interpreter/wasm_interp_fast.c | 10 +- core/iwasm/interpreter/wasm_loader.c | 5 +- core/iwasm/interpreter/wasm_runtime.c | 2 +- .../wamr-test-suites/spec-test-script/all.py | 7 +- .../spec-test-script/gc_ignore_cases.patch | 993 +++++++++--------- .../spec-test-script/gc_nuttx_tail_call.patch | 33 +- tests/wamr-test-suites/test_wamr.sh | 11 +- 10 files changed, 531 insertions(+), 551 deletions(-) diff --git a/.github/workflows/spec_test_on_nuttx.yml b/.github/workflows/spec_test_on_nuttx.yml index 2cf80d743..8138a8612 100644 --- a/.github/workflows/spec_test_on_nuttx.yml +++ b/.github/workflows/spec_test_on_nuttx.yml @@ -127,7 +127,8 @@ jobs: wamr_feature_option: # Empty option for default - { option: "", mode: "" } - - { option: "CONFIG_INTERPRETERS_WAMR_GC CONFIG_INTERPRETERS_WAMR_AOT_STACK_FRAME", mode: "-G" } + # need to install menhir + # - { option: "CONFIG_INTERPRETERS_WAMR_GC CONFIG_INTERPRETERS_WAMR_AOT_STACK_FRAME", mode: "-G" } exclude: # XIP is not fully supported yet on RISCV64, some relocations can not be resolved diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 5517fe60f..cc6badd9e 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3014,9 +3014,9 @@ static const char *exception_msgs[] = { "wasm operand stack overflow", /* EXCE_OPERAND_STACK_OVERFLOW */ "failed to compile fast jit function", /* EXCE_FAILED_TO_COMPILE_FAST_JIT_FUNC */ /* GC related exceptions */ - "null function object", /* EXCE_NULL_FUNC_OBJ */ - "null structure object", /* EXCE_NULL_STRUCT_OBJ */ - "null array reference", /* EXCE_NULL_ARRAY_OBJ */ + "null function reference", /* EXCE_NULL_FUNC_OBJ */ + "null structure reference", /* EXCE_NULL_STRUCT_OBJ */ + "null array reference", /* EXCE_NULL_ARRAY_OBJ */ "null i31 reference", /* EXCE_NULL_I31_OBJ */ "null reference", /* EXCE_NULL_REFERENCE */ "create rtt type failed", /* EXCE_FAILED_TO_CREATE_RTT_TYPE */ @@ -3024,7 +3024,7 @@ static const char *exception_msgs[] = { "create array object failed", /* EXCE_FAILED_TO_CREATE_ARRAY_OBJ */ "create externref object failed", /* EXCE_FAILED_TO_CREATE_EXTERNREF_OBJ */ "cast failure", /* EXCE_CAST_FAILURE */ - "out of bounds array access", /* EXCE_ARRAY_IDX_OOB */ + "out of bounds array access", /* EXCE_ARRAY_IDX_OOB */ /* stringref related exceptions */ "create string object failed", /* EXCE_FAILED_TO_CREATE_STRING */ "create stringref failed", /* EXCE_FAILED_TO_CREATE_STRINGREF */ diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 834311f7e..98668470f 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -2649,7 +2649,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, read_leb_uint32(frame_ip, frame_ip_end, type_index); func_obj = POP_REF(); if (!func_obj) { - wasm_set_exception(module, "null function object"); + wasm_set_exception(module, "null function reference"); goto got_exception; } @@ -2666,7 +2666,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, read_leb_uint32(frame_ip, frame_ip_end, type_index); func_obj = POP_REF(); if (!func_obj) { - wasm_set_exception(module, "null function object"); + wasm_set_exception(module, "null function reference"); goto got_exception; } @@ -2813,7 +2813,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, struct_obj = POP_REF(); if (!struct_obj) { - wasm_set_exception(module, "null structure object"); + wasm_set_exception(module, + "null structure reference"); goto got_exception; } @@ -2869,7 +2870,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, struct_obj = POP_REF(); if (!struct_obj) { - wasm_set_exception(module, "null structure object"); + wasm_set_exception(module, + "null structure reference"); goto got_exception; } diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index f44644e45..359a6979c 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -1992,7 +1992,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #endif func_obj = POP_REF(); if (!func_obj) { - wasm_set_exception(module, "null function object"); + wasm_set_exception(module, "null function reference"); goto got_exception; } @@ -2007,7 +2007,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #endif func_obj = POP_REF(); if (!func_obj) { - wasm_set_exception(module, "null function object"); + wasm_set_exception(module, "null function reference"); goto got_exception; } @@ -2148,7 +2148,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, struct_obj = POP_REF(); if (!struct_obj) { - wasm_set_exception(module, "null structure object"); + wasm_set_exception(module, + "null structure reference"); goto got_exception; } @@ -2204,7 +2205,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, struct_obj = POP_REF(); if (!struct_obj) { - wasm_set_exception(module, "null structure object"); + wasm_set_exception(module, + "null structure reference"); goto got_exception; } diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 6cd1ece4f..d495ba63e 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -2139,8 +2139,9 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, if (!wasm_type_is_subtype_of(cur_type, parent_type, module->types, module->type_count)) { - set_error_buf(error_buf, error_buf_size, - "sub type does not match super type"); + set_error_buf_v(error_buf, error_buf_size, + "sub type %u does not match super type", + processed_type_count + j); return false; } } diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index c3f35916c..18c56417e 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -4660,7 +4660,7 @@ llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx, if (!(func_obj = wasm_create_func_obj(module_inst, init_values[i].u.ref_index, true, NULL, 0))) { - wasm_set_exception(module_inst, "null function object"); + wasm_set_exception(module_inst, "null function reference"); return; } table_elems[i] = func_obj; diff --git a/tests/wamr-test-suites/spec-test-script/all.py b/tests/wamr-test-suites/spec-test-script/all.py index 005874eee..fe694124a 100644 --- a/tests/wamr-test-suites/spec-test-script/all.py +++ b/tests/wamr-test-suites/spec-test-script/all.py @@ -100,7 +100,12 @@ def ignore_the_case( return True if gc_flag: - if case_name in ["array_init_elem", "array_init_data"]: + if case_name in [ + "array_init_elem", + "array_init_data", + "array_new_data", + "array_new_elem" + ]: return True if sgx_flag: diff --git a/tests/wamr-test-suites/spec-test-script/gc_ignore_cases.patch b/tests/wamr-test-suites/spec-test-script/gc_ignore_cases.patch index bc91d6b06..e333dd933 100644 --- a/tests/wamr-test-suites/spec-test-script/gc_ignore_cases.patch +++ b/tests/wamr-test-suites/spec-test-script/gc_ignore_cases.patch @@ -1,417 +1,332 @@ -diff --git a/test/core/binary-leb128.wast b/test/core/binary-leb128.wast -index 335496f0..5b975028 100644 ---- a/test/core/binary-leb128.wast -+++ b/test/core/binary-leb128.wast -@@ -1078,5 +1078,5 @@ - "\e0\7f" ;; Malformed functype, -0x20 in signed LEB128 encoding - "\00\00" - ) -- "integer representation too long" -+ "invalid type flag" ;; In GC extension, the first byte in rectype define is just one byte, not LEB128 encoded. +diff --git a/test/core/br_if.wast b/test/core/br_if.wast +index 9d0cdd81..19902310 100644 +--- a/test/core/br_if.wast ++++ b/test/core/br_if.wast +@@ -663,6 +663,7 @@ + "unknown label" ) + ++(;; Activate the test case once the capability to manage such edge cases is enabled. + ;; https://github.com/WebAssembly/gc/issues/516 + (assert_invalid + (module +@@ -677,3 +678,4 @@ + ) + "type mismatch" + ) ++;;) +diff --git a/test/core/br_on_non_null.wast b/test/core/br_on_non_null.wast +index 43800194..b9bb5c41 100644 +--- a/test/core/br_on_non_null.wast ++++ b/test/core/br_on_non_null.wast +@@ -72,7 +72,8 @@ + (assert_return (invoke "args-null" (i32.const 3)) (i32.const 3)) + (assert_return (invoke "args-f" (i32.const 3)) (i32.const 9)) + +- ++(;;Activate the test case once the capability to manage such edge cases is enabled. ++;; ASSERTION FAILED: 0, at file /workspaces/wasm-micro-runtime/core/iwasm/common/gc/gc_type.c, line 1059 + ;; https://github.com/WebAssembly/gc/issues/516 + (assert_invalid + (module +@@ -88,3 +89,4 @@ + ) + "type mismatch" + ) ++;;) +diff --git a/test/core/br_on_null.wast b/test/core/br_on_null.wast +index e47dae50..58abf6a9 100644 +--- a/test/core/br_on_null.wast ++++ b/test/core/br_on_null.wast +@@ -66,6 +66,7 @@ + (assert_return (invoke "args-f" (i32.const 3)) (i32.const 9)) + + ++(;; Activate the test case once the capability to manage such edge cases is enabled. + ;; https://github.com/WebAssembly/gc/issues/516 + ;; Tests that validators are correctly doing + ;; +@@ -92,3 +93,4 @@ + ) + "type mismatch" + ) ++;;) diff --git a/test/core/elem.wast b/test/core/elem.wast -index df1610f6..32c1d8b3 100644 +index bc1cc324..14af14ae 100644 --- a/test/core/elem.wast +++ b/test/core/elem.wast -@@ -400,7 +400,7 @@ +@@ -462,6 +462,7 @@ + "\02\00\0b" ;; Function 0: empty ) - (assert_invalid -- (module -+ (module - (table 1 funcref) - (elem (offset (;empty instruction sequence;))) - ) -@@ -476,7 +476,7 @@ ++(;; Enable the case once compatibility has been established. + (module + (func) + (table 1 (ref func) (ref.func 0)) +@@ -478,6 +479,7 @@ + "\0a\04\01" ;; Code section: 1 function + "\02\00\0b" ;; Function 0: empty + ) ++;;) + + (module + (func) +@@ -536,6 +538,7 @@ + "type mismatch" ) - (assert_invalid -- (module -+ (module - (table 1 funcref) - (elem (global.get 0)) - ) -@@ -493,7 +493,7 @@ ++(;; Enable the case once compatibility has been established. + (module + (func) + (table 1 (ref func) (ref.func 0)) +@@ -552,6 +555,7 @@ + "\0a\04\01" ;; Code section: 1 function + "\02\00\0b" ;; Function 0: empty ) ++;;) - (assert_invalid -- (module -+ (module - (global (import "test" "global-mut-i32") (mut i32)) - (table 1 funcref) - (elem (global.get 0)) -@@ -603,12 +603,13 @@ - ) - ) + (module + (func) +@@ -929,8 +933,9 @@ + (assert_return (invoke "call-overwritten-element") (i32.const 66)) --(register "module1" $module1) -+(; (register "module1" $module1) ;) --(assert_trap (invoke $module1 "call-7") "uninitialized element") --(assert_return (invoke $module1 "call-8") (i32.const 65)) --(assert_return (invoke $module1 "call-9") (i32.const 66)) -+(assert_trap (invoke "call-7") "uninitialized element") -+(assert_return (invoke "call-8") (i32.const 65)) -+(assert_return (invoke "call-9") (i32.const 66)) - -+(; - (module $module2 ++(;;Activate test cases once the capability to import table is enabled ++;; + ;; Element sections across multiple modules change the same table +- + (module $module1 (type $out-i32 (func (result i32))) - (import "module1" "shared-table" (table 10 funcref)) -@@ -617,11 +618,15 @@ - (func $const-i32-c (type $out-i32) (i32.const 67)) - (func $const-i32-d (type $out-i32) (i32.const 68)) - ) -+;) - -+(; - (assert_return (invoke $module1 "call-7") (i32.const 67)) - (assert_return (invoke $module1 "call-8") (i32.const 68)) - (assert_return (invoke $module1 "call-9") (i32.const 66)) -+;) - -+(; - (module $module3 - (type $out-i32 (func (result i32))) - (import "module1" "shared-table" (table 10 funcref)) -@@ -634,6 +639,7 @@ + (table (export "shared-table") 10 funcref) +@@ -980,6 +985,7 @@ (assert_return (invoke $module1 "call-7") (i32.const 67)) (assert_return (invoke $module1 "call-8") (i32.const 69)) (assert_return (invoke $module1 "call-9") (i32.const 70)) -+;) ++;;) ;; Element segments must match element type of table -@@ -666,6 +672,7 @@ +@@ -1019,17 +1025,18 @@ + (func (export "set") (param $i i32) (param $x externref) + (table.set $t (local.get $i) (local.get $x)))) - ;; Initializing a table with an externref-type element segment +-(register "exporter" $m) ++;; (register "exporter" $m) -+(; - (module $m - (table $t (export "table") 2 externref) - (func (export "get") (param $i i32) (result externref) -@@ -713,3 +720,5 @@ +-(assert_return (invoke $m "get" (i32.const 0)) (ref.null extern)) +-(assert_return (invoke $m "get" (i32.const 1)) (ref.null extern)) ++(assert_return (invoke "get" (i32.const 0)) (ref.null extern)) ++(assert_return (invoke "get" (i32.const 1)) (ref.null extern)) + +-(assert_return (invoke $m "set" (i32.const 0) (ref.extern 42))) +-(assert_return (invoke $m "set" (i32.const 1) (ref.extern 137))) ++(assert_return (invoke "set" (i32.const 0) (ref.extern 42))) ++(assert_return (invoke "set" (i32.const 1) (ref.extern 137))) + +-(assert_return (invoke $m "get" (i32.const 0)) (ref.extern 42)) +-(assert_return (invoke $m "get" (i32.const 1)) (ref.extern 137)) ++(assert_return (invoke "get" (i32.const 0)) (ref.extern 42)) ++(assert_return (invoke "get" (i32.const 1)) (ref.extern 137)) + ++(;;Activate test cases once the capability to import table is enabled + (module + (import "exporter" "table" (table $t 2 externref)) + (elem (i32.const 0) externref (ref.null extern))) +@@ -1059,3 +1066,4 @@ ) (assert_return (invoke "call_imported_elem") (i32.const 42)) -+ -+;) ++;;) diff --git a/test/core/gc/array.wast b/test/core/gc/array.wast -index f5888cb2..b4a2dc0a 100644 +index 6ad95c08..a184435d 100644 --- a/test/core/gc/array.wast +++ b/test/core/gc/array.wast -@@ -95,7 +95,7 @@ +@@ -95,7 +95,10 @@ ) (assert_return (invoke "new") (ref.array)) -(assert_return (invoke "new") (ref.eq)) ++(; Activate once the scripts perform ++ ; typing comparison rather than comparing strings ++ ;) +;; (assert_return (invoke "new") (ref.eq)) (assert_return (invoke "get" (i32.const 0)) (f32.const 0)) (assert_return (invoke "set_get" (i32.const 1) (f32.const 7)) (f32.const 7)) (assert_return (invoke "len") (i32.const 3)) -@@ -140,7 +140,7 @@ +@@ -140,7 +143,10 @@ ) (assert_return (invoke "new") (ref.array)) -(assert_return (invoke "new") (ref.eq)) ++(; Activate once the scripts perform ++ ; typing comparison rather than comparing strings ++ ;) +;; (assert_return (invoke "new") (ref.eq)) (assert_return (invoke "get" (i32.const 0)) (f32.const 1)) (assert_return (invoke "set_get" (i32.const 1) (f32.const 7)) (f32.const 7)) (assert_return (invoke "len") (i32.const 2)) -@@ -185,7 +185,7 @@ +@@ -192,7 +198,10 @@ ) (assert_return (invoke "new") (ref.array)) -(assert_return (invoke "new") (ref.eq)) ++(; Activate once the scripts perform ++ ; typing comparison rather than comparing strings ++ ;) +;; (assert_return (invoke "new") (ref.eq)) - (assert_return (invoke "get" (i32.const 0)) (i32.const 1)) + (assert_return (invoke "get_u" (i32.const 2)) (i32.const 0xff)) + (assert_return (invoke "get_s" (i32.const 2)) (i32.const -1)) (assert_return (invoke "set_get" (i32.const 1) (i32.const 7)) (i32.const 7)) - (assert_return (invoke "len") (i32.const 3)) -@@ -193,6 +193,7 @@ - (assert_trap (invoke "get" (i32.const 10)) "out of bounds array access") +@@ -202,6 +211,7 @@ + (assert_trap (invoke "get_s" (i32.const 10)) "out of bounds array access") (assert_trap (invoke "set_get" (i32.const 10) (i32.const 7)) "out of bounds array access") -+(; array.new_elem not supported ++(;; Activate once aligned `array.new_elem` (module (type $bvec (array i8)) (type $vec (array (ref $bvec))) -@@ -251,6 +252,7 @@ +@@ -260,6 +270,7 @@ (assert_trap (invoke "get" (i32.const 10) (i32.const 0)) "out of bounds array access") (assert_trap (invoke "set_get" (i32.const 10) (i32.const 0) (i32.const 0)) "out of bounds array access") -+;) ++;;) (assert_invalid (module +diff --git a/test/core/gc/br_on_cast.wast b/test/core/gc/br_on_cast.wast +index 3c895c07..147f9a1a 100644 +--- a/test/core/gc/br_on_cast.wast ++++ b/test/core/gc/br_on_cast.wast +@@ -267,6 +267,7 @@ + ) + + ++(;;Activate the test case once the capability to manage such edge cases is enabled. + ;; https://github.com/WebAssembly/gc/issues/516 + (assert_invalid + (module +@@ -283,3 +284,4 @@ + ) + "type mismatch" + ) ++;;) +diff --git a/test/core/gc/br_on_cast_fail.wast b/test/core/gc/br_on_cast_fail.wast +index db6db11b..b0224c84 100644 +--- a/test/core/gc/br_on_cast_fail.wast ++++ b/test/core/gc/br_on_cast_fail.wast +@@ -282,6 +282,7 @@ + ) + + ++(;;Activate the test case once the capability to manage such edge cases is enabled. + ;; https://github.com/WebAssembly/gc/issues/516 + (assert_invalid + (module +@@ -298,3 +299,4 @@ + ) + "type mismatch" + ) ++;;) diff --git a/test/core/gc/extern.wast b/test/core/gc/extern.wast -index abf31669..9ef86506 100644 +index abf31669..4243808d 100644 --- a/test/core/gc/extern.wast +++ b/test/core/gc/extern.wast -@@ -43,7 +43,7 @@ +@@ -43,7 +43,10 @@ (assert_return (invoke "externalize-i" (i32.const 1)) (ref.extern)) (assert_return (invoke "externalize-i" (i32.const 2)) (ref.extern)) (assert_return (invoke "externalize-i" (i32.const 3)) (ref.extern)) -(assert_return (invoke "externalize-i" (i32.const 4)) (ref.extern)) ++(; Switch back to the original configuration once the scripts perform ++ ; typing comparison rather than comparing strings ++ ;) +(assert_return (invoke "externalize-i" (i32.const 4)) (ref.extern 0)) (assert_return (invoke "externalize-i" (i32.const 5)) (ref.null extern)) (assert_return (invoke "externalize-ii" (i32.const 0)) (ref.null any)) -diff --git a/test/core/gc/initializer.wast b/test/core/gc/initializer.wast -new file mode 100644 -index 00000000..32650644 ---- /dev/null -+++ b/test/core/gc/initializer.wast -@@ -0,0 +1,34 @@ -+;; added cases to test constant expressions -+ -+(module -+ (type $struct (struct (field f32) (field $y (mut f32)) (field $z f32))) -+ (type $vec (array f32)) -+ -+ ;; table initializer -+ (table 10 anyref) -+ -+ ;; global initializer -+ (global (ref $vec) (array.new_fixed $vec 2 (f32.const 1) (f32.const 2))) -+ (global (ref $struct) (struct.new_default $struct)) -+ -+ ;; elem initializer -+ (elem (i32.const 0) (ref $vec) (array.new_default $vec (i32.const 2))) -+ (elem (i32.const 1) (ref $vec) (array.new $vec (f32.const 1) (i32.const 3))) -+ (elem (i32.const 2) (ref $struct) (struct.new_default $struct)) -+ -+ (func (export "get_table") (param $i i32) (result anyref) -+ (table.get (local.get $i)) -+ ) -+) -+ -+(assert_return (invoke "get_table" (i32.const 0)) (ref.array)) -+(assert_return (invoke "get_table" (i32.const 1)) (ref.array)) -+(assert_return (invoke "get_table" (i32.const 2)) (ref.struct)) -+ -+(assert_invalid -+ (module -+ (type $struct (struct (field f32) (field $y (mut f32)) (field $z f32))) -+ (table 10 anyref (struct.new_default $struct)) -+ ) -+ "unsupported initializer expression for table" -+) -diff --git a/test/core/gc/type-subtyping.wast b/test/core/gc/type-subtyping.wast -index a9022fc3..4aa36e2a 100644 ---- a/test/core/gc/type-subtyping.wast -+++ b/test/core/gc/type-subtyping.wast -@@ -740,7 +740,7 @@ - "sub type" +diff --git a/test/core/gc/i31.wast b/test/core/gc/i31.wast +index 6309e72b..39f35692 100644 +--- a/test/core/gc/i31.wast ++++ b/test/core/gc/i31.wast +@@ -52,12 +52,19 @@ + + (assert_trap (invoke "get_u-null") "null i31 reference") + (assert_trap (invoke "get_s-null") "null i31 reference") +- + (assert_return (invoke "get_globals") (i32.const 2) (i32.const 3)) +- + (invoke "set_global" (i32.const 1234)) + (assert_return (invoke "get_globals") (i32.const 2) (i32.const 1234)) + ++(;; Activate the following test once the new init expr is supported. ++ ;; ++ ;; ASSERTION FAILED: ++ ;; (init_expr->init_expr_type == INIT_EXPR_TYPE_GET_GLOBAL) ++ ;; || (init_expr->init_expr_type == INIT_EXPR_TYPE_REFNULL_CONST) ++ ;; || (init_expr->init_expr_type >= INIT_EXPR_TYPE_FUNCREF_CONST ++ ;; && init_expr->init_expr_type <= INIT_EXPR_TYPE_ARRAY_NEW_FIXED), ++ ;; at file /workspaces/wasm-micro-runtime/core/iwasm/interpreter/wasm_loader.c, line 4454 ++ ;; + (module $tables_of_i31ref + (table $table 3 10 i31ref) + (elem (table $table) (i32.const 0) i31ref (item (ref.i31 (i32.const 999))) +@@ -119,7 +126,9 @@ + (assert_return (invoke "get" (i32.const 1)) (i32.const 123)) + (assert_return (invoke "get" (i32.const 2)) (i32.const 456)) + (assert_return (invoke "get" (i32.const 3)) (i32.const 789)) ++;;) + ++(;; + (module $env + (global (export "g") i32 (i32.const 42)) + ) +@@ -146,6 +155,7 @@ ) --(assert_invalid -+(assert_invalid - (module - (type $f0 (sub (func (param i32) (result i32)))) - (type $s0 (sub $f0 (struct))) -@@ -764,7 +764,7 @@ - "sub type" - ) + (assert_return (invoke "get") (i32.const 42)) ++ ;;) --(assert_invalid -+(assert_invalid - (module - (type $s0 (sub (struct))) - (type $f0 (sub $s0 (func (param i32) (result i32)))) -@@ -772,7 +772,7 @@ - "sub type" - ) + (module $anyref_global_of_i31ref + (global $c anyref (ref.i31 (i32.const 1234))) +@@ -165,6 +175,15 @@ + (invoke "set_global" (i32.const 0)) + (assert_return (invoke "get_globals") (i32.const 1234) (i32.const 0)) --(assert_invalid -+(assert_invalid - (module - (type $a0 (sub (array i32))) - (type $f0 (sub $a0 (func (param i32) (result i32)))) ++(;; Activate the following test once the new init expr is supported. ++ ;; ++ ;; ASSERTION FAILED: ++ ;; (init_expr->init_expr_type == INIT_EXPR_TYPE_GET_GLOBAL) ++ ;; || (init_expr->init_expr_type == INIT_EXPR_TYPE_REFNULL_CONST) ++ ;; || (init_expr->init_expr_type >= INIT_EXPR_TYPE_FUNCREF_CONST ++ ;; && init_expr->init_expr_type <= INIT_EXPR_TYPE_ARRAY_NEW_FIXED), ++ ;; at file /workspaces/wasm-micro-runtime/core/iwasm/interpreter/wasm_loader.c, line 4454 ++ ;; + (module $anyref_table_of_i31ref + (table $table 3 10 anyref) + (elem (table $table) (i32.const 0) i31ref (item (ref.i31 (i32.const 999))) +@@ -226,3 +245,5 @@ + (assert_return (invoke "get" (i32.const 1)) (i32.const 123)) + (assert_return (invoke "get" (i32.const 2)) (i32.const 456)) + (assert_return (invoke "get" (i32.const 3)) (i32.const 789)) ++ ;; ++ ;;) diff --git a/test/core/global.wast b/test/core/global.wast -index 8c47fde2..1a8cc7e3 100644 +index 8c47fde2..8d3d8228 100644 --- a/test/core/global.wast +++ b/test/core/global.wast -@@ -644,7 +644,7 @@ +@@ -644,7 +644,10 @@ ) ) -(assert_return (invoke "get-elem" (i32.const 0)) (ref.null)) ++(; Switch back to the original configuration once the scripts perform ++ ; typing comparison rather than comparing strings ++ ;) +(assert_return (invoke "get-elem" (i32.const 0)) (ref.null func)) (assert_return (invoke "get-elem" (i32.const 4)) (ref.func)) (assert_return (invoke "get-elem" (i32.const 8)) (ref.func)) -@@ -652,7 +652,7 @@ - (assert_return (invoke "get-data" (i32.const 8)) (i32.const 0x88888888)) - - (assert_invalid -- (module -+ (module - (global $g1 i32 (global.get $g2)) - (global $g2 i32 (i32.const 0)) - ) -diff --git a/test/core/imports.wast b/test/core/imports.wast -index 69f76a0b..a3844c65 100644 ---- a/test/core/imports.wast -+++ b/test/core/imports.wast -@@ -572,6 +572,7 @@ - (assert_return (invoke "grow" (i32.const 1)) (i32.const -1)) - (assert_return (invoke "grow" (i32.const 0)) (i32.const 2)) - -+(; unsupported by multi-module currently - (module $Mgm - (memory (export "memory") 1) ;; initial size is 1 - (func (export "grow") (result i32) (memory.grow (i32.const 1))) -@@ -591,6 +592,7 @@ - (func (export "size") (result i32) (memory.size)) - ) - (assert_return (invoke $Mgim2 "size") (i32.const 3)) -+;) - - - ;; Syntax errors -diff --git a/test/core/linking.wast b/test/core/linking.wast -index 6a8ba1d0..a45534fd 100644 ---- a/test/core/linking.wast -+++ b/test/core/linking.wast -@@ -64,6 +64,7 @@ - (export "Mg.set_mut" (func $set_mut)) - ) - -+(; - (assert_return (get $Mg "glob") (i32.const 42)) - (assert_return (get $Ng "Mg.glob") (i32.const 42)) - (assert_return (get $Ng "glob") (i32.const 43)) -@@ -81,6 +82,7 @@ - (assert_return (get $Ng "Mg.mut_glob") (i32.const 241)) - (assert_return (invoke $Mg "get_mut") (i32.const 241)) - (assert_return (invoke $Ng "Mg.get_mut") (i32.const 241)) -+;) - - - (assert_unlinkable -@@ -300,6 +302,7 @@ - ) - ) - -+(; - (assert_return (invoke $Mt "call" (i32.const 2)) (i32.const 4)) - (assert_return (invoke $Nt "Mt.call" (i32.const 2)) (i32.const 4)) - (assert_return (invoke $Nt "call" (i32.const 2)) (i32.const 5)) -@@ -322,6 +325,7 @@ - - (assert_return (invoke $Nt "call" (i32.const 3)) (i32.const -4)) - (assert_trap (invoke $Nt "call" (i32.const 4)) "indirect call type mismatch") -+;) - - (module $Ot - (type (func (result i32))) -@@ -336,6 +340,7 @@ - ) - ) - -+(; - (assert_return (invoke $Mt "call" (i32.const 3)) (i32.const 4)) - (assert_return (invoke $Nt "Mt.call" (i32.const 3)) (i32.const 4)) - (assert_return (invoke $Nt "call Mt.call" (i32.const 3)) (i32.const 4)) -@@ -360,6 +365,7 @@ - (assert_trap (invoke $Ot "call" (i32.const 0)) "uninitialized element") - - (assert_trap (invoke $Ot "call" (i32.const 20)) "undefined element") -+;) - - (module - (table (import "Mt" "tab") 0 funcref) -@@ -398,6 +404,7 @@ - - ;; Unlike in the v1 spec, active element segments stored before an - ;; out-of-bounds access persist after the instantiation failure. -+(; - (assert_trap - (module - (table (import "Mt" "tab") 10 funcref) -@@ -409,7 +416,9 @@ - ) - (assert_return (invoke $Mt "call" (i32.const 7)) (i32.const 0)) - (assert_trap (invoke $Mt "call" (i32.const 8)) "uninitialized element") -+;) - -+(; - (assert_trap - (module - (table (import "Mt" "tab") 10 funcref) -@@ -421,6 +430,7 @@ - "out of bounds memory access" - ) - (assert_return (invoke $Mt "call" (i32.const 7)) (i32.const 0)) -+;) - - - (module $Mtable_ex -@@ -503,10 +513,12 @@ - ) - ) - -+(; - (assert_return (invoke $Mm "load" (i32.const 12)) (i32.const 0xa7)) - (assert_return (invoke $Nm "Mm.load" (i32.const 12)) (i32.const 0xa7)) - (assert_return (invoke $Nm "load" (i32.const 12)) (i32.const 0xf2)) - (assert_return (invoke $Om "load" (i32.const 12)) (i32.const 0xa7)) -+;) - - (module - (memory (import "Mm" "mem") 0) -@@ -529,6 +541,7 @@ - ) - ) - -+(; - (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 1)) - (assert_return (invoke $Pm "grow" (i32.const 2)) (i32.const 1)) - (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 3)) -@@ -537,6 +550,7 @@ - (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5)) - (assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const -1)) - (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5)) -+;) - - (assert_unlinkable - (module -@@ -560,8 +574,10 @@ - ) - "out of bounds memory access" - ) -+(; - (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97)) - (assert_return (invoke $Mm "load" (i32.const 327670)) (i32.const 0)) -+;) - - (assert_trap - (module -@@ -573,7 +589,9 @@ - ) - "out of bounds table access" - ) -+(; - (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97)) -+;) - - ;; Store is modified if the start function traps. - (module $Ms -@@ -589,6 +607,7 @@ - ) - (register "Ms" $Ms) - -+(; - (assert_trap - (module - (import "Ms" "memory" (memory 1)) -@@ -608,3 +627,4 @@ - - (assert_return (invoke $Ms "get memory[0]") (i32.const 104)) ;; 'h' - (assert_return (invoke $Ms "get table[0]") (i32.const 0xdead)) -+;) diff --git a/test/core/ref_func.wast b/test/core/ref_func.wast -index adb5cb78..590f6262 100644 +index adb5cb78..a4f8de5a 100644 --- a/test/core/ref_func.wast +++ b/test/core/ref_func.wast @@ -4,7 +4,8 @@ @@ -419,71 +334,85 @@ index adb5cb78..590f6262 100644 (module - (func $f (import "M" "f") (param i32) (result i32)) -+ (; aot mode does not support module linking ;) ++ (;Revert to the previous once the GC feature is operational with the multi-module feature.;) + (func $f (param $x i32) (result i32) (local.get $x)) (func $g (param $x i32) (result i32) (i32.add (local.get $x) (i32.const 1)) ) diff --git a/test/core/ref_null.wast b/test/core/ref_null.wast -index 1ffd03f8..bdf7471f 100644 +index 1ffd03f8..2961ffcd 100644 --- a/test/core/ref_null.wast +++ b/test/core/ref_null.wast -@@ -11,7 +11,7 @@ +@@ -11,7 +11,10 @@ (assert_return (invoke "anyref") (ref.null any)) (assert_return (invoke "funcref") (ref.null func)) -(assert_return (invoke "ref") (ref.null)) -+(assert_return (invoke "ref") (ref.null func)) ;; we alwasy require type information ++(; Switch back to the original configuration once the scripts perform ++ ; typing comparison rather than comparing strings ++ ;) ++(assert_return (invoke "ref") (ref.null func)) (module -@@ -41,23 +41,23 @@ +@@ -40,24 +43,33 @@ + (global (ref null $t) (ref.null nofunc)) ) ++(; Switch back to the original configuration once the scripts perform ++ ; typing comparison rather than comparing strings ++ ;) ++(assert_return (invoke "anyref") (ref.null any)) ++(assert_return (invoke "anyref") (ref.null any)) (assert_return (invoke "anyref") (ref.null any)) -(assert_return (invoke "anyref") (ref.null none)) -(assert_return (invoke "anyref") (ref.null)) -+;; (assert_return (invoke "anyref") (ref.null none)) -+;; (assert_return (invoke "anyref") (ref.null func)) ++ ++(assert_return (invoke "nullref") (ref.null any)) ++(assert_return (invoke "nullref") (ref.null any)) (assert_return (invoke "nullref") (ref.null any)) -(assert_return (invoke "nullref") (ref.null none)) -(assert_return (invoke "nullref") (ref.null)) -+;; (assert_return (invoke "nullref") (ref.null none)) -+;; (assert_return (invoke "nullref") (ref.null func)) ++ ++(assert_return (invoke "funcref") (ref.null func)) ++(assert_return (invoke "funcref") (ref.null func)) (assert_return (invoke "funcref") (ref.null func)) -(assert_return (invoke "funcref") (ref.null nofunc)) -(assert_return (invoke "funcref") (ref.null)) -+;; (assert_return (invoke "funcref") (ref.null nofunc)) -+(assert_return (invoke "funcref") (ref.null func)) ++ +(assert_return (invoke "nullfuncref") (ref.null func)) -+;; (assert_return (invoke "nullfuncref") (ref.null nofunc)) (assert_return (invoke "nullfuncref") (ref.null func)) -(assert_return (invoke "nullfuncref") (ref.null nofunc)) -(assert_return (invoke "nullfuncref") (ref.null)) ++(assert_return (invoke "nullfuncref") (ref.null func)) ++ ++(assert_return (invoke "externref") (ref.null extern)) (assert_return (invoke "externref") (ref.null extern)) -(assert_return (invoke "externref") (ref.null noextern)) -(assert_return (invoke "externref") (ref.null)) -+;; (assert_return (invoke "externref") (ref.null noextern)) -+;; (assert_return (invoke "externref") (ref.null func)) ++(assert_return (invoke "externref") (ref.null extern)) ++ (assert_return (invoke "nullexternref") (ref.null extern)) -(assert_return (invoke "nullexternref") (ref.null noextern)) -(assert_return (invoke "nullexternref") (ref.null)) -+;; (assert_return (invoke "nullexternref") (ref.null noextern)) -+;; (assert_return (invoke "nullexternref") (ref.null func)) ++(assert_return (invoke "nullexternref") (ref.null extern)) ++(assert_return (invoke "nullexternref") (ref.null extern)) ++ ++(assert_return (invoke "ref") (ref.null func)) +(assert_return (invoke "ref") (ref.null func)) -+;; (assert_return (invoke "ref") (ref.null nofunc)) (assert_return (invoke "ref") (ref.null func)) -(assert_return (invoke "ref") (ref.null nofunc)) -(assert_return (invoke "ref") (ref.null)) diff --git a/test/core/return_call.wast b/test/core/return_call.wast -index 2f91f4de..ad66acca 100644 +index b9e8f8f0..8a3d7512 100644 --- a/test/core/return_call.wast +++ b/test/core/return_call.wast -@@ -102,20 +102,20 @@ +@@ -102,20 +102,23 @@ (assert_return (invoke "count" (i64.const 0)) (i64.const 0)) (assert_return (invoke "count" (i64.const 1000)) (i64.const 0)) -(assert_return (invoke "count" (i64.const 1_000_000)) (i64.const 0)) ++(;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) +(assert_return (invoke "count" (i64.const 100_000)) (i64.const 0)) (assert_return (invoke "even" (i64.const 0)) (i32.const 44)) @@ -492,6 +421,7 @@ index 2f91f4de..ad66acca 100644 (assert_return (invoke "even" (i64.const 77)) (i32.const 99)) -(assert_return (invoke "even" (i64.const 1_000_000)) (i32.const 44)) -(assert_return (invoke "even" (i64.const 1_000_001)) (i32.const 99)) ++(;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) +(assert_return (invoke "even" (i64.const 100_000)) (i32.const 44)) +(assert_return (invoke "even" (i64.const 100_001)) (i32.const 99)) (assert_return (invoke "odd" (i64.const 0)) (i32.const 99)) @@ -500,36 +430,39 @@ index 2f91f4de..ad66acca 100644 (assert_return (invoke "odd" (i64.const 77)) (i32.const 44)) -(assert_return (invoke "odd" (i64.const 1_000_000)) (i32.const 99)) -(assert_return (invoke "odd" (i64.const 999_999)) (i32.const 44)) ++(;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) +(assert_return (invoke "odd" (i64.const 100_000)) (i32.const 99)) -+(assert_return (invoke "odd" (i64.const 99_999)) (i32.const 44)) ++(assert_return (invoke "odd" (i64.const 99_999)) (i32.const 44)) ;; Invalid typing diff --git a/test/core/return_call_indirect.wast b/test/core/return_call_indirect.wast -index acf0a72e..6b95c24b 100644 +index aa158be2..7f68b4a5 100644 --- a/test/core/return_call_indirect.wast +++ b/test/core/return_call_indirect.wast -@@ -263,8 +263,8 @@ +@@ -263,8 +263,9 @@ (assert_return (invoke "odd" (i32.const 1)) (i32.const 44)) (assert_return (invoke "odd" (i32.const 200)) (i32.const 99)) (assert_return (invoke "odd" (i32.const 77)) (i32.const 44)) -(assert_return (invoke "odd" (i32.const 200_002)) (i32.const 99)) -(assert_return (invoke "odd" (i32.const 300_003)) (i32.const 44)) ++(;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) +(assert_return (invoke "odd" (i32.const 100_002)) (i32.const 99)) +(assert_return (invoke "odd" (i32.const 100_003)) (i32.const 44)) ;; Invalid syntax diff --git a/test/core/return_call_ref.wast b/test/core/return_call_ref.wast -index 353811f0..f79975b4 100644 +index 5f5a7cba..574d34a3 100644 --- a/test/core/return_call_ref.wast +++ b/test/core/return_call_ref.wast -@@ -192,20 +192,20 @@ +@@ -192,20 +192,23 @@ (assert_return (invoke "count" (i64.const 0)) (i64.const 0)) (assert_return (invoke "count" (i64.const 1000)) (i64.const 0)) -(assert_return (invoke "count" (i64.const 1_000_000)) (i64.const 0)) -+(assert_return (invoke "count" (i64.const 1200)) (i64.const 0)) ++(;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) ++(assert_return (invoke "count" (i64.const 1_200)) (i64.const 0)) (assert_return (invoke "even" (i64.const 0)) (i64.const 44)) (assert_return (invoke "even" (i64.const 1)) (i64.const 99)) @@ -537,53 +470,62 @@ index 353811f0..f79975b4 100644 (assert_return (invoke "even" (i64.const 77)) (i64.const 99)) -(assert_return (invoke "even" (i64.const 1_000_000)) (i64.const 44)) -(assert_return (invoke "even" (i64.const 1_000_001)) (i64.const 99)) -+(assert_return (invoke "even" (i64.const 1200)) (i64.const 44)) -+(assert_return (invoke "even" (i64.const 1201)) (i64.const 99)) ++(;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) ++(assert_return (invoke "even" (i64.const 1_200)) (i64.const 44)) ++(assert_return (invoke "even" (i64.const 1_201)) (i64.const 99)) (assert_return (invoke "odd" (i64.const 0)) (i64.const 99)) (assert_return (invoke "odd" (i64.const 1)) (i64.const 44)) (assert_return (invoke "odd" (i64.const 200)) (i64.const 99)) (assert_return (invoke "odd" (i64.const 77)) (i64.const 44)) -(assert_return (invoke "odd" (i64.const 1_000_000)) (i64.const 99)) -(assert_return (invoke "odd" (i64.const 999_999)) (i64.const 44)) -+(assert_return (invoke "odd" (i64.const 1200)) (i64.const 99)) -+(assert_return (invoke "odd" (i64.const 1119)) (i64.const 44)) ++(;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) ++(assert_return (invoke "odd" (i64.const 1_200)) (i64.const 99)) ++(assert_return (invoke "odd" (i64.const 1_199)) (i64.const 44)) ;; More typing diff --git a/test/core/select.wast b/test/core/select.wast -index 61e4dc22..b0b1344c 100644 +index 61e4dc22..f7f92f81 100644 --- a/test/core/select.wast +++ b/test/core/select.wast -@@ -277,7 +277,7 @@ +@@ -277,7 +277,10 @@ (assert_return (invoke "select-f64-t" (f64.const 2) (f64.const nan:0x20304) (i32.const 0)) (f64.const nan:0x20304)) (assert_return (invoke "join-funcnull" (i32.const 1)) (ref.func)) -(assert_return (invoke "join-funcnull" (i32.const 0)) (ref.null)) -+(assert_return (invoke "join-funcnull" (i32.const 0)) (ref.null func)) ;; we require type in expected results ++(; Switch back to the original configuration once the scripts perform ++ ; typing comparison rather than comparing strings ++ ;) ++(assert_return (invoke "join-funcnull" (i32.const 0)) (ref.null func)) (assert_trap (invoke "select-trap-left" (i32.const 1)) "unreachable") (assert_trap (invoke "select-trap-left" (i32.const 0)) "unreachable") diff --git a/test/core/table.wast b/test/core/table.wast -index a11dce56..ace19ac8 100644 +index a11dce56..d9820382 100644 --- a/test/core/table.wast +++ b/test/core/table.wast -@@ -103,11 +103,11 @@ +@@ -103,11 +103,15 @@ (func (export "get5") (result funcref) (table.get $t5 (i32.const 9))) ) -(assert_return (invoke "get1") (ref.null)) ++(; Switch back to the original configuration once the scripts perform ++ ; typing comparison rather than comparing strings ++ ;) +(assert_return (invoke "get1") (ref.null func)) (assert_return (invoke "get2") (ref.func)) (assert_return (invoke "get3") (ref.func)) -(assert_return (invoke "get4") (ref.func)) -(assert_return (invoke "get5") (ref.func)) -+(assert_return (invoke "get4") (ref.null func)) ;; We don't give a value to the imported global -+(assert_return (invoke "get5") (ref.null func)) ;; So these two tables are initialized as ref.null ++(;Revert to previous ones once the capability to import global is aligned;) ++(assert_return (invoke "get4") (ref.null func)) ++(assert_return (invoke "get5") (ref.null func)) (assert_invalid diff --git a/test/core/table_copy.wast b/test/core/table_copy.wast -index 380e84ee..f37e745c 100644 +index 380e84ee..288cc985 100644 --- a/test/core/table_copy.wast +++ b/test/core/table_copy.wast @@ -14,11 +14,12 @@ @@ -595,33 +537,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ ;; aot mode does not support module linking -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 - (table $t0 30 30 funcref) - (table $t1 30 30 funcref) - (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -106,11 +107,11 @@ - - (module - (type (func (result i32))) ;; type #0 -- (import "a" "ef0" (func (result i32))) ;; index 0 -- (import "a" "ef1" (func (result i32))) -- (import "a" "ef2" (func (result i32))) -- (import "a" "ef3" (func (result i32))) -- (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 + (func (export "ef1") (result i32) (i32.const 1)) + (func (export "ef2") (result i32) (i32.const 2)) + (func (export "ef3") (result i32) (i32.const 3)) -+ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -198,11 +199,11 @@ +@@ -106,11 +107,12 @@ (module (type (func (result i32))) ;; type #0 @@ -630,15 +555,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -290,11 +291,11 @@ +@@ -198,11 +200,12 @@ (module (type (func (result i32))) ;; type #0 @@ -647,15 +573,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -382,11 +383,11 @@ +@@ -290,11 +293,12 @@ (module (type (func (result i32))) ;; type #0 @@ -664,15 +591,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -474,11 +475,11 @@ +@@ -382,11 +386,12 @@ (module (type (func (result i32))) ;; type #0 @@ -681,15 +609,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -566,11 +567,11 @@ +@@ -474,11 +479,12 @@ (module (type (func (result i32))) ;; type #0 @@ -698,15 +627,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -658,11 +659,11 @@ +@@ -566,11 +572,12 @@ (module (type (func (result i32))) ;; type #0 @@ -715,15 +645,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -750,11 +751,11 @@ +@@ -658,11 +665,12 @@ (module (type (func (result i32))) ;; type #0 @@ -732,15 +663,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) -@@ -842,11 +843,11 @@ +@@ -750,11 +758,12 @@ (module (type (func (result i32))) ;; type #0 @@ -749,15 +681,34 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -842,11 +851,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -934,11 +935,11 @@ +@@ -934,11 +944,12 @@ (module (type (func (result i32))) ;; type #0 @@ -766,15 +717,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1026,11 +1027,11 @@ +@@ -1026,11 +1037,12 @@ (module (type (func (result i32))) ;; type #0 @@ -783,15 +735,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1118,11 +1119,11 @@ +@@ -1118,11 +1130,12 @@ (module (type (func (result i32))) ;; type #0 @@ -800,15 +753,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1210,11 +1211,11 @@ +@@ -1210,11 +1223,12 @@ (module (type (func (result i32))) ;; type #0 @@ -817,15 +771,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1302,11 +1303,11 @@ +@@ -1302,11 +1316,12 @@ (module (type (func (result i32))) ;; type #0 @@ -834,15 +789,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1394,11 +1395,11 @@ +@@ -1394,11 +1409,12 @@ (module (type (func (result i32))) ;; type #0 @@ -851,15 +807,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1486,11 +1487,11 @@ +@@ -1486,11 +1502,12 @@ (module (type (func (result i32))) ;; type #0 @@ -868,15 +825,16 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) -@@ -1578,11 +1579,11 @@ +@@ -1578,11 +1595,12 @@ (module (type (func (result i32))) ;; type #0 @@ -885,16 +843,17 @@ index 380e84ee..f37e745c 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) diff --git a/test/core/table_init.wast b/test/core/table_init.wast -index 0b2d26f7..bdab6a01 100644 +index 0b2d26f7..65b92bf8 100644 --- a/test/core/table_init.wast +++ b/test/core/table_init.wast @@ -14,11 +14,12 @@ @@ -906,12 +865,12 @@ index 0b2d26f7..bdab6a01 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ ;; aot mode does not support module linking -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) @@ -924,12 +883,12 @@ index 0b2d26f7..bdab6a01 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ ;; aot mode does not support module linking -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) @@ -942,12 +901,12 @@ index 0b2d26f7..bdab6a01 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ ;; aot mode does not support module linking -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t0) (i32.const 2) func 3 1 4 1) @@ -960,12 +919,12 @@ index 0b2d26f7..bdab6a01 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ ;; aot mode does not support module linking -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) @@ -978,12 +937,12 @@ index 0b2d26f7..bdab6a01 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ ;; aot mode does not support module linking -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) @@ -996,12 +955,12 @@ index 0b2d26f7..bdab6a01 100644 - (import "a" "ef2" (func (result i32))) - (import "a" "ef3" (func (result i32))) - (import "a" "ef4" (func (result i32))) ;; index 4 -+ ;; aot mode does not support module linking -+ (func (result i32) (i32.const 0)) ;; index 0 -+ (func (result i32) (i32.const 1)) -+ (func (result i32) (i32.const 2)) -+ (func (result i32) (i32.const 3)) -+ (func (result i32) (i32.const 4)) ;; index 4 ++ (;Revert to previous ones once the capability to import table is enabled;) ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 (table $t0 30 30 funcref) (table $t1 30 30 funcref) (elem (table $t1) (i32.const 2) func 3 1 4 1) diff --git a/tests/wamr-test-suites/spec-test-script/gc_nuttx_tail_call.patch b/tests/wamr-test-suites/spec-test-script/gc_nuttx_tail_call.patch index efbd9e178..599295090 100644 --- a/tests/wamr-test-suites/spec-test-script/gc_nuttx_tail_call.patch +++ b/tests/wamr-test-suites/spec-test-script/gc_nuttx_tail_call.patch @@ -1,53 +1,56 @@ diff --git a/test/core/return_call.wast b/test/core/return_call.wast -index ad66acca..b27af19b 100644 +index 8a3d7512..5a4eba68 100644 --- a/test/core/return_call.wast +++ b/test/core/return_call.wast -@@ -102,20 +102,20 @@ - +@@ -103,22 +103,22 @@ (assert_return (invoke "count" (i64.const 0)) (i64.const 0)) (assert_return (invoke "count" (i64.const 1000)) (i64.const 0)) + (;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) -(assert_return (invoke "count" (i64.const 100_000)) (i64.const 0)) -+(assert_return (invoke "count" (i64.const 1001)) (i64.const 0)) ++(assert_return (invoke "count" (i64.const 1_001)) (i64.const 0)) (assert_return (invoke "even" (i64.const 0)) (i32.const 44)) (assert_return (invoke "even" (i64.const 1)) (i32.const 99)) (assert_return (invoke "even" (i64.const 100)) (i32.const 44)) (assert_return (invoke "even" (i64.const 77)) (i32.const 99)) + (;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) -(assert_return (invoke "even" (i64.const 100_000)) (i32.const 44)) -(assert_return (invoke "even" (i64.const 100_001)) (i32.const 99)) -+(assert_return (invoke "even" (i64.const 1000)) (i32.const 44)) -+(assert_return (invoke "even" (i64.const 1001)) (i32.const 99)) ++(assert_return (invoke "even" (i64.const 1_000)) (i32.const 44)) ++(assert_return (invoke "even" (i64.const 1_001)) (i32.const 99)) (assert_return (invoke "odd" (i64.const 0)) (i32.const 99)) (assert_return (invoke "odd" (i64.const 1)) (i32.const 44)) (assert_return (invoke "odd" (i64.const 200)) (i32.const 99)) (assert_return (invoke "odd" (i64.const 77)) (i32.const 44)) + (;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) -(assert_return (invoke "odd" (i64.const 100_000)) (i32.const 99)) --(assert_return (invoke "odd" (i64.const 99_999)) (i32.const 44)) -+(assert_return (invoke "odd" (i64.const 1000)) (i32.const 99)) -+(assert_return (invoke "odd" (i64.const 999)) (i32.const 44)) +-(assert_return (invoke "odd" (i64.const 99_999)) (i32.const 44)) ++(assert_return (invoke "odd" (i64.const 1_000)) (i32.const 99)) ++(assert_return (invoke "odd" (i64.const 999)) (i32.const 44)) ;; Invalid typing diff --git a/test/core/return_call_indirect.wast b/test/core/return_call_indirect.wast -index 6b95c24b..a9e86d42 100644 +index 7f68b4a5..08a31417 100644 --- a/test/core/return_call_indirect.wast +++ b/test/core/return_call_indirect.wast -@@ -257,14 +257,14 @@ +@@ -257,15 +257,15 @@ (assert_return (invoke "even" (i32.const 1)) (i32.const 99)) (assert_return (invoke "even" (i32.const 100)) (i32.const 44)) (assert_return (invoke "even" (i32.const 77)) (i32.const 99)) -(assert_return (invoke "even" (i32.const 100_000)) (i32.const 44)) -(assert_return (invoke "even" (i32.const 111_111)) (i32.const 99)) -+(assert_return (invoke "even" (i32.const 1000)) (i32.const 44)) -+(assert_return (invoke "even" (i32.const 1111)) (i32.const 99)) ++(assert_return (invoke "even" (i32.const 1_000)) (i32.const 44)) ++(assert_return (invoke "even" (i32.const 1_001)) (i32.const 99)) (assert_return (invoke "odd" (i32.const 0)) (i32.const 99)) (assert_return (invoke "odd" (i32.const 1)) (i32.const 44)) (assert_return (invoke "odd" (i32.const 200)) (i32.const 99)) (assert_return (invoke "odd" (i32.const 77)) (i32.const 44)) + (;Return to the original configuration after we have corrected the error in the AOT/JIT tail-call implementation.;) -(assert_return (invoke "odd" (i32.const 100_002)) (i32.const 99)) -(assert_return (invoke "odd" (i32.const 100_003)) (i32.const 44)) -+(assert_return (invoke "odd" (i32.const 1002)) (i32.const 99)) -+(assert_return (invoke "odd" (i32.const 1003)) (i32.const 44)) ++(assert_return (invoke "odd" (i32.const 1_002)) (i32.const 99)) ++(assert_return (invoke "odd" (i32.const 1_003)) (i32.const 44)) ;; Invalid syntax diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 64abd9f35..31f8b3746 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -467,8 +467,8 @@ function spec_test() git clone -b main --single-branch https://github.com/WebAssembly/gc.git spec pushd spec - # Reset to commit: "[test] Unify the error message." - git reset --hard 0caaadc65b5e1910512d8ae228502edcf9d60390 + # Dec 9, 2024. Merge branch 'funcref' + git reset --hard 756060f5816c7e2159f4817fbdee76cf52f9c923 git apply ../../spec-test-script/gc_ignore_cases.patch || exit 1 if [[ ${ENABLE_QEMU} == 1 ]]; then @@ -477,6 +477,13 @@ function spec_test() git apply ../../spec-test-script/gc_nuttx_tail_call.patch || exit 1 fi + # As of version 1.0.36, wabt is still unable to correctly handle the GC proposal. + # + # $ $ /opt/wabt-1.0.36/bin/wast2json --enable-all ../spec/test/core/br_if.wast + # + # ../spec/test/core/br_if.wast:670:26: error: unexpected token "null", expected a numeric index or a name (e.g. 12 or $foo). + # (func $f (param (ref null $t)) (result funcref) (local.get 0)) + # compile_reference_interpreter elif [[ ${ENABLE_MEMORY64} == 1 ]]; then echo "checkout spec for memory64 proposal" From b6dea221a609606ce6c3dcaa0f4d0399ea5bc4dc Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Tue, 21 Jan 2025 13:08:09 +0800 Subject: [PATCH 102/105] Fix wasm loader check data segment count (#4039) correctly report error when datacount section has non-zero data segment count while the data section is not present --- core/iwasm/interpreter/wasm_loader.c | 29 ++++++++++++++++++++--- core/iwasm/interpreter/wasm_mini_loader.c | 5 ++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index d495ba63e..559d1c33e 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -4713,6 +4713,21 @@ fail: return false; } +#if WASM_ENABLE_BULK_MEMORY != 0 +static bool +check_data_count_consistency(bool has_datacount_section, int datacount_len, + int data_seg_len, char *error_buf, + uint32 error_buf_size) +{ + if (has_datacount_section && datacount_len != data_seg_len) { + set_error_buf(error_buf, error_buf_size, + "data count and data section have inconsistent lengths"); + return false; + } + return true; +} +#endif + static bool load_data_segment_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, @@ -4736,9 +4751,9 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end, read_leb_uint32(p, p_end, data_seg_count); #if WASM_ENABLE_BULK_MEMORY != 0 - if (has_datacount_section && data_seg_count != module->data_seg_count1) { - set_error_buf(error_buf, error_buf_size, - "data count and data section have inconsistent lengths"); + if (!check_data_count_consistency(has_datacount_section, + module->data_seg_count1, data_seg_count, + error_buf, error_buf_size)) { return false; } #endif @@ -5926,6 +5941,14 @@ load_from_sections(WASMModule *module, WASMSection *sections, section = section->next; } +#if WASM_ENABLE_BULK_MEMORY != 0 + if (!check_data_count_consistency( + has_datacount_section, module->data_seg_count1, + module->data_seg_count, error_buf, error_buf_size)) { + return false; + } +#endif + module->aux_data_end_global_index = (uint32)-1; module->aux_heap_base_global_index = (uint32)-1; module->aux_stack_top_global_index = (uint32)-1; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 1638459a5..d20c28d7d 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -2734,6 +2734,11 @@ load_from_sections(WASMModule *module, WASMSection *sections, section = section->next; } +#if WASM_ENABLE_BULK_MEMORY != 0 + bh_assert(!has_datacount_section + || module->data_seg_count == module->data_seg_count1); +#endif + module->aux_data_end_global_index = (uint32)-1; module->aux_heap_base_global_index = (uint32)-1; module->aux_stack_top_global_index = (uint32)-1; From 5dcffaa7d2685e9bf31015fc68fc75cd049399c5 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Sat, 1 Feb 2025 12:14:06 +0800 Subject: [PATCH 103/105] Update Rust target from 'wasm32-wasi' to 'wasm32-wasip1' in CI (#4050) - update Rust target from 'wasm32-wasi' to 'wasm32-wasip1' in ci --- .github/workflows/compilation_on_android_ubuntu.yml | 2 +- doc/build_wasm_app.md | 10 +++++----- samples/debug-tools/CMakeLists.txt | 2 +- .../wamr-ide/VSCode-Extension/resource/test/build.sh | 2 +- .../wamr-ide/VSCode-Extension/src/test/suite/utils.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 119c8b2d0..b08498cc0 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -817,7 +817,7 @@ jobs: - name: install dependencies run: | - rustup target add wasm32-wasi + rustup target add wasm32-wasip1 sudo apt update && sudo apt-get install -y lld ninja-build npm install working-directory: test-tools/wamr-ide/VSCode-Extension diff --git a/doc/build_wasm_app.md b/doc/build_wasm_app.md index 9536d1a8d..95d237346 100644 --- a/doc/build_wasm_app.md +++ b/doc/build_wasm_app.md @@ -16,24 +16,24 @@ For [AssemblyScript](https://github.com/AssemblyScript/assemblyscript), please r For Rust, please refer to [Install Rust and Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) to install *cargo*, *rustc* and *rustup*. By default they are under ~/.cargo/bin. -And then run such a command to install `wasm32-wasi` target. +And then run such a command to install `wasm32-wasip1` target. ``` bash -$ rustup target add wasm32-wasi +$ rustup target add wasm32-wasip1 ``` To build WASM applications, run ``` bash -$ cargo build --target wasm32-wasi +$ cargo build --target wasm32-wasip1 ``` -The output files are under `target/wasm32-wasi`. +The output files are under `target/wasm32-wasip1`. To build a release version ``` bash -$ cargo build --release --target wasm32-wasi +$ cargo build --release --target wasm32-wasip1 ``` diff --git a/samples/debug-tools/CMakeLists.txt b/samples/debug-tools/CMakeLists.txt index ce06029a5..411106bb3 100644 --- a/samples/debug-tools/CMakeLists.txt +++ b/samples/debug-tools/CMakeLists.txt @@ -72,7 +72,7 @@ add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) include(ExternalProject) # wasm32-wasi -ExternalProject_Add(wasm33-wasi +ExternalProject_Add(wasm32-wasi SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps" CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps -B build -DWASI_SDK_PREFIX=${WASISDK_HOME} diff --git a/test-tools/wamr-ide/VSCode-Extension/resource/test/build.sh b/test-tools/wamr-ide/VSCode-Extension/resource/test/build.sh index e175c9106..33ae79d44 100755 --- a/test-tools/wamr-ide/VSCode-Extension/resource/test/build.sh +++ b/test-tools/wamr-ide/VSCode-Extension/resource/test/build.sh @@ -1,2 +1,2 @@ # compile with debug symbols and no optimization -rustc --target wasm32-wasi ./test.rs -g -C opt-level=0 \ No newline at end of file +rustc --target wasm32-wasip1 ./test.rs -g -C opt-level=0 \ No newline at end of file diff --git a/test-tools/wamr-ide/VSCode-Extension/src/test/suite/utils.ts b/test-tools/wamr-ide/VSCode-Extension/src/test/suite/utils.ts index 3f40596c3..69c474b25 100644 --- a/test-tools/wamr-ide/VSCode-Extension/src/test/suite/utils.ts +++ b/test-tools/wamr-ide/VSCode-Extension/src/test/suite/utils.ts @@ -39,7 +39,7 @@ export function setBpAtMarker(file: string, bpMarker: string): void { export function compileRustToWasm(): void { const testResourceFolder = `${EXTENSION_PATH}/resource/test`; // compile with debug symbols and no optimization - const cmd = `rustc --target wasm32-wasi ${testResourceFolder}/test.rs -g -C opt-level=0 -o ${testResourceFolder}/test.wasm`; + const cmd = `rustc --target wasm32-wasip1 ${testResourceFolder}/test.rs -g -C opt-level=0 -o ${testResourceFolder}/test.wasm`; try { cp.execSync(cmd, { stdio: [null, null, process.stderr] }); From 6f0e0e5f0687489c6db0d2a16950ba6fdba52d59 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 10:37:29 +0000 Subject: [PATCH 104/105] build(deps): Bump github/codeql-action from 3.28.1 to 3.28.5 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.1 to 3.28.5. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.1...v3.28.5) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .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 753322fcc..431969a3c 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.28.1 + uses: github/codeql-action/init@v3.28.5 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.28.1 + uses: github/codeql-action/analyze@v3.28.5 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.28.1 + uses: github/codeql-action/upload-sarif@v3.28.5 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 39f2f9835..5c1b0448d 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@db7177a1c66bea89f5e7ce32d0ea48bea4a0d460 # v2.2.4 + uses: github/codeql-action/upload-sarif@e7c0c9d71b7bd108fd12e06b56fc58d3d154164d # v2.2.4 with: sarif_file: results.sarif From 7f1e6125a25fa14a3ae18b6a1b28735bfebcce5a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:29:13 +0000 Subject: [PATCH 105/105] build(deps): Bump github/codeql-action from 3.28.5 to 3.28.8 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.5 to 3.28.8. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.5...v3.28.8) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .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 431969a3c..a98d5f1a9 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.28.5 + uses: github/codeql-action/init@v3.28.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.28.5 + uses: github/codeql-action/analyze@v3.28.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.28.5 + uses: github/codeql-action/upload-sarif@v3.28.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 5c1b0448d..4c743d2ec 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@e7c0c9d71b7bd108fd12e06b56fc58d3d154164d # v2.2.4 + uses: github/codeql-action/upload-sarif@0701025a8b1600e416be4f3bb5a830b1aa6af01e # v2.2.4 with: sarif_file: results.sarif