Commit Graph

363 Commits

Author SHA1 Message Date
YAMAMOTO Takashi
67d6a2886e
core/iwasm/aot/aot_loader.c: Fix a zero-sized malloc warning (#1108)
Fix the following warning when loading an aot file without relocations:
```
[20:19:00:528 - 1119F1600]: warning: wasm_runtime_malloc with size zero
```
2022-04-20 18:27:13 +08:00
Wenyong Huang
d6e781af28
Add more operand stack overflow checks for fast-interp (#1104)
And clear some compile warnings on Windows
2022-04-20 16:19:12 +08:00
YAMAMOTO Takashi
0f505aafd9
aot_runtime.c: Add static assertions for some offset assumptions (#1103) 2022-04-20 13:58:02 +08:00
YAMAMOTO Takashi
b36931a589
aot_loader.c: Fix issues in "Refine interp/aot string storage" (#1102)
Fix issues in PR "Refine interp/aot string storage and emitting (#820)",
which had a few issues:
- It looks a wrong byte to mark the flag
- It doesn't work for long strings (>= 0x80 in case of little endian)

This commit fixes them by maintaining a list of loaded symbols while loading
relocation section to avoid reading a string repeatedly, and no need to mark
the flag again.
2022-04-19 15:44:30 +08:00
YAMAMOTO Takashi
87784cfb65
core/iwasm/aot/aot_runtime.c: Fix an unused function warning (#1099) 2022-04-19 09:48:28 +08:00
YAMAMOTO Takashi
b4574123c9
aot_get_module_mem_consumption: Fix const strings size (#1098)
Fix the issue that the `*(uint32 *)p_const_string_size` is added repeatedly
while calculating the aot module's memory consumption.
2022-04-19 08:57:44 +08:00
liang.he
78e099b6ab
Add more input checks for some wasm-c-api functions (#1090)
Protect wasm_valtype_new and wasm_tabletype_new from invalid inputs
2022-04-18 19:55:31 +08:00
Wenyong Huang
d4758d7380
Refine codes and fix several issues (#1094)
Add aot relocation for ".rodata.str" symbol to support more cases
Fix some coding style issues
Fix aot block/value stack destroy issue
Refine classic/fast interpreter codes
Clear compile warning of libc_builtin_wrapper.c in 32-bit platform
2022-04-18 17:33:30 +08:00
YAMAMOTO Takashi
2366e8c493
Fix a few signedness warnings (#1095)
Fix compile warnings in libc-wasi posix.c:
```
posix.c:880:41: warning: comparison of integers of different signs:
 'unsigned long' and 'ssize_t' (aka 'long') [-Wsign-compare]
            if (bufoff + iov[i].buf_len < len) {
posix.c:1359:32: warning: comparison of integers of different signs:
 'off_t' (aka 'long long') and 'unsigned long long' [-Wsign-compare]
    if (ret == 0 && sb.st_size < offset + len)
```
2022-04-18 16:54:15 +08:00
Xu Jun
8589ed155d
Fix %ld specifier issue in libc-builtin printf wrapper (#1088)
The format specifiers of %ld/%lu/%li/%lx/%lp/%lo (or %z* and %t* like) should
be treated as 32-bit integer in wasm.
And merge the handle of unsigned/signed for %u/%d and %llu/%lld specifier
when calling snprintf.
2022-04-14 14:02:19 +08:00
Xu Jun
87c67eb6f0
Enhance printf_wrapper in libc-builtin (#1074)
Use snprintf to format the string and then output it,
so as to support more formats and reduce the footprint.
2022-04-12 17:13:18 +08:00
Wenyong Huang
4864302a1f
Fix wasi implementation issues (#1078)
Fix args_get and environ_get issues in libc-wasi and libc-uvwasi implementation.
2022-04-11 11:55:37 +08:00
Xu Jun
fd9cce0eef
Add fast interpreter offset overflow check (#1076)
* check fast interpreter offset overflow
2022-04-07 21:07:32 +08:00
Xu Jun
24afd4e7cb
Preserve execution memory for debug instance (#1072)
During debugging, the debug client may request to malloc a memory space
to evaluate the user expressions. If we malloc memory from the linear memory,
it may fail when the thread is in stop status. We preserve a buffer during
creating debug instance, and use a simple bump pointer allocator to serve lldb's
memory request.
2022-04-04 08:23:55 +08:00
Xu Jun
f0dc6a3015
Fix fast interpreter constant space overflow issue (#1071)
Fix the potential integer overflow of const index in const space of fast interpreter,
emit i32/i64.const opcode when the const index is larger than INT32_MAX.
And add check for the function local cell num.
2022-04-04 07:55:37 +08:00
liang.he
559a0502f1
Enable socket-api recvmsg() and sendmsg() (#1042)
Implement socket-api `recvmsg()` and `sendmsg()` for wasm app,
add sample and update document.
2022-03-30 15:57:40 +08:00
Wenyong Huang
5264ce4118
Fix issues reported by klocwork (#1060)
Fix issues reported by klocwork, fix host_tool compile error,
and update build script of benchmark jetstream
2022-03-24 17:34:22 +08:00
Wenyong Huang
7262aebf77
Fix issues found by GC and Fast JIT, refine some codes (#1055)
Fix handle OP_TABLE_COPY issue
Fix loader handle OP_BLOCK/IF/LOOP issue if type_index is larger than 256
Fix loader handle OP_GET_GLOBAL, allow to change to GET_GLOBAL_64 for
aot compiler similiar to handling OP_SET_GLOBAL
Refine loader handle OP_GET/SET/TEE_LOCAL, disable changing opcode when
source debugging is enabled, so as no need to record the change of opcode
Refine wasm_interp_interp_frame_size to reduce the wasm operand stack usage

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
2022-03-24 14:14:42 +08:00
Wenyong Huang
b6e5206e61
Fix wasm_runtime_load argument type invalid issue (#1059)
Remove the `const` flag for the first argument `buf` of wasm_runtime_load as
it might be modified by runtime for footprint and performance purpose, and
update the related functions and document.
2022-03-24 10:08:49 +08:00
Wenyong Huang
38b07b3614
Add libuv and uvwasi to attributions (#1057) 2022-03-24 10:05:10 +08:00
liang.he
86b79cfb93
Enable lock for Vector to protect wasm-c-api read/write/extend operations (#1010) 2022-03-23 11:42:57 +08:00
lucianoiam
f8ee05db4b
Add a reference counter to wasm_engine_t (#1001)
This patch allows safer (note: safer, not safe) embedding in a plugin
environment where multiple instances of the engine could be needed.

Original code initializes and tears down the full runtime during
wasm_engine_new() and wasm_engine_delete() respectively. After this
update the C API implementation keeps track of engine instances count
and inits/deinits the runtime only when needed.

This allows for example to call wasm_engine_new() twice and then call
wasm_engine_delete() once without rendering the first engine instance
invalid.
2022-03-22 17:14:15 +08:00
Hanged Fish
a02cc6626d
Fix libc-wasi not working in spawned exec_env (#1053)
In thread_manager.c, `wasm_cluster_spawn_exec_env` creates a new module
instance but not sets wasi_ctx, so when the new exec_env calls wasm function
which uses WASI API, the WASI API functions in `libc_wasi_wrapper.c` will get
null result in calling `get_wasi_ctx`  and then return `wasi_errno`.

Signed-off-by: HangedFish <bravohangedman@outlook.com>
2022-03-22 12:17:14 +08:00
liang.he
310b9ca0d8
Fix classic interpreter handling BLOCK/IF/LOOP issue (#1051)
`PUSH_CSP()` should set label's begin frame_sp as the bottom of current label's stack
but not the top of it
2022-03-20 18:07:33 +08:00
Wenyong Huang
b1a4dd2e46
Fix Windows failed to relocate __ymm symbol error (#1047)
Resolve the "__ymm@" prefixed symbols like "__xmm@" and "__real@" symbols
in Windows platform.
2022-03-16 11:07:11 +08:00
Wenyong Huang
21d89135da
Enhance uvwasi build process and fix wamrc windows build error (#1046)
And update related document
2022-03-15 21:43:55 +08:00
Xu Jun
7a0ec1cd17
Use nanosecond for atomic wait (#1041)
Fix issue reported by #1038
2022-03-10 19:43:27 +08:00
Wenyong Huang
9c87a1ee17
Implement part of Berkeley Socket API for libc-wasi (#1036)
Refer to [Networking API design](https://github.com/WebAssembly/WASI/issues/370)
and [feat(socket): berkeley socket API v2](https://github.com/WebAssembly/WASI/pull/459):

- Support the socket API of synchronous mode, including `socket/bind/listen/accept/send/recv/close/shutdown`,
    the asynchronous mode isn't supported yet.
- Support adding `--addr-pool=<pool1,pool2,..>` argument for command line to identify the valid ip address range
- Add socket-api sample and update the document
2022-03-10 15:13:38 +08:00
Wenyong Huang
55ad4c7ec7
Fix wasm-c-api wasm_module_imports issues (#1021)
Fix several issues in wasm-c-api wasm_module_imports function:
1. Two of the if branches never set the module_name and name fields which are later passed as arguments to wasm_importtype_new, and eventually might cause double-free and/or use-after-free
2. Should zero module_name/name/extern_type at the start of loop iteration, and destroy their resources when failed at the end of loop iteration
2. No need to check `if (!extern_type) { continue; }`, as extern_type is converted from type and type is already checked
3. No need to wasm_importtype_vec_delete(out) when failed, as it is passed from outside and should be destroyed by outside
2022-02-24 09:36:46 +08:00
Wenyong Huang
25fc006c33
Refine call native function from AOT code (#1015)
When calling native function from AOT code, current implementation is to return
back to runtime to call aot_invoke_native, which calls wasm_runtime_invoke_native
and the latter calls assembly code. We did it before as there may be pointer and
string arguments to check and convert if the native function's registered signature
has character '*' and '$'.
As the built-in native function's signatures can be gotten in compilation time, we
check the pointer/string arguments and convert them into native address in AOT
code, and then invoke the native function directly, so as to improve performance.
2022-02-23 14:58:32 +08:00
Xu Jun
3fe191b0df
[debugger enhance] don't block gdbserver thread while executing (#989)
Allow to set break point again when all break points are removed and
wasm app starts running.
2022-02-16 17:35:35 +08:00
Wenyong Huang
bb87180b72
Update document and fix wasm_runtime_call_wasm_a issue (#1005)
Update document memory_tune.md: fix embed wamr link error,
fix description error of wasm operand stack size, update picture.

Fix wasm_runtime_call_wasm_a issue reported by #1003 and update
sample basic to call this API.
2022-02-14 17:36:38 +08:00
Xu Jun
5f8c7655a7
Fix pthread_getspecific return value (#999)
Fix pthread_getspecific return value as mentioned in #995
2022-02-05 22:45:59 +08:00
Xu Jun
68fd6454c2
Fix debug thread not created issue (#983)
And fix a double free issue when starting debug server failed
2022-01-26 09:56:01 +08:00
Xu Jun
90a0057d33
Implement pthread_cond_broadcast wrapper for lib-pthread (#982)
Implement pthread_cond_broadcast wrapper for lib-pthread
- support pthread_cond_broadcast wrapper for posix/linux-sgx/windows
- update document for building multi-thread wasm app with emcc
2022-01-25 09:28:02 +08:00
Wenyong Huang
5631a2aa18
Use LLVM new pass manager for wamrc (#978)
Use LLVM new pass manager for wamrc to replace the legacy pass manger,
so as to gain better performance and reduce the compilation time.
Reference links:
- https://llvm.org/docs/NewPassManager.html
- https://blog.llvm.org/posts/2021-03-26-the-new-pass-manager

And add an option to use the legacy pm mode when building wamrc:
cmake .. -DWAMR_BUILD_LLVM_LEGACY_PM=1

For JIT mode, keep it unchanged as it only runs several function passes and
using new pass manager will increase the compilation time.

And refactor the codes of applying LLVM passes.
2022-01-24 11:10:37 +08:00
Wenyong Huang
7636d86a76
Refactor Orc JIT to enable lazy compilation (#974)
Refactor LLVM Orc JIT to actually enable the lazy compilation and speedup
the launching process:
  https://llvm.org/docs/ORCv2.html#laziness

Main modifications:
- Create LLVM module for each wasm function, wrap it with thread safe module
  so that the modules can be compiled parallelly
- Lookup function from aot module instance's func_ptrs but not directly call the
  function to decouple the module relationship
- Compile the function when it is first called and hasn't been compiled
- Create threads to pre-compile the WASM functions parallelly when loading
- Set Lazy JIT as default, update document and build/test scripts
2022-01-20 18:40:13 +08:00
Wenyong Huang
260d36a62d
Refactor externref related APIs of reference types feature (#971)
Currently when calling wasm_runtime_call_wasm() to invoke wasm function
with externref type argument from runtime embedder, developer needs to
use wasm_externref_obj2ref() to convert externref obj into an internal ref
index firstly, which is not convenient to developer.
To align with GC feature in which all the references passed to
wasm_runtime_call_wasm() can be object pointers directly, we change the
interface of wasm_runtime_call_wasm() to allow to pass object pointer
directly for the externref argument, and refactor the related codes, update
the related samples and the document.
2022-01-19 11:25:08 +08:00
Huang Qi
2c743dbd51
Add log info for heap and stack like wasm loader in aot loader (#968)
Add log info for heap and stack like wasm loader in aot loader

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Change-Id: I349848d75f1a26cde29217c14cfb6e779c976a8b
2022-01-19 08:55:59 +08:00
Wenyong Huang
8088783775
Refine is_xip_file and pointer range check (#965)
Refine is_xip_file check, when e_type isn't E_TYPE_XIP, just return false
and no need to go through all the other sections of the AOT file.

Refine pointer range check, convert pointer to uintptr_t type before
comparison to yield possible sanitizer pointer overflow error.
2022-01-18 11:05:58 +08:00
Wenyong Huang
552f85075d
Fix __wasi_subscription_t inconsistent with wasi-libc issue (#964)
Fix __wasi_subscription_t structure definition inconsistent with wasi-libc
definition issue, reported by #961, tested with sleep, poll API and other
wasi cases on x86-64, x86-32 and arm32 targets.
2022-01-17 20:52:45 +08:00
Wenyong Huang
092efbfe21
Fix thread manager issues (#962)
Fix the issue that joining a detached thread might result in joining hang,
resolve the issue by adding wait_count for a thread's exec_env to indicate
whether a thread needs to detach itself or not when it exits.

And add checks for the input exec_env for cluster's join/detach/cancel thread.
2022-01-17 17:09:04 +08:00
Xu Jun
ee97e30a1a
Fix pointer unchecked issue in thread-mgr.c (#960)
And refine the code format of thread_manager.h
2022-01-14 17:57:59 +08:00
Wenyong Huang
30cb05f223
Refine llvm pass order (#948)
Put Vectorize passes before GVN/LICM passes as normally the former
gains more performance improvement and the latter might break the
optimizations for the former. Can improve performance of several
sightglass cases.

And don't check exception throw after calling an AOT function if it is
and recursive call, similar to handing of Spec tail call opcode.
2022-01-12 18:56:56 +08:00
Wenyong Huang
4b5543cc1a
Enable Windows XIP (#944)
Enable running XIP file on Windows platform.
And add more strict checks for wamrc to report error when the input file
is same with output file, or the input file is AOT file but not wasm file.
2022-01-10 15:59:58 +08:00
Wenyong Huang
f6197962ef
Fix MacOS invokeNative float ret type pass error (#940) 2022-01-07 18:17:37 +08:00
Wenyong Huang
78308e7bda
GetCurrentThreadStackLimits dynamically for Windows platform (#939)
GetCurrentThreadStackLimits dynamically for Windows platform
according to suggestion in #902
And fix some compiling warnings on Windows platform
2022-01-07 17:00:38 +08:00
Wenyong Huang
cb51dbb513
Fix some issues on MacOS platform (#937)
Fix some issues on MacOS platform
- Enable libc-wasi by default
- Set target abi to "gnu" if it is not set for wamrc to avoid generating
  object file of unsupported Mach-O format
- Set `<vendor>-<sys>` info according to target abi for wamrc to support
  generating AOT file for other OSs but not current host
- Set cpu name if arch/abi/cpu are not set to avoid checking SIMD
  capability failed
- Set size level to 1 for MacOS/Windows platform to avoid relocation type
  unsupported warning
- Clear posix_memmap.c compiling warning
- Fix spec case test script issues, enable test spec cases on MacOS

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
2022-01-07 09:53:48 +08:00
Wenyong Huang
308d31c621
Upgrade uvwasi to 1.42.0 and fix Android link issues (#938)
Upgrade uvwasi to 1.42.0 and fix Android link issues reported by #934
2022-01-06 18:25:37 +08:00
Huang Qi
9d2576d8e0
Wrap data width according to atomic opcode specified (#936)
Wrap data width according to atomic opcode specified

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-01-06 11:43:34 +08:00