Commit Graph

1755 Commits

Author SHA1 Message Date
dongheng
9b28a8a80e
Update esp-idf platform support in main (#3304)
1. Fix API "futimens" and "utimensat" compiling error in different esp-idf version
2. Update component registry description file

ps. refer to PR #3296 on branch release/1.3x
2024-04-11 19:46:34 +08:00
TianlongLiang
4e634bed3f
Add necessary comments for doxygen (#3299)
- Add necessary comments for doxygen to generate API documentation
- Update README.md to add a link for End-user APIs documentation
2024-04-11 07:50:08 +08:00
mkolchurin
8756d29e19
zephyr: Add missing pthread library functions (#3291)
For use with WAMR_BUILD_LIB_PTHREAD, add os_thread_detach,
os_thread_exit, os_cond_broadcast.

Signed-off-by: Maxim Kolchurin <maxim.kolchurin@gmail.com>
2024-04-10 08:19:46 +08:00
liang.he
bcc2a2d2e1
Sync simd opcode definitions spec (#3290)
Remove undefined simd opcodes.
2024-04-09 16:54:42 +08:00
TianlongLiang
4a29794a1b
Update release CI (#3295)
In the release CI and related scripts, when comparing and printing to the CI,
use the most recent **ancestor** tag(s) for the release branch rather than
the most recent one(s).

And fix the build_wamr_sdk.yml and build_wamr_lldb.yml CIs.
2024-04-09 16:51:36 +08:00
dongheng
dacb3c4105
Add wamr to esp-idf components registry (#3287)
This PR is for the main branch, but only the released branch will be pushed
into Espressif component registry.

See also similar fixes in branch release/1.3.x:
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3264
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3288
2024-04-08 12:34:08 +08:00
Wenyong Huang
ef3babc658
interp: Restore context from prev_frame after tail calling a native function (#3283)
The current frame was freed before tail calling to an import or native function
and the prev_frame was set as exec_env's cur_frame, so after the tail calling,
we should recover context from prev_frame but not current frame.

Found in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3279.
2024-04-08 09:23:20 +08:00
Wenyong Huang
b11dbcba0a
thread mgr: Free aux stack only when it was allocated (#3282)
When thread manager is enabled, the aux stack of exec_env may be allocated
by wasm_cluster_allocate_aux_stack or disabled by setting aux_stack_bottom
as UINTPTR_MAX directly. For the latter, no need to free it.

And fix an issue when paring `--gc-heap-size=n` argument for iwasm, and
fix a variable shadowed warning in fast-jit.
2024-04-08 09:06:49 +08:00
liang.he
4ef724bbff
Enhance wasm loading with LoadArgs and support module names (#3265)
- Add new API wasm_runtime_load_ex() in wasm_export.h
  and wasm_module_new_ex in wasm_c_api.h
- Put aot_create_perf_map() into a separated file aot_perf_map.c
- In perf.map, function names include user specified module name
- Enhance the script to help flamegraph generations
2024-04-07 15:04:35 +08:00
TianlongLiang
cee9b826a5
Update document for GC, exception handling and memory64 features (#3284)
Add GC, exception handling and memory64 to README.md post MVP feature list,
and update build_wamr.md for how to build them.

And remove `Non-trapping float-to-int conversions`, `Sign-extension operators`,
`Multi-value` links in README since they are in wasm MVP and very common now.
2024-04-07 14:54:02 +08:00
Wenyong Huang
2013f1f7d7
Fix warnings/issues reported in Windows and by CodeQL/Coverity (#3275)
Fix the warnings and issues reported:
- in Windows platform
- by CodeQL static code analyzing
- by Coverity static code analyzing

And update CodeQL script to build exception handling and memory features.
2024-04-07 11:57:31 +08:00
YAMAMOTO Takashi
53f0941ffa
Revert "lldb_function_to_function_dbi: A hack to avoid crashing on C++ methods (#3190)" (#3281)
This reverts commit 0e8d949440.

Because it doesn't make much sense anymore after we disabled debug info
processing on C++ functions in:
"aot debug: process lldb_function_to_function_dbi only for C".
2024-04-06 15:00:48 +08:00
liang.he
202abc1937
Small enhancement on addr2line.py (#3276)
- If can't parse function name with dwarf information, use "name
  section" instead
- Add introduction about using custom section
2024-04-04 18:32:53 +08:00
YAMAMOTO Takashi
b4cab84e5f
aot debug: Process lldb_function_to_function_dbi only for C (#3278)
This is a workaroud for:
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3187
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3163
2024-04-03 18:03:31 +08:00
YAMAMOTO Takashi
dae09c0e03
aot debug: Fix a NULL dereference (#3274)
It happens on eg. a C function taking a structure argument.
2024-04-03 17:10:46 +08:00
YAMAMOTO Takashi
4806e4e298
LLVM 19: Switch to debug records (#3272)
References:
    https://llvm.org/docs/RemoveDIsDebugInfo.html
    https://github.com/llvm/llvm-project/pull/86529
2024-04-02 16:00:43 +08:00
Wenyong Huang
a23fa9f86c
Implement memory64 for classic interpreter (#3266)
Adding a new cmake flag (cache variable) `WAMR_BUILD_MEMORY64` to enable
the memory64 feature, it can only be enabled on the 64-bit platform/target and
can only use software boundary check. And when it is enabled, it can support both
i32 and i64 linear memory types. The main modifications are:

- wasm loader & mini-loader: loading and bytecode validating process 
- wasm runtime: memory instantiating process
- classic-interpreter: wasm code executing process
- Support memory64 memory in related runtime APIs
- Modify main function type check when it's memory64 wasm file
- Modify `wasm_runtime_invoke_native` and `wasm_runtime_invoke_native_raw` to
  handle registered native function pointer argument when memory64 is enabled
- memory64 classic-interpreter spec test in `test_wamr.sh` and in CI

Currently, it supports memory64 memory wasm file that uses core spec
(including bulk memory proposal) opcodes and threads opcodes.

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3091
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3240
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3260
2024-04-02 15:22:07 +08:00
YAMAMOTO Takashi
6b0b5de1c5
aot debug: Fix a few NULL dereferences on errors (#3273) 2024-04-02 14:30:08 +08:00
dongsheng28849455
250829c0cc
Set is_vram_word_align as false in aot_const_str_set_insert function (#3271)
Set `is_vram_word_align` as false in aot_const_str_set_insert function when
`const char *name` is not from vram required word_align reading.
2024-04-02 14:17:30 +08:00
Xin Xu
bad9a2a231
nuttx: Migrate NuttX CMake build for WAMR (#3256)
Add NuttX CMake build support for platforms.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-04-02 08:53:30 +08:00
Wenyong Huang
6ee71000f9
Fix dynamic offset not updated in op_br for block with ret type (#3269)
The PR #3259 reverted PR #3192, it fixes #3210 but makes #3170 failed again.

The workaround is that we should update `ctx->dynamic_offset` only for opcode br
and should not update it for opcode br_if. This PR fixes both issue #3170 and #3210.
2024-04-01 15:40:20 +08:00
Wenyong Huang
b1502258ea
Fix CI error when install packages for macos-14 (#3270)
MacOS CI ran failed with "error: externally-managed-environment" reported
when installing dependencies. Add argument "--break-system-packages" to
fix it.

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/8503917001/job/23291537189
https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/8502961539/job/23289867170
2024-04-01 15:27:15 +08:00
Wenyong Huang
ec15b6bbad
Add lock and ref_count for runtime init (#3263)
Some environment may call wasm_runtime_full_init/wasm_runtime_init multiple
times without knowing that runtime is initialized or not, it is better to add lock
and increase reference count during initialization.

ps. https://github.com/bytecodealliance/wasm-micro-runtime/discussions/3253.
2024-04-01 12:39:46 +08:00
Wenyong Huang
9c8551cf75
Add cmake flag to control aot intrinsics (#3261)
Add cmake variable `-DWAMR_BUILD_AOT_INTRINSICS=1/0` to enable/disable
the aot intrinsic functions, which are normally used by AOT XIP feature, and
can be disabled to reduce the aot runtime binary size.

And refactor the code in aot_intrinsics.h/.c.
2024-04-01 11:26:05 +08:00
TianlongLiang
b9740beb31
Disable CodeQL on fork repo (#3262) 2024-03-28 16:17:48 +08:00
Wenyong Huang
f933d4c829
loader: Remove updating ctx->dynamic_offset in emit_br_info (#3259)
Should not update `ctx->dynamic_offset` in emit_br_info, since the `Part e` only
sets the dst offsets, the operand stack should not be changed, e.g., the stack
operands are to be used by the opcodes followed by `br_if` opcode.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3210.
2024-03-28 16:07:02 +08:00
Wenyong Huang
89f4982123
Fix compilation errors on zephyr platform (#3255)
Refer to https://github.com/bytecodealliance/wasm-micro-runtime/issues/3252.
2024-03-26 17:55:53 +08:00
liang.he
498eb5d54a
Append \0 to every name string in aot name section (#3249)
Since strings in .name section in .wasm is not c-style, need to append
a `\0` to each string in .name section in AOT file when emitting.
2024-03-26 14:27:20 +08:00
liang.he
d8d8f8ce04
Implement apis to set and get the name of a wasm module (#3254)
Add API wasm_runtime_set_module_name and wasm_runtime_get_module_name,
and by default, a module's name is "" if the set module name api isn't called.
2024-03-26 12:10:13 +08:00
Wenyong Huang
ca364eb5d7
Fix nightly-run CI and CodeQL CI (#3250)
- Fix nightly run CI failure which was introduced by PR #3239 and now it must set
  WAMR_BUILD_TARGET when building iwasm for Android platform
- Remove building llvm, wamrc and jit in CodeQL CI, since it will
  do static code analyzing for llvm project and cause CodeQL run
  failed: `Oops! A fatal internal error occurred.
  This particular kind of error most often happens as a side effect of running out of
  disk space.`
2024-03-22 14:29:30 +08:00
Wenyong Huang
6a55bde5b3
Add issue templates (#3248)
Add issue templates of blank issue, improvement and reporting bug in WAMR.
And fix several invalid links in ATTRIBUTIONS.md.
2024-03-22 13:49:39 +08:00
TianlongLiang
64b6c688a2
posix_file.c: Correct the dirfd argument that passes to fstatat (#3244)
This PR fixes the random failing test case `nofollow_errors` mentioned in
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3222

```C
// dirfd: This is the file descriptor of the directory relative to which the pathname is interpreted. 
int openat(int dirfd, const char *pathname, int flags, ...);
```
The value should be a directory handle instead of a file handle (which is always -1 in this context)
returned from `openat`.
2024-03-22 10:55:39 +08:00
Yo Han Joo
b4941b0cde
Go binding: Change C.long to C.int64_t when call wasm_runtime_set_wasi_args_ex (#3235)
- Change `C.long` to `C.int64_t` due to error:
```sh
./module.go:119:64: cannot use _Ctype_long(stdinfd) (value of type _Ctype_long) as _Ctype_longlong value in variable declaration
./module.go:120:43: cannot use _Ctype_long(stdoutfd) (value of type _Ctype_long) as _Ctype_longlong value in variable declaration
./module.go:120:60: cannot use _Ctype_long(stderrfd) (value of type _Ctype_long) as _Ctype_longlong value in variable declaration
```
- Change offset from `uint32` to `uint64` due to casting error

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3220
https://stackoverflow.com/questions/70243683/how-to-convert-c-uint64-t-to-cgo-consistently-across-os
2024-03-22 10:45:14 +08:00
Xu Jinyang
cef88deedb
Add wasi_ephemeral_nn module support (#3241)
Add `wasi_ephemeral_nn` module support with optional cmake variable,
which was mentioned in #3229.
2024-03-21 21:05:34 +08:00
Wenyong Huang
e003ee1e29
CodeQL: Add more build combinations and disable run on PR (#3246)
Enhance CodeQL Code Security Analysis:
- Add more compilation combinations to build iwasm with different kinds of features
- Disable run on PR created and keep nightly run, since the whole time is very long,
   and will check how to restore run on PR created in the future
2024-03-21 14:18:27 +08:00
Brian
a86eeb273c
Add CodeQL Workflow for Code Security Analysis (#2812)
Add CodeQL Workflow for Code Security Analysis

This pull request introduces a CodeQL workflow to enhance the security analysis of our repository.
CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in
our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify
and address potential issues before they become security threats.

We added a new CodeQL workflow file (.github/workflows/codeql.yml) that
- Runs on nightly-run, and consider runs on every pull request to the main branch in the future.
- Excludes queries with a high false positive rate or low-severity findings.
- Does not display results for third-party code, focusing only on our own codebase.

Testing:
To validate the functionality of this workflow, we have run several test scans on the codebase and
reviewed the results. The workflow successfully compiles the project, identifies issues, and provides
actionable insights while reducing noise by excluding certain queries and third-party code.

Deployment:
Once this pull request is merged, the CodeQL workflow will be active and automatically run on
every push and pull request to the main branch. To view the results of these code scans, please
follow these steps:
1. Under the repository name, click on the Security tab.
2. In the left sidebar, click Code scanning alerts.

Additional Information:
- You can further customize the workflow to adapt to your specific needs by modifying the workflow file.
- For more information on CodeQL and how to interpret its results, refer to the GitHub documentation
and the CodeQL documentation.

Signed-off-by: Brian <bayuan@purdue.edu>
2024-03-21 12:37:47 +08:00
Wenyong Huang
76254183f9
Make android platform's cmake flags configurable (#3239)
Don't hardcode the cmake configurations in the Android platform's CMakeLists.txt.

Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3238
2024-03-21 11:08:40 +08:00
Tao Xiong
29d83224a8
Add esp32c6 support (#3234)
This PR adds support for ESP32 C6, which has been mentioned in #3208.
2024-03-19 08:15:46 +08:00
Liangyu Zhang
b11a1d157d
GC: Add wasm_struct_obj_get_field_count API (#3236) 2024-03-18 16:26:30 +08:00
TianlongLiang
7486056aee
Fix nightly run tsan ASLR issue (#3233)
The nightly run CI reported error:
  "FATAL: ThreadSanitizer: unexpected memory mapping 0x5be565bf3000-0x5be565bfb000"
which is caused by the ASLR issue, we set `vm.mmap_rnd_bits` to 28 to resolve it,
according to the post below:
https://stackoverflow.com/questions/77850769/fatal-threadsanitizer-unexpected-memory-mapping-when-running-on-linux-kernels

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/8319242277/job/22762363873#step:14:2008
2024-03-18 11:15:47 +08:00
liang.he
8c1269d44d
trans_wasm_func_name.py: Correct function index during translation (#3232)
Adding the N from "aot_func#N" with the import function count is the correct
wasm function index.
2024-03-18 10:32:55 +08:00
Wenyong Huang
ff296c1a62
Fix aot relocation symbols not found on windows 32-bit (#3231)
The symbols in windows 32-bit may start with '_' and can not be found
when resolving the relocations to them. This PR ignores the underscore
when handling the relocation name of AOT_FUNC_INTERNAL_PREFIX, and
redirect the relocation with name "_aot_stack_sizes" to the relocation with
name ".aot_stack_sizes" (the name of the data section created).

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3216
2024-03-18 09:51:38 +08:00
Wenyong Huang
5e2011ca1d
Fix compilation errors on esp-idf platform (#3224)
The issue was reported in #3208.
2024-03-14 21:31:44 +08:00
TianlongLiang
de803b2beb
Small refactor on WASMModuleInstance and fix Go/Python language bindings (#3227)
- Merge unused field `used_to_be_wasi_ctx` in `AOTModuleInstance` into `reserved` area
- Add field `memory_lock` in `WASMMemoryInstance` for future refactor
- Go binding: fix type error
    https://github.com/bytecodealliance/wasm-micro-runtime/issues/3220
- Python binding:
    type annotation uses the union operator "|", which requires Python version >=3.10
2024-03-14 15:30:28 +08:00
TianlongLiang
c3e33a96ea
Remove unused argument in wasm_runtime_lookup_function and refactor WASMModuleInstance (#3218)
Remove the unused parameter `signature` from `wasm_runtime_lookup_function`.

Refactor the layout of WASMModuleInstance structure:
- move common data members `c_api_func_imports` and `cur_exec_env` from
  `WASMModuleInstanceExtraCommon` to `WASMModuleInstance`
- In `WASMModuleInstance`, enlarge `reserved[3]` to `reserved[5]` in case that
  we need to add more fields in the future

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/2530
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3202
2024-03-13 12:28:45 +08:00
Marcin Kolny
ce44e0ec0c
Allow converting the zero wasm address to native (#3215)
This allows to know the beginning of the wasm address space. At the moment
to achieve that, we need to apply a `hack wasm_runtime_addr_app_to_native(X)-X`
to get the beginning of WASM memory in the nativ code, but I don't see a good
reason why not to allow zero address as a parameter value for this function.
2024-03-12 17:46:11 +08:00
lucianoiam
df57e70437
Fix compilation errors on MinGW (#3217)
Before PR compilation failed because of two errors:

1 - Usage of CMake target_link_libraries()

Make Error at CMakeLists.txt:154 (target_link_libraries):
  The keyword signature for target_link_libraries has already been used with
  the target "iwasm_shared".  All uses of target_link_libraries with a target
  must be either all-keyword or all-plain.

  The uses of the keyword signature are here:

   * CMakeLists.txt:148 (target_link_libraries)

See https://stackoverflow.com/questions/47737558/uses-of-target-link-libraries-must-be-either-all-keyword-or-all-plain

Fixed by adding keyword INTERFACE

2 - Undefined symbols during linkage, fixed by adding -lwsock32.
2024-03-12 17:38:07 +08:00
Wenyong Huang
0ee5ffce85
Refactor APIs and data structures as preliminary work for Memory64 (#3209)
# Change the data type representing linear memory address from u32 to u64

## APIs signature changes
- (Export)wasm_runtime_module_malloc
  - wasm_module_malloc
    - wasm_module_malloc_internal
  - aot_module_malloc
    - aot_module_malloc_internal
- wasm_runtime_module_realloc
  - wasm_module_realloc
    - wasm_module_realloc_internal
  - aot_module_realloc
    - aot_module_realloc_internal
- (Export)wasm_runtime_module_free
  - wasm_module_free
    - wasm_module_free_internal
  - aot_module_malloc
    - aot_module_free_internal
- (Export)wasm_runtime_module_dup_data
  - wasm_module_dup_data
  - aot_module_dup_data
- (Export)wasm_runtime_validate_app_addr
- (Export)wasm_runtime_validate_app_str_addr
- (Export)wasm_runtime_validate_native_addr
- (Export)wasm_runtime_addr_app_to_native
- (Export)wasm_runtime_addr_native_to_app
- (Export)wasm_runtime_get_app_addr_range
- aot_set_aux_stack
- aot_get_aux_stack
- wasm_set_aux_stack
- wasm_get_aux_stack
- aot_check_app_addr_and_convert, wasm_check_app_addr_and_convert
  and jit_check_app_addr_and_convert
- wasm_exec_env_set_aux_stack
- wasm_exec_env_get_aux_stack
- wasm_cluster_create_thread
- wasm_cluster_allocate_aux_stack
- wasm_cluster_free_aux_stack

## Data structure changes
- WASMModule and AOTModule
  - field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMExecEnv
  - field aux_stack_boundary and aux_stack_bottom
- AOTCompData
  - field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMMemoryInstance(AOTMemoryInstance)
  - field memory_data_size and change __padding to is_memory64
- WASMModuleInstMemConsumption
  - field total_size and memories_size
- WASMDebugExecutionMemory
  - field start_offset and current_pos
- WASMCluster
  - field stack_tops

## Components that are affected by the APIs and data structure changes
- libc-builtin
- libc-emcc
- libc-uvwasi
- libc-wasi
- Python and Go Language Embedding
- Interpreter Debug engine
- Multi-thread: lib-pthread, wasi-threads and thread manager
2024-03-12 11:38:50 +08:00
Wenyong Huang
b6216a5f8a
Fix ip (bytecode offset) not committed into the latest aot frame (#3213) 2024-03-11 18:11:43 +08:00
Enrico Loparco
f550feb039
Demangle function names in stack trace when using addr2line script (#3211)
Last bit missing from #3206: demangling of function names (useful for wasm
generated from Rust for instance) using `llvm-cxxfilt`.

Before this PR:
```text
0: abort
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/panic_abort/src/lib.rs:85
1: _ZN3std3sys4wasi14abort_internal17h50698daab05bf73bE
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys/wasi/mod.rs:181
2: _ZN3std7process5abort17h6bc522b6749f17cfE
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/process.rs:2278
3: _ZN3std5alloc8rust_oom17h452ad5ba6cebff96E
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/alloc.rs:364
```

After:
```text
0: abort
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/panic_abort/src/lib.rs:85
1: std::sys::wasi::abort_internal::h50698daab05bf73b
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys/wasi/mod.rs:181
2: std::process::abort::h6bc522b6749f17cf
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/process.rs:2278
3: std::alloc::rust_oom::h452ad5ba6cebff96
        at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/alloc.rs:364
```
2024-03-11 14:27:09 +08:00