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

Better align wasm support with the latest specification #448

Merged
merged 3 commits into from
Jul 8, 2023
Merged
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ if(DEFINED WASI_SDK_PREFIX)
install(DIRECTORY ${WASI_SDK_PREFIX}/ USE_SOURCE_PERMISSIONS DESTINATION . COMPONENT WASI EXCLUDE_FROM_ALL)
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
ExternalProject_Add(wasi-sdk
URL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz
URL_HASH SHA256=d900abc826eec1955b9afd250e7cc2496338abbf6c440d86a313c06e42083fa1
URL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz
URL_HASH SHA256=7030139d495a19fbeccb9449150c2b1531e15d8fb74419872a719a7580aad0f9
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
Expand Down
20 changes: 15 additions & 5 deletions libraries/psibase/native/src/ExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ using eosio::vm::span;
namespace psibase
{
struct ExecutionContextImpl;
using rhf_t = eosio::vm::registered_host_functions<ExecutionContextImpl>;
using rhf_t = eosio::vm::registered_host_functions<ExecutionContextImpl>;
#ifdef __x86_64__
using backend_t = eosio::vm::backend<rhf_t, eosio::vm::jit_profile, VMOptions>;
#else
using backend_t = eosio::vm::backend<rhf_t, eosio::vm::interpreter, VMOptions>;
#endif

// Rethrow with detailed info
template <typename F>
Expand Down Expand Up @@ -70,10 +74,12 @@ namespace psibase

struct BackendEntry
{
Checksum256 hash;
VMOptions vmOptions;
std::unique_ptr<backend_t> backend;
Checksum256 hash;
VMOptions vmOptions;
std::unique_ptr<backend_t> backend;
#ifdef __x86_64__
std::shared_ptr<dwarf::debugger_registration> debug;
#endif

auto byHash() const { return std::tie(hash, vmOptions); }
};
Expand Down Expand Up @@ -201,6 +207,7 @@ namespace psibase
{
psio::input_stream s{reinterpret_cast<const char*>(c->code.data()),
c->code.size()};
#ifdef __x86_64__
if (dwarf::has_debug_info(s))
{
debug_eos_vm::debug_instr_map debug;
Expand All @@ -215,6 +222,9 @@ namespace psibase
backend.backend = std::make_unique<backend_t>(c->code, nullptr, vmOptions);
backend.debug = dwarf::register_with_debugger(backend.backend->get_module());
}
#else
backend.backend = std::make_unique<backend_t>(c->code, nullptr, vmOptions);
#endif
}
});
}
Expand Down Expand Up @@ -310,7 +320,7 @@ namespace psibase

std::uint32_t ExecutionContext::remainingStack() const
{
return impl->backend.backend->get_context()._remaining_call_depth;
return impl->backend.backend->get_context().get_remaining_call_depth();
}

void ExecutionContext::execProcessTransaction(ActionContext& actionContext)
Expand Down
2 changes: 1 addition & 1 deletion libraries/psibase/sdk/psibase-wasm-opt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
# generates code that won't run on psibase.
if which wasm-opt >/dev/null 2>&1
then
wasm-opt --disable-sign-ext --enable-simd --enable-bulk-memory "$@"
wasm-opt --enable-sign-ext --enable-nontrapping-float-to-int --enable-simd --enable-bulk-memory "$@"
fi
2 changes: 1 addition & 1 deletion libraries/psibase/sdk/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES WASI_SDK_PREFIX)

if(NOT __psibase_toolchain_included)
set(__psibase_toolchain_included 1)
string(APPEND CMAKE_CXX_FLAGS_INIT "-mno-sign-ext -msimd128")
string(APPEND CMAKE_CXX_FLAGS_INIT "-msign-ext -msimd128 -mnontrapping-fptoint -mbulk-memory")
string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -ggdb")
string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " -ggdb")
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -ggdb")
Expand Down
4 changes: 4 additions & 0 deletions programs/psitest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ void eosio::vm::machine_code_writer<eosio::vm::jit_execution_context<callbacks,

using backend_t = eosio::vm::backend< //
rhf_t,
#ifdef __x86_64__
eosio::vm::jit_profile,
#else
eosio::vm::interpreter,
#endif
vm_options,
debug_eos_vm::debug_instr_map>;

Expand Down
2 changes: 1 addition & 1 deletion services/system/VerifyEcSys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function(add suffix)
add_custom_command(TARGET VerifyEcSys${suffix} POST_BUILD
COMMAND wasm-ctor-eval
-c prestart
--enable-bulk-memory
--enable-sign-ext --enable-nontrapping-float-to-int --enable-simd --enable-bulk-memory
VerifyEcSys-prestart${suffix}.wasm
-o ${ROOT_BINARY_DIR}/VerifyEcSys${suffix}.wasm
)
Expand Down
10 changes: 6 additions & 4 deletions wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ endmacro()
include(GNUInstallDirs)
install(FILES ${ROOT_SOURCE_DIR}/LICENSE DESTINATION ${CMAKE_INSTALL_DATADIR}/psibase/licenses COMPONENT libpsibase)

set(WASM_FEATURES -msign-ext -mnontrapping-fptoint -msimd128 -mbulk-memory)

add_library(wasm-base INTERFACE)
target_compile_options(wasm-base INTERFACE -mno-sign-ext -fno-exceptions -DCOMPILING_WASM -mthread-model single -O3)
target_link_options(wasm-base INTERFACE -mno-sign-ext -B${ROOT_SOURCE_DIR}/libraries/psibase/sdk/psibase- -Wl,--strip-all -O3 -L${ROOT_BINARY_DIR}/wasm/deps/lib)
target_compile_options(wasm-base INTERFACE ${WASM_FEATURES} -fno-exceptions -DCOMPILING_WASM -mthread-model single -O3)
target_link_options(wasm-base INTERFACE ${WASM_FEATURES} -B${ROOT_SOURCE_DIR}/libraries/psibase/sdk/psibase- -Wl,--strip-all -O3 -L${ROOT_BINARY_DIR}/wasm/deps/lib)

add_library(wasm-base-debug INTERFACE)
target_compile_options(wasm-base-debug INTERFACE -mno-sign-ext -fno-exceptions -DCOMPILING_WASM -mthread-model single -ggdb)
target_link_options(wasm-base-debug INTERFACE -mno-sign-ext -ggdb -L${ROOT_BINARY_DIR}/wasm/deps/lib)
target_compile_options(wasm-base-debug INTERFACE ${WASM_FEATURES} -fno-exceptions -DCOMPILING_WASM -mthread-model single -ggdb)
target_link_options(wasm-base-debug INTERFACE ${WASM_FEATURES} -ggdb -L${ROOT_BINARY_DIR}/wasm/deps/lib)

function(target_mapped_include_directories target type)
target_include_directories(${target} ${type} ${ARGN})
Expand Down
Loading