Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6b733b8
Automatically detect the host platform in CMakeLists.txt (#929)
PiotrSikora Jan 4, 2022
2c3f284
Add extern "C" in libc-builtin-sysroot pthread.h (#933)
xujuntwt95329 Jan 4, 2022
78414b6
ESP IDF fixes (#927)
wallento Jan 5, 2022
9169eff
Remove hardcoded stack size in thread_manager.c (#931)
no1wudi Jan 5, 2022
ff997c2
Update document of multi-module (#930)
lum1n0us Jan 5, 2022
9d2576d
Wrap data width according to atomic opcode specified (#936)
no1wudi Jan 6, 2022
308d31c
Upgrade uvwasi to 1.42.0 and fix Android link issues (#938)
wenyongh Jan 6, 2022
cb51dbb
Fix some issues on MacOS platform (#937)
wenyongh Jan 7, 2022
78308e7
GetCurrentThreadStackLimits dynamically for Windows platform (#939)
wenyongh Jan 7, 2022
f619796
Fix MacOS invokeNative float ret type pass error (#940)
wenyongh Jan 7, 2022
ae18a03
Fix link in multi_module.md (#941)
Therdel Jan 8, 2022
4b5543c
Enable Windows XIP (#944)
wenyongh Jan 10, 2022
6bcf048
Fix aarch64 build support (#946)
timonwong Jan 11, 2022
30cb05f
Refine llvm pass order (#948)
wenyongh Jan 12, 2022
3fddd3f
Fix wasi checks in multi-module CMakelists (#951)
Therdel Jan 13, 2022
36b8f8f
Use clang+llvm released binaries instead of "apt install" in Dockerfi…
lum1n0us Jan 13, 2022
6917137
Fix a typo in ci/Dockerfile (#953)
lum1n0us Jan 13, 2022
9eb3ed6
Update documents about building wasm app with wasi-sdk (#955)
lum1n0us Jan 13, 2022
ee97e30
Fix pointer unchecked issue in thread-mgr.c (#960)
xujuntwt95329 Jan 14, 2022
092efbf
Fix thread manager issues (#962)
wenyongh Jan 17, 2022
e0511fe
Correct stack base calculation on Mac and NuttX (#963)
no1wudi Jan 17, 2022
552f850
Fix __wasi_subscription_t inconsistent with wasi-libc issue (#964)
wenyongh Jan 17, 2022
8088783
Refine is_xip_file and pointer range check (#965)
wenyongh Jan 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required (VERSION 2.8...3.16)
project (iwasm)
# set (CMAKE_VERBOSE_MAKEFILE 1)

set (WAMR_BUILD_PLATFORM "linux")
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)

# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
Expand All @@ -18,7 +18,7 @@ set (CMAKE_C_STANDARD 99)
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
Expand Down
31 changes: 31 additions & 0 deletions build-scripts/esp-idf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# wasm-micro-runtime as ESP-IDF component

You can build an ESP-IDF project with wasm-micro-runtime as a component:

- Make sure you have the ESP-IDF properly installed and setup
- In particular have the following paths set:
- `WAMR_PATH` to point to your wasm-micro-runtime repository
- `IDF_PATH` to point to your ESP-IDF
- `source $IDF_PATH/export.sh`
- Create a new project, e.g.: `idf.py create-project wamr-hello`
- In the newly created project folder edit the `CMakeList.txt`:

```
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

set (COMPONENTS ${IDF_TARGET} main freertos esptool_py wamr)

list(APPEND EXTRA_COMPONENT_DIRS "$ENV{WAMR_PATH}/build-scripts/esp-idf")

project(wamr-hello)
```
- Develop your project in it's `main` component folder.

You can find an example [here](../../product-mini/platforms/esp-idf).

- Set target platform: `idf.py set-target esp32c3`
- Build: `idf.py build`
- Flash: `idf.py flash`
- Check the output: `idf.py monitor`
57 changes: 57 additions & 0 deletions build-scripts/esp-idf/wamr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (C) 2021 Intel Corporation and others. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Set WAMR's build options
if("${IDF_TARGET}" STREQUAL "esp32c3")
set(WAMR_BUILD_TARGET "RISCV32")
else()
set(WAMR_BUILD_TARGET "XTENSA")
endif()

set(WAMR_BUILD_PLATFORM "esp-idf")

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()

if (NOT DEFINED WAMR_BUILD_INTERP)
set (WAMR_BUILD_INTERP 1)
endif ()

if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
set (WAMR_BUILD_FAST_INTERP 1)
endif ()

if (NOT DEFINED WAMR_BUILD_AOT)
set (WAMR_BUILD_AOT 1)
endif ()

if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()

if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK)
set (WAMR_BUILD_APP_FRAMEWORK 0)
endif ()

if (NOT CMAKE_BUILD_EARLY_EXPANSION)
if (WAMR_BUILD_TARGET STREQUAL "XTENSA")
idf_build_set_property(COMPILE_DEFINITIONS "-DBUILD_TARGET_XTENSA=1" APPEND)
endif ()
if (WAMR_BUILD_INTERP)
idf_build_set_property(COMPILE_DEFINITIONS "-DWASM_ENABLE_INTERP=1" APPEND)
endif ()
if (WAMR_BUILD_AOT)
idf_build_set_property(COMPILE_DEFINITIONS "-DWASM_ENABLE_AOT=1" APPEND)
endif ()

set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
endif()

idf_component_register(SRCS ${WAMR_RUNTIME_LIB_SOURCE} ${PLATFORM_SHARED_SOURCE}
INCLUDE_DIRS ${IWASM_DIR}/include ${UTILS_SHARED_DIR} ${PLATFORM_SHARED_DIR} ${PLATFORM_SHARED_DIR}/../include
REQUIRES pthread
)


2 changes: 1 addition & 1 deletion build-scripts/runtime_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ endif ()
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
Expand Down
40 changes: 28 additions & 12 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# tie the ${VARIANT} and a llvm binary release together
# please find a matched version on https://github.com/llvm/llvm-project/releases
ARG VARIANT=focal
FROM ubuntu:${VARIANT}

Expand Down Expand Up @@ -34,6 +36,24 @@ RUN cd /opt/emsdk \
&& ./emsdk activate 2.0.26 \
&& echo "source /opt/emsdk/emsdk_env.sh" >> /root/.bashrc

#
# install clang and llvm release
ARG CLANG_VER=13.0.0
RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_VER}/clang+llvm-${CLANG_VER}-x86_64-linux-gnu-ubuntu-20.04.tar.xz -P /opt
RUN cd /opt \
&& tar xf clang+llvm-${CLANG_VER}-x86_64-linux-gnu-ubuntu-20.04.tar.xz \
&& ln -sf clang+llvm-${CLANG_VER}-x86_64-linux-gnu-ubuntu-20.04 clang-llvm
RUN rm /opt/clang+llvm-${CLANG_VER}-x86_64-linux-gnu-ubuntu-20.04.tar.xz


#
# install wasi-sdk
ARG WASI_SDK_VER=14
RUN wget -c https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VER}/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -P /opt
RUN tar xf /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -C /opt \
&& ln -fs /opt/wasi-sdk-${WASI_SDK_VER}.0 /opt/wasi-sdk
RUN rm /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz

#
#install wabt
ARG WABT_VER=1.0.24
Expand All @@ -42,15 +62,6 @@ RUN tar xf /opt/wabt-${WABT_VER}-ubuntu.tar.gz -C /opt \
&& ln -fs /opt/wabt-${WABT_VER} /opt/wabt
RUN rm /opt/wabt-${WABT_VER}-ubuntu.tar.gz

#
# install binaryen
ARG BINARYEN_VER=version_101
RUN wget -c https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VER}/binaryen-${BINARYEN_VER}-x86_64-linux.tar.gz -P /opt
RUN tar xf /opt/binaryen-${BINARYEN_VER}-x86_64-linux.tar.gz -C /opt \
&& ln -fs /opt/binaryen-${BINARYEN_VER} /opt/binaryen
RUN rm /opt/binaryen-${BINARYEN_VER}-x86_64-linux.tar.gz


#
# install bazelisk
ARG BAZELISK_VER=1.10.1
Expand All @@ -59,8 +70,13 @@ RUN wget -c https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK
RUN chmod a+x /opt/bazelisk/bazelisk-linux-amd64 \
&& ln -fs /opt/bazelisk/bazelisk-linux-amd64 /opt/bazelisk/bazel

#
# install
RUN apt update && apt install -y clang-format

# set path
RUN echo "PATH=/opt/clang_llvm/bin:/opt/wasi-sdk/bin:/opt/wabt/bin:/opt/binaryen/bin:/opt/bazelisk:${PATH}" >> /root/.bashrc
ENV PATH "$PATH:/opt/wasi-sdk/bin:/opt/wabt/bin:/opt/binaryen/bin:/opt/bazelisk:/opt/clang-llvm/bin"
RUN echo "export PATH=/opt/wasi-sdk/bin:/opt/wabt/bin:/opt/binaryen/bin:/opt/bazelisk:/opt/clang-llvm/bin:${PATH}" >> /root/.bashrc

#
# PS
Expand All @@ -72,5 +88,5 @@ RUN apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/*

VOLUME workspace
WORKDIR workspace
VOLUME /workspace
WORKDIR /workspace
47 changes: 24 additions & 23 deletions ci/build_wamr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ readonly ROOT=$(realpath "${CURRENT_PATH}/..")
readonly VARIANT=$(lsb_release -c | awk '{print $2}')

docker build \
--build-arg VARIANT=${VARIANT} \
--memory=4G --cpu-quota=50000 \
-t wamr_dev_${VARIANT}:0.1 -f "${CURRENT_PATH}"/Dockerfile "${CURRENT_PATH}" &&
docker run --rm -it \
--cpus=".5" \
--memory=4G \
--name wamr_build_env \
--mount type=bind,src="${ROOT}",dst=/workspace \
wamr_dev_${VARIANT}:0.1 \
/bin/bash -c "\
pwd \
&& pushd product-mini/platforms/linux \
&& rm -rf build \
&& mkdir build \
&& pushd build \
&& cmake .. \
&& make \
&& popd \
&& popd \
&& echo 'Copying the binary ...' \
&& rm -rf build_out \
&& mkdir build_out \
&& cp product-mini/platforms/linux/build/iwasm build_out/iwasm"
--memory=4G --cpu-quota=50000 \
-t wamr_dev_${VARIANT}:0.1 -f "${CURRENT_PATH}"/Dockerfile "${CURRENT_PATH}" \
&& docker run --rm -it \
--cap-add=SYS_PTRACE \
--cpus=".5" \
--memory=4G \
--mount type=bind,src="${ROOT}",dst=/workspace \
--name wamr_build_env \
--security-opt=seccomp=unconfined \
wamr_dev_${VARIANT}:0.1 \
/bin/bash -c "\
pwd \
&& pushd product-mini/platforms/linux \
&& rm -rf build \
&& mkdir build \
&& pushd build \
&& cmake .. \
&& make \
&& popd \
&& popd \
&& echo 'Copying the binary ...' \
&& rm -rf build_out \
&& mkdir build_out \
&& cp product-mini/platforms/linux/build/iwasm build_out/iwasm"
27 changes: 20 additions & 7 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ static bool
check_buf(const uint8 *buf, const uint8 *buf_end, uint32 length,
char *error_buf, uint32 error_buf_size)
{
if (buf + length < buf || buf + length > buf_end) {
if ((uintptr_t)buf + length < (uintptr_t)buf
|| (uintptr_t)buf + length > (uintptr_t)buf_end) {
set_error_buf(error_buf, error_buf_size, "unexpect end");
return false;
}
Expand Down Expand Up @@ -1575,8 +1576,10 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,

#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
if (module->func_count > 0) {
uint32 plt_table_size =
module->is_indirect_mode ? 0 : get_plt_table_size();
rtl_func_table[module->func_count - 1].EndAddress =
(DWORD)(module->code_size - get_plt_table_size());
(DWORD)(module->code_size - plt_table_size);

if (!RtlAddFunctionTable(rtl_func_table, module->func_count,
(DWORD64)(uintptr_t)module->code)) {
Expand Down Expand Up @@ -2113,19 +2116,29 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
memcpy(group_name_buf, group_name, group_name_len);
memcpy(symbol_name_buf, symbol_name, symbol_name_len);

if (group_name_len == strlen(".text")
if ((group_name_len == strlen(".text")
|| (module->is_indirect_mode
&& group_name_len == strlen(".text") + 1))
&& !strncmp(group_name, ".text", strlen(".text"))) {
if (symbol_name_len == strlen(XMM_PLT_PREFIX) + 32
if ((symbol_name_len == strlen(XMM_PLT_PREFIX) + 32
|| (module->is_indirect_mode
&& symbol_name_len == strlen(XMM_PLT_PREFIX) + 32 + 1))
&& !strncmp(symbol_name, XMM_PLT_PREFIX,
strlen(XMM_PLT_PREFIX))) {
module->xmm_plt_count++;
}
else if (symbol_name_len == strlen(REAL_PLT_PREFIX) + 16
else if ((symbol_name_len == strlen(REAL_PLT_PREFIX) + 16
|| (module->is_indirect_mode
&& symbol_name_len
== strlen(REAL_PLT_PREFIX) + 16 + 1))
&& !strncmp(symbol_name, REAL_PLT_PREFIX,
strlen(REAL_PLT_PREFIX))) {
module->real_plt_count++;
}
else if (symbol_name_len == strlen(REAL_PLT_PREFIX) + 8
else if ((symbol_name_len >= strlen(REAL_PLT_PREFIX) + 8
|| (module->is_indirect_mode
&& symbol_name_len
== strlen(REAL_PLT_PREFIX) + 8 + 1))
&& !strncmp(symbol_name, REAL_PLT_PREFIX,
strlen(REAL_PLT_PREFIX))) {
module->float_plt_count++;
Expand Down Expand Up @@ -2230,7 +2243,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
#endif
) {
#if !defined(BH_PLATFORM_LINUX) && !defined(BH_PLATFORM_LINUX_SGX) \
&& !defined(BH_PLATFORM_DARWIN)
&& !defined(BH_PLATFORM_DARWIN) && !defined(BH_PLATFORM_WINDOWS)
if (module->is_indirect_mode) {
set_error_buf(error_buf, error_buf_size,
"cannot apply relocation to text section "
Expand Down
5 changes: 5 additions & 0 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,11 @@ aot_exception_handler(EXCEPTION_POINTERS *exce_info)
return EXCEPTION_CONTINUE_EXECUTION;
}
}

os_printf("Unhandled exception thrown: exception code: 0x%lx, "
"exception address: %p, exception information: %p\n",
ExceptionRecord->ExceptionCode, ExceptionRecord->ExceptionAddress,
sig_addr);
return EXCEPTION_CONTINUE_SEARCH;
}
#endif /* end of BH_PLATFORM_WINDOWS */
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/aot/arch/aot_reloc_xtensa.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ put_imm16_to_addr(int16 imm16, int16 *addr)
if ((intptr_t)addr % 4 != 3) {
*(int32 *)bytes = *addr_aligned1;
*(int16 *)(bytes + ((intptr_t)addr % 4)) = imm16;
memcpy(addr_aligned1, bytes, 4);
*addr_aligned1 = *(int32 *)bytes;
}
else {
addr_aligned2 = (int32 *)(((intptr_t)addr + 3) & ~3);
Expand Down
2 changes: 2 additions & 0 deletions core/iwasm/common/wasm_exec_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ typedef struct WASMExecEnv {
/* used to support debugger */
korp_mutex wait_lock;
korp_cond wait_cond;
/* the count of threads which are joining current thread */
uint32 wait_count;
#endif

#if WASM_ENABLE_DEBUG_INTERP != 0
Expand Down
24 changes: 17 additions & 7 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ align_ptr(const uint8 *p, uint32 b)
return (uint8 *)((v + m) & ~m);
}

#define CHECK_BUF(buf, buf_end, length) \
do { \
if (buf + length < buf || buf + length > buf_end) \
return false; \
#define CHECK_BUF(buf, buf_end, length) \
do { \
if ((uintptr_t)buf + length < (uintptr_t)buf \
|| (uintptr_t)buf + length > (uintptr_t)buf_end) \
return false; \
} while (0)

#define read_uint16(p, p_end, res) \
Expand Down Expand Up @@ -347,9 +348,7 @@ wasm_runtime_is_xip_file(const uint8 *buf, uint32 size)
if (section_type == AOT_SECTION_TYPE_TARGET_INFO) {
p += 4;
read_uint16(p, p_end, e_type);
if (e_type == E_TYPE_XIP) {
return true;
}
return (e_type == E_TYPE_XIP) ? true : false;
}
else if (section_type >= AOT_SECTION_TYPE_SIGANATURE) {
return false;
Expand Down Expand Up @@ -3227,8 +3226,19 @@ typedef uint32x4_t __m128i;
#endif /* end of WASM_ENABLE_SIMD != 0 */

typedef void (*GenericFunctionPointer)();
#if defined(__APPLE__) || defined(__MACH__)
/**
* Define the return type as 'void' in MacOS, since after converting
* 'int64 invokeNative' into 'float64 invokeNative_Float64', the
* return value passing might be invalid, the caller reads the return
* value from register rax but not xmm0.
*/
void
invokeNative(GenericFunctionPointer f, uint64 *args, uint64 n_stacks);
#else
int64
invokeNative(GenericFunctionPointer f, uint64 *args, uint64 n_stacks);
#endif

typedef float64 (*Float64FuncPtr)(GenericFunctionPointer, uint64 *, uint64);
typedef float32 (*Float32FuncPtr)(GenericFunctionPointer, uint64 *, uint64);
Expand Down
Loading