diff --git a/aya-obj/src/btf/btf.rs b/aya-obj/src/btf/btf.rs index a94cac95..ec455376 100644 --- a/aya-obj/src/btf/btf.rs +++ b/aya-obj/src/btf/btf.rs @@ -942,8 +942,8 @@ impl BtfExt { self.info_data(self.header.line_info_off, self.header.line_info_len) } - pub(crate) fn relocations(&self) -> impl Iterator)> { - self.relocations.iter() + pub(crate) fn relocations(&self) -> &[(u32, Vec)] { + self.relocations.as_slice() } pub(crate) fn func_info_rec_size(&self) -> usize { diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index 07417a81..b451595a 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -529,6 +529,13 @@ impl Object { } } + /// Returns true if this object contains CO-RE relocations. + pub fn has_btf_relocations(&self) -> bool { + self.btf_ext + .as_ref() + .is_some_and(|ext| !ext.relocations().is_empty()) + } + /// Patches map data pub fn patch_map_data( &mut self, diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index 5055e923..a2868f81 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -436,6 +436,10 @@ impl<'a> EbpfLoader<'a> { } } + if obj.has_btf_relocations() { + return Err(EbpfError::BtfError(err)); + } + warn!("object BTF couldn't be loaded in the kernel: {err}"); None diff --git a/xtask/public-api/aya-obj.txt b/xtask/public-api/aya-obj.txt index b04d69cf..b40c040d 100644 --- a/xtask/public-api/aya-obj.txt +++ b/xtask/public-api/aya-obj.txt @@ -8784,6 +8784,7 @@ pub aya_obj::obj::Object::programs: std::collections::hash::map::HashMap core::result::Result, aya_obj::btf::BtfError> impl aya_obj::Object +pub fn aya_obj::Object::has_btf_relocations(&self) -> bool pub fn aya_obj::Object::parse(data: &[u8]) -> core::result::Result pub fn aya_obj::Object::patch_map_data(&mut self, globals: std::collections::hash::map::HashMap<&str, (&[u8], bool)>) -> core::result::Result<(), aya_obj::ParseError> pub fn aya_obj::Object::sanitize_functions(&mut self, features: &aya_obj::Features) @@ -9646,6 +9647,7 @@ pub aya_obj::Object::programs: std::collections::hash::map::HashMap core::result::Result, aya_obj::btf::BtfError> impl aya_obj::Object +pub fn aya_obj::Object::has_btf_relocations(&self) -> bool pub fn aya_obj::Object::parse(data: &[u8]) -> core::result::Result pub fn aya_obj::Object::patch_map_data(&mut self, globals: std::collections::hash::map::HashMap<&str, (&[u8], bool)>) -> core::result::Result<(), aya_obj::ParseError> pub fn aya_obj::Object::sanitize_functions(&mut self, features: &aya_obj::Features)