diff --git a/circle.yml b/circle.yml index 6aff27301..4c7a4f5e1 100644 --- a/circle.yml +++ b/circle.yml @@ -154,7 +154,7 @@ defaults: run: name: "Test shared Hera (wavm)" command: | - export ASAN_OPTIONS=detect_leaks=0 + export ASAN_OPTIONS=detect_leaks=1 SO=$([ $(uname) = Darwin ] && echo dylib || echo so) if [[ $PRELOAD_ASAN ]]; then export LD_PRELOAD=/usr/lib/clang/8/lib/linux/libclang_rt.asan-x86_64.so; fi testeth --version diff --git a/cmake/ProjectWAVM.cmake b/cmake/ProjectWAVM.cmake index 66199895f..0d3319c84 100644 --- a/cmake/ProjectWAVM.cmake +++ b/cmake/ProjectWAVM.cmake @@ -11,16 +11,16 @@ llvm_map_components_to_libnames(llvm_libs support core passes mcjit native Debug set(prefix ${CMAKE_BINARY_DIR}/deps) set(source_dir ${prefix}/src/wavm) -set(binary_dir ${prefix}/src/wavm-build) -set(include_dir ${source_dir}/Include) +set(binary_dir ${prefix}/lib/WAVM) +set(include_dir ${prefix}/include) -set(runtime_library ${binary_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}Runtime${CMAKE_STATIC_LIBRARY_SUFFIX}) -set(platform_library ${binary_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}Platform${CMAKE_STATIC_LIBRARY_SUFFIX}) -set(wasm_library ${binary_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}WASM${CMAKE_STATIC_LIBRARY_SUFFIX}) -set(ir_library ${binary_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}IR${CMAKE_STATIC_LIBRARY_SUFFIX}) -set(logging_library ${binary_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}Logging${CMAKE_STATIC_LIBRARY_SUFFIX}) -set(unwind_library ${binary_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}WAVMUnwind${CMAKE_STATIC_LIBRARY_SUFFIX}) -set(llvmjit_library ${binary_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}LLVMJIT${CMAKE_STATIC_LIBRARY_SUFFIX}) +set(runtime_library ${binary_dir}/Release/${CMAKE_STATIC_LIBRARY_PREFIX}Runtime${CMAKE_STATIC_LIBRARY_SUFFIX}) +set(platform_library ${binary_dir}/Release/${CMAKE_STATIC_LIBRARY_PREFIX}Platform${CMAKE_STATIC_LIBRARY_SUFFIX}) +set(wasm_library ${binary_dir}/Release/${CMAKE_STATIC_LIBRARY_PREFIX}WASM${CMAKE_STATIC_LIBRARY_SUFFIX}) +set(ir_library ${binary_dir}/Release/${CMAKE_STATIC_LIBRARY_PREFIX}IR${CMAKE_STATIC_LIBRARY_SUFFIX}) +set(logging_library ${binary_dir}/Release/${CMAKE_STATIC_LIBRARY_PREFIX}Logging${CMAKE_STATIC_LIBRARY_SUFFIX}) +set(unwind_library ${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}WAVMUnwind${CMAKE_STATIC_LIBRARY_SUFFIX}) +set(llvmjit_library ${binary_dir}/Release/${CMAKE_STATIC_LIBRARY_PREFIX}LLVMJIT${CMAKE_STATIC_LIBRARY_SUFFIX}) set(other_libraries ${platform_library} ${wasm_library} ${ir_library} ${logging_library} ${unwind_library} ${llvmjit_library}) @@ -28,12 +28,12 @@ set(flags "-Wno-error -fvisibility=hidden") ExternalProject_Add(wavm PREFIX ${prefix} - DOWNLOAD_NAME wavm-a0baaec170b55cc60cfe6bcc6b36add953a065d8.tar.gz + DOWNLOAD_NAME wavm-c1d2ba945edcc9d87e9fc0044777ab1850a1c2a6.tar.gz DOWNLOAD_DIR ${prefix}/downloads SOURCE_DIR ${source_dir} BINARY_DIR ${binary_dir} - URL https://github.com/AndrewScheidecker/WAVM/archive/fa5434e03efbc2154ecf4aafede169da76a4da40.tar.gz - URL_HASH SHA256=1a380461ca6570b39d548dcedfacb3c105769d5d5957e85674253250f585c07d + URL https://github.com/WAVM/WAVM/archive/c1d2ba945edcc9d87e9fc0044777ab1850a1c2a6.tar.gz + URL_HASH SHA256=ff1ecb896e6bc5a4e0835ff5b7a490c46cb7032e03f8cbdb26803f3ab6e5db00 PATCH_COMMAND sh ${CMAKE_CURRENT_LIST_DIR}/patch_wavm.sh CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} @@ -44,7 +44,9 @@ ExternalProject_Add(wavm -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CXX_FLAGS=${flags} -DCMAKE_C_FLAGS=${flags} - INSTALL_COMMAND "" + -DWAVM_ENABLE_RUNTIME=ON + -DWAVM_ENABLE_STATIC_LINKING=ON + INSTALL_COMMAND cmake --build --config Release --target install BUILD_BYPRODUCTS ${runtime_library} ${other_libraries} ) diff --git a/cmake/patch_wavm.sh b/cmake/patch_wavm.sh index 73a9f1652..9997c8ffb 100644 --- a/cmake/patch_wavm.sh +++ b/cmake/patch_wavm.sh @@ -1,4 +1,3 @@ #!/bin/sh -sed -iE 's/SHARED//' CMakeLists.txt sed -iE 's/-Werror//' CMakeLists.txt diff --git a/src/wavm.cpp b/src/wavm.cpp index 770548917..9ab266e4b 100644 --- a/src/wavm.cpp +++ b/src/wavm.cpp @@ -22,14 +22,21 @@ #include "wavm.h" -#define DLL_IMPORT // Needed by wavm on some platforms -#include "Inline/Serialization.h" -#include "IR/Module.h" -#include "IR/Validate.h" -#include "Runtime/Intrinsics.h" -#include "Runtime/Linker.h" -#include "Runtime/Runtime.h" -#include "WASM/WASM.h" +// Needed by wavm on some platforms +#define IR_API +#define RUNTIME_API +#define LOGGING_API +#define WASM_API +#define PLATFORM_API +#define DLL_IMPORT + +#include +#include +#include +#include +#include +#include +#include #include "debugging.h" #include "eei.h" @@ -39,6 +46,7 @@ #pragma GCC diagnostic ignored "-Wunused-variable" using namespace std; +using namespace WAVM; namespace hera { @@ -54,7 +62,7 @@ class WavmEthereumInterface : public EthereumInterface { EthereumInterface(_context, _code, _msg, _result, _meterGas) {} - void setWasmMemory(Runtime::MemoryInstance* _wasmMemory) { + void setWasmMemory(Runtime::Memory* _wasmMemory) { m_wasmMemory = _wasmMemory; } @@ -64,7 +72,7 @@ class WavmEthereumInterface : public EthereumInterface { void memorySet(size_t offset, uint8_t value) override { (Runtime::memoryArrayPtr(m_wasmMemory, offset, 1))[0] = value; } uint8_t memoryGet(size_t offset) override { return (Runtime::memoryArrayPtr(m_wasmMemory, offset, 1))[0]; } - Runtime::MemoryInstance* m_wasmMemory; + Runtime::Memory* m_wasmMemory; }; unique_ptr WavmEngine::create() @@ -252,7 +260,7 @@ namespace wavm_host_module { bool resolve( const string& moduleName, const string& exportName, - IR::ObjectType type, + IR::ExternType type, Runtime::Object*& outObject ) override { @@ -288,12 +296,14 @@ ExecutionResult WavmEngine::execute( instantiationStarted(); ExecutionResult result = internalExecute(context, code, state_code, msg, meterInterfaceGas); // And clean up mess left by this run. - Runtime::collectGarbage(); + // TODO: enable this. + // Runtime::collectCompartmentGarbage(compartment); executionFinished(); return result; } catch (exception const&) { // And clean up mess left by this run. - Runtime::collectGarbage(); + // TODO: enable this. + // Runtime::collectCompartmentGarbage(compartment); // We only catch this exception here in order to clean up garbage.. // TODO: hopefully WAVM is fixed so that this isn't needed throw; @@ -353,8 +363,7 @@ ExecutionResult WavmEngine::internalExecute( ensureCondition(linkResult.success, ContractValidationFailure, "Couldn't link contract against host module."); // compile the module from IR to LLVM bitcode - Runtime::GCPointer module = Runtime::compileModule(moduleIR); - heraAssert(module, "Couldn't compile IR to bitcode."); + Runtime::ModuleRef module = Runtime::compileModule(moduleIR); // instantiate contract module Runtime::GCPointer moduleInstance = Runtime::instantiateModule(compartment, module, move(linkResult.resolvedImports), ""); @@ -372,7 +381,7 @@ ExecutionResult WavmEngine::internalExecute( wavm_host_module::interface.top()->setWasmMemory(memory); // invoke the main function - Runtime::GCPointer mainFunction = asFunctionNullable(Runtime::getInstanceExport(moduleInstance, "main")); + Runtime::GCPointer mainFunction = asFunctionNullable(Runtime::getInstanceExport(moduleInstance, "main")); ensureCondition(mainFunction, ContractValidationFailure, "\"main\" not found"); executionStarted(); diff --git a/src/wavm.h b/src/wavm.h index 7295e3a87..259ddf056 100644 --- a/src/wavm.h +++ b/src/wavm.h @@ -19,9 +19,11 @@ #include "eei.h" +namespace WAVM { namespace IR { class Module; } +} namespace hera { @@ -49,7 +51,7 @@ class WavmEngine : public WasmEngine { bool meterInterfaceGas ); - IR::Module parseModule(bytes_view code); + WAVM::IR::Module parseModule(bytes_view code); }; } // namespace hera