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

Cranelift upgrade #4289

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 55 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/compiler-cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ version.workspace = true
[dependencies]
wasmer-compiler = { path = "../compiler", version = "=4.2.3", features = ["translator", "compiler"], default-features = false }
wasmer-types = { path = "../types", version = "=4.2.3", default-features = false, features = ["std"] }
cranelift-entity = { version = "0.91.1", default-features = false }
cranelift-codegen = { version = "0.91.1", default-features = false, features = ["x86", "arm64", "riscv64"] }
cranelift-frontend = { version = "0.91.1", default-features = false }
cranelift-entity = { version = "0.101.4", default-features = false }
cranelift-codegen = { version = "0.101.4", default-features = false, features = ["x86", "arm64", "riscv64"] }
cranelift-frontend = { version = "0.101.4", default-features = false }
tracing = "0.1"
hashbrown = { version = "0.11", optional = true }
rayon = { version = "1.5", optional = true }
more-asserts = "0.2"
gimli = { version = "0.26", optional = true }
gimli = { version = "0.28.0", optional = true }
smallvec = "1.6"
target-lexicon = { version = "0.12.2", default-features = false }

[dev-dependencies]
cranelift-codegen = { version = "0.91.1", features = ["all-arch"] }
cranelift-codegen = { version = "0.101.4", features = ["all-arch"] }
lazy_static = "1.4"

[badges]
Expand Down
25 changes: 16 additions & 9 deletions lib/compiler-cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::translator::{
signature_to_cranelift_ir, CraneliftUnwindInfo, FuncTranslator,
};
use cranelift_codegen::ir::{ExternalName, UserFuncName};
use cranelift_codegen::{ir, MachReloc};
use cranelift_codegen::{ir, FinalizedMachReloc, FinalizedRelocTarget};
use cranelift_codegen::{Context, MachTrap};
#[cfg(feature = "unwind")]
use gimli::write::{Address, EhFrame, FrameTable};
Expand Down Expand Up @@ -160,7 +160,7 @@ impl Compiler for CraneliftCompiler {

let mut code_buf: Vec<u8> = Vec::new();
context
.compile_and_emit(&*isa, &mut code_buf)
.compile_and_emit(&*isa, &mut code_buf, &mut Default::default())
.map_err(|error| CompileError::Codegen(error.inner.to_string()))?;

let result = context.compiled_code().unwrap();
Expand Down Expand Up @@ -272,7 +272,7 @@ impl Compiler for CraneliftCompiler {

let mut code_buf: Vec<u8> = Vec::new();
context
.compile_and_emit(&*isa, &mut code_buf)
.compile_and_emit(&*isa, &mut code_buf, &mut Default::default())
.map_err(|error| CompileError::Codegen(error.inner.to_string()))?;

let result = context.compiled_code().unwrap();
Expand Down Expand Up @@ -415,24 +415,30 @@ impl Compiler for CraneliftCompiler {
}
}

fn mach_reloc_to_reloc(module: &ModuleInfo, reloc: &MachReloc) -> Relocation {
let &MachReloc {
fn mach_reloc_to_reloc(module: &ModuleInfo, reloc: &FinalizedMachReloc) -> Relocation {
let &FinalizedMachReloc {
offset,
kind,
ref name,
addend,
target,
} = reloc;
let reloc_target = if let ExternalName::User(extname_ref) = *name {
let name = match target {
FinalizedRelocTarget::ExternalName(external_name) => external_name,
FinalizedRelocTarget::Func(CodeOffset) => {
unimplemented!("relocations to offset in the same function are not yet supported")
}
};
let reloc_target: RelocationTarget = if let ExternalName::User(extname_ref) = name {
//debug_assert_eq!(namespace, 0);
RelocationTarget::LocalFunc(
module
.local_func_index(FunctionIndex::from_u32(extname_ref.as_u32()))
.expect("The provided function should be local"),
)
} else if let ExternalName::LibCall(libcall) = *name {
} else if let ExternalName::LibCall(libcall) = name {
RelocationTarget::LibCall(irlibcall_to_libcall(libcall))
} else {
panic!("unrecognized external name")
panic!("unrecognized external target")
};
Relocation {
kind: irreloc_to_relocationkind(kind),
Expand Down Expand Up @@ -464,6 +470,7 @@ fn translate_ir_trapcode(trap: ir::TrapCode) -> TrapCode {
ir::TrapCode::BadConversionToInteger => TrapCode::BadConversionToInteger,
ir::TrapCode::UnreachableCodeReached => TrapCode::UnreachableCodeReached,
ir::TrapCode::Interrupt => unimplemented!("Interrupts not supported"),
ir::TrapCode::NullReference => unimplemented!("Null reference not supported"),
ir::TrapCode::User(_user_code) => unimplemented!("User trap code not supported"),
// ir::TrapCode::Interrupt => TrapCode::Interrupt,
// ir::TrapCode::User(user_code) => TrapCode::User(user_code),
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler-cranelift/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Cranelift {
}

/// Generates the ISA for the provided target
pub fn isa(&self, target: &Target) -> CodegenResult<Box<dyn TargetIsa>> {
pub fn isa(&self, target: &Target) -> CodegenResult<Arc<dyn TargetIsa>> {
let mut builder =
lookup(target.triple().clone()).expect("construct Cranelift ISA for triple");
// Cpu Features
Expand Down