Skip to content

Commit 5bdab7f

Browse files
authored
Merge pull request #959 from bytecodealliance/main
Merge main into dev/socket_api
2 parents 20a1973 + 8088783 commit 5bdab7f

File tree

57 files changed

+1120
-582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1120
-582
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required (VERSION 2.8...3.16)
66
project (iwasm)
77
# set (CMAKE_VERBOSE_MAKEFILE 1)
88

9-
set (WAMR_BUILD_PLATFORM "linux")
9+
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
1010

1111
# Reset default linker flags
1212
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
@@ -18,7 +18,7 @@ set (CMAKE_C_STANDARD 99)
1818
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
1919
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
2020
if (NOT DEFINED WAMR_BUILD_TARGET)
21-
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
21+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
2222
set (WAMR_BUILD_TARGET "AARCH64")
2323
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
2424
set (WAMR_BUILD_TARGET "RISCV64")

build-scripts/esp-idf/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# wasm-micro-runtime as ESP-IDF component
2+
3+
You can build an ESP-IDF project with wasm-micro-runtime as a component:
4+
5+
- Make sure you have the ESP-IDF properly installed and setup
6+
- In particular have the following paths set:
7+
- `WAMR_PATH` to point to your wasm-micro-runtime repository
8+
- `IDF_PATH` to point to your ESP-IDF
9+
- `source $IDF_PATH/export.sh`
10+
- Create a new project, e.g.: `idf.py create-project wamr-hello`
11+
- In the newly created project folder edit the `CMakeList.txt`:
12+
13+
```
14+
cmake_minimum_required(VERSION 3.5)
15+
16+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
17+
18+
set (COMPONENTS ${IDF_TARGET} main freertos esptool_py wamr)
19+
20+
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{WAMR_PATH}/build-scripts/esp-idf")
21+
22+
project(wamr-hello)
23+
```
24+
- Develop your project in it's `main` component folder.
25+
26+
You can find an example [here](../../product-mini/platforms/esp-idf).
27+
28+
- Set target platform: `idf.py set-target esp32c3`
29+
- Build: `idf.py build`
30+
- Flash: `idf.py flash`
31+
- Check the output: `idf.py monitor`
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (C) 2021 Intel Corporation and others. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
# Set WAMR's build options
5+
if("${IDF_TARGET}" STREQUAL "esp32c3")
6+
set(WAMR_BUILD_TARGET "RISCV32")
7+
else()
8+
set(WAMR_BUILD_TARGET "XTENSA")
9+
endif()
10+
11+
set(WAMR_BUILD_PLATFORM "esp-idf")
12+
13+
if (NOT CMAKE_BUILD_TYPE)
14+
set(CMAKE_BUILD_TYPE Release)
15+
endif ()
16+
17+
if (NOT DEFINED WAMR_BUILD_INTERP)
18+
set (WAMR_BUILD_INTERP 1)
19+
endif ()
20+
21+
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
22+
set (WAMR_BUILD_FAST_INTERP 1)
23+
endif ()
24+
25+
if (NOT DEFINED WAMR_BUILD_AOT)
26+
set (WAMR_BUILD_AOT 1)
27+
endif ()
28+
29+
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
30+
set (WAMR_BUILD_LIBC_BUILTIN 1)
31+
endif ()
32+
33+
if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK)
34+
set (WAMR_BUILD_APP_FRAMEWORK 0)
35+
endif ()
36+
37+
if (NOT CMAKE_BUILD_EARLY_EXPANSION)
38+
if (WAMR_BUILD_TARGET STREQUAL "XTENSA")
39+
idf_build_set_property(COMPILE_DEFINITIONS "-DBUILD_TARGET_XTENSA=1" APPEND)
40+
endif ()
41+
if (WAMR_BUILD_INTERP)
42+
idf_build_set_property(COMPILE_DEFINITIONS "-DWASM_ENABLE_INTERP=1" APPEND)
43+
endif ()
44+
if (WAMR_BUILD_AOT)
45+
idf_build_set_property(COMPILE_DEFINITIONS "-DWASM_ENABLE_AOT=1" APPEND)
46+
endif ()
47+
48+
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
49+
include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
50+
endif()
51+
52+
idf_component_register(SRCS ${WAMR_RUNTIME_LIB_SOURCE} ${PLATFORM_SHARED_SOURCE}
53+
INCLUDE_DIRS ${IWASM_DIR}/include ${UTILS_SHARED_DIR} ${PLATFORM_SHARED_DIR} ${PLATFORM_SHARED_DIR}/../include
54+
REQUIRES pthread
55+
)
56+
57+

build-scripts/runtime_lib.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ endif ()
3434
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
3535
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
3636
if (NOT DEFINED WAMR_BUILD_TARGET)
37-
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
37+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
3838
set (WAMR_BUILD_TARGET "AARCH64")
3939
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
4040
set (WAMR_BUILD_TARGET "RISCV64")

ci/Dockerfile

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (C) 2019 Intel Corporation. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

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

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

39+
#
40+
# install clang and llvm release
41+
ARG CLANG_VER=13.0.0
42+
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
43+
RUN cd /opt \
44+
&& tar xf clang+llvm-${CLANG_VER}-x86_64-linux-gnu-ubuntu-20.04.tar.xz \
45+
&& ln -sf clang+llvm-${CLANG_VER}-x86_64-linux-gnu-ubuntu-20.04 clang-llvm
46+
RUN rm /opt/clang+llvm-${CLANG_VER}-x86_64-linux-gnu-ubuntu-20.04.tar.xz
47+
48+
49+
#
50+
# install wasi-sdk
51+
ARG WASI_SDK_VER=14
52+
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
53+
RUN tar xf /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -C /opt \
54+
&& ln -fs /opt/wasi-sdk-${WASI_SDK_VER}.0 /opt/wasi-sdk
55+
RUN rm /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz
56+
3757
#
3858
#install wabt
3959
ARG WABT_VER=1.0.24
@@ -42,15 +62,6 @@ RUN tar xf /opt/wabt-${WABT_VER}-ubuntu.tar.gz -C /opt \
4262
&& ln -fs /opt/wabt-${WABT_VER} /opt/wabt
4363
RUN rm /opt/wabt-${WABT_VER}-ubuntu.tar.gz
4464

45-
#
46-
# install binaryen
47-
ARG BINARYEN_VER=version_101
48-
RUN wget -c https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VER}/binaryen-${BINARYEN_VER}-x86_64-linux.tar.gz -P /opt
49-
RUN tar xf /opt/binaryen-${BINARYEN_VER}-x86_64-linux.tar.gz -C /opt \
50-
&& ln -fs /opt/binaryen-${BINARYEN_VER} /opt/binaryen
51-
RUN rm /opt/binaryen-${BINARYEN_VER}-x86_64-linux.tar.gz
52-
53-
5465
#
5566
# install bazelisk
5667
ARG BAZELISK_VER=1.10.1
@@ -59,8 +70,13 @@ RUN wget -c https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK
5970
RUN chmod a+x /opt/bazelisk/bazelisk-linux-amd64 \
6071
&& ln -fs /opt/bazelisk/bazelisk-linux-amd64 /opt/bazelisk/bazel
6172

73+
#
74+
# install
75+
RUN apt update && apt install -y clang-format
76+
6277
# set path
63-
RUN echo "PATH=/opt/clang_llvm/bin:/opt/wasi-sdk/bin:/opt/wabt/bin:/opt/binaryen/bin:/opt/bazelisk:${PATH}" >> /root/.bashrc
78+
ENV PATH "$PATH:/opt/wasi-sdk/bin:/opt/wabt/bin:/opt/binaryen/bin:/opt/bazelisk:/opt/clang-llvm/bin"
79+
RUN echo "export PATH=/opt/wasi-sdk/bin:/opt/wabt/bin:/opt/binaryen/bin:/opt/bazelisk:/opt/clang-llvm/bin:${PATH}" >> /root/.bashrc
6480

6581
#
6682
# PS
@@ -72,5 +88,5 @@ RUN apt-get autoremove -y \
7288
&& rm -rf /var/lib/apt/lists/* \
7389
&& rm -rf /tmp/*
7490

75-
VOLUME workspace
76-
WORKDIR workspace
91+
VOLUME /workspace
92+
WORKDIR /workspace

ci/build_wamr.sh

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@ readonly ROOT=$(realpath "${CURRENT_PATH}/..")
88
readonly VARIANT=$(lsb_release -c | awk '{print $2}')
99

1010
docker build \
11-
--build-arg VARIANT=${VARIANT} \
12-
--memory=4G --cpu-quota=50000 \
13-
-t wamr_dev_${VARIANT}:0.1 -f "${CURRENT_PATH}"/Dockerfile "${CURRENT_PATH}" &&
14-
docker run --rm -it \
15-
--cpus=".5" \
16-
--memory=4G \
17-
--name wamr_build_env \
18-
--mount type=bind,src="${ROOT}",dst=/workspace \
19-
wamr_dev_${VARIANT}:0.1 \
20-
/bin/bash -c "\
21-
pwd \
22-
&& pushd product-mini/platforms/linux \
23-
&& rm -rf build \
24-
&& mkdir build \
25-
&& pushd build \
26-
&& cmake .. \
27-
&& make \
28-
&& popd \
29-
&& popd \
30-
&& echo 'Copying the binary ...' \
31-
&& rm -rf build_out \
32-
&& mkdir build_out \
33-
&& cp product-mini/platforms/linux/build/iwasm build_out/iwasm"
11+
--memory=4G --cpu-quota=50000 \
12+
-t wamr_dev_${VARIANT}:0.1 -f "${CURRENT_PATH}"/Dockerfile "${CURRENT_PATH}" \
13+
&& docker run --rm -it \
14+
--cap-add=SYS_PTRACE \
15+
--cpus=".5" \
16+
--memory=4G \
17+
--mount type=bind,src="${ROOT}",dst=/workspace \
18+
--name wamr_build_env \
19+
--security-opt=seccomp=unconfined \
20+
wamr_dev_${VARIANT}:0.1 \
21+
/bin/bash -c "\
22+
pwd \
23+
&& pushd product-mini/platforms/linux \
24+
&& rm -rf build \
25+
&& mkdir build \
26+
&& pushd build \
27+
&& cmake .. \
28+
&& make \
29+
&& popd \
30+
&& popd \
31+
&& echo 'Copying the binary ...' \
32+
&& rm -rf build_out \
33+
&& mkdir build_out \
34+
&& cp product-mini/platforms/linux/build/iwasm build_out/iwasm"

core/iwasm/aot/aot_loader.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static bool
9090
check_buf(const uint8 *buf, const uint8 *buf_end, uint32 length,
9191
char *error_buf, uint32 error_buf_size)
9292
{
93-
if (buf + length < buf || buf + length > buf_end) {
93+
if ((uintptr_t)buf + length < (uintptr_t)buf
94+
|| (uintptr_t)buf + length > (uintptr_t)buf_end) {
9495
set_error_buf(error_buf, error_buf_size, "unexpect end");
9596
return false;
9697
}
@@ -1575,8 +1576,10 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
15751576

15761577
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
15771578
if (module->func_count > 0) {
1579+
uint32 plt_table_size =
1580+
module->is_indirect_mode ? 0 : get_plt_table_size();
15781581
rtl_func_table[module->func_count - 1].EndAddress =
1579-
(DWORD)(module->code_size - get_plt_table_size());
1582+
(DWORD)(module->code_size - plt_table_size);
15801583

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

2116-
if (group_name_len == strlen(".text")
2119+
if ((group_name_len == strlen(".text")
2120+
|| (module->is_indirect_mode
2121+
&& group_name_len == strlen(".text") + 1))
21172122
&& !strncmp(group_name, ".text", strlen(".text"))) {
2118-
if (symbol_name_len == strlen(XMM_PLT_PREFIX) + 32
2123+
if ((symbol_name_len == strlen(XMM_PLT_PREFIX) + 32
2124+
|| (module->is_indirect_mode
2125+
&& symbol_name_len == strlen(XMM_PLT_PREFIX) + 32 + 1))
21192126
&& !strncmp(symbol_name, XMM_PLT_PREFIX,
21202127
strlen(XMM_PLT_PREFIX))) {
21212128
module->xmm_plt_count++;
21222129
}
2123-
else if (symbol_name_len == strlen(REAL_PLT_PREFIX) + 16
2130+
else if ((symbol_name_len == strlen(REAL_PLT_PREFIX) + 16
2131+
|| (module->is_indirect_mode
2132+
&& symbol_name_len
2133+
== strlen(REAL_PLT_PREFIX) + 16 + 1))
21242134
&& !strncmp(symbol_name, REAL_PLT_PREFIX,
21252135
strlen(REAL_PLT_PREFIX))) {
21262136
module->real_plt_count++;
21272137
}
2128-
else if (symbol_name_len == strlen(REAL_PLT_PREFIX) + 8
2138+
else if ((symbol_name_len >= strlen(REAL_PLT_PREFIX) + 8
2139+
|| (module->is_indirect_mode
2140+
&& symbol_name_len
2141+
== strlen(REAL_PLT_PREFIX) + 8 + 1))
21292142
&& !strncmp(symbol_name, REAL_PLT_PREFIX,
21302143
strlen(REAL_PLT_PREFIX))) {
21312144
module->float_plt_count++;
@@ -2230,7 +2243,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22302243
#endif
22312244
) {
22322245
#if !defined(BH_PLATFORM_LINUX) && !defined(BH_PLATFORM_LINUX_SGX) \
2233-
&& !defined(BH_PLATFORM_DARWIN)
2246+
&& !defined(BH_PLATFORM_DARWIN) && !defined(BH_PLATFORM_WINDOWS)
22342247
if (module->is_indirect_mode) {
22352248
set_error_buf(error_buf, error_buf_size,
22362249
"cannot apply relocation to text section "

core/iwasm/aot/aot_runtime.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,11 @@ aot_exception_handler(EXCEPTION_POINTERS *exce_info)
12601260
return EXCEPTION_CONTINUE_EXECUTION;
12611261
}
12621262
}
1263+
1264+
os_printf("Unhandled exception thrown: exception code: 0x%lx, "
1265+
"exception address: %p, exception information: %p\n",
1266+
ExceptionRecord->ExceptionCode, ExceptionRecord->ExceptionAddress,
1267+
sig_addr);
12631268
return EXCEPTION_CONTINUE_SEARCH;
12641269
}
12651270
#endif /* end of BH_PLATFORM_WINDOWS */

core/iwasm/aot/arch/aot_reloc_xtensa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ put_imm16_to_addr(int16 imm16, int16 *addr)
112112
if ((intptr_t)addr % 4 != 3) {
113113
*(int32 *)bytes = *addr_aligned1;
114114
*(int16 *)(bytes + ((intptr_t)addr % 4)) = imm16;
115-
memcpy(addr_aligned1, bytes, 4);
115+
*addr_aligned1 = *(int32 *)bytes;
116116
}
117117
else {
118118
addr_aligned2 = (int32 *)(((intptr_t)addr + 3) & ~3);

core/iwasm/common/wasm_exec_env.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ typedef struct WASMExecEnv {
9898
/* used to support debugger */
9999
korp_mutex wait_lock;
100100
korp_cond wait_cond;
101+
/* the count of threads which are joining current thread */
102+
uint32 wait_count;
101103
#endif
102104

103105
#if WASM_ENABLE_DEBUG_INTERP != 0

0 commit comments

Comments
 (0)