Commit Graph

1675 Commits

Author SHA1 Message Date
Xu Jun
12f834aebd
fast-interp: Fix frame_offset overflow issue (#3149)
The issue was found in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3137.
2024-02-08 11:32:17 +08:00
Xu Jun
7cac0531ad
fast-interp: Fix copy_stack_top_i64 overlap issue (#3146)
This fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3145.
2024-02-07 13:24:47 +08:00
Wenyong Huang
16a4d71b34
Implement GC (Garbage Collection) feature for interpreter, AOT and LLVM-JIT (#3125)
Implement the GC (Garbage Collection) feature for interpreter mode,
AOT mode and LLVM-JIT mode, and support most features of the latest
spec proposal, and also enable the stringref feature.

Use `cmake -DWAMR_BUILD_GC=1/0` to enable/disable the feature,
and `wamrc --enable-gc` to generate the AOT file with GC supported.

And update the AOT file version from 2 to 3 since there are many AOT
ABI breaks, including the changes of AOT file format, the changes of
AOT module/memory instance layouts, the AOT runtime APIs for the
AOT code to invoke and so on.
2024-02-06 20:47:11 +08:00
YAMAMOTO Takashi
5931aaacbe
aot compiler: Place precheck wrapper before the corresponding wrapped function (#3141)
This increases the chance to use "short" calls.

Assumptions:
- LLVM preserves the order of functions in a module
- The wrapper function are smaller than the wrapped functions
- The target CPU has "short" PC-relative variation of call/jmp instructions
  and they are preferrable over the "long" ones.

A motivation:
- To avoid some relocations for XIP, I want to use xtensa PC-relative
  call instructions, which can only reach ~512KB.
2024-02-06 15:05:32 +08:00
YAMAMOTO Takashi
6e547baf46
aot_compile_op_call: Stop setting calling convention explicitly (#3140)
The current logic doesn't work for some cases.
cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3138

It's unclear why we are setting the calling convention explicitly here
at all. In many cases, the default just seems working.
2024-02-06 13:14:25 +08:00
Enrico Loparco
cfa90ca44f
Use logger for runtime error/debug prints (#3097)
Change runtime internal error/debug prints from using `os_printf()`
to using `LOG_ERROR()`/`LOG_DEBUG()`.
2024-02-06 13:02:54 +08:00
TianlongLiang
f359b51525
Fix threads opcodes' boundary check in classic-interp and fast-interp (#3136)
Using `CHECK_BULK_MEMORY_OVERFLOW(addr + offset, n, maddr)` to do the
boundary check may encounter integer overflow in `addr + offset`, change to
use `CHECK_MEMORY_OVERFLOW(n)` instead, which converts `addr` and `offset`
to uint64 first and then add them to avoid integer overflow.
2024-02-06 11:52:30 +08:00
Xu Jun
d6d5072cc6
Fix locel.set in polymorphic stack (#3135)
The issue was reported in #3123.
2024-02-05 17:41:33 +08:00
Wenyong Huang
b8ff98c810
Fix possible integer overflow in loader target block check (#3133)
Checking with `loader_ctx->csp_num < depth + 1` has potential integer overflow
issue when depth is UINT_MAX, change to `loader_ctx->csp_num - 1 < depth`
instead.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3130.
2024-02-05 16:00:58 +08:00
Huang Qi
1a676f212b
Zero the memory mapped from os_mmap in NuttX (#3132)
Zero the memory which is required by os_mmap.

This fixes the nuttx spec test CI failure:
https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/7777804669
2024-02-05 15:45:22 +08:00
Wenyong Huang
06df58f20e
Fix loader check_wasi_abi_compatibility (#3126)
Assume that wasi exported `_start` and `_initialize` functions can not
be an import function.

Fixes issue #3122.
2024-02-04 17:27:43 +08:00
YAMAMOTO Takashi
529fa9dd17
EH: Fix broken stack usage calculation (#3121)
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3108
2024-02-03 12:21:15 +08:00
Enrico Loparco
a32b082d2a
Add ARM MacOS to the CI (#3120)
Add ARM MacOS to the CI, to prevent regressions like the one fixed in #3102 in the future.
And add the AOT compilation to the wasi-threads example.
2024-02-03 11:51:02 +08:00
Marcin Kolny
a27ddece7f
Always allocate linear memory using mmap (#3052)
With this approach we can omit using memset() for the newly allocated memory
therefore the physical pages are not being used unless touched by the program.

This also simplifies the implementation.
2024-02-02 22:17:44 +08:00
Wenyong Huang
2eb60060d8
Fix read and validation of misc/simd/atomic sub opcodes (#3115)
The format of sub opcodes after misc, simd and atomic prefix is leb u32.

The issue was found in #2921.
2024-02-02 12:03:58 +08:00
Wenyong Huang
b3f728ceb3
Update version number to 1.3.2 and update release notes (#3083) 2024-02-01 12:42:12 +08:00
YAMAMOTO Takashi
edc3643909
EH: Fix validation of delegate opcode (#3107)
cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/1884#issuecomment-1914000294
2024-02-01 12:32:06 +08:00
Xu Jun
40e51faca8
fast-interp: Fix block with parameter in polymorphic stack issue (#3112)
The issue was reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3061.
2024-02-01 11:55:29 +08:00
YAMAMOTO Takashi
3111a86cb3
EH: Fix delegate parsing in wasm_loader_find_block_addr (#3106) 2024-02-01 07:46:49 +08:00
YAMAMOTO Takashi
10e87d2966
EH: Don't call word_copy with zero size (#3105) 2024-01-31 21:54:19 +08:00
YAMAMOTO Takashi
43c4a5c434
exception handling: Fix build error (#3104) 2024-01-31 20:24:34 +08:00
Enrico Loparco
dfd2a5b0b4
Fix AOT compilation on MacOS (#3102)
After #2995, AOT may stop working properly on arm MacOS:
```bash
wasm-micro-runtime/core/iwasm/common/wasm_runtime_common.c,
line 1270, WASM module load failed
AOT module load failed: mmap memory failed
```
That's because, without `#include <TargetConditionals.h>`, `TARGET_OS_OSX` is undefined,
since it's definition is in that header file.
2024-01-31 20:06:22 +08:00
Xu Jun
51e25ef01f
fast-interp: Fix frame_offset pop order (#3101)
The issue was reported in #3062.
2024-01-31 19:26:27 +08:00
Xu Jun
5a99866c01
fast-interp: Fix stack recovery for else branch (#3100)
The issue was reported in #3090.
2024-01-31 11:23:23 +08:00
Wenyong Huang
af318bac81
Implement Exception Handling for classic interpreter (#3096)
This PR adds the initial support for WASM exception handling:
* Inside the classic interpreter only:
  * Initial handling of Tags
  * Initial handling of Exceptions based on W3C Exception Proposal
  * Import and Export of Exceptions and Tags
* Add `cmake -DWAMR_BUILD_EXCE_HANDLING=1/0` option to enable/disable
  the feature, and by default it is disabled
* Update the wamr-test-suites scripts to test the feature
* Additional CI/CD changes to validate the exception spec proposal cases

Refer to:
https://github.com/bytecodealliance/wasm-micro-runtime/issues/1884
587513f3c6
8bebfe9ad7
59bccdfed8

Signed-off-by: Ricardo Aguilar <ricardoaguilar@siemens.com>
Co-authored-by: Chris Woods <chris.woods@siemens.com>
Co-authored-by: Rene Ermler <rene.ermler@siemens.com>
Co-authored-by: Trenner Thomas <trenner.thomas@siemens.com>
2024-01-31 08:27:17 +08:00
YAMAMOTO Takashi
7e65f9a244
aot: Fix LLVMSetTailCallKind check (#3099) 2024-01-30 20:50:33 +08:00
Enrico Loparco
170ae35131
test_wamr.sh: Allow using test script on different platforms (#3098)
The `^^` for uppercase is not widely supported, e.g. not working on some MacOS M1.
2024-01-30 11:02:40 +08:00
Wenyong Huang
7f8e2133ec
Fix windows build error and compilation warnings (#3095)
Fix wamrc build error reported on Windows:
```bash
CMake Error at CMakeLists.txt:84 (message):
  Unsupported CMAKE_HOST_SYSTEM_PROCESSOR AMD64
```
And clear several compilation warnings.
2024-01-29 18:57:57 +08:00
Huang Qi
b98f150f82
CI: Update version of checkout to suppress warnings (#3093) 2024-01-27 07:55:49 +08:00
tkernelcn
83c3ef0f46
freertos: Thread exit more common (#3094)
In native side,  even not call `os_thread_exit` at end of thread code,
can also exit correctly.
2024-01-26 18:38:55 +08:00
liang.he
99bbad8cdb
perf profiling: Adjust the calculation of execution time (#3089) 2024-01-26 18:06:21 +08:00
Huang Qi
9fb5fcc709
Add comments to suppress warning from clang-tidy (#3088)
Suppress style warnings for macro definition, name of these macros is
inconsistent with others (upper case).
2024-01-26 17:02:24 +08:00
Huang Qi
ad46290770
Update outdated reference link in multi_module.md (#3092) 2024-01-26 16:55:27 +08:00
Wenyong Huang
313ce8cb61
Fix memory/table segment checks in memory.init/table.init (#3081)
According to the wasm core spec, the checks for the table segments in
`table.init` opcode are similar to the checks for `memory.init` opcode:
- The size of a passive segment is shrunk to zero after `data.drop`
  (or `elem.drop`) opcode is executed, and the segment can be used to do
  `memory.init` (or `table.init`) again
- The `memory.init` only traps when `s+n > len(data.data)` or `d+n > len(mem.data)`
  and `table.init` only traps when `s+n > len(elem.elem)` or `d+n > len(tab.elem)`
- The active segment can also be used to do `memory.init` (or `table.init`),
  while it behaves like a dropped passive segment

https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
```
Segments can also be shrunk to size zero by using the following new instructions:
- data.drop: discard the data in an data segment
- elem.drop: discard the data in an element segment

An active segment is equivalent to a passive segment, but with an implicit
memory.init followed by a data.drop (or table.init followed by a elem.drop)
that is prepended to the module's start function.
```
ps.
https://webassembly.github.io/spec/core/bikeshed/#-hrefsyntax-instr-memorymathsfmemoryinitx%E2%91%A0
https://webassembly.github.io/spec/core/bikeshed/#-hrefsyntax-instr-tablemathsftableinitxy%E2%91%A0
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3020
2024-01-26 09:45:59 +08:00
Huang Qi
6daaf6d27a
Fix inconsistent code style in aot_loader.c (#3082) 2024-01-25 17:19:14 +08:00
YAMAMOTO Takashi
9afbeab1c8
wasi: Apply wasm_runtime_begin_blocking_op to poll as well (#3080)
While we used a different approach for poll_oneoff [1],
the implementation works only when the poll list includes
an absolute clock event. That is, if we have a thread which is
polling on descriptors without a timeout, we fail to terminate
the thread.

This commit fixes it by applying wasm_runtime_begin_blocking_op
to poll as well.

[1] https://github.com/bytecodealliance/wasm-micro-runtime/pull/1951
2024-01-25 16:29:34 +08:00
Gavin Hayes
bf9fb2e680
cosmopolitan: Update compiler and update platform_internal.h (#3079)
This fixes the cosmopolitan platform.
- Switch `build_cosmocc.sh` and platform documentation to
  explicitly use the x86_64 cosmocc compiler as multi-arch
  cosmocc won't work here. Older version `cosmocc` just did
  a x86_64 build.
- Add missing items from `platform_internal.h` to fix build.
2024-01-24 16:04:48 +08:00
Bruce Mitchener
d815bbc3db
README.md: Fix typo tunning to tuning (#3078) 2024-01-24 15:35:45 +08:00
Bruce Mitchener
61fe78c9ff
Fix download link for wasi-sdk (#3077)
The wasi-sdk repo moved from CraneStation to the WebAssembly org
on GitHub.
2024-01-24 13:42:45 +08:00
Enrico Loparco
3fcd79867d
Forward log and log level to custom bh_log callback (#3070)
Follow-up on #2907. The log level is needed in the host embedder to
better integrate with the embedder's logger.

Allow the developer to customize his bh_log callback with
`cmake -DWAMR_BH_LOG=<log_callback>`,
and update sample/basic to show the usage.
2024-01-24 13:05:07 +08:00
Marcin Kolny
1505e61704
Remove a lot of "unused parameter" warnings (#3075)
They might shadow some of the real issues, so better to keep the number
of warnings as low as possible.
2024-01-24 11:21:13 +08:00
YAMAMOTO Takashi
f56154ed80
thread-mgr: Fix locking problems around aux stack allocation (#3073)
Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3069
2024-01-24 09:46:53 +08:00
Wenyong Huang
0eb788d711
build_wamr.md: Update the document (#3074)
Add description for `WAMR_BUILD_LINUX_PERF`, `WAMR_BUILD_QUICK_AOT_ENTRY`
and `WAMR_BUILD_MODULE_INST_CONTEXT`.
And add some reference links.
2024-01-24 09:45:57 +08:00
Wenyong Huang
9f64340529
Fix some issues reported by CodeQL (#3064)
Refer to https://github.com/bytecodealliance/wasm-micro-runtime/pull/2812
and https://github.com/bytecodealliance/wasm-micro-runtime/security/code-scanning?query=pr%3A2812+is%3Aopen
2024-01-23 21:38:30 +08:00
YAMAMOTO Takashi
ab97d543e0
wasm_cluster_destroy_spawned_exec_env: Avoid "invalid exec env" trap (#3068)
Possible alternatives:

* Make wasm_cluster_destroy_spawned_exec_env take two exec_env.
  One for wasm execution and another to specify the target to destroy.

* Make execute functions to switch exec_env as briefly discussed in
  https://github.com/bytecodealliance/wasm-micro-runtime/pull/2047
2024-01-23 15:20:01 +08:00
YAMAMOTO Takashi
b44aa654b8
aot_reloc_x86_64.c: Suggest to try --size-level=0 as well (#3067)
cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/3035
2024-01-23 13:00:19 +08:00
Wenyong Huang
c8b59588a7
Enhance setting write gs base with cmake variable (#3066)
In linux x86-64, developer can use cmake variable to configure whether
to enable writing linear memory base address to x86 GS register or not:
- `cmake -DWAMR_DISABLE_WRITE_GS_BASE=1`: disabled it
- `cmake -DWAMR_DISABLE_WRITE_GS_BASE=0`: enabled it
- `cmake` without `-DWAMR_DISABLE_WRITE_GS_BASE=1/0`:
        auto-detected by the compiler
2024-01-23 12:21:20 +08:00
Wenyong Huang
7f035d4206
perf_tune.md: Add refine the calling processes between host and wasm (#3065) 2024-01-23 12:20:28 +08:00
YAMAMOTO Takashi
4bafa40052
nuttx: If STACK_GUARD_SIZE is not set, leave it to config.h (#2927)
cf. https://github.com/apache/nuttx-apps/pull/2241
2024-01-23 11:52:25 +08:00
Marcin Kolny
627debcefb
Add flag to control Winsocket initialization (#3060)
When WAMR is embedded to other application, the lifecycle of the socket
might conflict with other usecases. E.g. if WAMR is deinitialized before any
other use of sockets, the application goes into the invalid state. The new
flag allows host application to take control over the socket initialization.
2024-01-22 07:33:26 +08:00