diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index f0168950..bb1a3d92 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -5,6 +5,7 @@ use alloc::{ collections::BTreeMap, ffi::CString, string::{String, ToString}, + vec, vec::Vec, }; use core::{ffi::CStr, mem, ptr, slice::from_raw_parts_mut, str::FromStr}; @@ -1193,7 +1194,7 @@ fn get_map_field(btf: &Btf, type_id: u32) -> Result { // bytes and are relocated based on their section index. fn parse_data_map_section(section: &Section) -> Result { let (def, data) = match section.kind { - EbpfSectionKind::Bss | EbpfSectionKind::Data | EbpfSectionKind::Rodata => { + EbpfSectionKind::Data | EbpfSectionKind::Rodata => { let def = bpf_map_def { map_type: BPF_MAP_TYPE_ARRAY as u32, key_size: mem::size_of::() as u32, @@ -1210,6 +1211,17 @@ fn parse_data_map_section(section: &Section) -> Result { }; (def, section.data.to_vec()) } + EbpfSectionKind::Bss => { + let def = bpf_map_def { + map_type: BPF_MAP_TYPE_ARRAY as u32, + key_size: mem::size_of::() as u32, + value_size: section.size as u32, + max_entries: 1, + map_flags: 0, + ..Default::default() + }; + (def, vec![0; section.size as usize]) + } _ => unreachable!(), }; Ok(Map::Legacy(LegacyMap { diff --git a/aya/src/maps/mod.rs b/aya/src/maps/mod.rs index 6f36b6b3..bb641288 100644 --- a/aya/src/maps/mod.rs +++ b/aya/src/maps/mod.rs @@ -637,7 +637,7 @@ impl MapData { pub(crate) fn finalize(&mut self) -> Result<(), MapError> { let Self { obj, fd } = self; - if !obj.data().is_empty() && obj.section_kind() != EbpfSectionKind::Bss { + if !obj.data().is_empty() { bpf_map_update_elem_ptr(fd.as_fd(), &0 as *const _, obj.data_mut().as_mut_ptr(), 0) .map_err(|(_, io_error)| SyscallError { call: "bpf_map_update_elem",