Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion 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 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
)


33 changes: 21 additions & 12 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ RUN cd /opt/emsdk \
&& ./emsdk activate 2.0.26 \
&& echo "source /opt/emsdk/emsdk_env.sh" >> /root/.bashrc

#
# install clang and llvm
RUN cd /tmp && wget https://apt.llvm.org/llvm.sh && chmod a+x llvm.sh
RUN cd /tmp && ./llvm.sh 12

#
# 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/was-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 +55,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 +63,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"
RUN echo "export PATH=/opt/wasi-sdk/bin:/opt/wabt/bin:/opt/binaryen/bin:/opt/bazelisk:${PATH}" >> /root/.bashrc

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

VOLUME workspace
WORKDIR workspace
VOLUME /workspace
WORKDIR /workspace
48 changes: 25 additions & 23 deletions ci/build_wamr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ 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"
--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 \
--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"
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
80 changes: 75 additions & 5 deletions core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,74 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)
abi = "ilp32d";
}

if (arch) {
#if defined(__APPLE__) || defined(__MACH__)
if (!abi) {
/* On MacOS platform, set abi to "gnu" to avoid generating
object file of Mach-O binary format which is unsupported */
abi = "gnu";
if (!arch && !cpu && !features) {
/* Get CPU name of the host machine to avoid checking
SIMD capability failed */
if (!(cpu = cpu_new = LLVMGetHostCPUName())) {
aot_set_last_error("llvm get host cpu name failed.");
goto fail;
}
}
}
#endif

if (abi) {
/* Construct target triple: <arch>-<vendor>-<sys>-<abi> */
const char *vendor_sys;
char *arch1 = arch, default_arch[32] = { 0 };

if (!arch1) {
char *default_triple = LLVMGetDefaultTargetTriple();

if (!default_triple) {
aot_set_last_error(
"llvm get default target triple failed.");
goto fail;
}

vendor_sys = strstr(default_triple, "-");
bh_assert(vendor_sys);
bh_memcpy_s(default_arch, sizeof(default_arch), default_triple,
vendor_sys - default_triple);
arch1 = default_arch;

LLVMDisposeMessage(default_triple);
}

/**
* Set <vendor>-<sys> according to abi to generate the object file
* with the correct file format which might be different from the
* default object file format of the host, e.g., generating AOT file
* for Windows/MacOS under Linux host, or generating AOT file for
* Linux/MacOS under Windows host.
*/
if (!strcmp(abi, "msvc")) {
if (!strcmp(arch1, "i386"))
vendor_sys = "-pc-win32-";
else
vendor_sys = "-pc-windows-";
}
else {
vendor_sys = "-pc-linux-";
}

bh_assert(strlen(arch1) + strlen(vendor_sys) + strlen(abi)
< sizeof(triple_buf));
bh_memcpy_s(triple_buf, sizeof(triple_buf), arch1, strlen(arch1));
bh_memcpy_s(triple_buf + strlen(arch1),
sizeof(triple_buf) - strlen(arch1), vendor_sys,
strlen(vendor_sys));
bh_memcpy_s(triple_buf + strlen(arch1) + strlen(vendor_sys),
sizeof(triple_buf) - strlen(arch1) - strlen(vendor_sys),
abi, strlen(abi));
triple = triple_buf;
}
else if (arch) {
/* Construct target triple: <arch>-<vendor>-<sys>-<abi> */
const char *vendor_sys;
char *default_triple = LLVMGetDefaultTargetTriple();
Expand Down Expand Up @@ -1640,10 +1707,13 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option)

bh_assert(strlen(arch) + strlen(vendor_sys) + strlen(abi)
< sizeof(triple_buf));
memcpy(triple_buf, arch, strlen(arch));
memcpy(triple_buf + strlen(arch), vendor_sys, strlen(vendor_sys));
memcpy(triple_buf + strlen(arch) + strlen(vendor_sys), abi,
strlen(abi));
bh_memcpy_s(triple_buf, sizeof(triple_buf), arch, strlen(arch));
bh_memcpy_s(triple_buf + strlen(arch),
sizeof(triple_buf) - strlen(arch), vendor_sys,
strlen(vendor_sys));
bh_memcpy_s(triple_buf + strlen(arch) + strlen(vendor_sys),
sizeof(triple_buf) - strlen(arch) - strlen(vendor_sys),
abi, strlen(abi));
triple = triple_buf;
}

Expand Down
5 changes: 5 additions & 0 deletions core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -3389,6 +3389,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();

expect = (uint8)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint32)(*(uint8 *)maddr);
if (readv == expect)
Expand All @@ -3399,6 +3400,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();

expect = (uint16)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint32)LOAD_U16(maddr);
if (readv == expect)
Expand Down Expand Up @@ -3433,6 +3435,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();

expect = (uint8)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint64)(*(uint8 *)maddr);
if (readv == expect)
Expand All @@ -3443,6 +3446,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();

expect = (uint16)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint64)LOAD_U16(maddr);
if (readv == expect)
Expand All @@ -3453,6 +3457,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();

expect = (uint32)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint64)LOAD_U32(maddr);
if (readv == expect)
Expand Down
5 changes: 5 additions & 0 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3308,6 +3308,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(1);

expect = (uint8)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint32)(*(uint8 *)maddr);
if (readv == expect)
Expand All @@ -3318,6 +3319,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(2);

expect = (uint16)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint32)LOAD_U16(maddr);
if (readv == expect)
Expand Down Expand Up @@ -3352,6 +3354,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(1);

expect = (uint8)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint64)(*(uint8 *)maddr);
if (readv == expect)
Expand All @@ -3362,6 +3365,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(2);

expect = (uint16)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint64)LOAD_U16(maddr);
if (readv == expect)
Expand All @@ -3372,6 +3376,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS(4);

expect = (uint32)expect;
os_mutex_lock(&memory->mem_lock);
readv = (uint64)LOAD_U32(maddr);
if (readv == expect)
Expand Down
Loading