diff --git a/Cargo.toml b/Cargo.toml index a566f077..2834e050 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,6 @@ bytes = { version = "1", default-features = false } cargo_metadata = { version = "0.18.0", default-features = false } clap = { version = "4", default-features = false } const-assert = { version = "1.0.1", default-features = false } -core-error = { version = "0.0.0", default-features = false } dialoguer = { version = "0.11", default-features = false } diff = { version = "0.1.13", default-features = false } env_logger = { version = "0.11", default-features = false } @@ -92,7 +91,7 @@ tempfile = { version = "3", default-features = false } test-case = { version = "3.1.0", default-features = false } test-log = { version = "0.2.13", default-features = false } testing_logger = { version = "0.1.1", default-features = false } -thiserror = { version = "1", default-features = false } +thiserror = { version = "2.0.3", default-features = false } tokio = { version = "1.24.0", default-features = false } which = { version = "7.0.0", default-features = false } xdpilone = { version = "1.0.5", default-features = false } diff --git a/aya-obj/Cargo.toml b/aya-obj/Cargo.toml index bca508bf..96603fb7 100644 --- a/aya-obj/Cargo.toml +++ b/aya-obj/Cargo.toml @@ -13,7 +13,6 @@ edition.workspace = true [dependencies] bytes = { workspace = true } -core-error = { workspace = true, default-features = true } hashbrown = { workspace = true, default-features = true } log = { workspace = true } object = { workspace = true, features = ["elf", "read_core"] } @@ -24,4 +23,4 @@ assert_matches = { workspace = true } rbpf = { workspace = true } [features] -std = [] +std = ["thiserror/std"] diff --git a/aya-obj/src/btf/btf.rs b/aya-obj/src/btf/btf.rs index 0d160a7d..51f9594b 100644 --- a/aya-obj/src/btf/btf.rs +++ b/aya-obj/src/btf/btf.rs @@ -11,8 +11,6 @@ use bytes::BufMut; use log::debug; use object::{Endianness, SectionIndex}; -#[cfg(not(feature = "std"))] -use crate::std; use crate::{ btf::{ info::{FuncSecInfo, LineSecInfo}, @@ -282,7 +280,7 @@ impl Btf { /// Adds a string to BTF metadata, returning an offset pub fn add_string(&mut self, name: &str) -> u32 { - let str = name.bytes().chain(std::iter::once(0)); + let str = name.bytes().chain(core::iter::once(0)); let name_offset = self.strings.len(); self.strings.extend(str); self.header.str_len = self.strings.len() as u32; @@ -532,7 +530,7 @@ impl Btf { name_offset = self.add_string(&fixed_name); } - let entries = std::mem::take(&mut d.entries); + let entries = core::mem::take(&mut d.entries); let members = entries .iter() @@ -788,7 +786,7 @@ impl BtfExt { pub hdr_len: u32, } - if data.len() < std::mem::size_of::() { + if data.len() < core::mem::size_of::() { return Err(BtfError::InvalidHeader); } @@ -809,18 +807,18 @@ impl BtfExt { // forwards compatibility: if newer headers are bigger // than the pre-generated btf_ext_header we should only // read up to btf_ext_header - let len_to_read = len_to_read.min(std::mem::size_of::()); + let len_to_read = len_to_read.min(core::mem::size_of::()); // now create our full-fledge header; but start with it // zeroed out so unavailable fields stay as zero on older // BTF.ext sections - let mut header = std::mem::MaybeUninit::::zeroed(); + let mut header = core::mem::MaybeUninit::::zeroed(); // Safety: we have checked that len_to_read is less than // size_of:: and less than // data.len(). Additionally, we know that the header has // been initialized so it's safe to call for assume_init. unsafe { - std::ptr::copy(data.as_ptr(), header.as_mut_ptr() as *mut u8, len_to_read); + core::ptr::copy(data.as_ptr(), header.as_mut_ptr() as *mut u8, len_to_read); header.assume_init() } }; diff --git a/aya-obj/src/btf/relocation.rs b/aya-obj/src/btf/relocation.rs index c78431df..87a1efc0 100644 --- a/aya-obj/src/btf/relocation.rs +++ b/aya-obj/src/btf/relocation.rs @@ -10,8 +10,6 @@ use core::{mem, ops::Bound::Included, ptr}; use object::SectionIndex; -#[cfg(not(feature = "std"))] -use crate::std; use crate::{ btf::{ fields_are_compatible, types_are_compatible, Array, Btf, BtfError, BtfMember, BtfType, diff --git a/aya-obj/src/lib.rs b/aya-obj/src/lib.rs index c6e3a45c..f1054707 100644 --- a/aya-obj/src/lib.rs +++ b/aya-obj/src/lib.rs @@ -71,19 +71,6 @@ extern crate alloc; #[cfg(feature = "std")] extern crate std; -#[cfg(not(feature = "std"))] -mod std { - pub mod error { - pub use core_error::Error; - } - pub use core::*; - - pub mod os { - pub mod fd { - pub type RawFd = core::ffi::c_int; - } - } -} pub mod btf; pub mod generated; @@ -109,15 +96,15 @@ impl VerifierLog { } } -impl std::fmt::Debug for VerifierLog { +impl core::fmt::Debug for VerifierLog { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let Self(log) = self; f.write_str(log) } } -impl std::fmt::Display for VerifierLog { +impl core::fmt::Display for VerifierLog { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - ::fmt(self, f) + ::fmt(self, f) } } diff --git a/aya-obj/src/maps.rs b/aya-obj/src/maps.rs index 3eb82409..902c5b17 100644 --- a/aya-obj/src/maps.rs +++ b/aya-obj/src/maps.rs @@ -3,8 +3,6 @@ use alloc::vec::Vec; use core::mem; -#[cfg(not(feature = "std"))] -use crate::std; use crate::{EbpfSectionKind, InvalidTypeBinding}; impl TryFrom for crate::generated::bpf_map_type { diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index bb1a3d92..7d304426 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -17,8 +17,6 @@ use object::{ SymbolKind, }; -#[cfg(not(feature = "std"))] -use crate::std; use crate::{ btf::{ Array, Btf, BtfError, BtfExt, BtfFeatures, BtfType, DataSecEntry, FuncSecInfo, LineSecInfo, diff --git a/aya-obj/src/relocation.rs b/aya-obj/src/relocation.rs index b05648ba..b46b277c 100644 --- a/aya-obj/src/relocation.rs +++ b/aya-obj/src/relocation.rs @@ -6,8 +6,6 @@ use core::mem; use log::debug; use object::{SectionIndex, SymbolKind}; -#[cfg(not(feature = "std"))] -use crate::std; use crate::{ generated::{ bpf_insn, BPF_CALL, BPF_JMP, BPF_K, BPF_PSEUDO_CALL, BPF_PSEUDO_FUNC, BPF_PSEUDO_MAP_FD, @@ -19,6 +17,11 @@ use crate::{ EbpfSectionKind, }; +#[cfg(feature = "std")] +type RawFd = std::os::fd::RawFd; +#[cfg(not(feature = "std"))] +type RawFd = core::ffi::c_int; + pub(crate) const INS_SIZE: usize = mem::size_of::(); /// The error type returned by [`Object::relocate_maps`] and [`Object::relocate_calls`] @@ -104,7 +107,7 @@ pub(crate) struct Symbol { impl Object { /// Relocates the map references - pub fn relocate_maps<'a, I: Iterator>( + pub fn relocate_maps<'a, I: Iterator>( &mut self, maps: I, text_sections: &HashSet, @@ -179,8 +182,8 @@ impl Object { fn relocate_maps<'a, I: Iterator>( fun: &mut Function, relocations: I, - maps_by_section: &HashMap, - maps_by_symbol: &HashMap, + maps_by_section: &HashMap, + maps_by_symbol: &HashMap, symbol_table: &HashMap, text_sections: &HashSet, ) -> Result<(), RelocationError> {