Skip to content

Commit

Permalink
Merge pull request #3003 from bytecodealliance/main
Browse files Browse the repository at this point in the history
Merge branch main into dev/rust_sdk
  • Loading branch information
wenyongh authored Jan 12, 2024
2 parents 2626737 + 0844245 commit 3f854ff
Show file tree
Hide file tree
Showing 69 changed files with 3,293 additions and 773 deletions.
70 changes: 70 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,73 @@
## WAMR-1.3.1

### Breaking Changes
- In multi-threading, when an exception was thrown in wasm_func_call(),
the trap returned contains the stack frames of the thread where the
exception occurs, but not the stack frames of the main thread.
- Disable emitting custom name section to AOT file with
`wamrc --enable-dump-call-stack` option, instead, use
`wamrc --emit-custom-sections=name` to emit it and make it clear.

### New Features
- Enable AOT linux perf support (#2930)

### Bug Fixes
- Corrects Zephyr include files for current versions of Zephyr (#2881)
- Fix possible dead lock in wasm_cluster_spawn_exec_env (#2882)
- Handle ambiguous fstflags on fd_filestat_set_times (#2892)
- Fix memory size not updating after growing in interpreter (#2898)
- fixed(freertos): Fix crash when wasm app call pthread_exit(NULL) (#2970)
- fast-jit: Fix const shift and const i64 compare issues (#2969)
- Fix ref.is_null processing in fast-interp loader (#2971)
- simd-128: The input lanes of integer-to-integer narrowing ops should be interpreted as signed (#2850)
- Fix ref.func function declared check in wasm loader (#2972)
- Fix fast-interp polymorphic stack processing (#2974)
- Fix potential recursive lock in pthread_create_wrapper (#2980)
- Fix build failure on esp-idf platform (#2991)
- Return stack frames of crashed thread when using wasm-c-api (#2908)
- Fix compilation error on iOS due to macOS-specific API (#2995)
- Fix a bug when emit the custom name section to aot file (#2987)
- Fix linux-sgx build error when libc-wasi is disabled (#2997)

### Enhancements
- fix command-reactor: Look for _initialize only if _start not found (#2891)
- Refactor reloc symbols for riscv (#2894)
- Avoid memory import failure when wasi-threads is enabled (#2893)
- interpreter: Simplify memory.grow a bit (#2899)
- Avoid reporting timestamp if custom logger is used (#2905)
- Expose API to set log level in embedder (#2907)
- Add a script to translate jitted function names in flamegraph (#2906)
- Refine wasm-c-api wasm_func_call (#2922)
- Add VectorCombine pass for JIT and AOT (#2923)
- Enable wasm_runtime_terminate for single-threading (#2924)
- nuttx: Add CONFIG_INTERPRETERS_WAMR_DEBUG_AOT (#2929)
- Allow to control built-in libraries for wamrc from command line options (#2928)
- Fix a bug that appends '_precheck' to aot_func (#2936)
- freertos: Add os_cond_broadcast for pthread wrapper (#2937)
- Append .aot to .wasm as a custom section named "aot" (#2933)
- fix(sgx-ra): Fix building when enclave is built without librats ahead (#2968)
- Refine LLVM JIT function call process (#2925)
- Refine AOT function call process (#2940)
- Allow to set segue flags for wasm-c-api JIT (#2926)
- freertos: Minor changes for freertos libc_wasi build adaption (#2973)
- freertos: Change ssp_config.h due to clock_nanosleep() not supported in freertos (#2979)
- aot compiler: Some updates for LLVM 18 (#2981)
- Enable MAP_32BIT for macOS (#2992)
- Register quick call entries to speedup the aot/jit func call process (#2978)
- Refine AOT/JIT code call wasm-c-api import process (#2982)

### Others
- compilation_on_nuttx.yml: Use docker image to simplify env setup (#2878)
- samples/spawn-thread: Disable libc and pthread (#2883)
- Add arm64 to nuttx compilation test (#2886)
- samples/spawn-thread: Tweak to expose a bug (#2888)
- Fix typo in CI config and suppress STORE_U8 in TSAN (#2802)
- Using docker image for nuttx spectest (#2887)
- doc: Separate source_debugging.md into two files (#2932)
- doc/build_wasm_app.md: Add a note about aot abi compatibility (#2993)

---

## WAMR-1.3.0

### Breaking Changes
Expand Down
30 changes: 29 additions & 1 deletion build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,20 @@ elseif (WAMR_BUILD_SANITIZER STREQUAL "asan")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=address -fno-sanitize-recover=all" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()
elseif (WAMR_BUILD_SANITIZER STREQUAL "tsan")
elseif (WAMR_BUILD_SANITIZER STREQUAL "tsan")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=thread -fno-sanitize-recover=all" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
elseif (NOT (WAMR_BUILD_SANITIZER STREQUAL "") )
message(SEND_ERROR "Unsupported sanitizer: ${WAMR_BUILD_SANITIZER}")
endif()

if (WAMR_BUILD_LINUX_PERF EQUAL 1)
if (NOT WAMR_BUILD_JIT AND NOT WAMR_BUILD_AOT)
message(WARNING "only support perf in aot and llvm-jit")
set(WAMR_BUILD_LINUX_PERF 0)
endif ()
endif ()

########################################

message ("-- Build Configurations:")
Expand Down Expand Up @@ -440,3 +447,24 @@ if (WAMR_CONFIGUABLE_BOUNDS_CHECKS EQUAL 1)
add_definitions (-DWASM_CONFIGURABLE_BOUNDS_CHECKS=1)
message (" Configurable bounds checks enabled")
endif ()
if (WAMR_BUILD_LINUX_PERF EQUAL 1)
add_definitions (-DWASM_ENABLE_LINUX_PERF=1)
message (" Linux perf support enabled")
endif ()
if (NOT DEFINED WAMR_BUILD_QUICK_AOT_ENTRY)
# Enable quick aot/jit entries by default
set (WAMR_BUILD_QUICK_AOT_ENTRY 1)
endif ()
if (WAMR_BUILD_QUICK_AOT_ENTRY EQUAL 1)
add_definitions (-DWASM_ENABLE_QUICK_AOT_ENTRY=1)
message (" Quick AOT/JIT entries enabled")
else ()
add_definitions (-DWASM_ENABLE_QUICK_AOT_ENTRY=0)
message (" Quick AOT/JIT entries disabled")
endif ()

if (APPLE)
# On recent macOS versions, by default, the size of page zero is 4GB.
# Shrink it to make MAP_32BIT mmap can work.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-pagezero_size,0x4000")
endif ()
12 changes: 12 additions & 0 deletions core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,16 @@
#define WASM_MAX_INSTANCE_CONTEXTS 8
#endif

/* linux perf support */
#ifndef WASM_ENABLE_LINUX_PERF
#define WASM_ENABLE_LINUX_PERF 0
#endif

/* Support registering quick AOT/JIT function entries of some func types
to speedup the calling process of invoking the AOT/JIT functions of
these types from the host embedder */
#ifndef WASM_ENABLE_QUICK_AOT_ENTRY
#define WASM_ENABLE_QUICK_AOT_ENTRY 1
#endif

#endif /* end of _CONFIG_H_ */
113 changes: 112 additions & 1 deletion core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,9 @@ load_custom_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
case AOT_CUSTOM_SECTION_NAME:
if (!load_name_section(buf, buf_end, module, is_load_from_file_buf,
error_buf, error_buf_size))
goto fail;
LOG_VERBOSE("Load name section failed.");
else
LOG_VERBOSE("Load name section success.");
break;
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
case AOT_CUSTOM_SECTION_RAW:
Expand Down Expand Up @@ -1202,6 +1204,11 @@ load_func_types(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module,

func_types[i]->param_cell_num = (uint16)param_cell_num;
func_types[i]->ret_cell_num = (uint16)ret_cell_num;

#if WASM_ENABLE_QUICK_AOT_ENTRY != 0
func_types[i]->quick_aot_entry =
wasm_native_lookup_quick_aot_entry(func_types[i]);
#endif
}

*p_buf = buf;
Expand Down Expand Up @@ -2764,6 +2771,104 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
return ret;
}

#if WASM_ENABLE_LINUX_PERF != 0
struct func_info {
uint32 idx;
void *ptr;
};

static uint32
get_func_size(const AOTModule *module, struct func_info *sorted_func_ptrs,
uint32 idx)
{
uint32 func_sz;

if (idx == module->func_count - 1)
func_sz = (uintptr_t)module->code + module->code_size
- (uintptr_t)(sorted_func_ptrs[idx].ptr);
else
func_sz = (uintptr_t)(sorted_func_ptrs[idx + 1].ptr)
- (uintptr_t)(sorted_func_ptrs[idx].ptr);

return func_sz;
}

static int
compare_func_ptrs(const void *f1, const void *f2)
{
return (intptr_t)((struct func_info *)f1)->ptr
- (intptr_t)((struct func_info *)f2)->ptr;
}

static struct func_info *
sort_func_ptrs(const AOTModule *module, char *error_buf, uint32 error_buf_size)
{
uint64 content_len;
struct func_info *sorted_func_ptrs;
unsigned i;

content_len = (uint64)sizeof(struct func_info) * module->func_count;
sorted_func_ptrs = loader_malloc(content_len, error_buf, error_buf_size);
if (!sorted_func_ptrs)
return NULL;

for (i = 0; i < module->func_count; i++) {
sorted_func_ptrs[i].idx = i;
sorted_func_ptrs[i].ptr = module->func_ptrs[i];
}

qsort(sorted_func_ptrs, module->func_count, sizeof(struct func_info),
compare_func_ptrs);

return sorted_func_ptrs;
}

static bool
create_perf_map(const AOTModule *module, char *error_buf, uint32 error_buf_size)
{
struct func_info *sorted_func_ptrs = NULL;
char perf_map_info[128] = { 0 };
FILE *perf_map = NULL;
uint32 i;
pid_t pid = getpid();
bool ret = false;

sorted_func_ptrs = sort_func_ptrs(module, error_buf, error_buf_size);
if (!sorted_func_ptrs)
goto quit;

snprintf(perf_map_info, 128, "/tmp/perf-%d.map", pid);
perf_map = fopen(perf_map_info, "w");
if (!perf_map) {
LOG_WARNING("warning: can't create /tmp/perf-%d.map, because %s", pid,
strerror(errno));
goto quit;
}

for (i = 0; i < module->func_count; i++) {
memset(perf_map_info, 0, 128);
snprintf(perf_map_info, 128, "%lx %x aot_func#%u\n",
(uintptr_t)sorted_func_ptrs[i].ptr,
get_func_size(module, sorted_func_ptrs, i),
sorted_func_ptrs[i].idx);

fwrite(perf_map_info, 1, strlen(perf_map_info), perf_map);
}

LOG_VERBOSE("generate /tmp/perf-%d.map", pid);
ret = true;

quit:
if (sorted_func_ptrs)
free(sorted_func_ptrs);

if (perf_map)
fclose(perf_map);

return ret;
}
#endif /* WASM_ENABLE_LINUX_PERF != 0*/

static bool
load_from_sections(AOTModule *module, AOTSection *sections,
bool is_load_from_file_buf, char *error_buf,
Expand Down Expand Up @@ -3224,6 +3329,12 @@ load(const uint8 *buf, uint32 size, AOTModule *module, char *error_buf,
}
#endif

#if WASM_ENABLE_LINUX_PERF != 0
if (wasm_runtime_get_linux_perf())
if (!create_perf_map(module, error_buf, error_buf_size))
goto fail;
#endif

return ret;
fail:
return false;
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/aot/aot_reloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ typedef struct {
REG_SYM(aot_enlarge_memory), \
REG_SYM(aot_set_exception), \
REG_SYM(aot_check_app_addr_and_convert),\
REG_SYM(wasm_runtime_quick_invoke_c_api_native),\
{ "memset", (void*)aot_memset }, \
{ "memmove", (void*)aot_memmove }, \
{ "memcpy", (void*)aot_memmove }, \
Expand Down
Loading

0 comments on commit 3f854ff

Please sign in to comment.