Merge pull request #38 from paritytech/externalize-mem-ops

Externalize mem ops
This commit is contained in:
Nikolay Volf 2017-11-07 12:22:14 +03:00 committed by GitHub
commit 9edf1cb467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -26,9 +26,16 @@ For development puposes, raw WASM contract can be injected with gas counters (th
cargo run --release --bin wasm-gas -- <input_binary.wasm> <output_binary.wasm> cargo run --release --bin wasm-gas -- <input_binary.wasm> <output_binary.wasm>
``` ```
## 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 -- <input_binary.wasm> <output_binary.wasm> cargo run --release --bin wasm-ext -- <input_binary.wasm> <output_binary.wasm>

View File

@ -71,8 +71,8 @@ fn main() {
.arg(Arg::with_name("skip_optimization") .arg(Arg::with_name("skip_optimization")
.help("Skip symbol optimization step producing final wasm") .help("Skip symbol optimization step producing final wasm")
.long("skip-optimization")) .long("skip-optimization"))
.arg(Arg::with_name("skip_alloc") .arg(Arg::with_name("skip_externalize")
.help("Skip allocator externalizer step producing final wasm") .help("Skip externalizer step producing final wasm")
.long("skip-externalize")) .long("skip-externalize"))
.arg(Arg::with_name("runtime_type") .arg(Arg::with_name("runtime_type")
.help("Injects RUNTIME_TYPE global export") .help("Injects RUNTIME_TYPE global export")
@ -93,10 +93,10 @@ fn main() {
let mut module = parity_wasm::deserialize_file(&path).unwrap(); 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 = wasm_utils::externalize(
module, module,
vec!["_free", "_malloc"], vec!["_free", "_malloc", "_memcpy", "_memset", "_memmove"],
); );
} }

View File

@ -14,8 +14,8 @@ fn main() {
} }
let module = wasm_utils::externalize( let module = wasm_utils::externalize(
parity_wasm::deserialize_file(&args[1]).expect("Module to deserialize ok"), parity_wasm::deserialize_file(&args[1]).expect("Module to deserialize ok"),
vec!["_free", "_malloc"], vec!["_free", "_malloc", "_memcpy", "_memset", "_memmove"],
); );
parity_wasm::serialize_to_file(&args[2], module).expect("Module to serialize ok"); parity_wasm::serialize_to_file(&args[2], module).expect("Module to serialize ok");