eosio / eos-vm Goto Github PK
View Code? Open in Web Editor NEWA Low-Latency, High Performance and Extensible WebAssembly Backend Library
License: Other
A Low-Latency, High Performance and Extensible WebAssembly Backend Library
License: Other
JIT currently starts the count over from scratch.
[[gnu::always_inline]] inline void operator()(const i64_ne_t& op) {
context.inc_pc();
const auto& rhs = context.pop_operand().to_ui64();
auto& lhs = context.peek_operand();
lhs = i32_const_t{ lhs.to_ui64() != rhs };
}
rhs always got 0 in gcc version 9.1.0 Ubuntu 18.04.3, but below code can get the right value.
[[gnu::always_inline]] inline void operator()(const i64_ne_t& op) {
context.inc_pc();
const auto& rhs = context.pop_operand();
auto& lhs = context.peek_operand();
lhs = i32_const_t{ lhs.to_ui64() != rhs.to_ui64() };
}
The table is fully instantiated by the parser, which may cause it to create a vector of 2^32-1 elements when parsing a small wasm, leading to potential DOS attacks. This is safe in nodeos for now, because the size of the table is bounded by validation, before eos-vm sees it.
Jit doesn't type check the arguments at all. The interpreter's type check is insufficient.
I've built eos-vm on Centos 7.7, gcc 7.4 compiler.
When running tools/hello-driver I'm getting exception:
terminate called after throwing an instance of 'eosio::vm::wasm_vector_oob_exception'
what(): wasm vector out of bounds
Here is a stack:
#0 0x00007f6ff7548337 in raise () from /lib64/libc.so.6
#1 0x00007f6ff7549a28 in abort () from /lib64/libc.so.6
#2 0x00007f6ff7e8a135 in __gnu_cxx::__verbose_terminate_handler () at ../../.././libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00007f6ff7e87f26 in __cxxabiv1::__terminate (handler=) at ../../.././libstdc++-v3/libsupc++/eh_terminate.cc:47
#4 0x00007f6ff7e87f71 in std::terminate () at ../../.././libstdc++-v3/libsupc++/eh_terminate.cc:57
#5 0x00007f6ff7e881b3 in __cxxabiv1::__cxa_throw (obj=,
tinfo=0x4f2870 ,
dest=0x41410a eosio::vm::wasm_vector_oob_exception::~wasm_vector_oob_exception())
at ../../.././libstdc++-v3/libsupc++/eh_throw.cc:93
#6 0x0000000000414473 in eosio::vm::detail::vector<unsigned int, eosio::vm::growable_allocator>::at (this=0x7ffe2be97098, i=0)
at /home/alr/eos-vm/include/eosio/vm/vector.hpp:58
#7 0x000000000040d5b1 in eosio::vm::detail::vector<unsigned int, eosio::vm::growable_allocator>::operator[] (this=0x7ffe2be97098,
i=0) at /home/alr/eos-vm/include/eosio/vm/vector.hpp:76
#8 0x00000000004173c3 in eosio::vm::registered_host_functions<example_host_methods>::resolveeosio::vm::module (mod=...)
at /home/alr/eos-vm/include/eosio/vm/host_function.hpp:575
#9 0x0000000000412312 in eosio::vm::backend<example_host_methods, eosio::vm::interpreter>::backend<eosio::vm::registered_host_functions<example_host_methods> > (this=0x7ffe2be96f10, code=...) at /home/alr/eos-vm/include/eosio/vm/backend.hpp:48
#10 0x0000000000403c47 in main (argc=4, argv=0x7ffe2be974a8) at /home/alr/eos-vm/tools/hello_driver.cpp:66
It's interesting to see that eos-vm has excellent performance comparing to wabt and WAVM. But could you publish the exact benchmarking process (including build and run command) so that we could play with it too? Thanks!
As we all know, Libra deploy a new language, which named Move. So Is there a plan to deploy a new smart contract program language to support safety or TPS?
The parameters that cause a difference in behavior vs softfloat are not currently known. This may also affect the interpreter, but has not been tested.
validate_ptr will siglongjmp from the signal handler if the pointer is out of bounds. This will bypass any destructors including those of aligned_array_wrapper. No intrinsics in nodeos can trigger this bug.
:eosio::vm::registered_host_functions<decltype(nullptr)>::operator()<eosio::vm::execution_context<decltype(nullptr)> >(decltype(nullptr)*, eosio::vm::execution_context<decltype(nullptr)>&, unsigned int) parsing running wasm file causing crash
cmake CMakeLIst.txt
CMake command after Error log
Determining if the pthread_create exist failed with the following output:
Change Dir: /home/eos/Documents/eos.tools/eos-vm/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_5200c/fast"
/usr/bin/make -f CMakeFiles/cmTC_5200c.dir/build.make CMakeFiles/cmTC_5200c.dir/build
make[1]: Entering directory '/home/eos/Documents/eos.tools/eos-vm/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_5200c.dir/CheckSymbolExists.c.o
/usr/bin/cc -o CMakeFiles/cmTC_5200c.dir/CheckSymbolExists.c.o -c /home/eos/Documents/eos.tools/eos-vm/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_5200c
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_5200c.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTC_5200c.dir/CheckSymbolExists.c.o -o cmTC_5200c
CMakeFiles/cmTC_5200c.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x1b): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_5200c.dir/build.make:97: recipe for target 'cmTC_5200c' failed
make[1]: *** [cmTC_5200c] Error 1
make[1]: Leaving directory '/home/eos/Documents/eos.tools/eos-vm/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_5200c/fast' failed
make: *** [cmTC_5200c/fast] Error 2
File /home/eos/Documents/eos.tools/eos-vm/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef pthread_create
return ((int*)(&pthread_create))[argc];
#else
(void)argc;
return 0;
#endif
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/eos/Documents/eos.tools/eos-vm/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_6007c/fast"
/usr/bin/make -f CMakeFiles/cmTC_6007c.dir/build.make CMakeFiles/cmTC_6007c.dir/build
make[1]: Entering directory '/home/eos/Documents/eos.tools/eos-vm/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_6007c.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_6007c.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.10/Modules/CheckFunctionExists.c
Linking C executable cmTC_6007c
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_6007c.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_6007c.dir/CheckFunctionExists.c.o -o cmTC_6007c -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_6007c.dir/build.make:97: recipe for target 'cmTC_6007c' failed
make[1]: *** [cmTC_6007c] Error 1
make[1]: Leaving directory '/home/eos/Documents/eos.tools/eos-vm/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_6007c/fast' failed
make: *** [cmTC_6007c/fast] Error 2
Why CMake compile failed?
Move mutable globals out of module and to the end of the linear memory section (past the 4GB addressable region).
func A {
call B; // not import function
call C;// not import function
}
interpreter error
in B return , the end_t which added by push call(B), does not clean in control_stack。
testing rust code :
#[no_mangle]
pub fn main() -> u64 {
let arr = [1,2,35,4,6,7,8];
let mut sum = 0;
for i in 0..1000000000 {
sum += arr[i % arr.len()];
}
sum
}
generated wasm file test.wat
:
(module
(type (;0;) (func (result i64)))
(func (;0;) (type 0) (result i64)
(local i32 i32 i64)
get_global 0
i32.const 64
i32.sub
tee_local 0
i64.const 8
i64.store offset=56
get_local 0
i64.const 7
i64.store offset=48
get_local 0
i64.const 6
i64.store offset=40
get_local 0
i64.const 4
i64.store offset=32
get_local 0
i64.const 35
i64.store offset=24
get_local 0
i64.const 2
i64.store offset=16
get_local 0
i64.const 1
i64.store offset=8
i32.const 0
set_local 1
i64.const 0
set_local 2
get_local 0
i32.const 8
i32.add
set_local 0
loop ;; label = @1
get_local 0
get_local 1
i32.const 7
i32.div_u
i32.const -56
i32.mul
i32.add
i64.load
get_local 2
i64.add
set_local 2
get_local 0
i32.const 8
i32.add
set_local 0
get_local 1
i32.const 1
i32.add
tee_local 1
i32.const 1000000000
i32.lt_u
br_if 0 (;@1;)
end
get_local 2)
(table (;0;) 1 1 anyfunc)
(memory (;0;) 16)
(global (;0;) (mut i32) (i32.const 1048576))
(export "main" (func 0)))
run cmd:
./bench-interp test.wasm
output(I commented out the catch
code in tools/bench_interp.cpp:37
, since it only print eos-vm interpreter error
and no other useful information):
terminate called after throwing an instance of 'eosio::vm::wasm_memory_exception'
what(): wasm memory exception
Aborted (core dumped)
The error appears in building process, gcc-7 (7.4.0).
I can't add additional branch for pull request, so just add:
#include <functional>
in
eos-vm/include/eosio/vm/variant.hpp
for fixing it.
Env: MacOS Catalina (also tried in OS version MacOS High Serria)
Clang:
llvm: 7.1.0 (also tried in llvm version 9.0.0)
Compile Error:
Scanning dependencies of target hello-driver
[ 98%] Building CXX object tools/CMakeFiles/hello-driver.dir/hello_driver.cpp.o
In file included from /Users/zhangyy/CLionProjects/eos-vm/tools/hello_driver.cpp:1:
In file included from /Users/zhangyy/CLionProjects/eos-vm/include/eosio/vm/backend.hpp:3:
/Users/zhangyy/CLionProjects/eos-vm/include/eosio/vm/allocator.hpp:213:45: error: no member named 'extract' in 'std::__1::set<std::__1::pair<unsigned long, void *>, eosio::vm::jit_allocator::by_size,
std::__1::allocator<std::__1::pair<unsigned long, void *> > >'
auto node = free_blocks_by_size.extract({lhs->second, lhs->first});
~~~~~~~~~~~~~~~~~~~ ^
/Users/zhangyy/CLionProjects/eos-vm/include/eosio/vm/allocator.hpp:174:27: error: no member named 'extract' in 'std::__1::map<void *, unsigned long, std::__1::less<void *>, std::__1::allocator<std::__1::pair<void *const, unsigned long> >
>'
auto node = from.extract(key);
~~~~ ^
/Users/zhangyy/CLionProjects/eos-vm/include/eosio/vm/allocator.hpp:106:10: note: in instantiation of function template specialization 'eosio::vm::jit_allocator::transfer_node<std::__1::map<void *, unsigned long, std::__1::less<void *>,
std::__1::allocator<std::__1::pair<void *const, unsigned long> > > >' requested here
transfer_node(free_blocks, allocated_blocks, best->second);
^
/Users/zhangyy/CLionProjects/eos-vm/include/eosio/vm/allocator.hpp:174:27: error: no member named 'extract' in 'std::__1::set<std::__1::pair<unsigned long, void *>, eosio::vm::jit_allocator::by_size,
std::__1::allocator<std::__1::pair<unsigned long, void *> > >'
auto node = from.extract(key);
~~~~ ^
/Users/zhangyy/CLionProjects/eos-vm/include/eosio/vm/allocator.hpp:107:17: note: in instantiation of function template specialization 'eosio::vm::jit_allocator::transfer_node<std::__1::set<std::__1::pair<unsigned long, void *>,
eosio::vm::jit_allocator::by_size, std::__1::allocator<std::__1::pair<unsigned long, void *> > > >' requested here
best = transfer_node(free_blocks_by_size, allocated_blocks_by_size, *best);
^
3 errors generated.
make[2]: *** [tools/CMakeFiles/hello-driver.dir/hello_driver.cpp.o] Error 1
make[1]: *** [tools/CMakeFiles/hello-driver.dir/all] Error 2
make: *** [all] Error 2
It seems Clang does not support C++17 feature map and set extract function.
Attempting to integrate this into CMake with the ExternalProject module. Git pull fails with various errors on Windows only; files (pretty much tests) include characters that give "invalid argument" errors (mainly colons and other characters disallowed by Windows in filenames). Is there a way this can either be fixed or ignored? As a result of this, git fails with the following error when pulling:
fatal: Could not reset index file to revision 'HEAD'.
Cannot rebase: You have unstaged changes.
Please commit or stash them.
No rebase in progress?
I'm trying to build the library in header only mode, when I compile I get the following error:
../external/eosio/vm/host_function.hpp:382:66: error: no member named 'apply' in
'eosio::vm::detail::no_viable_overload_of_from_wasm<const std::__1::basic_string<char> &>'
return detail::make_value_getter<S, Cons>().template apply<S>(alloc, static_cast<T&&>(val), tail);
I can't figure out what the issue is
jit will currently fail if there are too many locals or stack variables. nodeos cannot hit this because the limits are higher than nodeos' limits.
A 20MB function will currently cause jit to fail, even if the final size fits, because it pre-allocates too much memory.
When building against glibc 2.34, a build failure occurs rooted here due to the fact that SIGSTKSZ is no longer a constexpr
value (see glibc changelog). There is also an error about a type mismatch in the arguments to max
, but the 'interesting' error is the constexpr
trouble.
This seems to be a trivial fix, as it appears that nothing depends on stack_cutoff
being constexpr
. Simply replace line 273 with:
std::size_t stack_cutoff = std::max<long>(252144, SIGSTKSZ);
Master branch hasn't been updated in two years making the project look abandoned
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.