diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index a0d6525143..242132824c 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -34,11 +34,16 @@ if("eos-vm-oc" IN_LIST EOSIO_WASM_RUNTIMES) webassembly/runtimes/eos-vm-oc.cpp webassembly/runtimes/eos-vm-oc/default_real_main.cpp) + set_source_files_properties(webassembly/runtimes/eos-vm-oc/LLVMJIT.cpp PROPERTIES COMPILE_FLAGS "--std=gnu++17") + set_source_files_properties(webassembly/runtimes/eos-vm-oc/LLVMEmitIR.cpp PROPERTIES COMPILE_FLAGS "--std=gnu++17") + if(LLVM_VERSION VERSION_LESS 7.1 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") enable_language(ASM-LLVMWAR) list(APPEND CHAIN_EOSVMOC_SOURCES webassembly/runtimes/eos-vm-oc/llvmWARshim.llvmwar) + set_source_files_properties(webassembly/runtimes/eos-vm-oc/llvmWARshim.llvmwar PROPERTIES COMPILE_FLAGS "--std=gnu++17") else() list(APPEND CHAIN_EOSVMOC_SOURCES webassembly/runtimes/eos-vm-oc/llvmWARshim.cpp) + set_source_files_properties(webassembly/runtimes/eos-vm-oc/llvmWARshim.cpp PROPERTIES COMPILE_FLAGS "--std=gnu++17") endif() llvm_map_components_to_libnames(LLVM_LIBS support core passes mcjit native orcjit) diff --git a/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMEmitIR.h b/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMEmitIR.h new file mode 100644 index 0000000000..2451603a77 --- /dev/null +++ b/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMEmitIR.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Inline/BasicTypes.h" +#include "IR/Module.h" + +#include "llvm/IR/Module.h" + +#include +#include + +namespace eosio { namespace chain { namespace eosvmoc { + +namespace LLVMJIT { + bool getFunctionIndexFromExternalName(const char* externalName,Uptr& outFunctionDefIndex); + const char* getTableSymbolName(); + llvm::Module* emitModule(const IR::Module& module); +} +}}} diff --git a/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.cpp b/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.cpp index 8b76b715af..f1eca8073d 100644 --- a/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.cpp +++ b/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.cpp @@ -15,6 +15,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ #include "LLVMJIT.h" +#include "LLVMEmitIR.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/RTDyldMemoryManager.h" @@ -39,6 +40,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "llvm/Object/ObjectFile.h" #include "llvm/Object/SymbolSize.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/DataExtractor.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/TargetSelect.h" @@ -49,10 +51,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "llvm/Transforms/InstCombine/InstCombine.h" #include "llvm/Transforms/Utils.h" #include - -#include -#include -#include +#include #include "llvm/Support/LEB128.h" @@ -151,7 +150,7 @@ namespace LLVMJIT std::list> stack_sizes; U8* get_next_code_ptr(uintptr_t numBytes, U32 alignment) { - FC_ASSERT(alignment <= alignof(std::max_align_t), "alignment of section exceeds max_align_t"); + WAVM_ASSERT_THROW(alignment <= alignof(std::max_align_t)); uintptr_t p = (uintptr_t)ptr; p += alignment - 1LL; p &= ~(alignment - 1LL); @@ -306,12 +305,14 @@ namespace LLVMJIT unsigned num_functions_stack_size_found = 0; for(const auto& stacksizes : jitModule->unitmemorymanager->stack_sizes) { - fc::datastream ds(reinterpret_cast(stacksizes.data()), stacksizes.size()); - while(ds.remaining()) { - uint64_t funcaddr; - fc::unsigned_int stack_size; - fc::raw::unpack(ds, funcaddr); - fc::raw::unpack(ds, stack_size); + llvm::DataExtractor ds(llvm::ArrayRef(stacksizes.data(), stacksizes.size()), true, 8); + llvm::DataExtractor::Cursor c(0); + + while(!ds.eof(c)) { + ds.getAddress(c); + WAVM_ASSERT_THROW(!!c); + const uint64_t stack_size = ds.getULEB128(c); + WAVM_ASSERT_THROW(!!c); ++num_functions_stack_size_found; if(stack_size > 16u*1024u) diff --git a/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.h b/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.h index 4d5a685c29..13e2510195 100644 --- a/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.h +++ b/libraries/chain/webassembly/runtimes/eos-vm-oc/LLVMJIT.h @@ -3,10 +3,6 @@ #include "Inline/BasicTypes.h" #include "IR/Module.h" -#pragma push_macro("N") -#undef N -#include "llvm/IR/Module.h" -#pragma pop_macro("N") #include #include @@ -19,9 +15,6 @@ struct instantiated_code { }; namespace LLVMJIT { - bool getFunctionIndexFromExternalName(const char* externalName,Uptr& outFunctionDefIndex); - const char* getTableSymbolName(); - llvm::Module* emitModule(const IR::Module& module); instantiated_code instantiateModule(const IR::Module& module); } }}}