Merge branch 'master' into feature/singlepass-sign-extension

This commit is contained in:
Mark McCaskey
2019-11-18 11:38:12 -08:00
committed by GitHub
11 changed files with 126 additions and 40 deletions

View File

@ -1,4 +1,4 @@
FROM circleci/rust:1.38.0-stretch as wasmer-build-env FROM circleci/rust:1.39.0-stretch as wasmer-build-env
RUN sudo apt-get update && \ RUN sudo apt-get update && \
sudo apt-get install -y --no-install-recommends \ sudo apt-get install -y --no-install-recommends \
cmake \ cmake \

View File

@ -181,7 +181,7 @@ nginx and Lua do not work on Windows - you can track the progress on [this issue
## Building ## Building
[![Rustc Version 1.38+](https://img.shields.io/badge/rustc-1.37+-red.svg?style=flat-square)](https://blog.rust-lang.org/2019/09/26/Rust-1.38.0.html) [![Rustc Version 1.39+](https://img.shields.io/badge/rustc-1.39+-red.svg?style=flat-square)](https://blog.rust-lang.org/2019/09/26/Rust-1.39.0.html)
Wasmer is built with [Cargo](https://crates.io/), the Rust package manager. Wasmer is built with [Cargo](https://crates.io/), the Rust package manager.

View File

@ -22,7 +22,7 @@ jobs:
- script: cargo fmt --all -- --check - script: cargo fmt --all -- --check
displayName: Lint displayName: Lint
variables: variables:
rust_toolchain: '1.38.0' rust_toolchain: '1.39.0'
- job: Test - job: Test
strategy: strategy:
@ -39,7 +39,7 @@ jobs:
CARGO_HTTP_CHECK_REVOKE: false CARGO_HTTP_CHECK_REVOKE: false
windows: windows:
imageName: "vs2017-win2016" imageName: "vs2017-win2016"
rust_toolchain: '1.38.0' rust_toolchain: '1.39.0'
pool: pool:
vmImage: $(imageName) vmImage: $(imageName)
condition: in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/staging', 'refs/heads/trying') condition: in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/staging', 'refs/heads/trying')
@ -100,7 +100,7 @@ jobs:
MACOSX_DEPLOYMENT_TARGET: 10.10 MACOSX_DEPLOYMENT_TARGET: 10.10
windows: windows:
imageName: "vs2017-win2016" imageName: "vs2017-win2016"
rust_toolchain: '1.38.0' rust_toolchain: '1.39.0'
# RUSTFLAGS: -Ctarget-feature=+crt-static # RUSTFLAGS: -Ctarget-feature=+crt-static
pool: pool:
vmImage: $(imageName) vmImage: $(imageName)
@ -163,7 +163,7 @@ jobs:
MACOSX_DEPLOYMENT_TARGET: 10.10 MACOSX_DEPLOYMENT_TARGET: 10.10
windows: windows:
imageName: "vs2017-win2016" imageName: "vs2017-win2016"
rust_toolchain: '1.38.0' rust_toolchain: '1.39.0'
# RUSTFLAGS: -Ctarget-feature=+crt-static # RUSTFLAGS: -Ctarget-feature=+crt-static
pool: pool:
vmImage: $(imageName) vmImage: $(imageName)

View File

@ -54,6 +54,10 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
} }
} }
fn new_with_target(_: Option<String>, _: Option<String>, _: Option<String>) -> Self {
unimplemented!("cross compilation is not available for clif backend")
}
fn backend_id() -> Backend { fn backend_id() -> Backend {
Backend::Cranelift Backend::Cranelift
} }

View File

@ -8075,24 +8075,37 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
for LLVMModuleCodeGenerator for LLVMModuleCodeGenerator
{ {
fn new() -> LLVMModuleCodeGenerator { fn new() -> LLVMModuleCodeGenerator {
Self::new_with_target(None, None, None)
}
fn new_with_target(
triple: Option<String>,
cpu_name: Option<String>,
cpu_features: Option<String>,
) -> LLVMModuleCodeGenerator {
let context = Context::create(); let context = Context::create();
let module = context.create_module("module"); let module = context.create_module("module");
Target::initialize_x86(&InitializationConfig { let triple = triple.unwrap_or(TargetMachine::get_default_triple().to_string());
asm_parser: true,
asm_printer: true, match triple {
base: true, _ if triple.starts_with("x86") => Target::initialize_x86(&InitializationConfig {
disassembler: true, asm_parser: true,
info: true, asm_printer: true,
machine_code: true, base: true,
}); disassembler: true,
let triple = TargetMachine::get_default_triple().to_string(); info: true,
machine_code: true,
}),
_ => unimplemented!("compile to target other than x86-64 is not supported"),
}
let target = Target::from_triple(&triple).unwrap(); let target = Target::from_triple(&triple).unwrap();
let target_machine = target let target_machine = target
.create_target_machine( .create_target_machine(
&triple, &triple,
&TargetMachine::get_host_cpu_name().to_string(), &cpu_name.unwrap_or(TargetMachine::get_host_cpu_name().to_string()),
&TargetMachine::get_host_cpu_features().to_string(), &cpu_features.unwrap_or(TargetMachine::get_host_cpu_features().to_string()),
OptimizationLevel::Aggressive, OptimizationLevel::Aggressive,
RelocMode::Static, RelocMode::Static,
CodeModel::Large, CodeModel::Large,

View File

@ -129,6 +129,11 @@ pub struct CompilerConfig {
pub enforce_stack_check: bool, pub enforce_stack_check: bool,
pub track_state: bool, pub track_state: bool,
pub features: Features, pub features: Features,
// target info used by LLVM
pub triple: Option<String>,
pub cpu_name: Option<String>,
pub cpu_features: Option<String>,
} }
pub trait Compiler { pub trait Compiler {

View File

@ -74,6 +74,13 @@ pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator<E>, RM: RunnableModule,
/// Creates a new module code generator. /// Creates a new module code generator.
fn new() -> Self; fn new() -> Self;
/// Creates a new module code generator for specified target.
fn new_with_target(
triple: Option<String>,
cpu_name: Option<String>,
cpu_features: Option<String>,
) -> Self;
/// Returns the backend id associated with this MCG. /// Returns the backend id associated with this MCG.
fn backend_id() -> Backend; fn backend_id() -> Backend;
@ -206,7 +213,14 @@ impl<
validate_with_features(wasm, &compiler_config.features)?; validate_with_features(wasm, &compiler_config.features)?;
} }
let mut mcg = MCG::new(); let mut mcg = match MCG::backend_id() {
Backend::LLVM => MCG::new_with_target(
compiler_config.triple.clone(),
compiler_config.cpu_name.clone(),
compiler_config.cpu_features.clone(),
),
_ => MCG::new(),
};
let mut chain = (self.middleware_chain_generator)(); let mut chain = (self.middleware_chain_generator)();
let info = crate::parse::read_module( let info = crate::parse::read_module(
wasm, wasm,

View File

@ -370,6 +370,10 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
} }
} }
fn new_with_target(_: Option<String>, _: Option<String>, _: Option<String>) -> Self {
unimplemented!("cross compilation is not available for singlepass backend")
}
fn backend_id() -> Backend { fn backend_id() -> Backend {
Backend::Singlepass Backend::Singlepass
} }

View File

@ -709,14 +709,18 @@ impl Emitter for Assembler {
match (sz, src) { match (sz, src) {
(Size::S64, Location::Imm32(src)) => dynasm!(self ; push src as i32), (Size::S64, Location::Imm32(src)) => dynasm!(self ; push src as i32),
(Size::S64, Location::GPR(src)) => dynasm!(self ; push Rq(src as u8)), (Size::S64, Location::GPR(src)) => dynasm!(self ; push Rq(src as u8)),
(Size::S64, Location::Memory(src, disp)) => dynasm!(self ; push QWORD [Rq(src as u8) + disp]), (Size::S64, Location::Memory(src, disp)) => {
dynasm!(self ; push QWORD [Rq(src as u8) + disp])
}
_ => panic!("singlepass can't emit PUSH {:?} {:?}", sz, src), _ => panic!("singlepass can't emit PUSH {:?} {:?}", sz, src),
} }
} }
fn emit_pop(&mut self, sz: Size, dst: Location) { fn emit_pop(&mut self, sz: Size, dst: Location) {
match (sz, dst) { match (sz, dst) {
(Size::S64, Location::GPR(dst)) => dynasm!(self ; pop Rq(dst as u8)), (Size::S64, Location::GPR(dst)) => dynasm!(self ; pop Rq(dst as u8)),
(Size::S64, Location::Memory(dst, disp)) => dynasm!(self ; pop QWORD [Rq(dst as u8) + disp]), (Size::S64, Location::Memory(dst, disp)) => {
dynasm!(self ; pop QWORD [Rq(dst as u8) + disp])
}
_ => panic!("singlepass can't emit POP {:?} {:?}", sz, dst), _ => panic!("singlepass can't emit POP {:?} {:?}", sz, dst),
} }
} }
@ -738,13 +742,21 @@ impl Emitter for Assembler {
fn emit_neg(&mut self, sz: Size, value: Location) { fn emit_neg(&mut self, sz: Size, value: Location) {
match (sz, value) { match (sz, value) {
(Size::S8, Location::GPR(value)) => dynasm!(self ; neg Rb(value as u8)), (Size::S8, Location::GPR(value)) => dynasm!(self ; neg Rb(value as u8)),
(Size::S8, Location::Memory(value, disp)) => dynasm!(self ; neg [Rq(value as u8) + disp]), (Size::S8, Location::Memory(value, disp)) => {
dynasm!(self ; neg [Rq(value as u8) + disp])
}
(Size::S16, Location::GPR(value)) => dynasm!(self ; neg Rw(value as u8)), (Size::S16, Location::GPR(value)) => dynasm!(self ; neg Rw(value as u8)),
(Size::S16, Location::Memory(value, disp)) => dynasm!(self ; neg [Rq(value as u8) + disp]), (Size::S16, Location::Memory(value, disp)) => {
dynasm!(self ; neg [Rq(value as u8) + disp])
}
(Size::S32, Location::GPR(value)) => dynasm!(self ; neg Rd(value as u8)), (Size::S32, Location::GPR(value)) => dynasm!(self ; neg Rd(value as u8)),
(Size::S32, Location::Memory(value, disp)) => dynasm!(self ; neg [Rq(value as u8) + disp]), (Size::S32, Location::Memory(value, disp)) => {
dynasm!(self ; neg [Rq(value as u8) + disp])
}
(Size::S64, Location::GPR(value)) => dynasm!(self ; neg Rq(value as u8)), (Size::S64, Location::GPR(value)) => dynasm!(self ; neg Rq(value as u8)),
(Size::S64, Location::Memory(value, disp)) => dynasm!(self ; neg [Rq(value as u8) + disp]), (Size::S64, Location::Memory(value, disp)) => {
dynasm!(self ; neg [Rq(value as u8) + disp])
}
_ => panic!("singlepass can't emit NEG {:?} {:?}", sz, value), _ => panic!("singlepass can't emit NEG {:?} {:?}", sz, value),
} }
} }
@ -997,18 +1009,30 @@ impl Emitter for Assembler {
fn emit_vmovaps(&mut self, src: XMMOrMemory, dst: XMMOrMemory) { fn emit_vmovaps(&mut self, src: XMMOrMemory, dst: XMMOrMemory) {
match (src, dst) { match (src, dst) {
(XMMOrMemory::XMM(src), XMMOrMemory::XMM(dst)) => dynasm!(self ; movaps Rx(dst as u8), Rx(src as u8)), (XMMOrMemory::XMM(src), XMMOrMemory::XMM(dst)) => {
(XMMOrMemory::Memory(base, disp), XMMOrMemory::XMM(dst)) => dynasm!(self ; movaps Rx(dst as u8), [Rq(base as u8) + disp]), dynasm!(self ; movaps Rx(dst as u8), Rx(src as u8))
(XMMOrMemory::XMM(src), XMMOrMemory::Memory(base, disp)) => dynasm!(self ; movaps [Rq(base as u8) + disp], Rx(src as u8)), }
(XMMOrMemory::Memory(base, disp), XMMOrMemory::XMM(dst)) => {
dynasm!(self ; movaps Rx(dst as u8), [Rq(base as u8) + disp])
}
(XMMOrMemory::XMM(src), XMMOrMemory::Memory(base, disp)) => {
dynasm!(self ; movaps [Rq(base as u8) + disp], Rx(src as u8))
}
_ => panic!("singlepass can't emit VMOVAPS {:?} {:?}", src, dst), _ => panic!("singlepass can't emit VMOVAPS {:?} {:?}", src, dst),
}; };
} }
fn emit_vmovapd(&mut self, src: XMMOrMemory, dst: XMMOrMemory) { fn emit_vmovapd(&mut self, src: XMMOrMemory, dst: XMMOrMemory) {
match (src, dst) { match (src, dst) {
(XMMOrMemory::XMM(src), XMMOrMemory::XMM(dst)) => dynasm!(self ; movapd Rx(dst as u8), Rx(src as u8)), (XMMOrMemory::XMM(src), XMMOrMemory::XMM(dst)) => {
(XMMOrMemory::Memory(base, disp), XMMOrMemory::XMM(dst)) => dynasm!(self ; movapd Rx(dst as u8), [Rq(base as u8) + disp]), dynasm!(self ; movapd Rx(dst as u8), Rx(src as u8))
(XMMOrMemory::XMM(src), XMMOrMemory::Memory(base, disp)) => dynasm!(self ; movapd [Rq(base as u8) + disp], Rx(src as u8)), }
(XMMOrMemory::Memory(base, disp), XMMOrMemory::XMM(dst)) => {
dynasm!(self ; movapd Rx(dst as u8), [Rq(base as u8) + disp])
}
(XMMOrMemory::XMM(src), XMMOrMemory::Memory(base, disp)) => {
dynasm!(self ; movapd [Rq(base as u8) + disp], Rx(src as u8))
}
_ => panic!("singlepass can't emit VMOVAPD {:?} {:?}", src, dst), _ => panic!("singlepass can't emit VMOVAPD {:?} {:?}", src, dst),
}; };
} }
@ -1080,57 +1104,77 @@ impl Emitter for Assembler {
fn emit_vblendvps(&mut self, src1: XMM, src2: XMMOrMemory, mask: XMM, dst: XMM) { fn emit_vblendvps(&mut self, src1: XMM, src2: XMMOrMemory, mask: XMM, dst: XMM) {
match src2 { match src2 {
XMMOrMemory::XMM(src2) => dynasm!(self ; vblendvps Rx(dst as u8), Rx(mask as u8), Rx(src2 as u8), Rx(src1 as u8)), XMMOrMemory::XMM(src2) => {
XMMOrMemory::Memory(base, disp) => dynasm!(self ; vblendvps Rx(dst as u8), Rx(mask as u8), [Rq(base as u8) + disp], Rx(src1 as u8)), dynasm!(self ; vblendvps Rx(dst as u8), Rx(mask as u8), Rx(src2 as u8), Rx(src1 as u8))
}
XMMOrMemory::Memory(base, disp) => {
dynasm!(self ; vblendvps Rx(dst as u8), Rx(mask as u8), [Rq(base as u8) + disp], Rx(src1 as u8))
}
} }
} }
fn emit_vblendvpd(&mut self, src1: XMM, src2: XMMOrMemory, mask: XMM, dst: XMM) { fn emit_vblendvpd(&mut self, src1: XMM, src2: XMMOrMemory, mask: XMM, dst: XMM) {
match src2 { match src2 {
XMMOrMemory::XMM(src2) => dynasm!(self ; vblendvpd Rx(dst as u8), Rx(mask as u8), Rx(src2 as u8), Rx(src1 as u8)), XMMOrMemory::XMM(src2) => {
XMMOrMemory::Memory(base, disp) => dynasm!(self ; vblendvpd Rx(dst as u8), Rx(mask as u8), [Rq(base as u8) + disp], Rx(src1 as u8)), dynasm!(self ; vblendvpd Rx(dst as u8), Rx(mask as u8), Rx(src2 as u8), Rx(src1 as u8))
}
XMMOrMemory::Memory(base, disp) => {
dynasm!(self ; vblendvpd Rx(dst as u8), Rx(mask as u8), [Rq(base as u8) + disp], Rx(src1 as u8))
}
} }
} }
fn emit_ucomiss(&mut self, src: XMMOrMemory, dst: XMM) { fn emit_ucomiss(&mut self, src: XMMOrMemory, dst: XMM) {
match src { match src {
XMMOrMemory::XMM(x) => dynasm!(self ; ucomiss Rx(dst as u8), Rx(x as u8)), XMMOrMemory::XMM(x) => dynasm!(self ; ucomiss Rx(dst as u8), Rx(x as u8)),
XMMOrMemory::Memory(base, disp) => dynasm!(self ; ucomiss Rx(dst as u8), [Rq(base as u8) + disp]), XMMOrMemory::Memory(base, disp) => {
dynasm!(self ; ucomiss Rx(dst as u8), [Rq(base as u8) + disp])
}
} }
} }
fn emit_ucomisd(&mut self, src: XMMOrMemory, dst: XMM) { fn emit_ucomisd(&mut self, src: XMMOrMemory, dst: XMM) {
match src { match src {
XMMOrMemory::XMM(x) => dynasm!(self ; ucomisd Rx(dst as u8), Rx(x as u8)), XMMOrMemory::XMM(x) => dynasm!(self ; ucomisd Rx(dst as u8), Rx(x as u8)),
XMMOrMemory::Memory(base, disp) => dynasm!(self ; ucomisd Rx(dst as u8), [Rq(base as u8) + disp]), XMMOrMemory::Memory(base, disp) => {
dynasm!(self ; ucomisd Rx(dst as u8), [Rq(base as u8) + disp])
}
} }
} }
fn emit_cvttss2si_32(&mut self, src: XMMOrMemory, dst: GPR) { fn emit_cvttss2si_32(&mut self, src: XMMOrMemory, dst: GPR) {
match src { match src {
XMMOrMemory::XMM(x) => dynasm!(self ; cvttss2si Rd(dst as u8), Rx(x as u8)), XMMOrMemory::XMM(x) => dynasm!(self ; cvttss2si Rd(dst as u8), Rx(x as u8)),
XMMOrMemory::Memory(base, disp) => dynasm!(self ; cvttss2si Rd(dst as u8), [Rq(base as u8) + disp]), XMMOrMemory::Memory(base, disp) => {
dynasm!(self ; cvttss2si Rd(dst as u8), [Rq(base as u8) + disp])
}
} }
} }
fn emit_cvttss2si_64(&mut self, src: XMMOrMemory, dst: GPR) { fn emit_cvttss2si_64(&mut self, src: XMMOrMemory, dst: GPR) {
match src { match src {
XMMOrMemory::XMM(x) => dynasm!(self ; cvttss2si Rq(dst as u8), Rx(x as u8)), XMMOrMemory::XMM(x) => dynasm!(self ; cvttss2si Rq(dst as u8), Rx(x as u8)),
XMMOrMemory::Memory(base, disp) => dynasm!(self ; cvttss2si Rq(dst as u8), [Rq(base as u8) + disp]), XMMOrMemory::Memory(base, disp) => {
dynasm!(self ; cvttss2si Rq(dst as u8), [Rq(base as u8) + disp])
}
} }
} }
fn emit_cvttsd2si_32(&mut self, src: XMMOrMemory, dst: GPR) { fn emit_cvttsd2si_32(&mut self, src: XMMOrMemory, dst: GPR) {
match src { match src {
XMMOrMemory::XMM(x) => dynasm!(self ; cvttsd2si Rd(dst as u8), Rx(x as u8)), XMMOrMemory::XMM(x) => dynasm!(self ; cvttsd2si Rd(dst as u8), Rx(x as u8)),
XMMOrMemory::Memory(base, disp) => dynasm!(self ; cvttsd2si Rd(dst as u8), [Rq(base as u8) + disp]), XMMOrMemory::Memory(base, disp) => {
dynasm!(self ; cvttsd2si Rd(dst as u8), [Rq(base as u8) + disp])
}
} }
} }
fn emit_cvttsd2si_64(&mut self, src: XMMOrMemory, dst: GPR) { fn emit_cvttsd2si_64(&mut self, src: XMMOrMemory, dst: GPR) {
match src { match src {
XMMOrMemory::XMM(x) => dynasm!(self ; cvttsd2si Rq(dst as u8), Rx(x as u8)), XMMOrMemory::XMM(x) => dynasm!(self ; cvttsd2si Rq(dst as u8), Rx(x as u8)),
XMMOrMemory::Memory(base, disp) => dynasm!(self ; cvttsd2si Rq(dst as u8), [Rq(base as u8) + disp]), XMMOrMemory::Memory(base, disp) => {
dynasm!(self ; cvttsd2si Rq(dst as u8), [Rq(base as u8) + disp])
}
} }
} }

View File

@ -63,6 +63,7 @@ fn handle_client(mut stream: UnixStream) {
enforce_stack_check: true, enforce_stack_check: true,
track_state: false, track_state: false,
features: Default::default(), features: Default::default(),
..Default::default()
}, },
&SinglePassCompiler::new(), &SinglePassCompiler::new(),
) )

View File

@ -461,6 +461,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
enforce_stack_check: true, enforce_stack_check: true,
track_state, track_state,
features: options.features.into_backend_features(), features: options.features.into_backend_features(),
..Default::default()
}, },
&*compiler, &*compiler,
) )