Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from eosnetworkfoundation/backport-eosvm
Browse files Browse the repository at this point in the history
backport 2.1 eos-vm
  • Loading branch information
tbfleming authored Jan 7, 2022
2 parents 7ecc83d + 5681005 commit c9e94e9
Show file tree
Hide file tree
Showing 93 changed files with 5,035 additions and 5,712 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ endif()
# WASM runtimes to enable. Each runtime in this list will have:
# * definition EOSIO_<RUNTIME>_RUNTIME_ENABLED defined in public libchain interface
# * ctest entries with --runtime
list(APPEND EOSIO_WASM_RUNTIMES wabt) #always enable wabt; it works everywhere and parts of eosio still assume it's always available
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
list(APPEND EOSIO_WASM_RUNTIMES eos-vm-oc)
Expand Down Expand Up @@ -98,6 +97,7 @@ else()
set(no_whole_archive_flag "--no-whole-archive")
endif()

set(Boost_USE_MULTITHREADED ON)
set( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" )
# Most boost deps get implictly picked up via fc, as just about everything links to fc. In addition we pick up
# the pthread dependency through fc.
Expand Down Expand Up @@ -163,6 +163,8 @@ add_subdirectory( unittests )
add_subdirectory( tests )
add_subdirectory( tools )

option(DISABLE_WASM_SPEC_TESTS "disable building of wasm spec unit tests" OFF)

if (NOT DISABLE_WASM_SPEC_TESTS)
add_subdirectory( eosio-wasm-spec-tests/generated-tests )
endif()
Expand All @@ -189,8 +191,6 @@ install(FILES ${CMAKE_BINARY_DIR}/modules/EosioTester.cmake DESTINATION ${CMAKE_

configure_file(${CMAKE_SOURCE_DIR}/LICENSE
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/libraries/wabt/LICENSE
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE.wabt COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/libraries/softfloat/COPYING.txt
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE.softfloat COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/libraries/wasm-jit/LICENSE
Expand All @@ -207,7 +207,6 @@ configure_file(${CMAKE_SOURCE_DIR}/libraries/eos-vm/LICENSE
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE.eos-vm COPYONLY)

install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ COMPONENT base)
install(FILES libraries/wabt/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.wabt COMPONENT base)
install(FILES libraries/softfloat/COPYING.txt DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.softfloat COMPONENT base)
install(FILES libraries/wasm-jit/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.wavm COMPONENT base)
install(FILES libraries/fc/secp256k1/upstream/COPYING DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.secp256k1 COMPONENT base)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017-2020 block.one and its contributors. All rights reserved.
Copyright (c) 2017-2021 block.one and its contributors. All rights reserved.

The MIT License

Expand Down
2 changes: 1 addition & 1 deletion eosio-wasm-spec-tests
Submodule eosio-wasm-spec-tests updated 61 files
+1 −1 LICENSE
+2 −9 generated-tests/CMakeLists.txt
+40 −41 generated-tests/address.cpp
+130 −131 generated-tests/align.cpp
+125 −126 generated-tests/binary-leb128.cpp
+35 −36 generated-tests/binary.cpp
+5 −6 generated-tests/block.cpp
+5 −6 generated-tests/br.cpp
+5 −6 generated-tests/br_if.cpp
+5 −6 generated-tests/br_table.cpp
+5 −6 generated-tests/break-drop.cpp
+10 −11 generated-tests/call.cpp
+10 −11 generated-tests/call_indirect.cpp
+1,690 −1,691 generated-tests/const.cpp
+10 −11 generated-tests/conversions.cpp
+15 −16 generated-tests/custom.cpp
+5 −6 generated-tests/endianness.cpp
+5 −6 generated-tests/f32.cpp
+5 −6 generated-tests/f32_bitwise.cpp
+5 −6 generated-tests/f32_cmp.cpp
+5 −6 generated-tests/f64.cpp
+5 −6 generated-tests/f64_bitwise.cpp
+5 −6 generated-tests/f64_cmp.cpp
+10 −11 generated-tests/fac.cpp
+480 −481 generated-tests/float_exprs.cpp
+10 −11 generated-tests/float_literals.cpp
+30 −31 generated-tests/float_memory.cpp
+5 −6 generated-tests/float_misc.cpp
+5 −6 generated-tests/forward.cpp
+15 −16 generated-tests/func.cpp
+20 −21 generated-tests/func_ptrs.cpp
+15 −16 generated-tests/globals.cpp
+10 −11 generated-tests/i32.cpp
+10 −11 generated-tests/i64.cpp
+10 −11 generated-tests/if.cpp
+95 −96 generated-tests/int_exprs.cpp
+5 −6 generated-tests/int_literals.cpp
+5 −6 generated-tests/labels.cpp
+5 −6 generated-tests/left-to-right.cpp
+5 −6 generated-tests/load.cpp
+5 −6 generated-tests/local_get.cpp
+5 −6 generated-tests/local_set.cpp
+5 −6 generated-tests/local_tee.cpp
+5 −6 generated-tests/loop.cpp
+40 −41 generated-tests/memory.cpp
+30 −31 generated-tests/memory_grow.cpp
+5 −6 generated-tests/memory_redundancy.cpp
+20 −21 generated-tests/memory_size.cpp
+20 −21 generated-tests/memory_trap.cpp
+5 −6 generated-tests/nop.cpp
+5 −6 generated-tests/return.cpp
+10 −11 generated-tests/select.cpp
+10 −11 generated-tests/stack.cpp
+20 −21 generated-tests/start.cpp
+5 −6 generated-tests/store.cpp
+5 −6 generated-tests/switch.cpp
+20 −21 generated-tests/traps.cpp
+5 −6 generated-tests/type.cpp
+10 −11 generated-tests/unreachable.cpp
+10 −11 generated-tests/unwind.cpp
+15 −15 generator/eosio_wasm_spec_test_generator.cpp
7 changes: 0 additions & 7 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ add_subdirectory( chain )
add_subdirectory( testing )
add_subdirectory( version )

#turn tools&tests off; not needed for library build
set(BUILD_TESTS OFF CACHE BOOL "Build GTest-based tests")
set(BUILD_TOOLS OFF CACHE BOOL "Build wabt tools")
set(RUN_RE2C OFF CACHE BOOL "Run re2c")
set(WITH_EXCEPTIONS ON CACHE BOOL "Build with exceptions enabled" FORCE)
add_subdirectory( wabt )

set(USE_EXISTING_SOFTFLOAT ON CACHE BOOL "use pre-exisiting softfloat lib")
set(ENABLE_TOOLS OFF CACHE BOOL "Build tools")
set(ENABLE_TESTS OFF CACHE BOOL "Build tests")
Expand Down
68 changes: 43 additions & 25 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@ else()
endif()

if("eos-vm-oc" IN_LIST EOSIO_WASM_RUNTIMES)
set(CHAIN_EOSVMOC_SOURCES webassembly/eos-vm-oc/code_cache.cpp
webassembly/eos-vm-oc/executor.cpp
webassembly/eos-vm-oc/memory.cpp
webassembly/eos-vm-oc/intrinsic.cpp
webassembly/eos-vm-oc/LLVMJIT.cpp
webassembly/eos-vm-oc/LLVMEmitIR.cpp
webassembly/eos-vm-oc/compile_monitor.cpp
webassembly/eos-vm-oc/compile_trampoline.cpp
webassembly/eos-vm-oc/ipc_helpers.cpp
webassembly/eos-vm-oc/gs_seg_helpers.c
webassembly/eos-vm-oc.cpp)
enable_language(ASM)
set(CHAIN_EOSVMOC_SOURCES webassembly/runtimes/eos-vm-oc/code_cache.cpp
webassembly/runtimes/eos-vm-oc/executor.cpp
webassembly/runtimes/eos-vm-oc/memory.cpp
webassembly/runtimes/eos-vm-oc/intrinsic.cpp
webassembly/runtimes/eos-vm-oc/LLVMJIT.cpp
webassembly/runtimes/eos-vm-oc/LLVMEmitIR.cpp
webassembly/runtimes/eos-vm-oc/compile_monitor.cpp
webassembly/runtimes/eos-vm-oc/compile_trampoline.cpp
webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp
webassembly/runtimes/eos-vm-oc/gs_seg_helpers.c
webassembly/runtimes/eos-vm-oc/stack.cpp
webassembly/runtimes/eos-vm-oc/switch_stack_linux.s
webassembly/runtimes/eos-vm-oc.cpp
webassembly/runtimes/eos-vm-oc/default_real_main.cpp)

if(LLVM_VERSION VERSION_LESS 7.1 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
enable_language(ASM-LLVMWAR)
list(APPEND CHAIN_EOSVMOC_SOURCES webassembly/eos-vm-oc/llvmWARshim.llvmwar)
list(APPEND CHAIN_EOSVMOC_SOURCES webassembly/runtimes/eos-vm-oc/llvmWARshim.llvmwar)
else()
list(APPEND CHAIN_EOSVMOC_SOURCES webassembly/eos-vm-oc/llvmWARshim.cpp)
list(APPEND CHAIN_EOSVMOC_SOURCES webassembly/runtimes/eos-vm-oc/llvmWARshim.cpp)
endif()

llvm_map_components_to_libnames(LLVM_LIBS support core passes mcjit native orcjit)
Expand All @@ -45,10 +49,29 @@ if("eos-vm-oc" IN_LIST EOSIO_WASM_RUNTIMES)
endif()

if("eos-vm" IN_LIST EOSIO_WASM_RUNTIMES OR "eos-vm-jit" IN_LIST EOSIO_WASM_RUNTIMES)
set(CHAIN_EOSVM_SOURCES "webassembly/eos-vm.cpp")
set(CHAIN_EOSVM_SOURCES "webassembly/runtimes/eos-vm.cpp")
set(CHAIN_EOSVM_LIBRARIES eos-vm)
endif()

set(CHAIN_WEBASSEMBLY_SOURCES
webassembly/action.cpp
webassembly/authorization.cpp
webassembly/cf_system.cpp
webassembly/cf_transaction.cpp
webassembly/compiler_builtins.cpp
webassembly/context_free.cpp
webassembly/console.cpp
webassembly/crypto.cpp
webassembly/database.cpp
webassembly/memory.cpp
webassembly/permission.cpp
webassembly/privileged.cpp
webassembly/producer.cpp
webassembly/softfloat.cpp
webassembly/system.cpp
webassembly/transaction.cpp
)

## SORT .cpp by most likely to change / break compile
add_library( eosio_chain
merkle.cpp
Expand All @@ -72,8 +95,6 @@ add_library( eosio_chain
genesis_state.cpp
${CMAKE_CURRENT_BINARY_DIR}/genesis_state_root_key.cpp

# chain_config.cpp
# block_trace.cpp
wast_to_wasm.cpp
wasm_interface.cpp
wasm_eosio_validation.cpp
Expand All @@ -83,13 +104,9 @@ add_library( eosio_chain
asset.cpp
snapshot.cpp

webassembly/wabt.cpp
${CHAIN_EOSVMOC_SOURCES}
${CHAIN_EOSVM_SOURCES}

# get_config.cpp
#
# contracts/chain_initializer.cpp
${CHAIN_WEBASSEMBLY_SOURCES}

trace.cpp
transaction_metadata.cpp
Expand All @@ -106,18 +123,19 @@ add_library( eosio_chain
)

target_link_libraries( eosio_chain fc chainbase Logging IR WAST WASM Runtime
softfloat builtins wabt ${CHAIN_EOSVM_LIBRARIES} ${LLVM_LIBS} ${CHAIN_RT_LINKAGE}
softfloat builtins ${CHAIN_EOSVM_LIBRARIES} ${LLVM_LIBS} ${CHAIN_RT_LINKAGE}
)
target_include_directories( eosio_chain
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../wasm-jit/Include"
"${CMAKE_CURRENT_SOURCE_DIR}/libraries/eos-vm/include"
"${CMAKE_SOURCE_DIR}/libraries/wabt"
"${CMAKE_BINARY_DIR}/libraries/wabt"
)

add_library(eosio_chain_wrap INTERFACE )
target_link_libraries(eosio_chain_wrap INTERFACE eosio_chain)

if("eos-vm-oc" IN_LIST EOSIO_WASM_RUNTIMES)
target_link_libraries(eosio_chain "-Wl,-wrap=main")
target_link_libraries(eosio_chain_wrap INTERFACE "-Wl,-wrap=main")
endif()

foreach(RUNTIME ${EOSIO_WASM_RUNTIMES})
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <eosio/chain/platform_timer.hpp>

#include <chainbase/chainbase.hpp>
#include <eosio/vm/allocator.hpp>
#include <fc/io/json.hpp>
#include <fc/log/logger_config.hpp>
#include <fc/scoped_exit.hpp>
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/apply_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class apply_context {
/// Console methods:
public:

void console_append( const string& val ) {
void console_append( std::string_view val ) {
_pending_console_output += val;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const static uint32_t setcode_ram_bytes_multiplier = 10; ///< multip

const static uint32_t hashing_checktime_block_size = 10*1024; /// call checktime from hashing intrinsic once per this number of bytes

const static eosio::chain::wasm_interface::vm_type default_wasm_runtime = eosio::chain::wasm_interface::vm_type::wabt;
const static eosio::chain::wasm_interface::vm_type default_wasm_runtime = eosio::chain::wasm_interface::vm_type::eos_vm_jit;
const static uint32_t default_abi_serializer_max_time_us = 15*1000; ///< default deadline for abi serialization methods

/**
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace boost { namespace asio {
class thread_pool;
}}

namespace eosio { namespace vm { class wasm_allocator; }}

namespace eosio { namespace chain {

class authorization_manager;
Expand Down
25 changes: 20 additions & 5 deletions libraries/chain/include/eosio/chain/name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ namespace fc {
} // fc

namespace eosio::chain {
static constexpr uint64_t char_to_symbol( char c ) {
inline constexpr uint64_t char_to_symbol( char c ) {
if( c >= 'a' && c <= 'z' )
return (c - 'a') + 6;
if( c >= '1' && c <= '5' )
return (c - '1') + 1;
return 0;
}

static constexpr uint64_t string_to_uint64_t( std::string_view str ) {
inline constexpr uint64_t string_to_uint64_t( std::string_view str ) {
uint64_t n = 0;
int i = 0;
for ( ; str[i] && i < 12; ++i) {
for ( ; i < str.size() && i < 12; ++i) {
// NOTE: char_to_symbol() returns char type, and without this explicit
// expansion to uint64 type, the compilation fails at the point of usage
// of string_to_name(), where the usage requires constant (compile time) expression.
Expand All @@ -34,7 +34,7 @@ namespace eosio::chain {
// The for-loop encoded up to 60 high bits into uint64 'name' variable,
// if (strlen(str) > 12) then encode str[12] into the low (remaining)
// 4 bits of 'name'
if (i == 12)
if (i < str.size() && i == 12)
n |= char_to_symbol(str[12]) & 0x0F;
return n;
}
Expand Down Expand Up @@ -81,11 +81,26 @@ namespace eosio::chain {
// to its 5-bit slot starting with the highest slot for the first char.
// The 13th char, if str is long enough, is encoded into 4-bit chunk
// and placed in the lowest 4 bits. 64 = 12 * 5 + 4
static constexpr name string_to_name( std::string_view str )
inline constexpr name string_to_name( std::string_view str )
{
return name( string_to_uint64_t( str ) );
}

inline namespace literals {
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template"
#endif
template <typename T, T... Str>
inline constexpr name operator""_n() {
constexpr const char buf[] = {Str...};
return name{std::integral_constant<uint64_t, string_to_uint64_t(std::string_view{buf, sizeof(buf)})>::value};
}
#if defined(__clang__)
# pragma clang diagnostic pop
#endif
} // namespace literals

#define N(X) eosio::chain::string_to_name(#X)

} // eosio::chain
Expand Down
14 changes: 14 additions & 0 deletions libraries/chain/include/eosio/chain/transaction_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ namespace eosio { namespace chain {

void checktime()const;

template <typename DigestType>
inline DigestType hash_with_checktime( const char* data, uint32_t datalen )const {
const size_t bs = eosio::chain::config::hashing_checktime_block_size;
typename DigestType::encoder enc;
while ( datalen > bs ) {
enc.write( data, bs );
data += bs;
datalen -= bs;
checktime();
}
enc.write( data, datalen );
return enc.result();
}

void pause_billing_timer();
void resume_billing_timer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <functional>
#include <iterator>
#include <memory>
#include <fc/optional.hpp>
#include <fc/exception/exception.hpp>
#include <string>
#include <unordered_map>
Expand Down
Loading

0 comments on commit c9e94e9

Please sign in to comment.