-
Notifications
You must be signed in to change notification settings - Fork 824
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
Implement reference types in compiler-llvm. #2154
Changes from 3 commits
b14afa1
7d9dd4d
3c6168d
40f40bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,8 +92,7 @@ impl Abi for X86_64SystemV { | |
Type::I32 | Type::F32 => 32, | ||
Type::I64 | Type::F64 => 64, | ||
Type::V128 => 128, | ||
Type::ExternRef => unimplemented!("externref in the llvm backend"), | ||
Type::FuncRef => unimplemented!("funcref in the llvm backend"), | ||
Type::ExternRef | Type::FuncRef => 64, /* pointer */ | ||
}) | ||
.collect::<Vec<i32>>(); | ||
|
||
|
@@ -316,26 +315,7 @@ impl Abi for X86_64SystemV { | |
); | ||
builder.build_bitcast(value, intrinsics.f32_ty, "") | ||
} | ||
Type::I64 => { | ||
assert!( | ||
value.get_type() == intrinsics.i64_ty.as_basic_type_enum() | ||
|| value.get_type() == intrinsics.f64_ty.as_basic_type_enum() | ||
); | ||
builder.build_bitcast(value, intrinsics.i64_ty, "") | ||
} | ||
Type::F64 => { | ||
assert!( | ||
value.get_type() == intrinsics.i64_ty.as_basic_type_enum() | ||
|| value.get_type() == intrinsics.f64_ty.as_basic_type_enum() | ||
); | ||
builder.build_bitcast(value, intrinsics.f64_ty, "") | ||
} | ||
Type::V128 => { | ||
assert!(value.get_type() == intrinsics.i128_ty.as_basic_type_enum()); | ||
value | ||
} | ||
Type::ExternRef => unimplemented!("externref in the llvm backend"), | ||
Type::FuncRef => unimplemented!("funcref in the llvm backend"), | ||
_ => panic!("should only be called to repack 32-bit values"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just some other bug you noticed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On x86-64 this function is only called to cast 32-bit values, and should only be called to cast 32-bit values. I think this was copied out of the aarch64 code. I found this because I was auditing for places where ExternRef/FuncRef weren't handled and then investigated. |
||
} | ||
}; | ||
|
||
|
@@ -365,8 +345,7 @@ impl Abi for X86_64SystemV { | |
Type::I32 | Type::F32 => 32, | ||
Type::I64 | Type::F64 => 64, | ||
Type::V128 => 128, | ||
Type::ExternRef => unimplemented!("externref in the llvm backend"), | ||
Type::FuncRef => unimplemented!("funcref in the llvm backend"), | ||
Type::ExternRef | Type::FuncRef => 64, /* pointer */ | ||
}) | ||
.collect::<Vec<i32>>(); | ||
|
||
|
@@ -475,15 +454,12 @@ impl Abi for X86_64SystemV { | |
.results() | ||
.iter() | ||
.map(|ty| match ty { | ||
Type::I32 | Type::F32 => Ok(32), | ||
Type::I64 | Type::F64 => Ok(64), | ||
Type::V128 => Ok(128), | ||
ty => Err(CompileError::Codegen(format!( | ||
"is_sret: unimplemented wasmer_types type {:?}", | ||
ty | ||
))), | ||
Type::I32 | Type::F32 => 32, | ||
Type::I64 | Type::F64 => 64, | ||
Type::V128 => 128, | ||
Type::ExternRef | Type::FuncRef => 64, /* pointer */ | ||
}) | ||
.collect::<Result<Vec<i32>, _>>()?; | ||
.collect::<Vec<i32>>(); | ||
|
||
Ok(!matches!( | ||
func_sig_returns_bitwidths.as_slice(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,15 +54,65 @@ where | |
{ | ||
// TODO: use perfect hash function? | ||
let mut libcalls = HashMap::new(); | ||
libcalls.insert("wasmer_raise_trap".to_string(), LibCall::RaiseTrap); | ||
libcalls.insert("truncf".to_string(), LibCall::TruncF32); | ||
libcalls.insert("trunc".to_string(), LibCall::TruncF64); | ||
libcalls.insert("ceilf".to_string(), LibCall::CeilF32); | ||
libcalls.insert("ceil".to_string(), LibCall::CeilF64); | ||
libcalls.insert("floorf".to_string(), LibCall::FloorF32); | ||
libcalls.insert("floor".to_string(), LibCall::FloorF64); | ||
libcalls.insert("nearbyintf".to_string(), LibCall::NearestF32); | ||
libcalls.insert("nearbyint".to_string(), LibCall::NearestF64); | ||
libcalls.insert("truncf".to_string(), LibCall::TruncF32); | ||
libcalls.insert("trunc".to_string(), LibCall::TruncF64); | ||
libcalls.insert("wasmer_f32_ceil".to_string(), LibCall::CeilF32); | ||
libcalls.insert("wasmer_f64_ceil".to_string(), LibCall::CeilF64); | ||
libcalls.insert("wasmer_f32_floor".to_string(), LibCall::FloorF32); | ||
libcalls.insert("wasmer_f64_floor".to_string(), LibCall::FloorF64); | ||
libcalls.insert("wasmer_f32_nearest".to_string(), LibCall::NearestF32); | ||
libcalls.insert("wasmer_f64_nearest".to_string(), LibCall::NearestF64); | ||
libcalls.insert("wasmer_f32_trunc".to_string(), LibCall::TruncF32); | ||
libcalls.insert("wasmer_f64_trunc".to_string(), LibCall::TruncF64); | ||
Comment on lines
+65
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we using these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope! |
||
libcalls.insert("wasmer_memory32_size".to_string(), LibCall::Memory32Size); | ||
libcalls.insert( | ||
"wasmer_imported_memory32_size".to_string(), | ||
LibCall::ImportedMemory32Size, | ||
); | ||
libcalls.insert("wasmer_table_copy".to_string(), LibCall::TableCopy); | ||
libcalls.insert("wasmer_table_init".to_string(), LibCall::TableInit); | ||
libcalls.insert("wasmer_table_fill".to_string(), LibCall::TableFill); | ||
libcalls.insert("wasmer_table_size".to_string(), LibCall::TableSize); | ||
libcalls.insert( | ||
"wasmer_imported_table_size".to_string(), | ||
LibCall::ImportedTableSize, | ||
); | ||
libcalls.insert("wasmer_table_get".to_string(), LibCall::TableGet); | ||
libcalls.insert( | ||
"wasmer_imported_table_get".to_string(), | ||
LibCall::ImportedTableGet, | ||
); | ||
libcalls.insert("wasmer_table_set".to_string(), LibCall::TableSet); | ||
libcalls.insert( | ||
"wasmer_imported_table_set".to_string(), | ||
LibCall::ImportedTableSet, | ||
); | ||
libcalls.insert("wasmer_table_grow".to_string(), LibCall::TableGrow); | ||
libcalls.insert( | ||
"wasmer_imported_table_grow".to_string(), | ||
LibCall::ImportedTableGrow, | ||
); | ||
libcalls.insert("wasmer_func_ref".to_string(), LibCall::FuncRef); | ||
libcalls.insert("wasmer_elem_drop".to_string(), LibCall::ElemDrop); | ||
libcalls.insert("wasmer_memory32_copy".to_string(), LibCall::Memory32Copy); | ||
libcalls.insert( | ||
"wasmer_imported_memory32_copy".to_string(), | ||
LibCall::ImportedMemory32Copy, | ||
); | ||
libcalls.insert("wasmer_memory32_fill".to_string(), LibCall::Memory32Fill); | ||
libcalls.insert( | ||
"wasmer_imported_memory32_fill".to_string(), | ||
LibCall::ImportedMemory32Fill, | ||
); | ||
libcalls.insert("wasmer_memory32_init".to_string(), LibCall::Memory32Init); | ||
libcalls.insert("wasmer_data_drop".to_string(), LibCall::DataDrop); | ||
libcalls.insert("wasmer_raise_trap".to_string(), LibCall::RaiseTrap); | ||
libcalls.insert("wasmer_probestack".to_string(), LibCall::Probestack); | ||
|
||
let elf = goblin::elf::Elf::parse(&contents).map_err(map_goblin_err)?; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may be able to use something in VMOffsets for this to help prevent breakage. I don't think it'll change any time soon, but something to think about
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The presence of VMOffsets is optional in this function. The issue is that we don't have a VMContext when producing trampolines, so we don't have a VMOffset for it either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's fine. Really not a big deal because we do this thing in other places in compiler-llvm where we don't use data from
VMOffsets
so things may get out of sync. I think it's fine to not worry about it for now and we can update compiler-llvm later if we decide that that's a high enough priority thing to do.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really, a lot of
VMOffsets
stuff is static. In this case I don't know if we actually need aVMOffsets
but, yeah, generally speaking getting the size of things doesn't require anything other than knowing the size of a pointer on the target architecture. Maybe that means it needs to be split into two pieces