From bb2217c65f42b9dc43e7a825df1922f3e397397f Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Mon, 26 Feb 2018 16:46:40 -0500 Subject: [PATCH] Use eosio binaryen fork as a submodule --- .gitmodules | 3 +++ CMakeLists.txt | 2 ++ CMakeModules/wasm.cmake | 31 ++------------------- eosio_build.sh | 4 +-- externals/binaryen | 1 + scripts/eosio_build_amazon.sh | 21 --------------- scripts/eosio_build_darwin.sh | 20 -------------- scripts/eosio_build_fedora.sh | 21 --------------- scripts/eosio_build_ubuntu.sh | 21 --------------- tests/chain_tests/proof_tests.cpp | 45 +++++++++++++++++++++++++++++++ tools/eosiocpp.in | 4 +-- 11 files changed, 56 insertions(+), 117 deletions(-) create mode 160000 externals/binaryen diff --git a/.gitmodules b/.gitmodules index daa6a58c2dc..e25104d077a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -17,3 +17,6 @@ path = contracts/libc++/upstream url = https://github.com/EOSIO/libcxx.git branch = eosio +[submodule "externals/binaryen"] + path = externals/binaryen + url = https://github.com/EOSIO/binaryen diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bde96a85f2..2e8a7dc75e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,6 +164,8 @@ if(ENABLE_COVERAGE_TESTING) find_program( GENHTML_PATH NAMES genhtml) endif() +add_subdirectory( externals ) + include(wasm) if(WASM_TOOLCHAIN) message(STATUS "Using WASM clang => " ${WASM_CLANG}) diff --git a/CMakeModules/wasm.cmake b/CMakeModules/wasm.cmake index 464d1748066..337ad37b367 100644 --- a/CMakeModules/wasm.cmake +++ b/CMakeModules/wasm.cmake @@ -26,35 +26,8 @@ else() set(WASM_LLVM_LINK $ENV{WASM_LLVM_LINK}) endif() -if( NOT ("${WASM_CLANG}" STREQUAL "" OR "${WASM_LLC}" STREQUAL "" OR "${WASM_LLVM_LINK}" STREQUAL "") ) - if( NOT "${BINARYEN_ROOT}" STREQUAL "" ) - - if(EXISTS "${BINARYEN_ROOT}/bin/s2wasm") - - set(BINARYEN_BIN ${BINARYEN_ROOT}/bin) - - endif() - - else() - - message(STATUS "BINARYEN_BIN not defined looking in PATH") - find_path(BINARYEN_BIN - NAMES s2wasm - ENV PATH ) - if (BINARYEN_BIN AND NOT EXISTS ${BINARYEN_ROOT}/s2wasm) - - unset(BINARYEN_BIN) - - endif() - - endif() - - message(STATUS "BINARYEN_BIN => " ${BINARYEN_BIN}) - -endif() - # TODO: Check if compiler is able to generate wasm32 -if( NOT ("${WASM_CLANG}" STREQUAL "" OR "${WASM_LLC}" STREQUAL "" OR "${WASM_LLVM_LINK}" STREQUAL "" OR NOT BINARYEN_BIN) ) +if( NOT ("${WASM_CLANG}" STREQUAL "" OR "${WASM_LLC}" STREQUAL "" OR "${WASM_LLVM_LINK}" STREQUAL "") ) set(WASM_TOOLCHAIN TRUE) endif() @@ -199,7 +172,7 @@ macro(add_wast_executable) add_custom_command(OUTPUT ${DESTINATION_FOLDER}/${target}.wast DEPENDS ${target}.s - COMMAND ${BINARYEN_BIN}/s2wasm -o ${DESTINATION_FOLDER}/${target}.wast -s 4096 ${MAX_MEMORY_PARAM} ${target}.s + COMMAND $ -o ${DESTINATION_FOLDER}/${target}.wast -s 4096 ${MAX_MEMORY_PARAM} ${target}.s COMMENT "Generating WAST ${target}.wast" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM diff --git a/eosio_build.sh b/eosio_build.sh index 8c62bbaea5c..e0406cd6fdc 100755 --- a/eosio_build.sh +++ b/eosio_build.sh @@ -81,7 +81,6 @@ esac export BOOST_ROOT=${HOME}/opt/boost_1_66_0 - export BINARYEN_BIN=${HOME}/opt/binaryen/bin export OPENSSL_ROOT_DIR=/usr/include/openssl export OPENSSL_LIBRARIES=/usr/include/openssl export WASM_LLVM_CONFIG=${HOME}/opt/wasm/bin/llvm-config @@ -93,7 +92,6 @@ if [ $ARCH == "Darwin" ]; then OPENSSL_ROOT_DIR=/usr/local/opt/openssl OPENSSL_LIBRARIES=/usr/local/opt/openssl/lib - BINARYEN_BIN=/usr/local/binaryen/bin/ WASM_LLVM_CONFIG=/usr/local/wasm/bin/llvm-config CXX_COMPILER=clang++ C_COMPILER=clang @@ -122,7 +120,7 @@ # Build EOS $CMAKE -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \ -DCMAKE_C_COMPILER=${C_COMPILER} -DWASM_LLVM_CONFIG=${WASM_LLVM_CONFIG} \ - -DBINARYEN_BIN=${BINARYEN_BIN} -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} \ + -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} \ -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES} .. if [ $? -ne 0 ]; then printf "\n\t>>>>>>>>>>>>>>>>>>>> CMAKE building EOSIO has exited with the above error.\n\n" diff --git a/externals/binaryen b/externals/binaryen new file mode 160000 index 00000000000..0b980a9e877 --- /dev/null +++ b/externals/binaryen @@ -0,0 +1 @@ +Subproject commit 0b980a9e87740db4d657ee38b2668da35752264e diff --git a/scripts/eosio_build_amazon.sh b/scripts/eosio_build_amazon.sh index b2e51cfba02..efa49cf05e2 100644 --- a/scripts/eosio_build_amazon.sh +++ b/scripts/eosio_build_amazon.sh @@ -172,27 +172,6 @@ printf "\tsecp256k1 found\n" fi - printf "\n\tChecking for binaryen\n" - if [ ! -d ${HOME}/opt/binaryen ]; then - # Install binaryen v1.37.14: - printf "\tInstalling binaryen v1.37.14:\n" - cd ${TEMP_DIR} - git clone https://github.com/WebAssembly/binaryen - cd binaryen - git checkout tags/1.37.14 - $CMAKE . && make -j${CPU_CORE} - if [ $? -ne 0 ]; then - printf "\tError compiling binaryen.\n" - printf "\tExiting now.\n\n" - exit; - fi - mkdir -p ${HOME}/opt/binaryen/ 2>/dev/null - mv ${TEMP_DIR}/binaryen/bin ${HOME}/opt/binaryen/ - rm -rf ${TEMP_DIR}/binaryen - else - printf "\tBinaryen found at ${HOME}/opt/binaryen\n" - fi - printf "\n\tChecking for LLVM with WASM support.\n" if [ ! -d ${HOME}/opt/wasm/bin ]; then # Build LLVM and clang with EXPERIMENTAL WASM support: diff --git a/scripts/eosio_build_darwin.sh b/scripts/eosio_build_darwin.sh index 5242462687b..ab253023ed2 100644 --- a/scripts/eosio_build_darwin.sh +++ b/scripts/eosio_build_darwin.sh @@ -181,26 +181,6 @@ printf "\tsecp256k1 found at /usr/local/lib/\n" fi - printf "\n\tChecking for binaryen\n" - if [ ! -e /usr/local/binaryen/bin/binaryen.js ]; then - cd ${TEMP_DIR} - git clone https://github.com/WebAssembly/binaryen - cd binaryen - git checkout tags/1.37.14 - cmake . && make -j${CPU_CORE} - if [ $? -ne 0 ]; then - printf "\tError compiling binaryen.\n" - printf "\tExiting now.\n\n" - exit; - fi - sudo mkdir /usr/local/binaryen - sudo mv ${TEMP_DIR}/binaryen/bin /usr/local/binaryen - sudo ln -s /usr/local/binaryen/bin/* /usr/local - sudo rm -rf ${TEMP_DIR}/binaryen - else - printf "\tBinaryen found at /usr/local/binaryen/bin/\n" - fi - printf "\n\tChecking for WASM\n" if [ ! -d /usr/local/wasm/bin ]; then # Build LLVM and clang for WASM: diff --git a/scripts/eosio_build_fedora.sh b/scripts/eosio_build_fedora.sh index 94a83e93854..159fb37d34d 100644 --- a/scripts/eosio_build_fedora.sh +++ b/scripts/eosio_build_fedora.sh @@ -145,27 +145,6 @@ printf "\tsecp256k1 found\n" fi - printf "\n\tChecking for binaryen\n" - if [ ! -d ${HOME}/opt/binaryen ]; then - # Install binaryen v1.37.14: - printf "\tInstalling binaryen v1.37.14:\n" - cd ${TEMP_DIR} - git clone https://github.com/WebAssembly/binaryen - cd binaryen - git checkout tags/1.37.14 - cmake . && make -j${CPU_CORE} - if [ $? -ne 0 ]; then - printf "\tError compiling binaryen.\n" - printf "\tExiting now.\n\n" - exit; - fi - mkdir -p ${HOME}/opt/binaryen/ 2>/dev/null - mv ${TEMP_DIR}/binaryen/bin ${HOME}/opt/binaryen/ - rm -rf ${TEMP_DIR}/binaryen - else - printf "\tBinaryen found at ${HOME}/opt/binaryen\n" - fi - printf "\n\tChecking for LLVM with WASM support.\n" if [ ! -d ${HOME}/opt/wasm/bin ]; then # Build LLVM and clang with EXPERIMENTAL WASM support: diff --git a/scripts/eosio_build_ubuntu.sh b/scripts/eosio_build_ubuntu.sh index 6c3926ea26a..c394167d561 100644 --- a/scripts/eosio_build_ubuntu.sh +++ b/scripts/eosio_build_ubuntu.sh @@ -127,27 +127,6 @@ printf "\tsecp256k1 found\n" fi - printf "\n\tChecking for binaryen\n" - if [ ! -d ${HOME}/opt/binaryen ]; then - # Install binaryen v1.37.14: - printf "\tInstalling binaryen v1.37.14:\n" - cd ${TEMP_DIR} - git clone https://github.com/WebAssembly/binaryen - cd binaryen - git checkout tags/1.37.14 - cmake . && make -j${CPU_CORE} - if [ $? -ne 0 ]; then - printf "\tError compiling binaryen.\n" - printf "\tExiting now.\n\n" - exit; - fi - mkdir -p ${HOME}/opt/binaryen/ 2>/dev/null - mv ${TEMP_DIR}/binaryen/bin ${HOME}/opt/binaryen/ - rm -rf ${TEMP_DIR}/binaryen - else - printf "\tBinaryen found at ${HOME}/opt/binaryen\n" - fi - printf "\n\tChecking for LLVM with WASM support.\n" if [ ! -d ${HOME}/opt/wasm/bin ]; then # Build LLVM and clang for WASM: diff --git a/tests/chain_tests/proof_tests.cpp b/tests/chain_tests/proof_tests.cpp index 4f1edaa71be..858320dd949 100644 --- a/tests/chain_tests/proof_tests.cpp +++ b/tests/chain_tests/proof_tests.cpp @@ -118,6 +118,51 @@ bool proof_is_valid(const digest_type& digest, const vector& path, BOOST_AUTO_TEST_SUITE(proof_tests) +static const char poo[] = R"=====( +(module + (table 0 anyfunc) + (memory $0 16) + (export "memory" (memory $0)) + (export "apply" (func $apply)) + + (func $complex_stuff_and_return_a_bool (result i32) + (i32.const 0) + ) + + (func $apply (param $0 i64) (param $1 i64) + (br_if 0 (call $complex_stuff_and_return_a_bool)) + + (drop (i64.mul (i64.const 56) (i64.const 34))) + (drop (i64.mul (i64.const 12) (i64.const 55))) + (drop (i64.mul (i64.const 536) (i64.const 2333))) + (drop (i64.mul (i64.const 23) (i64.const 12))) + (drop (i64.mul (i64.const 543) (i64.const 76533))) + ) +) +)====="; + +BOOST_FIXTURE_TEST_CASE( big_memory, tester ) try { + produce_blocks(2); + + create_accounts( {N(bigmem)} ); + produce_block(); + + set_code(N(bigmem), poo); + produce_blocks(1); + + signed_transaction trx; + action act; + act.account = N(bigmem); + act.name = N(); + act.authorization = vector{{N(bigmem),config::active_name}}; + trx.actions.push_back(act); + + set_tapos(trx); + trx.sign(get_private_key( N(bigmem), "active" ), chain_id_type()); + push_transaction(trx); + +} FC_LOG_AND_RETHROW() + BOOST_FIXTURE_TEST_CASE( prove_block_in_chain, tester ) { try { vector known_blocks; known_blocks.reserve(100); diff --git a/tools/eosiocpp.in b/tools/eosiocpp.in index 4664ecfc0fd..8a55ed0c034 100755 --- a/tools/eosiocpp.in +++ b/tools/eosiocpp.in @@ -40,8 +40,8 @@ function build_contract { @WASM_LLVM_LINK@ -o $workdir/linked.bc $workdir/built/* # echo @WASM_LLC@ --asm-verbose=false -o $workdir/assembly.s $workdir/linked.bc @WASM_LLC@ --asm-verbose=false -o $workdir/assembly.s $workdir/linked.bc -# echo @BINARYEN_BIN@/s2wasm -o $outname -s 16384 $workdir/assembly.s - @BINARYEN_BIN@/s2wasm -o $outname -s 16384 $workdir/assembly.s +# echo ${EOSIO_INSTALL_DIR}/bin/eosio-s2wasm -o $outname -s 16384 $workdir/assembly.s + ${EOSIO_INSTALL_DIR}/bin/eosio-s2wasm -o $outname -s 16384 $workdir/assembly.s # echo rm -rf $workdir rm -rf $workdir