Skip to content

Commit

Permalink
Merge pull request #3631 from bytecodealliance/main
Browse files Browse the repository at this point in the history
Merge branch main into dev/shared_heap
  • Loading branch information
wenyongh authored Jul 16, 2024
2 parents 84411c6 + 8af1550 commit 57f2661
Show file tree
Hide file tree
Showing 24 changed files with 239 additions and 40 deletions.
71 changes: 71 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,74 @@
## WAMR-2.1.1

### Breaking Changes
- Sync up with latest wasi-nn spec (#3530)

### New Features
- Add APIs to get package version (#3601)
- Export API wasm_runtime_enlarge_memory (#3569)
- Add table type API support (#3515)
- Add wasm_runtime_get_module_package_type() and wasm_runtime_get_file_package_type() (#3600)

### Bug Fixes
- wasm_application.c: Avoid null pointer dereference (#3620)
- EH: Use the consistent type for EH handlers (#3619)
- wasm loader: Fix several issues in GC and exception handling (#3586)
- wasm loader: Fix push_frame_offset when pushing v128 type (#3588)
- Add integer overflow check for some indices in wasm/aot loader (#3579)
- aot-analyzer: Fix a few printf formats (#3590)
- aot-analyzer: Fix macos build (#3589)
- Fix compilation errors in aot-analyzer tool (#3584)
- interp debugger: Fix setting invalid value to step_count (#3583)
- aot loader: Check import global value type before using (#3571)
- Fix missing stack frame alloc/free in AOT multi-module invoke (#3562)
- aot loader: Verify global value type (#3560)
- aot loader: Add more checks in load_native_symbol_section() (#3559)
- core/shared/platform: Zero memory returned by os_mmap in some platforms (#3551)
- dwarf_extractor.cpp: Fix buffer overruns (#3541)
- aot loader: Prevent loading multiple native symbol sections (#3538)
- Validate func type in aot loader (#3535)
- wamrc: Fix truncated DW_AT_producer (#3537)
- wasm loader: Fix pop invalid offset count when stack top is ANY (#3516)
- Fix two fuzz issues (#3529)
- Fix several issues reported by oss-fuzz (#3526)

### Enhancements
- Fix compile warnings/error reported in Windows (#3616)
- wasm loader: Reject v128 for interpreters (#3611)
- Fix typos in wamrc and wasm_export.h (#3609)
- Bump ocaml/setup-ocaml from 2 to 3 (#3604)
- CMakeLists.txt: Fix Android pthread linkage (#3591)
- Add more arm AOT reloc entries (#3587)
- wasi-nn: Use numpy v1 in wasi-nn test requirements.txt (#3582)
- Optimize for multi-module support in AOT mode (#3563)
- aot compiler: Propagate const-ness by ourselves (#3567)
- aot_resolve_target_info: Avoid in-place modification of e_type (#3564)
- Allow missing imports in wasm loader and report error in wasm instantiation instead (#3539)
- aot compiler: Use larger alignment for load/store when possible (#3552)
- Consistent const keyword position in wasm_export.h (#3558)
- wasm_memory.c: Fix typo: hasn't been initialize -> `hasn't been initialized` (#3547)
- dwarf_extractor.cpp: Try to preserve link name (#3542)
- dwarf_extractor.cpp: Enable limited support for C++ (#3540)
- Sync up with latest wasi-nn spec (#3530)
- Expose more functions related to emitting AOT files (#3520)
- Make wasi-nn backends as separated shared libraries (#3509)
- build_llvm.py: Speed up llvm build with multi procs on windows (#3512)
- Fix compilation warnings of wasi-nn (#3497)
- Add missing functions to make RIOT work with the 2.x.x version (#3508)

### Others
- Update devcontainer.md (#3628)
- Fix compile errors on workload bwa and benchmark jetstream (#3617)
- wasm-mutator-fuzz: Set compilers earlier (#3585)
- wasm-mutator-fuzz: Make compilers overridable (#3578)
- wasi-nn: Add wasmedge-wasinn-example as smoke test (#3554)
- Add standalone cases (#3536)
- wasm-mutator-fuzz: Fix build errors and warnings for macOS (#3519)
- wasm-mutator-fuzz: Use another variable to check if in oss-fuzz environment (#3518)
- Add wasi-nn example as smoke test case (#3501)

---

## WAMR-2.1.0

### Breaking Changes
Expand Down
2 changes: 2 additions & 0 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4168,6 +4168,8 @@ load(const uint8 *buf, uint32 size, AOTModule *module,
return false;
}

module->package_version = version;

if (!create_sections(module, buf, size, &section_list, error_buf,
error_buf_size))
return false;
Expand Down
10 changes: 5 additions & 5 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ memories_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,

if (memory_inst->memory_data) {
bh_memcpy_s((uint8 *)memory_inst->memory_data + base_offset,
(uint32)memory_inst->memory_data_size - base_offset,
(uint32)(memory_inst->memory_data_size - base_offset),
data_seg->bytes, length);
}
}
Expand Down Expand Up @@ -1212,7 +1212,7 @@ aot_get_function_instance(AOTModuleInstance *module_inst, uint32 func_idx)
return NULL;
}

extra->function_count = func_count;
extra->function_count = (uint32)func_count;
}

/* instantiate function if needed */
Expand Down Expand Up @@ -1764,8 +1764,8 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
aot_get_data_section_addr(module, AOT_STACK_SIZES_SECTION_NAME, NULL);

#if WASM_ENABLE_PERF_PROFILING != 0
total_size = (uint64)sizeof(AOTFuncPerfProfInfo)
* (module->import_func_count + module->func_count);
total_size = sizeof(AOTFuncPerfProfInfo)
* ((uint64)module->import_func_count + module->func_count);
if (!(module_inst->func_perf_profilings =
runtime_malloc(total_size, error_buf, error_buf_size))) {
goto fail;
Expand Down Expand Up @@ -2536,7 +2536,7 @@ execute_malloc_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env,
if (ret) {
#if WASM_ENABLE_MEMORY64 != 0
if (is_memory64)
*p_result = GET_I64_FROM_ADDR(&argv.u64);
*p_result = argv.u64;
else
#endif
{
Expand Down
3 changes: 3 additions & 0 deletions core/iwasm/aot/aot_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ typedef struct LocalRefFlag {
typedef struct AOTModule {
uint32 module_type;

/* the package version read from the AOT file */
uint32 package_version;

/* import memories */
uint32 import_memory_count;
AOTImportMemory *import_memories;
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/common/wasm_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
bh_memcpy_s(&u.val, sizeof(double), &ud.d,
sizeof(double));
}
if (endptr[0] == ':') {
if (endptr && endptr[0] == ':') {
uint64 sig;
union ieee754_double ud;
sig = strtoull(endptr + 1, &endptr, 0);
Expand Down
4 changes: 3 additions & 1 deletion core/iwasm/common/wasm_loader_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ bool
is_valid_func_type(const WASMFuncType *func_type)
{
unsigned i;
for (i = 0; i < func_type->param_count + func_type->result_count; i++) {
for (i = 0;
i < (unsigned)(func_type->param_count + func_type->result_count);
i++) {
if (!is_valid_value_type(func_type->types[i]))
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/common/wasm_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,13 +930,13 @@ wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module_inst,
#if WASM_ENABLE_AOT != 0
if (module_inst->module_type == Wasm_Module_AoT) {
return aot_enlarge_memory((AOTModuleInstance *)module_inst,
inc_page_count);
(uint32)inc_page_count);
}
#endif
#if WASM_ENABLE_INTERP != 0
if (module_inst->module_type == Wasm_Module_Bytecode) {
return wasm_enlarge_memory((WASMModuleInstance *)module_inst,
inc_page_count);
(uint32)inc_page_count);
}
#endif

Expand Down
64 changes: 60 additions & 4 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,11 @@ wasm_runtime_set_default_running_mode(RunningMode running_mode)
PackageType
get_package_type(const uint8 *buf, uint32 size)
{
if (buf && size >= 4) {
#if (WASM_ENABLE_WORD_ALIGN_READ != 0)
uint32 buf32 = *(uint32 *)buf;
buf = (const uint8 *)&buf32;
uint32 buf32 = *(uint32 *)buf;
buf = (const uint8 *)&buf32;
#endif
if (buf && size >= 4) {
if (buf[0] == '\0' && buf[1] == 'a' && buf[2] == 's' && buf[3] == 'm')
return Wasm_Module_Bytecode;
if (buf[0] == '\0' && buf[1] == 'a' && buf[2] == 'o' && buf[3] == 't')
Expand All @@ -878,7 +878,7 @@ wasm_runtime_get_file_package_type(const uint8 *buf, uint32 size)
}

PackageType
wasm_runtime_get_module_package_type(WASMModuleCommon *module)
wasm_runtime_get_module_package_type(WASMModuleCommon *const module)
{
if (!module) {
return Package_Type_Unknown;
Expand All @@ -887,6 +887,62 @@ wasm_runtime_get_module_package_type(WASMModuleCommon *module)
return module->module_type;
}

uint32
wasm_runtime_get_file_package_version(const uint8 *buf, uint32 size)
{
if (buf && size >= 8) {
uint32 version;
#if (WASM_ENABLE_WORD_ALIGN_READ != 0)
uint32 buf32 = *(uint32 *)(buf + sizeof(uint32));
buf = (const uint8 *)&buf32;
version = buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24;
#else
version = buf[4] | buf[5] << 8 | buf[6] << 16 | buf[7] << 24;
#endif
return version;
}

return 0;
}

uint32
wasm_runtime_get_module_package_version(WASMModuleCommon *const module)
{
if (!module) {
return 0;
}

#if WASM_ENABLE_INTERP != 0
if (module->module_type == Wasm_Module_Bytecode) {
WASMModule *wasm_module = (WASMModule *)module;
return wasm_module->package_version;
}
#endif

#if WASM_ENABLE_AOT != 0
if (module->module_type == Wasm_Module_AoT) {
AOTModule *aot_module = (AOTModule *)module;
return aot_module->package_version;
}
#endif

return 0;
}

uint32
wasm_runtime_get_current_package_version(package_type_t package_type)
{
switch (package_type) {
case Wasm_Module_Bytecode:
return WASM_CURRENT_VERSION;
case Wasm_Module_AoT:
return AOT_CURRENT_VERSION;
case Package_Type_Unknown:
default:
return 0;
}
}

#if WASM_ENABLE_AOT != 0
static uint8 *
align_ptr(const uint8 *p, uint32 b)
Expand Down
19 changes: 18 additions & 1 deletion core/iwasm/compilation/aot_emit_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ get_memory_check_bound(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
return mem_check_bound;
}

#if defined(_WIN32) || defined(_WIN32_)
static inline int
ffs(int n)
{
int pos = 0;

if (n == 0)
return 0;

while (!(n & 1)) {
pos++;
n >>= 1;
}
return pos + 1;
}
#endif

static LLVMValueRef
get_memory_curr_page_count(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx);

Expand Down Expand Up @@ -198,7 +215,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
* has the natural alignment. for platforms using mmap, it can
* be even larger. for now, use a conservative value.
*/
const int max_align = 8;
const unsigned int max_align = 8;
int shift = ffs((int)(unsigned int)mem_offset);
if (shift == 0) {
*alignp = max_align;
Expand Down
7 changes: 4 additions & 3 deletions core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
* and more importantly doesn't involve relocations.
*/
LLVMAttributeRef attr_short_call = LLVMCreateStringAttribute(
comp_ctx->context, "short-call", strlen("short-call"), "", 0);
comp_ctx->context, "short-call", (unsigned)strlen("short-call"),
"", 0);
LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex,
attr_short_call);
}
Expand Down Expand Up @@ -3529,7 +3530,7 @@ aot_block_destroy(AOTCompContext *comp_ctx, AOTBlock *block)

bool
aot_checked_addr_list_add(AOTFuncContext *func_ctx, uint32 local_idx,
uint32 offset, uint32 bytes)
uint64 offset, uint32 bytes)
{
AOTCheckedAddr *node = func_ctx->checked_addr_list;

Expand Down Expand Up @@ -3573,7 +3574,7 @@ aot_checked_addr_list_del(AOTFuncContext *func_ctx, uint32 local_idx)

bool
aot_checked_addr_list_find(AOTFuncContext *func_ctx, uint32 local_idx,
uint32 offset, uint32 bytes)
uint64 offset, uint32 bytes)
{
AOTCheckedAddr *node = func_ctx->checked_addr_list;

Expand Down
6 changes: 3 additions & 3 deletions core/iwasm/compilation/aot_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ typedef struct AOTBlockStack {
typedef struct AOTCheckedAddr {
struct AOTCheckedAddr *next;
uint32 local_idx;
uint32 offset;
uint64 offset;
uint32 bytes;
} AOTCheckedAddr, *AOTCheckedAddrList;

Expand Down Expand Up @@ -574,14 +574,14 @@ wasm_type_to_llvm_type(const AOTCompContext *comp_ctx,

bool
aot_checked_addr_list_add(AOTFuncContext *func_ctx, uint32 local_idx,
uint32 offset, uint32 bytes);
uint64 offset, uint32 bytes);

void
aot_checked_addr_list_del(AOTFuncContext *func_ctx, uint32 local_idx);

bool
aot_checked_addr_list_find(AOTFuncContext *func_ctx, uint32 local_idx,
uint32 offset, uint32 bytes);
uint64 offset, uint32 bytes);

void
aot_checked_addr_list_destroy(AOTFuncContext *func_ctx);
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/compilation/aot_llvm_extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ aot_compress_aot_func_names(AOTCompContext *comp_ctx, uint32 *p_size)
return NULL;
}

compressed_str_len = Result.size();
compressed_str_len = (uint32)Result.size();
if (!(compressed_str = (char *)wasm_runtime_malloc(compressed_str_len))) {
aot_set_last_error("allocate memory failed");
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/compilation/aot_orc_extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ PartitionFunction(GlobalValueSet Requested)
auto GVName = GV->getName(); /* get the function name */
const char *gvname = GVName.begin(); /* C function name */
const char *wrapper;
uint32 prefix_len = strlen(AOT_FUNC_PREFIX);
uint32 prefix_len = (uint32)strlen(AOT_FUNC_PREFIX);

LOG_DEBUG("requested func %s", gvname);
/* Convert "aot_func#n_wrapper" to "aot_func#n" */
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/compilation/simd/simd_load_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
/* data_length in bytes */
static bool
simd_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align,
uint32 offset, uint32 data_length, LLVMValueRef value,
mem_offset_t offset, uint32 data_length, LLVMValueRef value,
LLVMTypeRef value_ptr_type, bool enable_segue)
{
LLVMValueRef maddr, result;
Expand Down
Loading

0 comments on commit 57f2661

Please sign in to comment.