diff --git a/aya-obj/src/btf/btf.rs b/aya-obj/src/btf/btf.rs index 52b04daa..ef7217ad 100644 --- a/aya-obj/src/btf/btf.rs +++ b/aya-obj/src/btf/btf.rs @@ -416,20 +416,6 @@ impl Btf { self.string_at(ty.name_offset()).ok().map(String::from) } - /// Returns a type id matching the type name - pub fn id_by_type_name(&self, name: &str) -> Result { - for (type_id, ty) in self.types().enumerate() { - if self.type_name(ty)? == name { - return Ok(type_id as u32); - } - continue; - } - - Err(BtfError::UnknownBtfTypeName { - type_name: name.to_owned(), - }) - } - /// Returns a type id matching the type name and [BtfKind] pub fn id_by_type_name_kind(&self, name: &str, kind: BtfKind) -> Result { for (type_id, ty) in self.types().enumerate() { diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index 50cb9fed..f6f4fc8b 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -8,7 +8,6 @@ use alloc::{ vec::Vec, }; use core::{ffi::CStr, mem, ptr, slice::from_raw_parts_mut, str::FromStr}; -use std::println; use log::debug; use object::{ diff --git a/aya-obj/src/relocation.rs b/aya-obj/src/relocation.rs index 46639bab..92d279c4 100644 --- a/aya-obj/src/relocation.rs +++ b/aya-obj/src/relocation.rs @@ -2,7 +2,6 @@ use alloc::{borrow::ToOwned, collections::BTreeMap, string::String}; use core::mem; -use std::println; use log::debug; use object::{SectionIndex, SymbolKind}; @@ -116,7 +115,7 @@ impl Object { let mut ignored_by_section = HashSet::new(); let mut ignored_by_symbol = HashSet::new(); - for (name, map) in ignored_maps { + for map in ignored_maps.values() { ignored_by_section.insert(map.section_index()); if let Some(index) = map.symbol_index() { ignored_by_symbol.insert(index); diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index 7ded6663..75e47f24 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -3,7 +3,7 @@ use std::{ collections::{HashMap, HashSet}, fs, io, os::{ - fd::{AsFd as _, AsRawFd as _, FromRawFd, OwnedFd}, + fd::{AsFd as _, AsRawFd as _, OwnedFd}, raw::c_int, }, path::{Path, PathBuf}, @@ -24,7 +24,7 @@ use crate::{ bpf_map_type::{self, *}, AYA_PERF_EVENT_IOC_DISABLE, AYA_PERF_EVENT_IOC_ENABLE, AYA_PERF_EVENT_IOC_SET_BPF, }, - maps::{Map, MapData, MapError, MapFd}, + maps::{Map, MapData, MapError}, obj::{ btf::{Btf, BtfError}, Object, ParseError, ProgramSection, @@ -237,7 +237,7 @@ impl<'a> EbpfLoader<'a> { /// /// ```no_run /// use aya::EbpfLoader; - /// use aya_obj::btf::Btf::bpf_map_type; + /// use aya_obj::generated::bpf_map_type; /// /// let mut set = HashSet::new(); /// set.insert(bpf_map_type::BPF_MAP_TYPE_RINGBUF); @@ -425,6 +425,7 @@ impl<'a> EbpfLoader<'a> { deactivate_maps, } = self; let mut obj = Object::parse(data)?; + obj.patch_map_data(globals.clone())?; let btf_fd = if let Some(features) = &FEATURES.btf() { if let Some(btf) = obj.fixup_and_sanitize_btf(features)? { @@ -495,9 +496,12 @@ impl<'a> EbpfLoader<'a> { { continue; } + let map_type: bpf_map_type = obj.map_type().try_into().map_err(MapError::from)?; - if deactivate_maps.contains(&obj.map_type().try_into().map_err(|_| EbpfError::MapError(MapError::InvalidMapType { map_type: obj.map_type() }))?) { + if deactivate_maps.contains(&map_type) { ignored_maps.insert(name, obj); + // ignore map creation. The map is saved in `ignored_maps` and filtered out + // in `relocate_maps()` later on continue; } @@ -509,7 +513,6 @@ impl<'a> EbpfLoader<'a> { })? .len() as u32) }; - let map_type: bpf_map_type = obj.map_type().try_into().map_err(MapError::from)?; if let Some(max_entries) = max_entries_override( map_type, max_entries.get(name.as_str()).copied(),