Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update WAVM to 7th Feb 2019 #493

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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 circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions cmake/ProjectWAVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ 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})

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}
Expand All @@ -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 <BINARY_DIR> --config Release --target install
BUILD_BYPRODUCTS ${runtime_library} ${other_libraries}
)

Expand Down
1 change: 0 additions & 1 deletion cmake/patch_wavm.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh

sed -iE 's/SHARED//' CMakeLists.txt
sed -iE 's/-Werror//' CMakeLists.txt
41 changes: 25 additions & 16 deletions src/wavm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <WAVM/Inline/Serialization.h>
#include <WAVM/IR/Module.h>
#include <WAVM/IR/Validate.h>
#include <WAVM/Runtime/Intrinsics.h>
#include <WAVM/Runtime/Linker.h>
#include <WAVM/Runtime/Runtime.h>
#include <WAVM/WASM/WASM.h>

#include "debugging.h"
#include "eei.h"
Expand All @@ -39,6 +46,7 @@
#pragma GCC diagnostic ignored "-Wunused-variable"

using namespace std;
using namespace WAVM;

namespace hera {

Expand All @@ -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;
}

Expand All @@ -64,7 +72,7 @@ class WavmEthereumInterface : public EthereumInterface {
void memorySet(size_t offset, uint8_t value) override { (Runtime::memoryArrayPtr<U8>(m_wasmMemory, offset, 1))[0] = value; }
uint8_t memoryGet(size_t offset) override { return (Runtime::memoryArrayPtr<U8>(m_wasmMemory, offset, 1))[0]; }

Runtime::MemoryInstance* m_wasmMemory;
Runtime::Memory* m_wasmMemory;
};

unique_ptr<WasmEngine> WavmEngine::create()
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Runtime::Module> module = Runtime::compileModule(moduleIR);
heraAssert(module, "Couldn't compile IR to bitcode.");
Runtime::ModuleRef module = Runtime::compileModule(moduleIR);

// instantiate contract module
Runtime::GCPointer<Runtime::ModuleInstance> moduleInstance = Runtime::instantiateModule(compartment, module, move(linkResult.resolvedImports), "<ewasmcontract>");
Expand All @@ -372,7 +381,7 @@ ExecutionResult WavmEngine::internalExecute(
wavm_host_module::interface.top()->setWasmMemory(memory);

// invoke the main function
Runtime::GCPointer<Runtime::FunctionInstance> mainFunction = asFunctionNullable(Runtime::getInstanceExport(moduleInstance, "main"));
Runtime::GCPointer<Runtime::Function> mainFunction = asFunctionNullable(Runtime::getInstanceExport(moduleInstance, "main"));
ensureCondition(mainFunction, ContractValidationFailure, "\"main\" not found");

executionStarted();
Expand Down
4 changes: 3 additions & 1 deletion src/wavm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

#include "eei.h"

namespace WAVM {
namespace IR {
class Module;
}
}

namespace hera {

Expand Down Expand Up @@ -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