From 023fe5e8cb34ad5fd7f77334f0b4f41a2af9dd3a Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Mon, 6 Nov 2017 19:06:26 +0300 Subject: [PATCH 1/2] Externalize mem ops --- build/src/main.rs | 8 ++++---- ext/src/main.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/src/main.rs b/build/src/main.rs index a95cefe..3f6adb6 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -71,8 +71,8 @@ fn main() { .arg(Arg::with_name("skip_optimization") .help("Skip symbol optimization step producing final wasm") .long("skip-optimization")) - .arg(Arg::with_name("skip_alloc") - .help("Skip allocator externalizer step producing final wasm") + .arg(Arg::with_name("skip_externalize") + .help("Skip externalizer step producing final wasm") .long("skip-externalize")) .arg(Arg::with_name("runtime_type") .help("Injects RUNTIME_TYPE global export") @@ -93,10 +93,10 @@ fn main() { let mut module = parity_wasm::deserialize_file(&path).unwrap(); - if !matches.is_present("skip_alloc") { + if !matches.is_present("skip_externalize") { module = wasm_utils::externalize( module, - vec!["_free", "_malloc"], + vec!["_free", "_malloc", "_memcpy", "_memset", "_memmove"], ); } diff --git a/ext/src/main.rs b/ext/src/main.rs index 99c7e22..6904d24 100644 --- a/ext/src/main.rs +++ b/ext/src/main.rs @@ -14,8 +14,8 @@ fn main() { } let module = wasm_utils::externalize( - parity_wasm::deserialize_file(&args[1]).expect("Module to deserialize ok"), - vec!["_free", "_malloc"], + parity_wasm::deserialize_file(&args[1]).expect("Module to deserialize ok"), + vec!["_free", "_malloc", "_memcpy", "_memset", "_memmove"], ); parity_wasm::serialize_to_file(&args[2], module).expect("Module to serialize ok"); From b7dd10e2bc28d107d250b9db6efdfdc8b364f440 Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Tue, 7 Nov 2017 12:17:28 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 89fbea3..d022f3a 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,16 @@ For development puposes, raw WASM contract can be injected with gas counters (th cargo run --release --bin wasm-gas -- ``` -## Allocators substiution (wasm-ext) +## Externalization (wasm-ext) -Parity WASM runtime provides simple memory allocators, if contract requires. When relied on this allocators, WASM binary size can be greatly reduced. This utility scans for `_malloc`, `_free` invokes inside the WASM binary and substitutes them with invokes of the imported `_malloc`, `_free`. Should be run before `wasm-opt` for better results. +Parity WASM runtime provides some library functions that can be commonly found in libc. WASM binary size can be reduced and performance may be improved if these functions are used. This utility scans for invocations of the following functions inside the WASM binary: +- `_malloc`, +- `_free`, +- `_memcpy`, +- `_memset`, +- `_memmove` + +And then substitutes them with invocations of the imported ones. Should be run before `wasm-opt` for better results. ``` cargo run --release --bin wasm-ext --