From eae5189c8df3d9602e394b72d42658dd340a8d14 Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Tue, 3 Sep 2019 15:16:07 -0700 Subject: [PATCH 1/8] wiggle things around to use pinned heap reg --- benchmarks/lucet-benchmarks/src/context.rs | 8 ++++---- .../lucet-runtime-internals/src/alloc/tests.rs | 2 ++ .../lucet-runtime-internals/src/context/context_asm.S | 2 ++ .../lucet-runtime-internals/src/context/mod.rs | 11 ++++++++++- .../src/context/tests/c_child.rs | 1 + .../lucet-runtime-internals/src/context/tests/mod.rs | 2 +- .../src/context/tests/rust_child.rs | 1 + lucet-runtime/lucet-runtime-internals/src/instance.rs | 4 +++- lucetc/src/compiler.rs | 2 ++ 9 files changed, 26 insertions(+), 7 deletions(-) diff --git a/benchmarks/lucet-benchmarks/src/context.rs b/benchmarks/lucet-benchmarks/src/context.rs index 1803e6735..9ae10b8a0 100644 --- a/benchmarks/lucet-benchmarks/src/context.rs +++ b/benchmarks/lucet-benchmarks/src/context.rs @@ -9,7 +9,7 @@ fn context_init(c: &mut Criterion) { c.bench_function("context_init", move |b| { b.iter(|| { - ContextHandle::create_and_init(&mut *stack, f as usize, &[]).unwrap(); + ContextHandle::create_and_init(&mut *stack, f as usize, &[], std::ptr::null_mut()).unwrap(); }) }); } @@ -22,7 +22,7 @@ fn context_swap_return(c: &mut Criterion) { b.iter_batched( || { let mut stack = vec![0u64; 1024].into_boxed_slice(); - let child = ContextHandle::create_and_init(&mut *stack, f as usize, &[]).unwrap(); + let child = ContextHandle::create_and_init(&mut *stack, f as usize, &[], std::ptr::null_mut()).unwrap(); (stack, child) }, |(stack, mut child)| unsafe { @@ -45,7 +45,7 @@ fn context_init_swap_return(c: &mut Criterion) { |mut stack| { let mut parent = ContextHandle::new(); let mut child = - ContextHandle::create_and_init(&mut *stack, f as usize, &[]).unwrap(); + ContextHandle::create_and_init(&mut *stack, f as usize, &[], std::ptr::null_mut()).unwrap(); unsafe { Context::swap(&mut parent, &mut child) }; stack }, @@ -333,7 +333,7 @@ fn context_init_swap_return_many_args(c: &mut Criterion) { |mut stack| { let mut parent = ContextHandle::new(); let mut child = - ContextHandle::create_and_init(&mut *stack, f as usize, &args).unwrap(); + ContextHandle::create_and_init(&mut *stack, f as usize, &args, std::ptr::null_mut()).unwrap(); unsafe { Context::swap(&mut parent, &mut child) }; stack }, diff --git a/lucet-runtime/lucet-runtime-internals/src/alloc/tests.rs b/lucet-runtime/lucet-runtime-internals/src/alloc/tests.rs index 03e667419..739e5ebaf 100644 --- a/lucet-runtime/lucet-runtime-internals/src/alloc/tests.rs +++ b/lucet-runtime/lucet-runtime-internals/src/alloc/tests.rs @@ -610,6 +610,7 @@ macro_rules! alloc_tests { inst.alloc_mut().stack_u64_mut(), heap_touching_child as usize, &[Val::CPtr(heap_ptr)], + heap_ptr, ) .expect("context init succeeds"); Context::swap(&mut parent, &mut child); @@ -659,6 +660,7 @@ macro_rules! alloc_tests { inst.alloc_mut().stack_u64_mut(), stack_pattern_child as usize, &[Val::CPtr(heap_ptr)], + heap_ptr, ) .expect("context init succeeds"); Context::swap(&mut parent, &mut child); diff --git a/lucet-runtime/lucet-runtime-internals/src/context/context_asm.S b/lucet-runtime/lucet-runtime-internals/src/context/context_asm.S index c844516ad..2856e3da6 100644 --- a/lucet-runtime/lucet-runtime-internals/src/context/context_asm.S +++ b/lucet-runtime/lucet-runtime-internals/src/context/context_asm.S @@ -118,6 +118,7 @@ _lucet_context_swap: mov %r14, (6*8)(%rdi) mov %r15, (7*8)(%rdi) mov %rsi, (8*8)(%rdi) + mov %r8, (9*8)(%rdi) movdqu %xmm0, (10*8 + 0*16)(%rdi) movdqu %xmm1, (10*8 + 1*16)(%rdi) @@ -137,6 +138,7 @@ _lucet_context_swap: mov (5*8)(%rsi), %r13 mov (6*8)(%rsi), %r14 mov (7*8)(%rsi), %r15 + mov (9*8)(%rsi), %r8 movdqu (10*8 + 0*16)(%rsi), %xmm0 movdqu (10*8 + 1*16)(%rsi), %xmm1 diff --git a/lucet-runtime/lucet-runtime-internals/src/context/mod.rs b/lucet-runtime/lucet-runtime-internals/src/context/mod.rs index d76c94ea0..db0a9dacf 100644 --- a/lucet-runtime/lucet-runtime-internals/src/context/mod.rs +++ b/lucet-runtime/lucet-runtime-internals/src/context/mod.rs @@ -35,6 +35,7 @@ pub(crate) struct GpRegs { r14: u64, r15: u64, pub(crate) rsi: u64, + r8: u64 } impl GpRegs { @@ -49,6 +50,7 @@ impl GpRegs { r14: 0, r15: 0, rsi: 0, + r8: 0, } } } @@ -206,9 +208,10 @@ impl ContextHandle { stack: &mut [u64], fptr: usize, args: &[Val], + heap: *mut core::ffi::c_void, ) -> Result { let mut child = ContextHandle::new(); - Context::init(stack, &mut child, fptr, args)?; + Context::init(stack, &mut child, fptr, args, heap)?; Ok(child) } } @@ -365,6 +368,7 @@ impl Context { child: &mut Context, fptr: usize, args: &[Val], + heap: *mut core::ffi::c_void, ) -> Result<(), Error> { Context::init_with_callback( stack, @@ -373,6 +377,7 @@ impl Context { ptr::null_mut(), fptr, args, + heap, ) } @@ -391,6 +396,7 @@ impl Context { backstop_data: *mut Instance, fptr: usize, args: &[Val], + heap: *mut core::ffi::c_void, ) -> Result<(), Error> { if !stack_is_aligned(stack) { return Err(Error::UnalignedStack); @@ -471,6 +477,9 @@ impl Context { child.gpr.rbp = child as *const Context as u64; + // testing out heap pinning + child.gpr.r15 = heap as u64; + // Read the mask to be restored if we ever need to jump out of a signal handler. If this // isn't possible, die. signal::pthread_sigmask( diff --git a/lucet-runtime/lucet-runtime-internals/src/context/tests/c_child.rs b/lucet-runtime/lucet-runtime-internals/src/context/tests/c_child.rs index 6c881c02c..b1bc23628 100644 --- a/lucet-runtime/lucet-runtime-internals/src/context/tests/c_child.rs +++ b/lucet-runtime/lucet-runtime-internals/src/context/tests/c_child.rs @@ -55,6 +55,7 @@ macro_rules! init_and_swap { &mut *$stack, $fn as usize, &[$( $args ),*], + std::ptr::null_mut(), ).unwrap())); child_regs = child; diff --git a/lucet-runtime/lucet-runtime-internals/src/context/tests/mod.rs b/lucet-runtime/lucet-runtime-internals/src/context/tests/mod.rs index c98930b16..cf3eca602 100644 --- a/lucet-runtime/lucet-runtime-internals/src/context/tests/mod.rs +++ b/lucet-runtime/lucet-runtime-internals/src/context/tests/mod.rs @@ -31,7 +31,7 @@ fn init_rejects_unaligned() { let mut stack_unaligned = unsafe { slice::from_raw_parts_mut(ptr, len) }; // now we have the unaligned stack, let's make sure it blows up right - let res = ContextHandle::create_and_init(&mut stack_unaligned, dummy as usize, &[]); + let res = ContextHandle::create_and_init(&mut stack_unaligned, dummy as usize, &[], std::ptr::null_mut()); if let Err(Error::UnalignedStack) = res { assert!(true); diff --git a/lucet-runtime/lucet-runtime-internals/src/context/tests/rust_child.rs b/lucet-runtime/lucet-runtime-internals/src/context/tests/rust_child.rs index 5c44053dc..7ffd9e902 100644 --- a/lucet-runtime/lucet-runtime-internals/src/context/tests/rust_child.rs +++ b/lucet-runtime/lucet-runtime-internals/src/context/tests/rust_child.rs @@ -51,6 +51,7 @@ macro_rules! init_and_swap { &mut *$stack, $fn as usize, &[$( $args ),*], + std::ptr::null_mut(), ).unwrap(); CHILD = Some(child); diff --git a/lucet-runtime/lucet-runtime-internals/src/instance.rs b/lucet-runtime/lucet-runtime-internals/src/instance.rs index 7501d14d8..0f56c1189 100644 --- a/lucet-runtime/lucet-runtime-internals/src/instance.rs +++ b/lucet-runtime/lucet-runtime-internals/src/instance.rs @@ -843,7 +843,8 @@ impl Instance { self.entrypoint = Some(func.ptr); - let mut args_with_vmctx = vec![Val::from(self.alloc.slot().heap)]; + let heap = self.alloc.slot().heap; + let mut args_with_vmctx = vec![Val::from(heap)]; args_with_vmctx.extend_from_slice(args); let self_ptr = self as *mut _; @@ -854,6 +855,7 @@ impl Instance { self_ptr, func.ptr.as_usize(), &args_with_vmctx, + heap, )?; // Set up the guest to set itself as terminable, then continue to diff --git a/lucetc/src/compiler.rs b/lucetc/src/compiler.rs index 552a2672f..6735568a1 100644 --- a/lucetc/src/compiler.rs +++ b/lucetc/src/compiler.rs @@ -253,6 +253,8 @@ impl<'a> Compiler<'a> { let isa_builder = cpu_features.isa_builder(target)?; flags_builder.enable("enable_verifier").unwrap(); flags_builder.enable("is_pic").unwrap(); + flags_builder.enable("enable_pinned_reg"); + flags_builder.enable("use_pinned_reg_as_heap_base"); flags_builder.set("opt_level", opt_level.to_flag()).unwrap(); if canonicalize_nans { flags_builder.enable("enable_nan_canonicalization").unwrap(); From 40b97904b7780bd79b375af223662d7732dcdd82 Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Tue, 3 Sep 2019 17:00:54 -0700 Subject: [PATCH 2/8] rustfmt --- lucet-runtime/lucet-runtime-internals/src/context/mod.rs | 2 +- lucetc/src/compiler.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lucet-runtime/lucet-runtime-internals/src/context/mod.rs b/lucet-runtime/lucet-runtime-internals/src/context/mod.rs index db0a9dacf..36eb9566a 100644 --- a/lucet-runtime/lucet-runtime-internals/src/context/mod.rs +++ b/lucet-runtime/lucet-runtime-internals/src/context/mod.rs @@ -35,7 +35,7 @@ pub(crate) struct GpRegs { r14: u64, r15: u64, pub(crate) rsi: u64, - r8: u64 + r8: u64, } impl GpRegs { diff --git a/lucetc/src/compiler.rs b/lucetc/src/compiler.rs index 6735568a1..a39541998 100644 --- a/lucetc/src/compiler.rs +++ b/lucetc/src/compiler.rs @@ -253,8 +253,8 @@ impl<'a> Compiler<'a> { let isa_builder = cpu_features.isa_builder(target)?; flags_builder.enable("enable_verifier").unwrap(); flags_builder.enable("is_pic").unwrap(); - flags_builder.enable("enable_pinned_reg"); - flags_builder.enable("use_pinned_reg_as_heap_base"); + flags_builder.enable("enable_pinned_reg").unwrap(); + flags_builder.enable("use_pinned_reg_as_heap_base").unwrap(); flags_builder.set("opt_level", opt_level.to_flag()).unwrap(); if canonicalize_nans { flags_builder.enable("enable_nan_canonicalization").unwrap(); From fde62fa3f74d5d112e7bd406bec677460d417218 Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Tue, 3 Sep 2019 17:09:13 -0700 Subject: [PATCH 3/8] get tests building and running --- lucet-runtime/lucet-runtime-internals/src/context/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lucet-runtime/lucet-runtime-internals/src/context/mod.rs b/lucet-runtime/lucet-runtime-internals/src/context/mod.rs index 36eb9566a..5ba3c8d4d 100644 --- a/lucet-runtime/lucet-runtime-internals/src/context/mod.rs +++ b/lucet-runtime/lucet-runtime-internals/src/context/mod.rs @@ -304,6 +304,7 @@ impl Context { /// &mut child, /// entrypoint as usize, /// &[Val::U64(120), Val::F32(3.14)], + /// std::ptr::null_mut(), /// ); /// assert!(res.is_ok()); /// ``` @@ -327,6 +328,7 @@ impl Context { /// &mut child, /// entrypoint as usize, /// &[Val::U64(120), Val::F32(3.14)], + /// std::ptr::null_mut(), /// ); /// assert!(res.is_ok()); /// ``` @@ -561,6 +563,7 @@ impl Context { /// &mut child, /// entrypoint as usize, /// &[], + /// std::ptr::null_mut(), /// ).unwrap(); /// /// unsafe { Context::swap(&mut parent, &mut child); } From 3cd23d7bb1d451050dfe0f69afe1e1041e3af5b9 Mon Sep 17 00:00:00 2001 From: iximeow Date: Fri, 14 Feb 2020 15:14:00 -0800 Subject: [PATCH 4/8] hack: find a new magic number for stack overflow test --- lucet-runtime/lucet-runtime-tests/src/stack.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lucet-runtime/lucet-runtime-tests/src/stack.rs b/lucet-runtime/lucet-runtime-tests/src/stack.rs index b9062476d..20b207321 100644 --- a/lucet-runtime/lucet-runtime-tests/src/stack.rs +++ b/lucet-runtime/lucet-runtime-tests/src/stack.rs @@ -157,7 +157,9 @@ macro_rules! stack_tests { expect_stack_overflow( // Same note as `expect_ok_locals64_481` stack_testcase(64 - 4).expect("generate stack_testcase 64"), - 481, + // TODO: pick some high enough number that this test overflows still + // cranelift changes made 480 the wrong magic number + 591, true, ); } From 71152a19ef0467b68593d849f5a0e81dc7987894 Mon Sep 17 00:00:00 2001 From: iximeow Date: Fri, 14 Feb 2020 15:54:38 -0800 Subject: [PATCH 5/8] add lucetc flag to select heap pinning --- lucet-module/src/module_data.rs | 2 ++ lucet-spectest/src/script.rs | 1 + lucetc/lucetc/options.rs | 6 ++++++ lucetc/src/compiler.rs | 14 +++++++++++--- lucetc/src/lib.rs | 16 ++++++++++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lucet-module/src/module_data.rs b/lucet-module/src/module_data.rs index 2196a5985..e0746890a 100644 --- a/lucet-module/src/module_data.rs +++ b/lucet-module/src/module_data.rs @@ -59,6 +59,7 @@ pub struct ModuleFeatures { pub lzcnt: bool, pub popcnt: bool, pub instruction_count: bool, + pub pinned_heap: bool, _hidden: (), } @@ -75,6 +76,7 @@ impl ModuleFeatures { lzcnt: false, popcnt: false, instruction_count: false, + pinned_heap: false, _hidden: (), } } diff --git a/lucet-spectest/src/script.rs b/lucet-spectest/src/script.rs index 20c2b042d..825ae3614 100644 --- a/lucet-spectest/src/script.rs +++ b/lucet-spectest/src/script.rs @@ -74,6 +74,7 @@ impl ScriptEnv { true, &None, false, + false, ) .map_err(program_error)?; diff --git a/lucetc/lucetc/options.rs b/lucetc/lucetc/options.rs index eb1bc2c4e..01403be99 100644 --- a/lucetc/lucetc/options.rs +++ b/lucetc/lucetc/options.rs @@ -453,6 +453,12 @@ SSE3 but not AVX: .takes_value(false) .help("Instrument the produced binary to count the number of wasm operations the translated program executes") ) + .arg( + Arg::with_name("pinned_heap") + .long("--pinned-heap-reg") + .takes_value(false) + .help("This feature is not stable - it may be removed in the future! Pin a register to use as this module's heap base. Typically improves performance.") + ) .arg( Arg::with_name("error_style") .long("error-style") diff --git a/lucetc/src/compiler.rs b/lucetc/src/compiler.rs index a39541998..fd1eb3c04 100644 --- a/lucetc/src/compiler.rs +++ b/lucetc/src/compiler.rs @@ -56,6 +56,7 @@ pub struct Compiler<'a> { count_instructions: bool, module_translation_state: ModuleTranslationState, canonicalize_nans: bool, + pinned_heap: bool, } impl<'a> Compiler<'a> { @@ -69,8 +70,9 @@ impl<'a> Compiler<'a> { count_instructions: bool, validator: &Option, canonicalize_nans: bool, + pinned_heap: bool, ) -> Result { - let isa = Self::target_isa(target.clone(), opt_level, &cpu_features, canonicalize_nans)?; + let isa = Self::target_isa(target.clone(), opt_level, &cpu_features, canonicalize_nans, pinned_heap)?; let frontend_config = isa.frontend_config(); let mut module_info = ModuleInfo::new(frontend_config.clone()); @@ -127,12 +129,14 @@ impl<'a> Compiler<'a> { module_translation_state, target, canonicalize_nans, + pinned_heap, }) } pub fn module_features(&self) -> ModuleFeatures { let mut mf: ModuleFeatures = (&self.cpu_features).into(); mf.instruction_count = self.count_instructions; + mf.pinned_heap = self.pinned_heap; mf } @@ -239,6 +243,7 @@ impl<'a> Compiler<'a> { self.opt_level, &self.cpu_features, self.canonicalize_nans, + self.pinned_heap, )?, )) } @@ -248,17 +253,20 @@ impl<'a> Compiler<'a> { opt_level: OptLevel, cpu_features: &CpuFeatures, canonicalize_nans: bool, + pinned_heap: bool, ) -> Result, Error> { let mut flags_builder = settings::builder(); let isa_builder = cpu_features.isa_builder(target)?; flags_builder.enable("enable_verifier").unwrap(); flags_builder.enable("is_pic").unwrap(); - flags_builder.enable("enable_pinned_reg").unwrap(); - flags_builder.enable("use_pinned_reg_as_heap_base").unwrap(); flags_builder.set("opt_level", opt_level.to_flag()).unwrap(); if canonicalize_nans { flags_builder.enable("enable_nan_canonicalization").unwrap(); } + if pinned_heap { + flags_builder.enable("enable_pinned_reg").unwrap(); + flags_builder.enable("use_pinned_reg_as_heap_base").unwrap(); + } Ok(isa_builder.finish(settings::Flags::new(flags_builder))) } } diff --git a/lucetc/src/lib.rs b/lucetc/src/lib.rs index 139ca2cdb..03d7136f1 100755 --- a/lucetc/src/lib.rs +++ b/lucetc/src/lib.rs @@ -55,6 +55,7 @@ pub struct Lucetc { verify: bool, count_instructions: bool, canonicalize_nans: bool, + pinned_heap: bool, } pub trait AsLucetc { @@ -116,6 +117,8 @@ pub trait LucetcOpts { fn with_count_instructions(self, enable_count: bool) -> Self; fn canonicalize_nans(&mut self, enable_canonicalize_nans: bool); fn with_canonicalize_nans(self, enable_canonicalize_nans: bool) -> Self; + fn pinned_heap(&mut self, enable_pinned_heap: bool); + fn with_pinned_heap(self, enable_pinned_heap: bool) -> Self; } impl LucetcOpts for T { @@ -265,6 +268,15 @@ impl LucetcOpts for T { self.canonicalize_nans(enable_nans_canonicalization); self } + + fn pinned_heap(&mut self, enable_pinned_heap: bool) { + self.as_lucetc().pinned_heap = enable_pinned_heap; + } + + fn with_pinned_heap(mut self, enable_pinned_heap: bool) -> Self { + self.pinned_heap(enable_pinned_heap); + self + } } impl Lucetc { @@ -285,6 +297,7 @@ impl Lucetc { verify: false, count_instructions: false, canonicalize_nans: false, + pinned_heap: false, } } @@ -305,6 +318,7 @@ impl Lucetc { verify: false, count_instructions: false, canonicalize_nans: false, + pinned_heap: false, }) } @@ -349,6 +363,7 @@ impl Lucetc { self.count_instructions, &self.validator, self.canonicalize_nans, + self.pinned_heap, )?; let obj = compiler.object_file()?; obj.write(output.as_ref())?; @@ -369,6 +384,7 @@ impl Lucetc { self.count_instructions, &self.validator, self.canonicalize_nans, + self.pinned_heap, )?; compiler.cranelift_funcs()?.write(&output)?; From e3a5b24ac7a0d89a6154e3c2adf75b8f8ca48d70 Mon Sep 17 00:00:00 2001 From: iximeow Date: Fri, 14 Feb 2020 15:56:20 -0800 Subject: [PATCH 6/8] rustfmt --- benchmarks/lucet-benchmarks/src/context.rs | 29 +++++++++++++++---- .../src/context/tests/mod.rs | 7 ++++- lucetc/src/compiler.rs | 8 ++++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/benchmarks/lucet-benchmarks/src/context.rs b/benchmarks/lucet-benchmarks/src/context.rs index 9ae10b8a0..4ef7b4d3f 100644 --- a/benchmarks/lucet-benchmarks/src/context.rs +++ b/benchmarks/lucet-benchmarks/src/context.rs @@ -9,7 +9,8 @@ fn context_init(c: &mut Criterion) { c.bench_function("context_init", move |b| { b.iter(|| { - ContextHandle::create_and_init(&mut *stack, f as usize, &[], std::ptr::null_mut()).unwrap(); + ContextHandle::create_and_init(&mut *stack, f as usize, &[], std::ptr::null_mut()) + .unwrap(); }) }); } @@ -22,7 +23,13 @@ fn context_swap_return(c: &mut Criterion) { b.iter_batched( || { let mut stack = vec![0u64; 1024].into_boxed_slice(); - let child = ContextHandle::create_and_init(&mut *stack, f as usize, &[], std::ptr::null_mut()).unwrap(); + let child = ContextHandle::create_and_init( + &mut *stack, + f as usize, + &[], + std::ptr::null_mut(), + ) + .unwrap(); (stack, child) }, |(stack, mut child)| unsafe { @@ -44,8 +51,13 @@ fn context_init_swap_return(c: &mut Criterion) { || vec![0u64; 1024].into_boxed_slice(), |mut stack| { let mut parent = ContextHandle::new(); - let mut child = - ContextHandle::create_and_init(&mut *stack, f as usize, &[], std::ptr::null_mut()).unwrap(); + let mut child = ContextHandle::create_and_init( + &mut *stack, + f as usize, + &[], + std::ptr::null_mut(), + ) + .unwrap(); unsafe { Context::swap(&mut parent, &mut child) }; stack }, @@ -332,8 +344,13 @@ fn context_init_swap_return_many_args(c: &mut Criterion) { || vec![0u64; 1024].into_boxed_slice(), |mut stack| { let mut parent = ContextHandle::new(); - let mut child = - ContextHandle::create_and_init(&mut *stack, f as usize, &args, std::ptr::null_mut()).unwrap(); + let mut child = ContextHandle::create_and_init( + &mut *stack, + f as usize, + &args, + std::ptr::null_mut(), + ) + .unwrap(); unsafe { Context::swap(&mut parent, &mut child) }; stack }, diff --git a/lucet-runtime/lucet-runtime-internals/src/context/tests/mod.rs b/lucet-runtime/lucet-runtime-internals/src/context/tests/mod.rs index cf3eca602..473acd1d7 100644 --- a/lucet-runtime/lucet-runtime-internals/src/context/tests/mod.rs +++ b/lucet-runtime/lucet-runtime-internals/src/context/tests/mod.rs @@ -31,7 +31,12 @@ fn init_rejects_unaligned() { let mut stack_unaligned = unsafe { slice::from_raw_parts_mut(ptr, len) }; // now we have the unaligned stack, let's make sure it blows up right - let res = ContextHandle::create_and_init(&mut stack_unaligned, dummy as usize, &[], std::ptr::null_mut()); + let res = ContextHandle::create_and_init( + &mut stack_unaligned, + dummy as usize, + &[], + std::ptr::null_mut(), + ); if let Err(Error::UnalignedStack) = res { assert!(true); diff --git a/lucetc/src/compiler.rs b/lucetc/src/compiler.rs index fd1eb3c04..292c925e9 100644 --- a/lucetc/src/compiler.rs +++ b/lucetc/src/compiler.rs @@ -72,7 +72,13 @@ impl<'a> Compiler<'a> { canonicalize_nans: bool, pinned_heap: bool, ) -> Result { - let isa = Self::target_isa(target.clone(), opt_level, &cpu_features, canonicalize_nans, pinned_heap)?; + let isa = Self::target_isa( + target.clone(), + opt_level, + &cpu_features, + canonicalize_nans, + pinned_heap, + )?; let frontend_config = isa.frontend_config(); let mut module_info = ModuleInfo::new(frontend_config.clone()); From 238b259174b1ea1cb70f799c61a8f88c435e0bee Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 18 Feb 2020 15:15:56 -0800 Subject: [PATCH 7/8] fix the rest of test --- lucet-wasi-sdk/tests/lucetc.rs | 5 +++++ lucetc/tests/wasm.rs | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lucet-wasi-sdk/tests/lucetc.rs b/lucet-wasi-sdk/tests/lucetc.rs index 1a6311b0c..efb922d59 100644 --- a/lucet-wasi-sdk/tests/lucetc.rs +++ b/lucet-wasi-sdk/tests/lucetc.rs @@ -55,6 +55,7 @@ mod lucetc_tests { false, &Some(v), false, + false, ) .expect("compile empty"); let mdata = c.module_data().unwrap(); @@ -101,6 +102,7 @@ mod lucetc_tests { false, &Some(v), false, + false, ) .expect("compile c"); let mdata = c.module_data().unwrap(); @@ -133,6 +135,7 @@ mod lucetc_tests { false, &Some(v), false, + false, ) .expect("compile d"); let mdata = c.module_data().unwrap(); @@ -161,6 +164,7 @@ mod lucetc_tests { false, &Some(v), false, + false, ) .expect("compile c & d"); let mdata = c.module_data().unwrap(); @@ -213,6 +217,7 @@ mod lucetc_tests { false, &Some(v), false, + false, ) .expect("compile empty"); let mdata = c.module_data().unwrap(); diff --git a/lucetc/tests/wasm.rs b/lucetc/tests/wasm.rs index 7e70cf7e1..cbd7db382 100644 --- a/lucetc/tests/wasm.rs +++ b/lucetc/tests/wasm.rs @@ -58,6 +58,7 @@ mod module_data { false, &None, false, + false, ) .expect("compiling exported_import"); let mdata = c.module_data().unwrap(); @@ -88,6 +89,7 @@ mod module_data { false, &None, false, + false, ) .expect("compiling multiple_import"); let mdata = c.module_data().unwrap(); @@ -114,6 +116,7 @@ mod module_data { false, &None, false, + false, ) .expect("compiling globals_export"); let mdata = c.module_data().unwrap(); @@ -141,6 +144,7 @@ mod module_data { false, &None, false, + false, ) .expect("compiling fibonacci"); let mdata = c.module_data().unwrap(); @@ -166,6 +170,7 @@ mod module_data { false, &None, false, + false, ) .expect("compiling arith"); let mdata = c.module_data().unwrap(); @@ -194,6 +199,7 @@ mod module_data { false, &None, false, + false, ) .expect("compile duplicate_imports"); let mdata = c.module_data().unwrap(); @@ -231,6 +237,7 @@ mod module_data { false, &None, false, + false, ) .expect("compile icall"); let mdata = c.module_data().unwrap(); @@ -278,6 +285,7 @@ mod module_data { false, &None, false, + false, ) .expect("compile icall"); let _module_data = c.module_data().unwrap(); @@ -314,6 +322,7 @@ mod module_data { false, &None, false, + false, ) .expect("compile icall_sparse"); let _module_data = c.module_data().unwrap(); @@ -364,6 +373,7 @@ mod module_data { false, &None, false, + false, ) .expect("compile globals_import"); let module_data = c.module_data().unwrap(); @@ -396,6 +406,7 @@ mod module_data { false, &None, false, + false, ) .expect("compiling heap_spec_import"); @@ -429,6 +440,7 @@ mod module_data { false, &None, false, + false, ) .expect("compiling heap_spec_definition"); @@ -461,6 +473,7 @@ mod module_data { false, &None, false, + false, ) .expect("compiling heap_spec_none"); assert_eq!(c.module_data().unwrap().heap_spec(), None,); @@ -482,6 +495,7 @@ mod module_data { false, &None, false, + false, ); assert!( c.is_err(), @@ -520,6 +534,7 @@ mod module_data { false, &None, false, + false, ); assert!( c.is_err(), @@ -547,6 +562,7 @@ mod module_data { false, &None, false, + false, ) .expect("compile start_section"); /* @@ -572,6 +588,7 @@ mod module_data { false, &None, false, + false, ) .expect("compile names_local"); let mdata = c.module_data().unwrap(); @@ -605,6 +622,7 @@ mod compile { false, &None, false, + false, ) .expect(&format!("compile {}", file)); let _obj = c.object_file().expect(&format!("codegen {}", file)); @@ -666,6 +684,7 @@ mod validate { false, &Some(v), false, + false, ) .expect("compile"); let _obj = c.object_file().expect("codegen"); @@ -695,6 +714,7 @@ mod validate { false, &Some(v), false, + false, ) .expect("compile"); let _obj = c.object_file().expect("codegen"); @@ -726,6 +746,7 @@ mod validate { false, &Some(v), false, + false, ) .expect("compile"); let _obj = c.object_file().expect("codegen"); @@ -755,6 +776,7 @@ mod validate { false, &Some(v), false, + false, ) .expect("compile"); let _obj = c.object_file().expect("codegen"); @@ -784,6 +806,7 @@ mod validate { false, &Some(v), false, + false, ) .expect("compile"); let _obj = c.object_file().expect("codegen"); @@ -815,6 +838,7 @@ mod validate { false, &Some(v), false, + false, ) .expect("compile"); let _obj = c.object_file().expect("codegen"); @@ -841,6 +865,7 @@ mod validate { false, &Some(v), false, + false, ) .expect("compile"); let _obj = c.object_file().expect("codegen"); From b698b0984fa9217844d27ecabb2973f2d31d9d4c Mon Sep 17 00:00:00 2001 From: iximeow Date: Wed, 19 Feb 2020 12:48:54 -0800 Subject: [PATCH 8/8] actually pass argument from command line to compiler --- lucetc/lucetc/main.rs | 4 ++++ lucetc/lucetc/options.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lucetc/lucetc/main.rs b/lucetc/lucetc/main.rs index 1dee241b7..c29e4436c 100644 --- a/lucetc/lucetc/main.rs +++ b/lucetc/lucetc/main.rs @@ -141,6 +141,10 @@ pub fn run(opts: &Options) -> Result<(), Error> { c.count_instructions(true); } + if opts.pinned_heap { + c.pinned_heap(true); + } + match opts.codegen { CodegenOutput::Obj => c.object_file(&opts.output)?, CodegenOutput::SharedObj => c.shared_object_file(&opts.output)?, diff --git a/lucetc/lucetc/options.rs b/lucetc/lucetc/options.rs index 01403be99..e6894cef2 100644 --- a/lucetc/lucetc/options.rs +++ b/lucetc/lucetc/options.rs @@ -120,6 +120,7 @@ pub struct Options { pub pk_path: Option, pub sk_path: Option, pub count_instructions: bool, + pub pinned_heap: bool, pub error_style: ErrorStyle, pub target: Triple, } @@ -212,6 +213,7 @@ impl Options { let sk_path = m.value_of("sk_path").map(PathBuf::from); let pk_path = m.value_of("pk_path").map(PathBuf::from); let count_instructions = m.is_present("count_instructions"); + let pinned_heap = m.is_present("pinned_heap"); let error_style = match m.value_of("error_style") { None => ErrorStyle::default(), @@ -240,6 +242,7 @@ impl Options { sk_path, pk_path, count_instructions, + pinned_heap, error_style, target, })