Commit Graph

1825 Commits

Author SHA1 Message Date
Wenyong Huang
18d363029c
wasm loader: Fix checks for opcode ref.func and opcode else (#3340)
Fix wasm loader integrity checks for opcode ref.func and opcode else:
for opcode ref.func, the function must be an import, exported, or present in a
table elem segment or global initializer to be used as the operand to ref.func,
for opcode else, there must not be an else opcode previously.

Reported in #3336 and #3337.

And fix mini loader PUSH_MEM_OFFSET/POP_MEM_OFFSET macro
definitions due to the introducing of memory64 feature.
2024-04-22 14:44:45 +08:00
Wenyong Huang
a6e008bca7
document: Update description about segue opt, update README (#3338) 2024-04-22 14:34:52 +08:00
komasayuki
67dc2ae0b2
Fix readdir for posix (#3339)
This PR fixes a readir for posix. readdir is not working correctly in rust.

The current WAMR's readdir implementation for posix is, if readdir returns 0,
it will exit with an error. But posix readdir returns 0 at the end of the directory.
To handle this correctly, if readdir returns 0, it should only raise an error if
errno has changed. We can reproduce it with the following rust code:

```rust
use std::fs;

fn main() {
    let entries  = fs::read_dir(".").unwrap();
    for entry in entries {
        println!("read_dir:{:?}", entry);
    }
}
```
2024-04-22 13:54:19 +08:00
Wenyong Huang
e7a8b3e743
Update version number to 2.0.0 and update release notes (#3327)
And enable code format check for wasm_export.h and add '\n' in os_printf
in sgx platform source files.
2024-04-20 10:16:34 +08:00
Benbuck Nason
8253c417a8
Add functions to expose module import/export info (#3330)
Resolves #3329.
2024-04-20 08:57:39 +08:00
Marcin Kolny
fd7f738451
Allow executing malloc/free from native in memory64 mode (#3315) 2024-04-19 17:15:54 +08:00
Wenyong Huang
902aa525d1
Fix windows relocation string parsing issue (#3333)
The AOT compiler emits string with '\0' now, some string parsing in aot loader
for Windows platform need to be updated.
2024-04-19 16:09:03 +08:00
YAMAMOTO Takashi
d6e8d224ce
Add native-stack-overflow sample (#3321)
This is a test code to examine native stack overflow detection logic.

The current output on my environment (macOS amd64):

```shell
====== Interpreter
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 14704 | failed | leaked | Exception: native stack overflow
14704 - 17904 | failed |     ok | Exception: native stack overflow
17904 - 24576 |     ok |     ok |

====== AOT
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 - 18176 | failed | leaked | Exception: native stack overflow
18176 - 24576 |     ok |     ok |

====== AOT WAMR_DISABLE_HW_BOUND_CHECK=1
 stack size   | fail?  | leak?  | exception
---------------------------------------------------------------------------
    0 -  1968 | failed |     ok | Exception: native stack overflow
 1968 - 24576 |     ok |     ok |
```

This is a preparation to work on relevant issues, including:

https://github.com/bytecodealliance/wasm-micro-runtime/issues/3325
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3320
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3314
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3297
2024-04-19 15:49:09 +08:00
YAMAMOTO Takashi
f6481cedec
Add a comment on WASM_STACK_GUARD_SIZE (#3332) 2024-04-19 10:19:59 +08:00
dongsheng28849455
ba59e56e19
User defined memory allocator for different purposes (#3316)
Some issues are related with memory fragmentation, which may cause
the linear memory cannot be allocated. In WAMR, the memory managed
by the system is often trivial, but linear memory usually directly allocates
a large block and often remains unchanged for a long time. Their sensitivity
and contribution to fragmentation are different, which is suitable for
different allocation strategies. If we can control the linear memory's allocation,
do not make it from system heap, the overhead of heap management might
be avoided.

Add `mem_alloc_usage_t usage` as the first argument for user defined
malloc/realloc/free functions when `WAMR_BUILD_ALLOC_WITH_USAGE` cmake
variable is set as 1, and make passing `Alloc_For_LinearMemory` to the
argument when allocating the linear memory.
2024-04-18 19:40:57 +08:00
Wenyong Huang
68bd30c6f9
Enhance GC subtyping checks (#3317)
Enhance the GC subtyping checks:
- Fix issues in the type equivalence check
- Enable the recursive type subtyping check
- Add a equivalence type flag in defined types of aot file, if there is an
  equivalence type before, just set it true and re-use the previous type
- Normalize the defined types for interpreter and AOT
- Enable spec test case type-equivalence.wast and type-subtyping.wast,
  and enable some commented cases
- Enable set WAMR_BUILD_SANITIZER from cmake variable
2024-04-18 12:32:01 +08:00
Yage Hu
d39d2ba3ca
Fix posix_fadvise error handling (#3323)
`posix_fadvise()` returns 0 on success and the errno on error.  This
commit fixes the handling of the return value such that it does not
always succeeds.

Fixes #3322.
2024-04-17 16:06:25 +08:00
TianlongLiang
30426be82c
Refactor CodeQL CI (#3319)
- Move CodeQL scripts to the scripts directory
- Only report error in CI if it's a CodeQL reported issue and was not dismissed
  before and is likely to be an actual error
2024-04-16 16:32:47 +08:00
liang.he
42199f163e
Log warning if growing table failed (#3310) 2024-04-15 18:29:54 +08:00
liang.he
fef26ead3e
addr2line.py: Support sourceMappingURL section produced by emcc (#3302)
And update the debug-tools sample.
2024-04-12 11:43:40 +08:00
dependabot[bot]
1a043b6eb5
Bump actions/upload-artifact from 3 to 4 (#3308)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-12 11:34:06 +08:00
dependabot[bot]
ff7bf7ad41
Bump actions/setup-node from 3 to 4 (#3307)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-12 11:33:30 +08:00
dependabot[bot]
b54551598a
Bump github/codeql-action from 2 to 3 (#3306)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-12 11:31:05 +08:00
Wenyong Huang
1c690b7561
Add more checks in wasm loader (#3300)
In opcode f32.const, f64.const and memory.copy, check whether the buffer
to read is out of the range of wasm file before reading it.
2024-04-11 19:56:48 +08:00
liang.he
19a6eb98b0
Add dependabot (#3303) 2024-04-11 19:56:02 +08:00
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