diff --git a/Cargo.lock b/Cargo.lock index 76c99d6e9d..37c27174dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -544,7 +544,6 @@ name = "cranelift-codegen" version = "0.73.0" dependencies = [ "bincode", - "byteorder", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", @@ -591,7 +590,6 @@ name = "cranelift-filetests" version = "0.73.0" dependencies = [ "anyhow", - "byteorder", "cranelift-codegen", "cranelift-frontend", "cranelift-interpreter", diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.toml index 90ca998ae8..9eb990f896 100644 --- a/cranelift/codegen/Cargo.toml +++ b/cranelift/codegen/Cargo.toml @@ -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" } diff --git a/cranelift/codegen/src/isa/unwind/winx64.rs b/cranelift/codegen/src/isa/unwind/winx64.rs index adac7caefa..1c232f6855 100644 --- a/cranelift/codegen/src/isa/unwind/winx64.rs +++ b/cranelift/codegen/src/isa/unwind/winx64.rs @@ -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(&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(&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::(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::(*stack_offset as u16); - writer.write_u16::((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::((*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::(*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::(0); + writer.write_u16_le(0); } // Ensure the correct number of bytes was emitted diff --git a/cranelift/filetests/Cargo.toml b/cranelift/filetests/Cargo.toml index ffeecd7ac6..f25cbcf5ac 100644 --- a/cranelift/filetests/Cargo.toml +++ b/cranelift/filetests/Cargo.toml @@ -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"] } diff --git a/cranelift/filetests/src/test_unwind.rs b/cranelift/filetests/src/test_unwind.rs index 0c7124e8b2..3d22c4d3d9 100644 --- a/cranelift/filetests/src/test_unwind.rs +++ b/cranelift/filetests/src/test_unwind.rs @@ -72,7 +72,6 @@ impl SubTest for TestUnwind { } mod windowsx64 { - use byteorder::{ByteOrder, LittleEndian}; use std::fmt::Write; pub fn dump(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, };