Skip to content

Commit

Permalink
Cumulative fixes for release/1.3.x (#3268)
Browse files Browse the repository at this point in the history
Apply patches which were fixed branch main to branch `release/1.3.x`:
- zephyr: Use zephyr sys_cache instead of CMSIS (#3162)
- Fix llvm jit push funcref/externref result type issue (#3169)
- Fix inconsistent coding convention (#3171)
- VSCode IDE enhancement and readme update (#3172)
- zephyr: include math only with minimal libc (#3177)
- Fix wasm loader handling opcode br_table (#3176)
- Specify language in the wasi socket ext project (#3183)
- lldb_function_to_function_dbi: Fix a null dereference (#3189)
- Fix LLVM assertion failure and update CONTRIBUTING.md (#3197)
- lldb_function_to_function_dbi: A hack to avoid crashing on C++ methods (#3190)
- Fix compilation errors on MinGW (#3217)
- Fix compilation errors on esp-idf platform (#3224)
- Fix aot relocation symbols not found on windows 32-bit (#3231)
- Fix nightly run tsan ASLR issue (#3233)
- Go binding: Change C.long to C.int64_t when call wasm_runtime_set_wasi_args_ex (#3235)
- posix_file.c: Correct the dirfd argument that passes to fstatat (#3244)
- Fix compilation errors on zephyr platform (#3255)
- Fix dynamic offset not updated in op_br for block with ret type (#3269)
- Fix CI error when install packages for macos-14 (#3270)
  • Loading branch information
wenyongh authored Apr 3, 2024
1 parent add9547 commit 9e07aa6
Show file tree
Hide file tree
Showing 47 changed files with 681 additions and 313 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build_llvm_libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ jobs:
- name: checkout
uses: actions/checkout@v4

- name: install dependencies
- name: install dependencies for non macos-14
if: inputs.os != 'macos-14'
run: /usr/bin/env python3 -m pip install -r requirements.txt
working-directory: build-scripts

- name: install dependencies for macos-14
if: inputs.os == 'macos-14'
run: /usr/bin/env python3 -m pip install -r requirements.txt --break-system-packages
working-directory: build-scripts

- name: retrive the last commit ID
id: get_last_commit
run: echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py --llvm-ver)" >> $GITHUB_OUTPUT
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/compilation_on_android_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,12 @@ jobs:
npm install
working-directory: test-tools/wamr-ide/VSCode-Extension

- name: code style check
run: |
npm install --save-dev prettier
npm run prettier-format-check
working-directory: test-tools/wamr-ide/VSCode-Extension

- name: build iwasm with source debugging feature
run: |
mkdir build
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/nightly_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,9 @@ jobs:
run: echo "TEST_ON_X86_32=true" >> $GITHUB_ENV

- name: set additional tsan options
run: echo "TSAN_OPTIONS=suppressions=$PWD/tsan_suppressions.txt" >> $GITHUB_ENV
run: |
echo "TSAN_OPTIONS=suppressions=$PWD/tsan_suppressions.txt" >> $GITHUB_ENV
sudo sysctl vm.mmap_rnd_bits=28
working-directory: tests/wamr-test-suites

#only download llvm libraries in jit and aot mode
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ if (WAMR_BUILD_WASM_CACHE EQUAL 1)
endif ()

if (MINGW)
target_link_libraries (iwasm_shared -lWs2_32)
target_link_libraries (iwasm_shared INTERFACE -lWs2_32 -lwsock32)
endif ()

install (TARGETS iwasm_shared LIBRARY DESTINATION lib)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ We Use Github Flow, So All Code Changes Happen Through Pull Requests. Pull reque
Coding Style
===============================
Please use [K&R](https://en.wikipedia.org/wiki/Indentation_style#K.26R) coding style, such as 4 spaces for indentation rather than tabs etc.
We suggest use Eclipse like IDE or stable coding format tools to make your code compliant to K&R format.
We suggest using VS Code like IDE or stable coding format tools, like clang-format, to make your code compliant to the customized format(in .clang-format).

Report bugs
===================
Expand Down
11 changes: 11 additions & 0 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,17 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
}
symbol_addr = module->func_ptrs[func_index];
}
else if (!strncmp(symbol, "_" AOT_FUNC_INTERNAL_PREFIX,
strlen("_" AOT_FUNC_INTERNAL_PREFIX))) {
p = symbol + strlen("_" AOT_FUNC_INTERNAL_PREFIX);
if (*p == '\0'
|| (func_index = (uint32)atoi(p)) > module->func_count) {
set_error_buf_v(error_buf, error_buf_size, "invalid symbol %s",
symbol);
goto check_symbol_fail;
}
symbol_addr = module->func_ptrs[func_index];
}
#endif
else if (is_text_section(symbol)) {
symbol_addr = module->code;
Expand Down
32 changes: 13 additions & 19 deletions core/iwasm/common/wasm_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "wasm_runtime_common.h"
#include "../interpreter/wasm_runtime.h"
#include "../aot/aot_runtime.h"
#include "bh_platform.h"
#include "mem_alloc.h"
#include "wasm_memory.h"

Expand Down Expand Up @@ -45,11 +44,11 @@ static unsigned int global_pool_size;
static bool
wasm_memory_init_with_pool(void *mem, unsigned int bytes)
{
mem_allocator_t _allocator = mem_allocator_create(mem, bytes);
mem_allocator_t allocator = mem_allocator_create(mem, bytes);

if (_allocator) {
if (allocator) {
memory_mode = MEMORY_MODE_POOL;
pool_allocator = _allocator;
pool_allocator = allocator;
global_pool_size = bytes;
return true;
}
Expand All @@ -76,18 +75,18 @@ wasm_memory_init_with_allocator(void *_user_data, void *_malloc_func,
}
#else
static bool
wasm_memory_init_with_allocator(void *_malloc_func, void *_realloc_func,
void *_free_func)
wasm_memory_init_with_allocator(void *malloc_func_ptr, void *realloc_func_ptr,
void *free_func_ptr)
{
if (_malloc_func && _free_func && _malloc_func != _free_func) {
if (malloc_func_ptr && free_func_ptr && malloc_func_ptr != free_func_ptr) {
memory_mode = MEMORY_MODE_ALLOCATOR;
malloc_func = _malloc_func;
realloc_func = _realloc_func;
free_func = _free_func;
malloc_func = malloc_func_ptr;
realloc_func = realloc_func_ptr;
free_func = free_func_ptr;
return true;
}
LOG_ERROR("Init memory with allocator (%p, %p, %p) failed.\n", _malloc_func,
_realloc_func, _free_func);
LOG_ERROR("Init memory with allocator (%p, %p, %p) failed.\n",
malloc_func_ptr, realloc_func_ptr, free_func_ptr);
return false;
}
#endif
Expand Down Expand Up @@ -115,18 +114,13 @@ wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type,
alloc_option->pool.heap_size);
}
else if (mem_alloc_type == Alloc_With_Allocator) {
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
return wasm_memory_init_with_allocator(
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
alloc_option->allocator.user_data,
#endif
alloc_option->allocator.malloc_func,
alloc_option->allocator.realloc_func,
alloc_option->allocator.free_func);
#else
return wasm_memory_init_with_allocator(
alloc_option->allocator.malloc_func,
alloc_option->allocator.realloc_func,
alloc_option->allocator.free_func);
#endif
}
else if (mem_alloc_type == Alloc_With_System_Allocator) {
memory_mode = MEMORY_MODE_SYSTEM_ALLOCATOR;
Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3574,7 +3574,7 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
{
WASMModuleInstanceCommon *module = wasm_runtime_get_module_inst(exec_env);
typedef void (*NativeRawFuncPtr)(WASMExecEnv *, uint64 *);
NativeRawFuncPtr invokeNativeRaw = (NativeRawFuncPtr)func_ptr;
NativeRawFuncPtr invoke_native_raw = (NativeRawFuncPtr)func_ptr;
uint64 argv_buf[16] = { 0 }, *argv1 = argv_buf, *argv_dst, size;
uint32 *argv_src = argv, i, argc1, ptr_len;
uint32 arg_i32;
Expand Down Expand Up @@ -3662,7 +3662,7 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
}

exec_env->attachment = attachment;
invokeNativeRaw(exec_env, argv1);
invoke_native_raw(exec_env, argv1);
exec_env->attachment = NULL;

if (func_type->result_count > 0) {
Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/common/wasm_shared_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ destroy_wait_info(void *wait_info)
}

static void
map_try_release_wait_info(HashMap *wait_map_, AtomicWaitInfo *wait_info,
map_try_release_wait_info(HashMap *wait_hash_map, AtomicWaitInfo *wait_info,
void *address)
{
if (wait_info->wait_list->len > 0) {
return;
}

bh_hash_map_remove(wait_map_, address, NULL, NULL);
bh_hash_map_remove(wait_hash_map, address, NULL, NULL);
destroy_wait_info(wait_info);
}

Expand Down
7 changes: 6 additions & 1 deletion core/iwasm/compilation/aot_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ check_type_compatible(uint8 src_type, uint8 dst_type)
goto fail; \
} \
memset(aot_value, 0, sizeof(AOTValue)); \
aot_value->type = value_type; \
if (comp_ctx->enable_ref_types \
&& (value_type == VALUE_TYPE_FUNCREF \
|| value_type == VALUE_TYPE_EXTERNREF)) \
aot_value->type = VALUE_TYPE_I32; \
else \
aot_value->type = value_type; \
aot_value->value = llvm_value; \
aot_value_stack_push( \
&func_ctx->block_stack.block_list_end->value_stack, aot_value); \
Expand Down
31 changes: 18 additions & 13 deletions core/iwasm/compilation/aot_emit_aot_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,28 +1004,28 @@ exchange_uint32(uint8 *p_data)
}

static void
exchange_uint64(uint8 *pData)
exchange_uint64(uint8 *p_data)
{
uint32 value;

value = *(uint32 *)pData;
*(uint32 *)pData = *(uint32 *)(pData + 4);
*(uint32 *)(pData + 4) = value;
exchange_uint32(pData);
exchange_uint32(pData + 4);
value = *(uint32 *)p_data;
*(uint32 *)p_data = *(uint32 *)(p_data + 4);
*(uint32 *)(p_data + 4) = value;
exchange_uint32(p_data);
exchange_uint32(p_data + 4);
}

static void
exchange_uint128(uint8 *pData)
exchange_uint128(uint8 *p_data)
{
/* swap high 64bit and low 64bit */
uint64 value = *(uint64 *)pData;
*(uint64 *)pData = *(uint64 *)(pData + 8);
*(uint64 *)(pData + 8) = value;
uint64 value = *(uint64 *)p_data;
*(uint64 *)p_data = *(uint64 *)(p_data + 8);
*(uint64 *)(p_data + 8) = value;
/* exchange high 64bit */
exchange_uint64(pData);
exchange_uint64(p_data);
/* exchange low 64bit */
exchange_uint64(pData + 8);
exchange_uint64(p_data + 8);
}

static union {
Expand Down Expand Up @@ -3106,7 +3106,12 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
* Note: aot_stack_sizes_section_name section only contains
* stack_sizes table.
*/
if (!strcmp(relocation->symbol_name, aot_stack_sizes_name)) {
if (!strcmp(relocation->symbol_name, aot_stack_sizes_name)
/* in windows 32, the symbol name may start with '_' */
|| (strlen(relocation->symbol_name) > 0
&& relocation->symbol_name[0] == '_'
&& !strcmp(relocation->symbol_name + 1,
aot_stack_sizes_name))) {
/* discard const */
relocation->symbol_name = (char *)aot_stack_sizes_section_name;
}
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
const char *prefix = AOT_FUNC_PREFIX;
const bool need_precheck =
comp_ctx->enable_stack_bound_check || comp_ctx->enable_stack_estimation;
LLVMValueRef precheck_func;
LLVMValueRef precheck_func = NULL;
if (need_precheck) {
precheck_func = aot_add_llvm_func1(comp_ctx, module, func_index,
aot_func_type->param_count,
Expand Down
38 changes: 28 additions & 10 deletions core/iwasm/compilation/debug/dwarf_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,27 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
LLVMDIBuilderCreateExpression(DIB, NULL, 0);
auto variable_list =
function.GetBlock().GetVariables(extractor->target, true, false, false);
unsigned int variable_offset = 0;
if (num_function_args != variable_list.GetSize()) {
LOG_ERROR(
"function args number dismatch!:value number=%d, function args=%d",
variable_list.GetSize(), num_function_args);
// A hack to detect C++ "this" pointer.
//
// REVISIT: is there a more reliable way?
// At the DWARF level, we can probably look at DW_AT_object_pointer
// and DW_AT_artificial. I'm not sure how it can be done via the
// LLDB API though.
if (num_function_args + 1 == variable_list.GetSize()) {
SBValue variable(variable_list.GetValueAtIndex(0));
const char *varname = variable.GetName();
if (varname != NULL && !strcmp(varname, "this")) {
variable_offset = 1;
}
}
if (!variable_offset) {
LOG_ERROR("function args number dismatch!:function %s %s value "
"number=%d, function args=%d",
function_name, function.GetMangledName(),
variable_list.GetSize(), num_function_args);
}
}

LLVMMetadataRef ParamLocation = LLVMDIBuilderCreateDebugLocation(
Expand All @@ -378,23 +395,24 @@ lldb_function_to_function_dbi(const AOTCompContext *comp_ctx,
LLVMDIBuilderInsertDbgValueAtEnd(DIB, Param, ParamVar, ParamExpression,
ParamLocation, block_curr);

for (uint32_t function_arg_idx = 0;
function_arg_idx < variable_list.GetSize(); ++function_arg_idx) {
SBValue variable(variable_list.GetValueAtIndex(function_arg_idx));
for (uint32_t function_arg_idx = 0; function_arg_idx < num_function_args;
++function_arg_idx) {
uint32_t variable_idx = variable_offset + function_arg_idx;
SBValue variable(variable_list.GetValueAtIndex(variable_idx));
if (variable.IsValid()) {
SBDeclaration dec(variable.GetDeclaration());
auto valtype = variable.GetType();
LLVMMetadataRef ParamLocation = LLVMDIBuilderCreateDebugLocation(
comp_ctx->context, dec.GetLine(), dec.GetColumn(),
FunctionMetadata, NULL);
const char *varname = variable.GetName();
LLVMMetadataRef ParamVar = LLVMDIBuilderCreateParameterVariable(
DIB, FunctionMetadata, variable.GetName(),
strlen(variable.GetName()), function_arg_idx + 1 + 1,
DIB, FunctionMetadata, varname, varname ? strlen(varname) : 0,
variable_idx + 1 + 1,
File, // starts form 1, and 1 is exenv,
dec.GetLine(), ParamTypes[function_arg_idx + 1], true,
LLVMDIFlagZero);
LLVMValueRef Param =
LLVMGetParam(func_ctx->func, function_arg_idx + 1);
LLVMValueRef Param = LLVMGetParam(func_ctx->func, variable_idx + 1);
LLVMDIBuilderInsertDbgValueAtEnd(DIB, Param, ParamVar,
ParamExpression, ParamLocation,
block_curr);
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/fast-jit/fe/jit_emit_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ jit_compile_op_br_if(JitCompContext *cc, uint32 br_depth,
}
}

/* Only opy parameters or results when their count > 0 and
/* Only copy parameters or results when their count > 0 and
the src/dst addr are different */
copy_arities = check_copy_arities(block_dst, jit_frame);

Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -3844,7 +3844,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#if WASM_ENABLE_SHARED_MEMORY != 0
HANDLE_OP(WASM_OP_ATOMIC_PREFIX)
{
uint32 offset = 0, align, addr;
uint32 offset = 0, align = 0, addr;
uint32 opcode1;

read_leb_uint32(frame_ip, frame_ip_end, opcode1);
Expand Down
Loading

0 comments on commit 9e07aa6

Please sign in to comment.