![]() * Optimize memory initialization handling in AOT loader (#3983) Save memory if the file buffer is always exist before exit. Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * Break aot_create_comp_data into small functions Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * Handle a new scenario where an item is both exported and imported. (#3984) * 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. * Ensure __heap_base and __data_end global indices are validated against import count (#3996) * Fix table index calculations in wasm_loader and wasm_mini_loader (#4004) * Add an example of how to embed WAMR in Zephyr user mode (#3998) * [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 * 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 * 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. * Add documentation regarding security issues and the status of Wasm proposals (#3972) Add documentation regarding security issues and the status of Wasm proposals. * 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 * 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] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * 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] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Refine read leb int wasm loader of fast interpreter (#4017) * .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. * fixes for compiling on windows (#4026) * 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 * 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 * 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 * Update Rust target from 'wasm32-wasi' to 'wasm32-wasip1' in CI (#4050) - update Rust target from 'wasm32-wasi' to 'wasm32-wasip1' in ci * 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] <support@github.com> * 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] <support@github.com> * Use wasm32-wasip1 instead of wasm32-wasi target for rust code (#4057) Rust compiler previously deprecated, and now removed the wasm32-wasi target and replaced it with wasm32-wasip1. This change updates all the occurrences of wasm32-wasi in the context of Rust compilation. covers the wasi-nn/test. * add a validator for aot module (#3995) - Add AOT module validation to ensure memory constraints are met - Enable AOT validator in build configuration and update related source files * Show wasm proposals status during compilation and execution (#3989) - add default build configuration options and enhance message output for WAMR features - Add Wasm proposal status printing functionality * initial * Add versioning support and update CMake configuration * Add versioning information for libraries and executables across multiple platforms * Refactor versioning documentation and adopt semantic versioning guidelines * Remove deprecated version.h file and update versioning documentation * Add version.h and update versioning documentation for embedded platforms * Add workflow to confirm version.h is in sync and integrate it into Android compilation workflow * Cleanup check_version_h workflow by removing unnecessary outputs and permissions * Update memory allocation functions to use allocator user data (#4043) * [fuzzing] execute every exported function (#3959) - Enhance wasm mutator fuzz tests by adding export function execution and random value generation - Use --fuel to limit loop size - Use predefined values and enhance argument logging in execution * In wasm32, fix potential conversion overflow when enlarging 65536 pages (#4064) fix enlarge 65536 pages conversion overflow in wasm32 * fix(aot): ensure value_cmp does not exceed br_count in branch table compilation (#4065) * build(deps): Bump github/codeql-action from 3.28.8 to 3.28.9 (#4074) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.8 to 3.28.9. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.8...v3.28.9) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Unit test:type matching issue and code redundancy (#4079) * Add a conditional check for the macro __STDC_VERSION__ (#4080) * build_llvm.py: Allow to build xtensa target on non-xtensa host Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * [gc] Subtyping fix (#4075) * fix(build_llvm.py): clean up whitespace and formatting in build script Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * feat: add support for EXTERNREF value type and enable AOT validator in fuzz tests (#4083) * fix(unit-test): libc_builtin_test issues (#4073) - uninitialized buffer pointers (crashes) - match integer constant size with printf specifier Signed-off-by: Peter Tatrai <peter.tatrai.ext@siemens.com> * fix(build_llvm_libraries.yml): Correct script path for build_llvm.py Signed-off-by: Huang Qi <huangqi3@xiaomi.com> * fix(aot_emit_aot_file): prevent buffer emission for zero byte_count (#4095) if using a debug building of wamrc to run spec test. there will be: core/iwasm/compilation/aot_emit_aot_file.c:1794:13: runtime error: null pointer passed as argument 2, which is declared to never be null * Cmake improvements (#4076) - Utilizes the standard CMake variable BUILD_SHARED_LIBS to simplify the CMake configuration. - Allows the use of a single library definition for both static and shared library cases, improving maintainability and readability of the CMake configuration. - Install vmlib public header files - Installs the public header files for the vmlib target to the include/iwasm directory. - Install cmake package - Adds the necessary CMake configuration files (iwasmConfig.cmake and iwasmConfigVersion.cmake). - Configures the installation of these files to the appropriate directory (lib/cmake/iwasm). - Ensures compatibility with the same major version. - Improve windows product-mini CMakeLists.txt - Fix missing symbols when linking windows product-mini with shared vmlib - Improve Darwin product-mini CMakeLists.txt --------- Signed-off-by: Peter Tatrai <peter.tatrai.ext@siemens.com> * fix: when load aot init expr,no type_idx set. (#4094) Fix an assertion from *gc_object.c line 91* `bh_assert(rtt_type->type_flag == WASM_TYPE_STRUCT;` * prevent data overflow on 32 bit platform for memory.grow * cr suggestions * cr suggestions * format * cr suggestions * feat: use C linkage in aot_comp_option.h for C++ embeding (#4106) Co-authored-by: xiangjia.xj <xiangjia.xj@alibaba-inc.com> * build(deps): Bump actions/upload-artifact from 4.6.0 to 4.6.1 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.6.0 to 4.6.1. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4.6.0...v4.6.1) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): Bump github/codeql-action from 3.28.9 to 3.28.10 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.9 to 3.28.10. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.28.9...v3.28.10) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Apply suggestions from code review remove confusing comments. * build(deps): Bump ossf/scorecard-action from 2.4.0 to 2.4.1 Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.4.0 to 2.4.1. - [Release notes](https://github.com/ossf/scorecard-action/releases) - [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md) - [Commits]( |
||
---|---|---|
.. | ||
host | ||
wasm | ||
.gitignore | ||
CMakeLists.txt | ||
README.md |
How to create imports
for wasm_instance_new() properly
It's always been asked how to create wasm_extern_vec_t *imports
for
wasm_instance_new()
?
WASM_API_EXTERN own wasm_instance_t* wasm_instance_new(
wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t *imports,
own wasm_trap_t** trap
);
wasm_extern_vec_t *imports
is required to match the requirement of the
import section of a .wasm.
$ /opt/wabt-1.0.31/bin/wasm-objdump -j Import -x <some_example>.wasm
Section Details:
Import[27]:
- func[0] sig=2 <pthread_mutex_lock> <- env.pthread_mutex_lock
- func[1] sig=2 <pthread_mutex_unlock> <- env.pthread_mutex_unlock
- func[2] sig=2 <pthread_cond_signal> <- env.pthread_cond_signal
- func[3] sig=3 <host_log> <- env.log
...
- func[11] sig=4 <__imported_wasi_snapshot_preview1_sock_bind> <- wasi_snapshot_preview1.sock_bind
- func[12] sig=4 <__imported_wasi_snapshot_preview1_sock_connect> <- wasi_snapshot_preview1.sock_connect
- func[13] sig=4 <__imported_wasi_snapshot_preview1_sock_listen> <- wasi_snapshot_preview1.sock_listen
- func[14] sig=5 <__imported_wasi_snapshot_preview1_sock_open> <- wasi_snapshot_preview1.sock_open
- func[15] sig=4 <__imported_wasi_snapshot_preview1_sock_addr_remote> <- wasi_snapshot_preview1.sock_addr_remote
- func[16] sig=4 <__imported_wasi_snapshot_preview1_args_get> <- wasi_snapshot_preview1.args_get
- func[17] sig=4 <__imported_wasi_snapshot_preview1_args_sizes_get> <- wasi_snapshot_preview1.args_sizes_get
...
Developers should fill in imports with enough host functions and make sure there are no linking problems during instantiation.
TODO: linking warnings
A natural way
One natural answer is "to create a list which matches every item in the import section" of the .wasm. Since developers can see the section details of a .wasm by tools like wasm-objdump, the answer is doable. Most of the time, if they also prepare Wasm modules, developers have full control over import requirements, and they only need to take a look at the order of the import section.
Yes, the order. A proper wasm_extern_vec_t *imports
includes two things:
- how many
wasm_extern_t
- and order of those
Because there is no "name information" in a wasm_extern_t
. The only way is let
wasm_instance_new()
to tell which item in the import section of a .wasm
should match any item in wasm_extern_vec_t *imports
is based on index.
The algorithm is quite straightforward. The first one of the import section matches
wasm_extern_vec_t *imports->data[0]
. The second one matches wasm_extern_vec_t *imports->data[1]
.
And so on.
So the order of wasm_extern_vec_t *imports
becomes quite a burden. It requires
developers always checking the import section visually.
Until here, the natural way is still workable although involving some handy work. Right?
A blocker
Sorry, the situation changes a lot when driving wasm32-wasi Wasm modules with wasm-c-api.
As you know, WASI provides a set of crossing-platform standard libraries for
Wasm modules, and leaves some interfaces for native platform-dependent supports.
Those interfaces are those import items with the module name wasi_snapshot_preview1
in a Wasm module.
It seems not economical to let developers provide their version of host
implementations of the wasi_snapshot_preview1.XXX
functions. All those support
should be packed into a common library and shared in different Wasm modules.
Like a cargo WASI.
WAMR chooses to integrate the WASI support library in the runtime to reduce
developers' compilation work. It brings developers a new thing of a proper
wasm_extern_vec_t *imports
that developers should avoid overwriting those items
of the import section of a Wasm module that will be provided by the runtime. It
also not economical to code for those functions.
Using module names as a filter seems to be a simple way. But some private
additional c/c++ libraries are supported in WAMR. Those supporting will bring
more import items that don't use wasi_snapshot_preview1
as module names but are still
covered by the WASM runtime. Like env.pthread_
. Plus, the native lib registration
provides another possible way to fill in the requirement of the import section.
Let's take summarize. A proper wasm_extern_vec_t *imports
should include:
- provides all necessary host implementations for items in the import section
- should not override runtime provided implementation or covered by native registrations. functional or econmical.
- keep them in a right order
A recommendation
The recommendation is:
- use
wasm_module_imports()
to build the order - use
wasm_importtype_is_linked()
to avoid overwriting
wasm-c-api-imports is a simple showcase of how to do that.
First, let's take a look at the Wasm module. send_recv
uses both standard WASI and WAMR_BUILD_LIB_PTHREAD supporting. Plus a private
native function host_log
.
So, wasm_extern_vec_t *imports
should only include the host implementation of
host_log
and avoid WASI related(wasm-c-api-imports.XXX
) and pthread related(env.pthread_XXX
).
- get import types with
wasm_module_imports(0)
. it contains name information
wasm_importtype_vec_t importtypes = { 0 };
wasm_module_imports(module, &importtypes);
- traversal import types. The final
wasm_importvec_t *imports
should have the same order withwasm_importtype_vec_t
for (unsigned i = 0; i < importtypes.num_elems; i++)
- use
wasm_importtype_is_linked()
to avoid those covered by the runtime and registered natives. A little tip is use "wasm_extern_new_empty()" to create a placeholder.
/* use wasm_extern_new_empty() to create a placeholder */
if (wasm_importtype_is_linked(importtype)) {
externs[i] = wasm_extern_new_empty(
store, wasm_externtype_kind(wasm_importtype_type(importtype)));
continue;
}
- use
wasm_importtype_module()
to get the module name, usewasm_importtype_name()
to get the field name.
const wasm_name_t *module_name =
wasm_importtype_module(importtypes.data[i]);
const wasm_name_t *field_name =
wasm_importtype_name(importtypes.data[i]);
- fill in
wasm_externvec_t *imports
dynamically and programmatically.
if (strncmp(module_name->data, "env", strlen("env")) == 0
&& strncmp(field_name->data, "log", strlen("log")) == 0) {
wasm_functype_t *log_type = wasm_functype_new_2_0(
wasm_valtype_new_i64(), wasm_valtype_new_i32());
wasm_func_t *log_func = wasm_func_new(store, log_type, host_logs);
wasm_functype_delete(log_type);
externs[i] = wasm_func_as_extern(log_func);
}
}