Skip to content

Commit 60d4ac7

Browse files
authored
Merge pull request #972 from bytecodealliance/main
Merge main into dev/refactor_orc_jit
2 parents 37c9b23 + 260d36a commit 60d4ac7

File tree

83 files changed

+2265
-1171
lines changed

Some content is hidden

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

83 files changed

+2265
-1171
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: 21 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
}
@@ -853,6 +854,7 @@ load_import_table_list(const uint8 **p_buf, const uint8 *buf_end,
853854

854855
/* keep sync with aot_emit_table_info() aot_emit_aot_file */
855856
for (i = 0; i < module->import_table_count; i++, import_table++) {
857+
read_uint32(buf, buf_end, import_table->elem_type);
856858
read_uint32(buf, buf_end, import_table->table_init_size);
857859
read_uint32(buf, buf_end, import_table->table_max_size);
858860
read_uint32(buf, buf_end, possible_grow);
@@ -1575,8 +1577,10 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
15751577

15761578
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
15771579
if (module->func_count > 0) {
1580+
uint32 plt_table_size =
1581+
module->is_indirect_mode ? 0 : get_plt_table_size();
15781582
rtl_func_table[module->func_count - 1].EndAddress =
1579-
(DWORD)(module->code_size - get_plt_table_size());
1583+
(DWORD)(module->code_size - plt_table_size);
15801584

15811585
if (!RtlAddFunctionTable(rtl_func_table, module->func_count,
15821586
(DWORD64)(uintptr_t)module->code)) {
@@ -2113,19 +2117,29 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
21132117
memcpy(group_name_buf, group_name, group_name_len);
21142118
memcpy(symbol_name_buf, symbol_name, symbol_name_len);
21152119

2116-
if (group_name_len == strlen(".text")
2120+
if ((group_name_len == strlen(".text")
2121+
|| (module->is_indirect_mode
2122+
&& group_name_len == strlen(".text") + 1))
21172123
&& !strncmp(group_name, ".text", strlen(".text"))) {
2118-
if (symbol_name_len == strlen(XMM_PLT_PREFIX) + 32
2124+
if ((symbol_name_len == strlen(XMM_PLT_PREFIX) + 32
2125+
|| (module->is_indirect_mode
2126+
&& symbol_name_len == strlen(XMM_PLT_PREFIX) + 32 + 1))
21192127
&& !strncmp(symbol_name, XMM_PLT_PREFIX,
21202128
strlen(XMM_PLT_PREFIX))) {
21212129
module->xmm_plt_count++;
21222130
}
2123-
else if (symbol_name_len == strlen(REAL_PLT_PREFIX) + 16
2131+
else if ((symbol_name_len == strlen(REAL_PLT_PREFIX) + 16
2132+
|| (module->is_indirect_mode
2133+
&& symbol_name_len
2134+
== strlen(REAL_PLT_PREFIX) + 16 + 1))
21242135
&& !strncmp(symbol_name, REAL_PLT_PREFIX,
21252136
strlen(REAL_PLT_PREFIX))) {
21262137
module->real_plt_count++;
21272138
}
2128-
else if (symbol_name_len == strlen(REAL_PLT_PREFIX) + 8
2139+
else if ((symbol_name_len >= strlen(REAL_PLT_PREFIX) + 8
2140+
|| (module->is_indirect_mode
2141+
&& symbol_name_len
2142+
== strlen(REAL_PLT_PREFIX) + 8 + 1))
21292143
&& !strncmp(symbol_name, REAL_PLT_PREFIX,
21302144
strlen(REAL_PLT_PREFIX))) {
21312145
module->float_plt_count++;
@@ -2230,7 +2244,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22302244
#endif
22312245
) {
22322246
#if !defined(BH_PLATFORM_LINUX) && !defined(BH_PLATFORM_LINUX_SGX) \
2233-
&& !defined(BH_PLATFORM_DARWIN)
2247+
&& !defined(BH_PLATFORM_DARWIN) && !defined(BH_PLATFORM_WINDOWS)
22342248
if (module->is_indirect_mode) {
22352249
set_error_buf(error_buf, error_buf_size,
22362250
"cannot apply relocation to text section "

core/iwasm/aot/aot_runtime.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ init_global_data(uint8 *global_data, uint8 type, WASMValue *initial_value)
8585
switch (type) {
8686
case VALUE_TYPE_I32:
8787
case VALUE_TYPE_F32:
88-
#if WASM_ENABLE_REF_TYPES
88+
#if WASM_ENABLE_REF_TYPES != 0
8989
case VALUE_TYPE_FUNCREF:
9090
case VALUE_TYPE_EXTERNREF:
9191
#endif
@@ -460,6 +460,8 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
460460
LOG_VERBOSE("Memory instantiate:");
461461
LOG_VERBOSE(" page bytes: %u, init pages: %u, max pages: %u",
462462
num_bytes_per_page, init_page_count, max_page_count);
463+
LOG_VERBOSE(" data offset: %u, stack size: %d", module->aux_data_end,
464+
module->aux_stack_size);
463465
LOG_VERBOSE(" heap offset: %u, heap size: %d\n", heap_offset, heap_size);
464466

465467
total_size = (uint64)num_bytes_per_page * init_page_count;
@@ -1260,6 +1262,11 @@ aot_exception_handler(EXCEPTION_POINTERS *exce_info)
12601262
return EXCEPTION_CONTINUE_EXECUTION;
12611263
}
12621264
}
1265+
1266+
os_printf("Unhandled exception thrown: exception code: 0x%lx, "
1267+
"exception address: %p, exception information: %p\n",
1268+
ExceptionRecord->ExceptionCode, ExceptionRecord->ExceptionAddress,
1269+
sig_addr);
12631270
return EXCEPTION_CONTINUE_SEARCH;
12641271
}
12651272
#endif /* end of BH_PLATFORM_WINDOWS */
@@ -1576,16 +1583,8 @@ aot_create_exec_env_and_call_function(AOTModuleInstance *module_inst,
15761583
}
15771584
}
15781585

1579-
#if WASM_ENABLE_REF_TYPES != 0
1580-
wasm_runtime_prepare_call_function(exec_env, func);
1581-
#endif
1582-
15831586
ret = aot_call_function(exec_env, func, argc, argv);
15841587

1585-
#if WASM_ENABLE_REF_TYPES != 0
1586-
wasm_runtime_finalize_call_function(exec_env, func, ret, argv);
1587-
#endif
1588-
15891588
/* don't destroy the exec_env if it's searched from the cluster */
15901589
if (!existing_exec_env)
15911590
wasm_exec_env_destroy(exec_env);

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);

0 commit comments

Comments
 (0)