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

Add AArch64 support for singlepass. #713

Merged
merged 131 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
4210715
AArch64 translation module.
losfair Sep 6, 2019
ce7c903
Add impl for more instructions for aarch64 translator.
losfair Sep 10, 2019
d3227f8
More instructions & aarch64 trampolines.
losfair Sep 15, 2019
9b77677
Relax constraints a bit to compile on aarch64.
losfair Sep 15, 2019
2af69f6
Fixed compilation on aarch64.
losfair Sep 15, 2019
96163a0
Temporarily disable all lints in runtime-core.
losfair Sep 15, 2019
05557fc
Bump dynasm to v0.5.1
losfair Sep 16, 2019
d8b313e
Fix emit_lea.
losfair Sep 16, 2019
574e4c4
Print return value from pure WASM binary.
losfair Sep 16, 2019
b57aba4
Add homomorphic host redirection abstraction for vm->host calls.
losfair Sep 17, 2019
97b75d0
Ensure callee-saved registers are properly preserved.
losfair Sep 17, 2019
e406005
Add missing `emit_mov` variants.
losfair Sep 17, 2019
72b6123
Fix memory grow
losfair Sep 17, 2019
8a91f80
Fix return from homomorphic host redirection trampoline.
losfair Sep 18, 2019
5f8b289
movzx/movsx
losfair Sep 18, 2019
a124d87
Fix Operator::MemorySize.
losfair Sep 18, 2019
3dadbc1
Integer subset done.
losfair Sep 23, 2019
89d8b5a
Fixes for aarch64.
losfair Sep 28, 2019
b304317
More mov variants.
losfair Sep 29, 2019
80d6c4c
Implement get_fault_info for aarch64.
losfair Oct 6, 2019
e0e7d58
Make state mapping work on non-x86 architectures.
losfair Oct 7, 2019
b5bb3fa
Move {push,pop}_code_version to caller side for non-mananged execution.
losfair Oct 8, 2019
c337999
x
losfair Oct 8, 2019
bd06aa0
x
losfair Oct 8, 2019
3778352
Update a few examples.
losfair Oct 8, 2019
8ee4b7f
Replace brk with undefined instruction.
losfair Oct 10, 2019
2e1fb7a
Update call_trace middleware to include a counter.
losfair Oct 11, 2019
db59127
Inline breakpoint support in core.
losfair Oct 11, 2019
94f9710
Include backend metadata in tiering module.
losfair Oct 11, 2019
36f95fc
Support emitting inline breakpoints in singlepass.
losfair Oct 11, 2019
ad3faa0
Add CallTrace CLI option.
losfair Oct 11, 2019
c18bdd5
Fix inline breakpoints on macOS.
losfair Oct 13, 2019
5499a69
Run cargo fmt on everything.
losfair Oct 13, 2019
128b006
Add a BlockTrace middleware.
losfair Oct 13, 2019
b0b0983
Allow accessing execution state in middleware breakpoint handlers.
losfair Oct 13, 2019
ba7e2b7
Add block-trace flag to CLI.
losfair Oct 13, 2019
a525907
Emit state information for internal breakpoints.
losfair Oct 14, 2019
2e532fa
Preserve fault.ip when calling middleware.
losfair Oct 14, 2019
e5f7dc8
Print the last frame in block trace output.
losfair Oct 14, 2019
ee88c45
Allow arbitrary size of `disp`.
losfair Oct 15, 2019
81d538a
Fix disp < 0 case.
losfair Oct 15, 2019
3de0c77
Skip inline non-instruction data.
losfair Oct 15, 2019
d325635
Increment aarch64 virtual stack size to 1MB.
losfair Oct 17, 2019
00242cd
Fix LEA simulation on aarch64.
losfair Oct 17, 2019
4df7973
Add mov variants.
losfair Oct 17, 2019
3f35a74
Two more mov variants.
losfair Oct 17, 2019
a057296
(S32, Imm64, GPR)
losfair Oct 17, 2019
cd0b49e
popcnt for aarch64.
losfair Oct 17, 2019
015491e
Add floating point instructions.
losfair Nov 5, 2019
6135a00
Add itruncf/fconverti fast path.
losfair Nov 6, 2019
0012137
Add fneg.
losfair Nov 6, 2019
50c30ab
runtime-core: Support cross-compilation.
losfair Nov 6, 2019
899fbed
Merge master.
losfair Nov 10, 2019
7d5699c
Add missing instructions for aarch64.
losfair Nov 10, 2019
03a9d1a
Cargo fmt
losfair Nov 10, 2019
03c5614
Rerun cargo fmt
losfair Nov 10, 2019
07ca48a
Try initial travis arm64 setup
bjfish Nov 10, 2019
41d207d
Trigger a build
bjfish Nov 10, 2019
2f699a3
Add cmake to CI
bjfish Nov 10, 2019
9828a37
Whitelist specific branches to run
bjfish Nov 10, 2019
8db67e4
Merge pull request #943 from bjfish/singlepass-aarch64-travis
losfair Nov 12, 2019
f1339b4
Fix known_registers size.
losfair Nov 12, 2019
c552514
Disable NaN canonicalizing on aarch64.
losfair Nov 13, 2019
47f1e2a
Fix parameter loading.
losfair Nov 13, 2019
e2956e7
Run cargo fmt
losfair Nov 13, 2019
08a1dd3
Merge master and add documentation.
losfair Nov 13, 2019
ccc474b
Remove debug files.
losfair Nov 13, 2019
605ada7
Run cargo fmt.
losfair Nov 13, 2019
66e9184
Specify test-threads=1 for singlepass spectests.
losfair Nov 13, 2019
a9c89eb
Merge remote-tracking branch 'origin/master' into feature/singlepass-…
losfair Nov 14, 2019
342974e
Comment out failing test.
losfair Nov 14, 2019
1db6425
Merge remote-tracking branch 'origin/master' into feature/singlepass-…
losfair Nov 16, 2019
08beb99
Fix popcnt.
losfair Nov 16, 2019
cbaa94a
Fix movsx(S32, S64).
losfair Nov 17, 2019
5d2ee4f
Fix floating point comparision involving NaNs.
losfair Nov 17, 2019
1eed6ce
Fix CONSTRUCT_STACK_AND_CALL_WASM for aarch64.
losfair Nov 17, 2019
f7f91c3
Merge remote-tracking branch 'origin-http/master' into feature/single…
losfair Nov 18, 2019
23f03f5
Fix compilation failure in tiering.rs.
losfair Nov 18, 2019
d7308c3
Fix call_indirect on imported functions.
losfair Nov 18, 2019
06a7e54
Inline entry trampolines.
losfair Nov 18, 2019
ddbdb3e
Ignore extra arguments.
losfair Nov 18, 2019
2776dae
Fix entry with more than 5/6 arguments.
losfair Nov 18, 2019
8ebf898
Reduce stack size.
losfair Nov 18, 2019
a7577df
Try further reducing preallocated stack size.
losfair Nov 19, 2019
3d48115
Allocate a big enough stack for invoke().
losfair Nov 19, 2019
85b1935
Uncomment previously disabled test.
losfair Nov 19, 2019
98052f8
Unmap stack after call.
losfair Nov 19, 2019
34bb321
Rename `emit_host_redirection`.
losfair Nov 19, 2019
c9aa37f
Cleanup.
losfair Nov 19, 2019
93f096b
Fix lint errors when singlepass is disabled.
losfair Nov 19, 2019
d56fd96
Merge remote-tracking branch 'origin/master' into feature/singlepass-…
losfair Nov 19, 2019
28ebe5f
Rustfmt
losfair Nov 19, 2019
0c7545d
Tell dynasm we are generating x64 code in `emitter_x64`.
losfair Nov 19, 2019
ef1713d
Update install.sh
syrusakbary Nov 21, 2019
b77dffb
Merge branch 'master' into feature/singlepass-aarch64
syrusakbary Nov 21, 2019
b8aee87
Skip atomic tests for now in singlepass Aarch64
syrusakbary Nov 21, 2019
b3322a6
Move xxx.wat to the examples dir
syrusakbary Nov 21, 2019
cafad45
Added make wapm command
syrusakbary Nov 21, 2019
27b1789
Move popcnt to examples
syrusakbary Nov 21, 2019
e5905c9
Added support for the aarch64/arm64 in the scripts
syrusakbary Nov 21, 2019
c531998
Try to generate an arm release on the travis script
syrusakbary Nov 21, 2019
46f43bf
Fix travis config
syrusakbary Nov 21, 2019
a4b1b9e
Trying to improve Travis build script
syrusakbary Nov 21, 2019
6a68ff7
Trying to fix sccache in arm
syrusakbary Nov 21, 2019
d0437db
Iterating on Travis
syrusakbary Nov 21, 2019
1e886e2
Trying to make cargo happy
syrusakbary Nov 21, 2019
605fdc9
Trying to fix installation
syrusakbary Nov 21, 2019
43a99cd
Trying to upload artifact to GH releases
syrusakbary Nov 21, 2019
10aa6c8
Allow deployment on branch
syrusakbary Nov 21, 2019
4d973da
Don’t try to create a new tag
syrusakbary Nov 21, 2019
df43759
Merge remote-tracking branch 'origin/master' into feature/singlepass-…
losfair Nov 21, 2019
5f26fcd
Make cranelift optional and enable singlepass by default on aarch64.
losfair Nov 21, 2019
d450761
Merge remote-tracking branch 'origin/feature/singlepass-aarch64' into…
losfair Nov 21, 2019
73cc86d
Fix compilation errors with cranelift.
losfair Nov 21, 2019
d135255
Remove accidentally added test files.
losfair Nov 21, 2019
15e3a03
Try fixing compilation on Windows.
losfair Nov 21, 2019
c0ff110
Merge remote-tracking branch 'origin/master' into feature/singlepass-…
losfair Nov 21, 2019
6f3e6fa
Try fixing compilation on Windows.
losfair Nov 21, 2019
4ec4fcf
Try fixing middleware failure.
losfair Nov 21, 2019
8709708
Unwind if breakpoint handler returns error.
losfair Nov 21, 2019
4dd810b
Ensure code version metadata is pushed properly.
losfair Nov 21, 2019
7626957
Enable block_trace middleware only on unix.
losfair Nov 21, 2019
daee31f
Add changelog entry.
losfair Nov 21, 2019
5da44c3
Add 'fault' placeholder for Windows.
losfair Nov 21, 2019
ee7b0d6
Skip push/pop code version on Windows.
losfair Nov 22, 2019
87f4183
Merge remote-tracking branch 'origin/master' into feature/singlepass-…
losfair Nov 22, 2019
0834ccf
Merge branch 'master' into feature/singlepass-aarch64
syrusakbary Nov 22, 2019
21e6766
Try pinning Rust version for arm64 build.
losfair Nov 22, 2019
80fb5b4
Merge remote-tracking branch 'origin/feature/singlepass-aarch64' into…
losfair Nov 22, 2019
a691d34
Skip serializing on singlepass
syrusakbary Nov 22, 2019
183dd32
Make travis work only on test branches
syrusakbary Nov 22, 2019
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
89 changes: 38 additions & 51 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ members = [
"lib/wasi-tests",
"lib/emscripten-tests",
"lib/middleware-common-tests",
"examples/plugin-for-example"
"examples/plugin-for-example",
"examples/hello_world"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other directory uses hyphens to separate words. Please follow suit.

]

[build-dependencies]
Expand Down
20 changes: 20 additions & 0 deletions examples/fib.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(module
(func $main (result i32)
(call $fib (i32.const 40))
)

(func $fib (param $n i32) (result i32)
(if (i32.eq (get_local $n) (i32.const 0))
(then (return (i32.const 1)))
)
(if (i32.eq (get_local $n) (i32.const 1))
(then (return (i32.const 1)))
)
(i32.add
(call $fib (i32.sub (get_local $n) (i32.const 1)))
(call $fib (i32.sub (get_local $n) (i32.const 2)))
)
)

(export "main" (func $main))
)
9 changes: 9 additions & 0 deletions examples/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "hello_world"
version = "0.1.0"
authors = ["losfair <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
7 changes: 7 additions & 0 deletions examples/hello_world/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
for i in 0..8 {
let s = format!("Hello, {}", i);
println!("{}", s);
}
panic!("OK");
}
2 changes: 1 addition & 1 deletion examples/iterative_hash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
let diff = millis - last_millis;
if diff >= 100 {
record_count += 1;
println!("{}", (i - round_count) as f64 / diff as f64);
println!("{}", ((i - round_count) as u128) * 1000000 / diff );
last_millis = millis;
round_count = i;
}
Expand Down
153 changes: 153 additions & 0 deletions lib/middleware-common/src/block_trace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
use wasmer_runtime_core::{
codegen::{Event, EventSink, FunctionMiddleware, InternalEvent},
module::ModuleInfo,
wasmparser::Operator,
};

pub struct BlockTrace {
func_idx: usize,
evt_idx: usize,
}

impl BlockTrace {
pub fn new() -> BlockTrace {
BlockTrace {
func_idx: std::usize::MAX,
evt_idx: 0,
}
}
}

impl FunctionMiddleware for BlockTrace {
type Error = String;
fn feed_event<'a, 'b: 'a>(
&mut self,
op: Event<'a, 'b>,
_module_info: &ModuleInfo,
sink: &mut EventSink<'a, 'b>,
) -> Result<(), Self::Error> {
match op {
Event::Internal(InternalEvent::FunctionBegin(_)) => {
self.func_idx = self.func_idx.wrapping_add(1);
self.evt_idx = 0;
let func_idx = self.func_idx;
let evt_idx = self.evt_idx;
sink.push(op);
sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(
move |info| {
eprintln!(
"[BlockTrace] ({}, {}) -> enter_func % {:?}",
func_idx,
evt_idx,
info.fault
.and_then(|x| unsafe { x.read_stack(Some(1)) })
.unwrap()
.frames[0]
);
Ok(())
},
))))
}
Event::Wasm(Operator::Call { .. }) => {
let func_idx = self.func_idx;
let evt_idx = self.evt_idx;
sink.push(op);
sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(
move |info| {
eprintln!(
"[BlockTrace] ({}, {}) -> leave_call % {:?}",
func_idx,
evt_idx,
info.fault
.and_then(|x| unsafe { x.read_stack(Some(1)) })
.unwrap()
.frames[0]
);
Ok(())
},
))))
}
Event::Wasm(Operator::Block { .. }) => {
let func_idx = self.func_idx;
let evt_idx = self.evt_idx;
sink.push(op);
sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(
move |info| {
eprintln!(
"[BlockTrace] ({}, {}) -> block % {:?}",
func_idx,
evt_idx,
info.fault
.and_then(|x| unsafe { x.read_stack(Some(1)) })
.unwrap()
.frames[0]
);
Ok(())
},
))))
}
Event::Wasm(Operator::Loop { .. }) => {
let func_idx = self.func_idx;
let evt_idx = self.evt_idx;
sink.push(op);
sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(
move |info| {
eprintln!(
"[BlockTrace] ({}, {}) -> loop % {:?}",
func_idx,
evt_idx,
info.fault
.and_then(|x| unsafe { x.read_stack(Some(1)) })
.unwrap()
.frames[0]
);
Ok(())
},
))))
}
Event::Wasm(Operator::If { .. }) => {
let func_idx = self.func_idx;
let evt_idx = self.evt_idx;
sink.push(op);
sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(
move |info| {
eprintln!(
"[BlockTrace] ({}, {}) -> if % {:?}",
func_idx,
evt_idx,
info.fault
.and_then(|x| unsafe { x.read_stack(Some(1)) })
.unwrap()
.frames[0]
);
Ok(())
},
))))
}
Event::Wasm(Operator::Else { .. }) => {
let func_idx = self.func_idx;
let evt_idx = self.evt_idx;
sink.push(op);
sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(
move |info| {
eprintln!(
"[BlockTrace] ({}, {}) -> else % {:?}",
func_idx,
evt_idx,
info.fault
.and_then(|x| unsafe { x.read_stack(Some(1)) })
.unwrap()
.frames[0]
);
Ok(())
},
))))
}
_ => {
sink.push(op);
}
}
self.evt_idx += 1;
Ok(())
}
}
21 changes: 19 additions & 2 deletions lib/middleware-common/src/call_trace.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
use std::sync::{
atomic::{AtomicU32, Ordering},
Arc,
};
use wasmer_runtime_core::{
codegen::{Event, EventSink, FunctionMiddleware, InternalEvent},
module::ModuleInfo,
};

pub struct CallTrace;
pub struct CallTrace {
counter: Arc<AtomicU32>,
}

impl CallTrace {
pub fn new() -> CallTrace {
CallTrace {
counter: Arc::new(AtomicU32::new(0)),
}
}
}

impl FunctionMiddleware for CallTrace {
type Error = String;
Expand All @@ -13,10 +27,13 @@ impl FunctionMiddleware for CallTrace {
_module_info: &ModuleInfo,
sink: &mut EventSink<'a, 'b>,
) -> Result<(), Self::Error> {
let counter = self.counter.clone();

match op {
Event::Internal(InternalEvent::FunctionBegin(id)) => sink.push(Event::Internal(
InternalEvent::Breakpoint(Box::new(move |_| {
eprintln!("func ({})", id);
let idx = counter.fetch_add(1, Ordering::SeqCst);
eprintln!("[{}] func ({})", idx, id);
Ok(())
})),
)),
Expand Down
1 change: 1 addition & 0 deletions lib/middleware-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
#![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")]
#![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")]

pub mod block_trace;
pub mod call_trace;
pub mod metering;
76 changes: 76 additions & 0 deletions lib/runtime-core/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,82 @@ impl std::str::FromStr for Backend {
}
}

#[derive(Copy, Clone, Debug)]
pub enum Architecture {
losfair marked this conversation as resolved.
Show resolved Hide resolved
X64,
Aarch64,
}

#[repr(u8)]
#[derive(Copy, Clone, Debug)]
pub enum InlineBreakpointType {
Trace,
losfair marked this conversation as resolved.
Show resolved Hide resolved
Middleware,
Unknown,
}

#[derive(Clone, Debug)]
pub struct InlineBreakpoint {
pub size: usize,
pub ty: InlineBreakpointType,
}

pub fn get_inline_breakpoint_size(arch: Architecture, backend: Backend) -> Option<usize> {
match (arch, backend) {
(Architecture::X64, Backend::Singlepass) => Some(7),
losfair marked this conversation as resolved.
Show resolved Hide resolved
(Architecture::Aarch64, Backend::Singlepass) => Some(12),
_ => None,
}
}

pub fn read_inline_breakpoint(
arch: Architecture,
backend: Backend,
code: &[u8],
) -> Option<InlineBreakpoint> {
match arch {
Architecture::X64 => match backend {
Backend::Singlepass => {
if code.len() < 7 {
None
} else if &code[..6] == &[0x0f, 0x0b, 0x0f, 0xb9, 0xcd, 0xff] {
// ud2 ud (int 0xff) code
losfair marked this conversation as resolved.
Show resolved Hide resolved
Some(InlineBreakpoint {
size: 7,
ty: match code[6] {
0 => InlineBreakpointType::Trace,
1 => InlineBreakpointType::Middleware,
_ => InlineBreakpointType::Unknown,
},
})
} else {
None
}
}
_ => None,
},
Architecture::Aarch64 => match backend {
Backend::Singlepass => {
if code.len() < 12 {
None
} else if &code[..8] == &[0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff] {
losfair marked this conversation as resolved.
Show resolved Hide resolved
Some(InlineBreakpoint {
size: 12,
ty: match code[8] {
0 => InlineBreakpointType::Trace,
1 => InlineBreakpointType::Middleware,
_ => InlineBreakpointType::Unknown,
},
})
} else {
None
}
}
_ => None,
},
}
}

#[cfg(test)]
mod backend_test {
use super::*;
Expand Down
3 changes: 2 additions & 1 deletion lib/runtime-core/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
backend::{Backend, CacheGen, Compiler, CompilerConfig, Features, Token},
cache::{Artifact, Error as CacheError},
error::{CompileError, CompileResult},
fault::FaultInfo,
module::{ModuleInfo, ModuleInner},
structures::Map,
types::{FuncIndex, FuncSig, SigIndex},
Expand Down Expand Up @@ -49,7 +50,7 @@ impl fmt::Debug for InternalEvent {
}

pub struct BreakpointInfo<'a> {
pub fault: Option<&'a dyn Any>,
pub fault: Option<&'a FaultInfo>,
}

pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator<E>, RM: RunnableModule, E: Debug> {
Expand Down
Loading