Skip to content

Commit

Permalink
Update wawaka support for WAMR-03-05-2020 (hyperledger-labs#249)
Browse files Browse the repository at this point in the history
* Update wawaka support for WAMR-03-05-2020

Update the wawaka to support WAMR tag release WAMR-03-05-2020. Several
changes to the build process and to the integration of native functions.
There are still opportunities to take advantage of the parameter passing
for pointers, however I think it best to keep the validation of pointers
that we have.

Must get the correct submodule for WAMR.

Signed-off-by: Mic Bowman <[email protected]>

* Update docker build file for WAMR submodule

Signed-off-by: Marcela Melara <[email protected]>

* Update build/install instructions

Signed-off-by: Marcela Melara <[email protected]>

* More updates to Dockerfiles

Signed-off-by: Marcela Melara <[email protected]>

Co-authored-by: Marcela Melara <[email protected]>
  • Loading branch information
cmickeyb and marcelamelara authored Mar 12, 2020
1 parent 337676a commit dd76c48
Show file tree
Hide file tree
Showing 18 changed files with 335 additions and 320 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "interpreters/wasm-micro-runtime"]
path = interpreters/wasm-micro-runtime
url = https://github.com/bytecodealliance/wasm-micro-runtime.git
2 changes: 1 addition & 1 deletion build/common-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var_set() {
"
env_key_sort[$i]="TINY_SCHEME_SRC"; i=$i+1; export TINY_SCHEME_SRC=${env_val[TINY_SCHEME_SRC]};

env_val[WASM_SRC]="${WASM_SRC:-${PDO_SOURCE_ROOT}/wasm}"
env_val[WASM_SRC]="${WASM_SRC:-${PDO_SOURCE_ROOT}/interpreters/wasm-micro-runtime}"
env_desc[WASM_SRC]="
WASM_SRC points to the installation of the micro-wasm
source in order to build the wasm interpreter
Expand Down
2 changes: 2 additions & 0 deletions common/CMakeVariables.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ if(NOT UNTRUSTED_ONLY)
IF("${SGX_MODE}" STREQUAL "SIM")
SET(TRTS_LIBRARY_NAME "sgx_trts_sim")
SET(URTS_LIBRARY_NAME "sgx_urts_sim")
SET(AE_SERVICE_LIBRARY_NAME "sgx_uae_service_sim")
SET(SERVICE_LIBRARY_NAME "sgx_tservice_sim")
SET(IAS_CA_CERT_REQUIRED_FLAGS "")
ELSE()
SET(TRTS_LIBRARY_NAME "sgx_trts")
SET(URTS_LIBRARY_NAME "sgx_urts")
SET(AE_SERVICE_LIBRARY_NAME "")
SET(SERVICE_LIBRARY_NAME "sgx_tservice")
SET(IAS_CA_CERT_REQUIRED_FLAGS "-DIAS_CA_CERT_REQUIRED")
ENDIF()
Expand Down
179 changes: 98 additions & 81 deletions common/interpreter/wawaka_wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,50 @@ ENDIF()

SET(WASM_SRC "$ENV{WASM_SRC}")

# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

# Set WAMR_BUILD_TARGET
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
endif ()
endif ()

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

if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()

if (NOT DEFINED WAMR_BUILD_AOT)
# Disable AOT by default.
set (WAMR_BUILD_AOT 0)
endif ()

if (NOT DEFINED WAMR_BUILD_JIT)
# Disable JIT by default.
set (WAMR_BUILD_JIT 0)
endif ()

if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
# Enable libc builtin support by default
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()

if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
# Disable libc wasi support by default
set (WAMR_BUILD_LIBC_WASI 0)
endif ()

SET(PDO_INCLUDE_DIRS ".")
LIST(APPEND PDO_INCLUDE_DIRS "${PDO_TOP_DIR}/common")
LIST(APPEND PDO_INCLUDE_DIRS "${PDO_TOP_DIR}/common/crypto")
Expand All @@ -36,96 +80,70 @@ LIST(APPEND SGX_INCLUDE_DIRS "${SGX_SDK}/include/tlibc")
LIST(APPEND SGX_INCLUDE_DIRS "${SGX_SDK}/include/libcxx")

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

SET(IWASM_STATIC_NAME iwasm)
SET(WAWAKA_STATIC_NAME wwasm)
PROJECT(wawaka_wasm C CXX)

SET(PLATFORM "linux-sgx")

SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

ADD_DEFINITIONS(-DUSE_SGX=1)
ADD_DEFINITIONS(-DOPS_INPUT_OUTPUT=1)
ADD_DEFINITIONS(-DOPS_UNSAFE_BUFFERS=1)
ADD_DEFINITIONS(-DWASM_ENABLE_LOG=0)
ADD_DEFINITIONS(-Dbh_printf=bh_printf_sgx)
ADD_DEFINITIONS(-Dvprintf=bh_vprintf_sgx)

IF (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
ADD_DEFINITIONS(-DNVALGRIND)
ENDIF ()

# Currently build as 64-bit by default.
IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
SET (BUILD_TARGET "X86_64")
ADD_DEFINITIONS(-DBUILD_TARGET_X86_64)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
SET (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
ELSE ()
# Build as X86_32 by default in 32-bit platform
SET (BUILD_TARGET "X86_32")
ADD_DEFINITIONS(-DBUILD_TARGET_X86_32)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
ENDIF ()

IF (NOT DEFINED WASM_ENABLE_WASI)
# Disable wasi support by default
SET (WASM_ENABLE_WASI 0)
ENDIF ()

IF (WASM_ENABLE_WASI EQUAL 1)
ADD_DEFINITIONS(-DWASM_ENABLE_WASI=1)
ADD_DEFINITIONS(-D_GNU_SOURCE)
MESSAGE ("-- WASI enabled")
ELSE ()
MESSAGE ("-- WASI disabled")
ENDIF ()

IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release)
ENDIF (NOT CMAKE_BUILD_TYPE)

SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -fvisibility=hidden -fpie")

SET(WASM_IWASM_ROOT ${WASM_SRC}/core/iwasm)
SET(WASM_SHARED_LIB_ROOT ${WASM_SRC}/core/shared-lib)

ENABLE_LANGUAGE(ASM)
set (WAMR_BUILD_PLATFORM "linux-sgx")

#################################################################
# Pull in all the WASM makefiles
#################################################################
INCLUDE(${WASM_IWASM_ROOT}/runtime/platform/${PLATFORM}/platform.cmake)
INCLUDE(${WASM_IWASM_ROOT}/runtime/utils/utils.cmake)
INCLUDE(${WASM_IWASM_ROOT}/runtime/vmcore-wasm/vmcore.cmake)
INCLUDE(${WASM_IWASM_ROOT}/lib/native/libc/wasmtime-wasi-c/wasi.cmake)
INCLUDE(${WASM_IWASM_ROOT}/lib/native/libc/wasm_libc.cmake)
INCLUDE(${WASM_SHARED_LIB_ROOT}/platform/${PLATFORM}/shared_platform.cmake)
INCLUDE(${WASM_SHARED_LIB_ROOT}/mem-alloc/mem_alloc.cmake)
INCLUDE(${WASM_SHARED_LIB_ROOT}/utils/shared_utils.cmake)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \
-Wall -Wno-unused-parameter -Wno-pedantic \
-nostdinc -fvisibility=hidden -fpie" )

set (WAMR_ROOT_DIR ${WASM_SRC})
set (SHARED_DIR ${WAMR_ROOT_DIR}/core/shared)
set (IWASM_DIR ${WAMR_ROOT_DIR}/core/iwasm)
set (APP_FRAMEWORK_DIR ${WAMR_ROOT_DIR}/core/app-framework)

enable_language (ASM)

#################################################################
# MicroWasm Library
# WAMR Library
#################################################################
ADD_LIBRARY(${IWASM_STATIC_NAME}
${WASM_PLATFORM_LIB_SOURCE}
${WASM_UTILS_LIB_SOURCE}
${VMCORE_LIB_SOURCE}
${WASM_IWASM_ROOT}/lib/native/base/base_lib_export.c
${WASM_LIBC_SOURCE}

# include the build config template file
include (${WAMR_ROOT_DIR}/build-scripts/config_common.cmake)

include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
include (${SHARED_DIR}/utils/shared_utils.cmake)
if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
include (${IWASM_DIR}/libraries/libc-builtin/libc_builtin.cmake)
endif ()
if (WAMR_BUILD_LIBC_WASI EQUAL 1)
include (${IWASM_DIR}/libraries/libc-wasi/libc_wasi.cmake)
endif ()

include (${IWASM_DIR}/common/iwasm_common.cmake)

if (WAMR_BUILD_INTERP EQUAL 1 OR WAMR_BUILD_JIT EQUAL 1)
include (${IWASM_DIR}/interpreter/iwasm_interp.cmake)
endif ()

if (WAMR_BUILD_AOT EQUAL 1)
include (${IWASM_DIR}/aot/iwasm_aot.cmake)
if (WAMR_BUILD_JIT EQUAL 1)
include (${IWASM_DIR}/compilation/iwasm_compl.cmake)
endif ()
endif ()

add_library (${IWASM_STATIC_NAME}
${PLATFORM_SHARED_SOURCE}
${MEM_ALLOC_SHARED_SOURCE})
${MEM_ALLOC_SHARED_SOURCE}
${UTILS_SHARED_SOURCE}
${LIBC_BUILTIN_SOURCE}
${LIBC_WASI_SOURCE}
${IWASM_COMMON_SOURCE}
${IWASM_INTERP_SOURCE}
${IWASM_AOT_SOURCE}
${IWASM_COMPL_SOURCE})

TARGET_INCLUDE_DIRECTORIES(${IWASM_STATIC_NAME} PRIVATE ".")

TARGET_INCLUDE_DIRECTORIES(${IWASM_STATIC_NAME} PUBLIC ${WASM_IWASM_ROOT}/runtime/include)
TARGET_INCLUDE_DIRECTORIES(${IWASM_STATIC_NAME} PUBLIC ${WASM_IWASM_ROOT}/runtime/platform/include)
TARGET_INCLUDE_DIRECTORIES(${IWASM_STATIC_NAME} PUBLIC ${WASM_SHARED_LIB_ROOT}/include)
TARGET_INCLUDE_DIRECTORIES(${IWASM_STATIC_NAME} PUBLIC ${SHARED_DIR}/include)
TARGET_INCLUDE_DIRECTORIES(${IWASM_STATIC_NAME} PUBLIC ${IWASM_DIR}/include)

TARGET_INCLUDE_DIRECTORIES(${IWASM_STATIC_NAME} PUBLIC ${SGX_INCLUDE_DIRS})

Expand All @@ -144,9 +162,8 @@ ADD_LIBRARY(${WAWAKA_STATIC_NAME}
TARGET_INCLUDE_DIRECTORIES(${WAWAKA_STATIC_NAME} PRIVATE ".")
TARGET_INCLUDE_DIRECTORIES(${WAWAKA_STATIC_NAME} PRIVATE ${PDO_INCLUDE_DIRS})

TARGET_INCLUDE_DIRECTORIES(${WAWAKA_STATIC_NAME} PUBLIC ${WASM_IWASM_ROOT}/runtime/include)
TARGET_INCLUDE_DIRECTORIES(${WAWAKA_STATIC_NAME} PUBLIC ${WASM_IWASM_ROOT}/runtime/platform/include)
TARGET_INCLUDE_DIRECTORIES(${WAWAKA_STATIC_NAME} PUBLIC ${WASM_SHARED_LIB_ROOT}/include)
TARGET_INCLUDE_DIRECTORIES(${WAWAKA_STATIC_NAME} PUBLIC ${IWASM_DIR}/include)
TARGET_INCLUDE_DIRECTORIES(${WAWAKA_STATIC_NAME} PUBLIC ${SHARED_DIR}/include)

TARGET_INCLUDE_DIRECTORIES(${WAWAKA_STATIC_NAME} PUBLIC ${SGX_INCLUDE_DIRS})
TARGET_INCLUDE_DIRECTORIES(${WAWAKA_STATIC_NAME} PUBLIC "${SGX_SSL}/include")
Expand Down
27 changes: 16 additions & 11 deletions common/interpreter/wawaka_wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ The Wawaka interpreter is not built by default. To build a contract
enclave with Wawaka enabled, you will need to do the following:

* Install and configure [emscripten](https://emscripten.org/)
* Clone the WAMR source code
* Set the `WASM_SRC` environment variable to the directory where you cloned WAMR
* Pull the WAMR submodule (if the repo was not cloned with the `--recurse-submodules` flag)
* Set the `PDO_INTERPRETER` environment variable to `wawaka`

### Install emscripten ###
Expand All @@ -43,22 +42,30 @@ cd ${PDO_SOURCE_ROOT}/emsdk
source ./emsdk_env.sh
```

### Clone the WAMR source ###
### WAMR setup ###

If wawaka is configured as the contract interpreter, the libraries implementing the WASM interpreter
will be built for use with Intel SGX. The source for the WAMR interpreter is distributed separately and must be downloaded.
will be built for use with Intel SGX. The source for the WAMR interpreter is
included as a submodule in the interpreters/ folder, and will
always point to the latest tagged commit that we have validated: `WAMR-03-05-2020`.
If the PDO parent repo was not cloned with the `--recurse-submodules` flag,
you will have to explictly pull the submodule source.

```bash
cd ${PDO_SOURCE_ROOT}
git clone --branch tag-11-28-2019 https://github.com/intel/wasm-micro-runtime.git wasm
```
cd ${PDO_SOURCE_ROOT}/interpreters/wasm-micro-runtime
git submodule update --init
git checkout WAMR-03-05-2020 # optional
```

The WAMR API is built during the Wawaka build, so no additional
build steps are required to set up WAMR.

### Set the environment variables ###

By default, PDO will be built with the Gipsy Scheme contract interpreter. To use the experimental wawaka interpreter, set the environment variables `WASM_SRC` (the directory where you downloaded the WAMR source) and `PDO_INTERPRETER` (the name of the contract interpreter to use.
By default, PDO will be built with the Gipsy Scheme contract interpreter. To use the experimental wawaka interpreter, set the environment variables `WASM_SRC` (default is the submodule directory with the WAMR source) and `PDO_INTERPRETER` (the name of the contract interpreter to use.

```bash
export WASM_SRC=${PDO_SOURCE_ROOT}/wasm
export WASM_SRC=${PDO_SOURCE_ROOT}/interpreters/wasm-micro-runtime
export PDO_INTERPRETER=wawaka
```

Expand All @@ -85,5 +92,3 @@ pdo-test-contract --no-ledger --interpreter wawaka --contract mock-contract \
## Basics of a Contract ##

Note that compilation into WASM that will run in the contract enclave can be somewhat tricky. Specifically, all symbols whether used or not must be bound. The wawaka interpreter will fail if it attempts to load WASM code with unbound symbols.

It may be easiest to copy the
Loading

0 comments on commit dd76c48

Please sign in to comment.