Factor out byteorder in cranelift
This removes an existing dependency on the byteorder crate in favor of using std equivalents directly. While not an issue for wasmtime per se, cranelift is now part of the critical path of building and testing Rust, and minimizing dependencies, even small ones, can help reduce the time and bandwidth required.
This commit is contained in:
@@ -24,7 +24,6 @@ bincode = { version = "1.2.1", optional = true }
|
||||
gimli = { version = "0.23.0", default-features = false, features = ["write"], optional = true }
|
||||
smallvec = { version = "1.6.1" }
|
||||
thiserror = "1.0.4"
|
||||
byteorder = { version = "1.3.2", default-features = false }
|
||||
peepmatic = { path = "../peepmatic", optional = true, version = "0.73.0" }
|
||||
peepmatic-traits = { path = "../peepmatic/crates/traits", optional = true, version = "0.73.0" }
|
||||
peepmatic-runtime = { path = "../peepmatic/crates/runtime", optional = true, version = "0.73.0" }
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
use crate::isa::unwind::input;
|
||||
use crate::result::{CodegenError, CodegenResult};
|
||||
use alloc::vec::Vec;
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use log::warn;
|
||||
#[cfg(feature = "enable-serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -31,13 +30,13 @@ impl<'a> Writer<'a> {
|
||||
self.offset += 1;
|
||||
}
|
||||
|
||||
fn write_u16<T: ByteOrder>(&mut self, v: u16) {
|
||||
T::write_u16(&mut self.buf[self.offset..(self.offset + 2)], v);
|
||||
fn write_u16_le(&mut self, v: u16) {
|
||||
self.buf[self.offset..(self.offset + 2)].copy_from_slice(&v.to_le_bytes());
|
||||
self.offset += 2;
|
||||
}
|
||||
|
||||
fn write_u32<T: ByteOrder>(&mut self, v: u32) {
|
||||
T::write_u32(&mut self.buf[self.offset..(self.offset + 4)], v);
|
||||
fn write_u32_le(&mut self, v: u32) {
|
||||
self.buf[self.offset..(self.offset + 4)].copy_from_slice(&v.to_le_bytes());
|
||||
self.offset += 4;
|
||||
}
|
||||
}
|
||||
@@ -121,11 +120,11 @@ impl UnwindCode {
|
||||
let scaled_stack_offset = stack_offset / 16;
|
||||
if scaled_stack_offset <= core::u16::MAX as u32 {
|
||||
writer.write_u8((*reg << 4) | (op_small as u8));
|
||||
writer.write_u16::<LittleEndian>(scaled_stack_offset as u16);
|
||||
writer.write_u16_le(scaled_stack_offset as u16);
|
||||
} else {
|
||||
writer.write_u8((*reg << 4) | (op_large as u8));
|
||||
writer.write_u16::<LittleEndian>(*stack_offset as u16);
|
||||
writer.write_u16::<LittleEndian>((stack_offset >> 16) as u16);
|
||||
writer.write_u16_le(*stack_offset as u16);
|
||||
writer.write_u16_le((stack_offset >> 16) as u16);
|
||||
}
|
||||
}
|
||||
Self::StackAlloc {
|
||||
@@ -143,10 +142,10 @@ impl UnwindCode {
|
||||
);
|
||||
} else if *size <= LARGE_ALLOC_16BIT_MAX_SIZE {
|
||||
writer.write_u8(UnwindOperation::LargeStackAlloc as u8);
|
||||
writer.write_u16::<LittleEndian>((*size / 8) as u16);
|
||||
writer.write_u16_le((*size / 8) as u16);
|
||||
} else {
|
||||
writer.write_u8((1 << 4) | (UnwindOperation::LargeStackAlloc as u8));
|
||||
writer.write_u32::<LittleEndian>(*size);
|
||||
writer.write_u32_le(*size);
|
||||
}
|
||||
}
|
||||
Self::SetFPReg { instruction_offset } => {
|
||||
@@ -248,7 +247,7 @@ impl UnwindInfo {
|
||||
|
||||
// To keep a 32-bit alignment, emit 2 bytes of padding if there's an odd number of 16-bit nodes
|
||||
if (node_count & 1) == 1 {
|
||||
writer.write_u16::<LittleEndian>(0);
|
||||
writer.write_u16_le(0);
|
||||
}
|
||||
|
||||
// Ensure the correct number of bytes was emitted
|
||||
|
||||
@@ -16,7 +16,6 @@ cranelift-interpreter = { path = "../interpreter", version = "0.73.0" }
|
||||
cranelift-native = { path = "../native", version = "0.73.0" }
|
||||
cranelift-reader = { path = "../reader", version = "0.73.0" }
|
||||
cranelift-preopt = { path = "../preopt", version = "0.73.0" }
|
||||
byteorder = { version = "1.3.2", default-features = false }
|
||||
file-per-thread-logger = "0.1.2"
|
||||
filecheck = "0.5.0"
|
||||
gimli = { version = "0.23.0", default-features = false, features = ["read"] }
|
||||
|
||||
@@ -72,7 +72,6 @@ impl SubTest for TestUnwind {
|
||||
}
|
||||
|
||||
mod windowsx64 {
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use std::fmt::Write;
|
||||
|
||||
pub fn dump<W: Write>(text: &mut W, mem: &[u8]) {
|
||||
@@ -165,23 +164,24 @@ mod windowsx64 {
|
||||
let op_and_info = mem[1];
|
||||
let op = UnwindOperation::from(op_and_info & 0xF);
|
||||
let info = (op_and_info & 0xF0) >> 4;
|
||||
let unwind_le_bytes = |bytes| match (bytes, &mem[2..]) {
|
||||
(2, &[b0, b1, ..]) => UnwindValue::U16(u16::from_le_bytes([b0, b1])),
|
||||
(4, &[b0, b1, b2, b3, ..]) => {
|
||||
UnwindValue::U32(u32::from_le_bytes([b0, b1, b2, b3]))
|
||||
}
|
||||
(_, _) => panic!("not enough bytes to unwind value"),
|
||||
};
|
||||
|
||||
let value = match op {
|
||||
UnwindOperation::LargeStackAlloc => match info {
|
||||
0 => UnwindValue::U16(LittleEndian::read_u16(&mem[2..])),
|
||||
1 => UnwindValue::U32(LittleEndian::read_u32(&mem[2..])),
|
||||
_ => panic!("unexpected stack alloc info value"),
|
||||
},
|
||||
UnwindOperation::SaveNonvolatileRegister => {
|
||||
UnwindValue::U16(LittleEndian::read_u16(&mem[2..]))
|
||||
}
|
||||
UnwindOperation::SaveNonvolatileRegisterFar => {
|
||||
UnwindValue::U32(LittleEndian::read_u32(&mem[2..]))
|
||||
}
|
||||
UnwindOperation::SaveXmm128 => UnwindValue::U16(LittleEndian::read_u16(&mem[2..])),
|
||||
UnwindOperation::SaveXmm128Far => {
|
||||
UnwindValue::U32(LittleEndian::read_u32(&mem[2..]))
|
||||
let value = match (&op, info) {
|
||||
(UnwindOperation::LargeStackAlloc, 0) => unwind_le_bytes(2),
|
||||
(UnwindOperation::LargeStackAlloc, 1) => unwind_le_bytes(4),
|
||||
(UnwindOperation::LargeStackAlloc, _) => {
|
||||
panic!("unexpected stack alloc info value")
|
||||
}
|
||||
(UnwindOperation::SaveNonvolatileRegister, _) => unwind_le_bytes(2),
|
||||
(UnwindOperation::SaveNonvolatileRegisterFar, _) => unwind_le_bytes(4),
|
||||
(UnwindOperation::SaveXmm128, _) => unwind_le_bytes(2),
|
||||
(UnwindOperation::SaveXmm128Far, _) => unwind_le_bytes(4),
|
||||
_ => UnwindValue::None,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user