Переглянути джерело

build(deps): update thiserror to 2.0.3

This removes the fake std module in aya-obj which is no longer needed as
thiserror now properly supports no_std.

Signed-off-by: Tamir Duberstein <[email protected]>
Tamir Duberstein 4 місяців тому
батько
коміт
e95a54f593

+ 1 - 2
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 }

+ 1 - 2
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"]

+ 6 - 8
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::<MinimalHeader>() {
+        if data.len() < core::mem::size_of::<MinimalHeader>() {
             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::<btf_ext_header>());
+            let len_to_read = len_to_read.min(core::mem::size_of::<btf_ext_header>());
 
             // 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::<btf_ext_header>::zeroed();
+            let mut header = core::mem::MaybeUninit::<btf_ext_header>::zeroed();
             // Safety: we have checked that len_to_read is less than
             // size_of::<btf_ext_header> 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()
             }
         };

+ 0 - 2
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,

+ 3 - 16
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 {
-        <Self as std::fmt::Debug>::fmt(self, f)
+        <Self as core::fmt::Debug>::fmt(self, f)
     }
 }

+ 0 - 2
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<u32> for crate::generated::bpf_map_type {

+ 0 - 2
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,

+ 8 - 5
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::<bpf_insn>();
 
 /// 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<Item = (&'a str, std::os::fd::RawFd, &'a Map)>>(
+    pub fn relocate_maps<'a, I: Iterator<Item = (&'a str, RawFd, &'a Map)>>(
         &mut self,
         maps: I,
         text_sections: &HashSet<usize>,
@@ -179,8 +182,8 @@ impl Object {
 fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
     fun: &mut Function,
     relocations: I,
-    maps_by_section: &HashMap<usize, (&str, std::os::fd::RawFd, &Map)>,
-    maps_by_symbol: &HashMap<usize, (&str, std::os::fd::RawFd, &Map)>,
+    maps_by_section: &HashMap<usize, (&str, RawFd, &Map)>,
+    maps_by_symbol: &HashMap<usize, (&str, RawFd, &Map)>,
     symbol_table: &HashMap<usize, Symbol>,
     text_sections: &HashSet<usize>,
 ) -> Result<(), RelocationError> {