Skip to content

Commit 0739126

Browse files
committed
aya-obj: Remove the no_std support
The original motivation for `no_std` support in `aya-obj` was to keep it closer to `object`. In practice, though, one of `aya-obj`'s main jobs is sanitizing bytecode and BTF, and that logic relies on dynamic data structures. Given that, keeping `no_std` support no longer reflects how the crate is actually used and only adds maintenance overhead.
1 parent 316524a commit 0739126

12 files changed

Lines changed: 24 additions & 72 deletions

File tree

aya-obj/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ workspace = true
1818

1919
[dependencies]
2020
bytes = { workspace = true }
21-
hashbrown = { workspace = true, features = ["default-hasher", "equivalent"] }
2221
log = { workspace = true }
2322
object = { workspace = true, features = ["elf", "read_core"] }
24-
thiserror = { workspace = true }
23+
thiserror = { workspace = true, features = ["std"] }
2524

2625
[dev-dependencies]
2726
assert_matches = { workspace = true }
2827
rbpf = { workspace = true }
29-
30-
[features]
31-
std = ["thiserror/std"]

aya-obj/src/btf/btf.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
use alloc::{
1+
use std::{
22
borrow::{Cow, ToOwned as _},
3-
format,
4-
string::String,
5-
vec,
6-
vec::Vec,
7-
};
8-
use core::{
93
cell::OnceCell,
104
ffi::{CStr, FromBytesUntilNulError},
11-
mem, ptr,
5+
format, mem, ptr,
126
};
137

148
use bytes::BufMut as _;
@@ -34,7 +28,6 @@ pub(crate) const MAX_SPEC_LEN: usize = 64;
3428
/// The error type returned when `BTF` operations fail.
3529
#[derive(thiserror::Error, Debug)]
3630
pub enum BtfError {
37-
#[cfg(feature = "std")]
3831
/// Error parsing file
3932
#[error("error parsing {path}")]
4033
FileError {
@@ -128,7 +121,6 @@ pub enum BtfError {
128121
type_id: u32,
129122
},
130123

131-
#[cfg(feature = "std")]
132124
/// Loading the btf failed
133125
#[error("the BPF_BTF_LOAD syscall returned {io_error}. Verifier output: {verifier_log}")]
134126
LoadError {
@@ -319,13 +311,11 @@ impl Btf {
319311
}
320312

321313
/// Loads BTF metadata from `/sys/kernel/btf/vmlinux`.
322-
#[cfg(feature = "std")]
323314
pub fn from_sys_fs() -> Result<Self, BtfError> {
324315
Self::parse_file("/sys/kernel/btf/vmlinux", Endianness::default())
325316
}
326317

327318
/// Loads BTF metadata from the given `path`.
328-
#[cfg(feature = "std")]
329319
pub fn parse_file<P: AsRef<std::path::Path>>(
330320
path: P,
331321
endianness: Endianness,
@@ -1878,7 +1868,6 @@ mod tests {
18781868
}
18791869

18801870
#[test]
1881-
#[cfg(feature = "std")]
18821871
#[cfg_attr(miri, ignore = "`open` not available when isolation is enabled")]
18831872
#[cfg_attr(
18841873
target_endian = "big",

aya-obj/src/btf/info.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use alloc::{string::String, vec, vec::Vec};
2-
31
use bytes::BufMut as _;
42
use object::Endianness;
53

aya-obj/src/btf/relocation.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use alloc::{
1+
use std::{
22
borrow::{Cow, ToOwned as _},
33
collections::BTreeMap,
44
format,
5-
string::{String, ToString as _},
6-
vec,
7-
vec::Vec,
5+
num::ParseIntError,
6+
ops::Bound::Included,
7+
ptr,
8+
string::ToString as _,
89
};
9-
use core::{num::ParseIntError, ops::Bound::Included, ptr};
1010

1111
use object::SectionIndex;
1212

@@ -37,7 +37,6 @@ pub struct BtfRelocationError {
3737
/// Relocation failures
3838
#[derive(thiserror::Error, Debug)]
3939
enum RelocationError {
40-
#[cfg(feature = "std")]
4140
/// I/O error
4241
#[error(transparent)]
4342
IOError(#[from] std::io::Error),

aya-obj/src/btf/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#![expect(clippy::unused_self, reason = "these APIs are horrible")]
22
#![expect(missing_docs, reason = "TODO")]
33

4-
use alloc::{string::ToString as _, vec, vec::Vec};
5-
use core::{fmt::Display, ptr};
4+
use std::{fmt::Display, ptr, string::ToString as _};
65

76
use object::Endianness;
87

aya-obj/src/lib.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
//! let bytes = std::fs::read("program.o").unwrap();
3838
//! let mut object = Object::parse(&bytes).unwrap();
3939
//! // Relocate the programs
40-
//! #[cfg(feature = "std")]
4140
//! let text_sections = std::collections::HashSet::new();
42-
//! #[cfg(not(feature = "std"))]
43-
//! let text_sections = hashbrown::HashSet::new();
4441
//! object.relocate_calls(&text_sections).unwrap();
4542
//! object.relocate_maps(std::iter::empty(), &text_sections).unwrap();
4643
//!
@@ -59,21 +56,13 @@
5956
//!
6057
//! [rbpf]: https://github.com/qmonnet/rbpf
6158
62-
#![no_std]
6359
#![doc(
6460
html_logo_url = "https://aya-rs.dev/assets/images/crabby.svg",
6561
html_favicon_url = "https://aya-rs.dev/assets/images/crabby.svg"
6662
)]
6763
#![cfg_attr(docsrs, feature(doc_cfg))]
6864
#![deny(missing_docs)]
69-
#![cfg_attr(
70-
any(feature = "std", test),
71-
expect(unused_crate_dependencies, reason = "used in doctests")
72-
)]
73-
74-
extern crate alloc;
75-
#[cfg(feature = "std")]
76-
extern crate std;
65+
#![cfg_attr(test, expect(unused_crate_dependencies, reason = "used in doctests"))]
7766

7867
pub mod btf;
7968
#[expect(
@@ -113,11 +102,11 @@ pub use obj::*;
113102
/// An error returned from the verifier.
114103
///
115104
/// Provides a [`Debug`] implementation that doesn't escape newlines.
116-
pub struct VerifierLog(alloc::string::String);
105+
pub struct VerifierLog(String);
117106

118107
impl VerifierLog {
119108
/// Create a new verifier log.
120-
pub const fn new(log: alloc::string::String) -> Self {
109+
pub const fn new(log: String) -> Self {
121110
Self(log)
122111
}
123112
}

aya-obj/src/maps.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Map struct and type bindings.
22
3-
use alloc::vec::Vec;
4-
53
use crate::{EbpfSectionKind, InvalidTypeBinding, generated::bpf_map_type};
64

75
impl TryFrom<u32> for bpf_map_type {

aya-obj/src/obj.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
//! Object file loading, parsing, and relocation.
22
3-
use alloc::{
3+
use std::{
44
borrow::ToOwned as _,
55
collections::BTreeMap,
6-
ffi::CString,
7-
string::{String, ToString as _},
8-
vec,
9-
vec::Vec,
10-
};
11-
use core::{
12-
ffi::{CStr, FromBytesWithNulError},
6+
ffi::{CStr, CString, FromBytesWithNulError},
137
mem, ptr,
148
slice::from_raw_parts_mut,
159
str::FromStr,
10+
string::ToString as _,
1611
};
1712

1813
use log::debug;
@@ -1164,7 +1159,7 @@ fn parse_license(data: &[u8]) -> Result<CString, ParseError> {
11641159
data: data.to_vec(),
11651160
},
11661161
})
1167-
.map(alloc::borrow::ToOwned::to_owned)
1162+
.map(ToOwned::to_owned)
11681163
}
11691164

11701165
fn parse_version(data: &[u8], endianness: Endianness) -> Result<Option<u32>, ParseError> {
@@ -1461,8 +1456,6 @@ fn get_func_and_line_info(
14611456

14621457
#[cfg(test)]
14631458
mod tests {
1464-
use alloc::vec;
1465-
14661459
use assert_matches::assert_matches;
14671460

14681461
use super::*;

aya-obj/src/relocation.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Program relocation handling.
22
3-
use alloc::{borrow::ToOwned as _, collections::BTreeMap, string::String};
3+
use std::{borrow::ToOwned as _, collections::BTreeMap};
44

55
use log::debug;
66
use object::{SectionIndex, SymbolKind};
@@ -16,10 +16,7 @@ use crate::{
1616
util::{HashMap, HashSet},
1717
};
1818

19-
#[cfg(feature = "std")]
2019
type RawFd = std::os::fd::RawFd;
21-
#[cfg(not(feature = "std"))]
22-
type RawFd = core::ffi::c_int;
2320

2421
pub(crate) const INS_SIZE: usize = size_of::<bpf_insn>();
2522

@@ -495,7 +492,7 @@ fn insn_is_call(ins: bpf_insn) -> bool {
495492

496493
#[cfg(test)]
497494
mod test {
498-
use alloc::{string::ToString as _, vec, vec::Vec};
495+
use std::string::ToString as _;
499496

500497
use super::*;
501498
use crate::maps::{BtfMap, LegacyMap};

aya-obj/src/util.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
use core::{ptr, slice};
2-
#[cfg(feature = "std")]
3-
pub(crate) use std::collections::HashMap;
4-
#[cfg(feature = "std")]
5-
pub(crate) use std::collections::HashSet;
6-
7-
#[cfg(not(feature = "std"))]
8-
pub(crate) use hashbrown::HashMap;
9-
#[cfg(not(feature = "std"))]
10-
pub(crate) use hashbrown::HashSet;
2+
pub(crate) use std::collections::{HashMap, HashSet};
113

124
/// Converts a <T> to a byte slice.
135
pub(crate) const unsafe fn bytes_of<T>(val: &T) -> &[u8] {

0 commit comments

Comments
 (0)