Merge pull request #68 from paritytech/stack-adjust

Make stack adjustments pass optional and disable it by default
This commit is contained in:
Nikolay Volf 2018-03-24 22:48:06 +08:00 committed by GitHub
commit c784fb2cbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -78,6 +78,9 @@ fn main() {
.arg(Arg::with_name("skip_optimization")
.help("Skip symbol optimization step producing final wasm")
.long("skip-optimization"))
.arg(Arg::with_name("enforce_stack_adjustment")
.help("Enforce stack size adjustment (used for old wasm32-unknown-unknown)")
.long("enforce-stack-adjustment"))
.arg(Arg::with_name("runtime_type")
.help("Injects RUNTIME_TYPE global export")
.takes_value(true)
@ -134,14 +137,17 @@ fn main() {
if let source::SourceTarget::Unknown = source_input.target() {
// 49152 is 48kb!
let stack_size: u32 = matches.value_of("shrink_stack").unwrap_or_else(|| "49152").parse().expect("New stack size is not valid u32");
assert!(stack_size <= 1024*1024);
let (new_module, new_stack_top) = shrink_unknown_stack(module, 1024 * 1024 - stack_size);
module = new_module;
let mut stack_top_page = new_stack_top / 65536;
if new_stack_top % 65536 > 0 { stack_top_page += 1 };
module = externalize_mem(module, Some(stack_top_page), 16);
if matches.is_present("enforce_stack_adjustment") {
let stack_size: u32 = matches.value_of("shrink_stack").unwrap_or_else(|| "49152").parse().expect("New stack size is not valid u32");
assert!(stack_size <= 1024*1024);
let (new_module, new_stack_top) = shrink_unknown_stack(module, 1024 * 1024 - stack_size);
module = new_module;
let mut stack_top_page = new_stack_top / 65536;
if new_stack_top % 65536 > 0 { stack_top_page += 1 };
module = externalize_mem(module, Some(stack_top_page), 16);
} else {
module = externalize_mem(module, None, 16);
}
}
if let Some(runtime_type) = matches.value_of("runtime_type") {

View File

@ -44,6 +44,10 @@ pub fn externalize_mem(mut module: elements::Module, adjust_pages: Option<u32>,
entry = elements::MemoryType::new(adjust_pages, Some(max_pages));
}
if entry.limits().maximum().is_none() {
entry = elements::MemoryType::new(entry.limits().initial(), Some(max_pages));
}
import_section(&mut module).expect("Import section to exist").entries_mut().push(
elements::ImportEntry::new(
"env".to_owned(),