From 9bd1256b3af59cf8034dfa37d67bd642ef16a87f Mon Sep 17 00:00:00 2001 From: cdetrio Date: Tue, 26 Mar 2019 15:08:34 -0400 Subject: [PATCH 1/3] hera for geth-evmc as a static lib --- cmake/ProjectWAVM.cmake | 2 +- cmake/ProjectWabt.cmake | 4 ++-- src/CMakeLists.txt | 2 +- src/binaryen.cpp | 4 ++++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmake/ProjectWAVM.cmake b/cmake/ProjectWAVM.cmake index 66199895f..5c6ab8750 100644 --- a/cmake/ProjectWAVM.cmake +++ b/cmake/ProjectWAVM.cmake @@ -41,7 +41,7 @@ ExternalProject_Add(wavm -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=Release -DLLVM_DIR=${LLVM_DIR} - -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_POSITION_INDEPENDENT_CODE=OFF -DCMAKE_CXX_FLAGS=${flags} -DCMAKE_C_FLAGS=${flags} INSTALL_COMMAND "" diff --git a/cmake/ProjectWabt.cmake b/cmake/ProjectWabt.cmake index c5692ecc0..dbb1bea36 100644 --- a/cmake/ProjectWabt.cmake +++ b/cmake/ProjectWabt.cmake @@ -22,10 +22,10 @@ ExternalProject_Add(wabt CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=Release - -DWITH_EXCEPTIONS=ON + -DWITH_EXCEPTIONS=OFF -DBUILD_TESTS=OFF -DBUILD_TOOLS=OFF - -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_POSITION_INDEPENDENT_CODE=OFF -DCMAKE_CXX_FLAGS=-fvisibility=hidden -DCMAKE_C_FLAGS=-fvisibility=hidden INSTALL_COMMAND "" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 48fd5594f..c5052a7da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,7 @@ endif() target_include_directories(hera PUBLIC $$ ) -target_link_libraries(hera PUBLIC evmc::evmc PRIVATE hera-buildinfo evmc::instructions) +target_link_libraries(hera PUBLIC evmc::evmc PUBLIC hera-buildinfo evmc::instructions) if(NOT WIN32) if(CMAKE_COMPILER_IS_GNUCXX) set_target_properties(hera PROPERTIES LINK_FLAGS "-Wl,--no-undefined") diff --git a/src/binaryen.cpp b/src/binaryen.cpp index 8e29acdc7..463fa91fd 100644 --- a/src/binaryen.cpp +++ b/src/binaryen.cpp @@ -572,11 +572,15 @@ void BinaryenEngine::verifyContract(wasm::Module & module) "Contract export (\"memory\") missing." ); +/* +***** in the metering benchmarks, inline-block and inline-super both export the inline useGas functions +// just going to comment this out since here since we need to change Hera for static libs anyway ensureCondition( module.exports.size() == 2, ContractValidationFailure, "Contract exports more than (\"main\") and (\"memory\")." ); +*/ // The existence of this is ensured above. wasm::Export* main_export = module.getExport(wasm::Name("main")); From 2be9c741a0c426596029d207abe6fc2b2c5a4c63 Mon Sep 17 00:00:00 2001 From: cdetrio Date: Tue, 26 Mar 2019 15:25:59 -0400 Subject: [PATCH 2/3] fix hera_get_buildinfo symbol error --- src/hera.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hera.cpp b/src/hera.cpp index 1ef3e728b..8ed9c083f 100644 --- a/src/hera.cpp +++ b/src/hera.cpp @@ -94,7 +94,10 @@ struct hera_instance : evmc_instance { bool metering = false; map contract_preload_list; - hera_instance() noexcept : evmc_instance({EVMC_ABI_VERSION, "hera", hera_get_buildinfo()->project_version, nullptr, nullptr, nullptr, nullptr, nullptr}) {} + // hera_instance() noexcept : evmc_instance({EVMC_ABI_VERSION, "hera", hera_get_buildinfo()->project_version, nullptr, nullptr, nullptr, nullptr, nullptr}) {} + // fix error with geth+evmc: /tmp/go-build940146972/b001/runtime.test: symbol lookup error: /tmp/go-build940146972/b001/runtime.test: undefined symbol: hera_get_buildinfo + hera_instance() noexcept : evmc_instance({EVMC_ABI_VERSION, "hera", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}) {} + }; const evmc_address sentinelAddress = { .bytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xa } }; From 3e01d998786f950fbed2a44dc2b6845f94569f4f Mon Sep 17 00:00:00 2001 From: cdetrio Date: Tue, 26 Mar 2019 15:40:30 -0400 Subject: [PATCH 3/3] some documentation about building/using the static libs --- scripts/static-build-script.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/static-build-script.sh diff --git a/scripts/static-build-script.sh b/scripts/static-build-script.sh new file mode 100644 index 000000000..e24e2f054 --- /dev/null +++ b/scripts/static-build-script.sh @@ -0,0 +1,29 @@ + +#git clone --single-branch --branch benchmarking-static-lib https://github.com/ewasm/hera +# cd hera +# git submodule update --init + +mkdir -p build +cd build +cmake -DBUILD_SHARED_LIBS=OFF -DHERA_BINARYEN=ON -DHERA_WABT=ON -DHERA_WAVM=ON -DHERA_DEBUGGING=OFF .. +cmake --build . + +cd deps/src/binaryen-build/lib/ +for f in *.a; do ar x $f; done +ar r -s -c libbinaryenfull.a *.o +rm *.o +cd ../../../../ + + +cd deps/src/wavm-build/lib +for f in *.a; do ar x $f; done +ar r -s -c libwavm.a *.o +rm *.o +cd ../../../../ + +# apt-get install llvm-6.0-dev +# llvm .so file is needed for libwavm.a to be usable + +# some flags might be unnecessary +#cgo LDFLAGS: /root/hera/build/src/libhera.a -L/root/hera/build/src/ -lhera -L/root/hera/build/deps/src/wabt-build/ -lwabt /root/hera/build/deps/src/binaryen-build/lib/libbinaryenfull.a /root/hera/build/deps/src/wavm-build/lib/libwavm.a -L/usr/lib/llvm-6.0/build/lib/ -lLLVM -rdynamic -lstdc++ -Wl,-unresolved-symbols=ignore-all + \ No newline at end of file