From a381022fca5d203a395aaf9b6855712485998ab0 Mon Sep 17 00:00:00 2001 From: astoycos Date: Tue, 17 Oct 2023 11:52:54 -0400 Subject: [PATCH] tmp: hack for btf verifier error Signed-off-by: astoycos --- aya-obj/src/btf/btf.rs | 34 +++++++++++++++++++++------------- aya-obj/src/obj.rs | 4 +++- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/aya-obj/src/btf/btf.rs b/aya-obj/src/btf/btf.rs index de9e54e4..744b917b 100644 --- a/aya-obj/src/btf/btf.rs +++ b/aya-obj/src/btf/btf.rs @@ -22,7 +22,7 @@ use crate::{ }, generated::{btf_ext_header, btf_header}, util::{bytes_of, HashMap}, - Object, + Object, Program, }; pub(crate) const MAX_RESOLVE_DEPTH: u8 = 32; @@ -483,6 +483,7 @@ impl Btf { // for Aya programs. These fixups are gradually moving into bpf-linker itself. pub(crate) fn fixup_and_sanitize( &mut self, + programs: &HashMap, section_infos: &HashMap, symbol_offsets: &HashMap, features: &BtfFeatures, @@ -676,6 +677,11 @@ impl Btf { } ty.set_linkage(FuncLinkage::Static); } + } else if !programs.contains_key(name.as_ref()) + && !name.as_ref().starts_with("prog") + { + debug!("changing FUNC {name} linkage to BTF_FUNC_STATIC"); + ty.set_linkage(FuncLinkage::Static); } } // Sanitize FLOAT. @@ -743,6 +749,7 @@ impl Object { } // fixup btf obj_btf.fixup_and_sanitize( + &self.programs, &self.section_infos, &self.symbol_offset_by_name, features, @@ -1238,7 +1245,7 @@ mod tests { let features = Default::default(); - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(ptr_type_id).unwrap(), BtfType::Ptr(fixed) => { assert_eq!(fixed.name_offset, 0); @@ -1271,7 +1278,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(var_type_id).unwrap(), BtfType::Int(fixed) => { assert_eq!(fixed.name_offset, name_offset); @@ -1313,7 +1320,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(datasec_type_id).unwrap(), BtfType::Struct(fixed) => { assert_eq!(fixed.name_offset , name_offset); @@ -1366,6 +1373,7 @@ mod tests { }; btf.fixup_and_sanitize( + &HashMap::new(), &HashMap::from([(".data/foo".to_owned(), (SectionIndex(0), 32u64))]), &HashMap::from([("foo".to_owned(), 64u64)]), &features, @@ -1429,7 +1437,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(func_proto_type_id).unwrap(), BtfType::Enum(fixed) => { assert_eq!(fixed.name_offset, 0); @@ -1486,7 +1494,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(func_proto_type_id).unwrap(), BtfType::FuncProto(fixed) => { @@ -1549,7 +1557,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(func_type_id).unwrap(), BtfType::Func(fixed) => { @@ -1600,7 +1608,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(func_type_id).unwrap(), BtfType::Func(fixed) => { @@ -1624,7 +1632,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(float_type_id).unwrap(), BtfType::Struct(fixed) => { assert_eq!(fixed.name_offset, 0); @@ -1663,7 +1671,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(decl_tag_type_id).unwrap(), BtfType::Int(fixed) => { assert_eq!(fixed.name_offset, name_offset); @@ -1690,7 +1698,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(type_tag_type).unwrap(), BtfType::Const(fixed) => { assert_eq!(fixed.btf_type, int_type_id); @@ -1750,7 +1758,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(enum_type_id).unwrap(), BtfType::Enum(fixed) => { @@ -1794,7 +1802,7 @@ mod tests { ..Default::default() }; - btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) + btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features) .unwrap(); assert_matches!(btf.type_by_id(enum_type_id).unwrap(), BtfType::Union(fixed) => { diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index 9d65690e..6eeb0283 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -1616,7 +1616,9 @@ mod tests { )) .unwrap(); - let btf = obj.fixup_and_sanitize_btf(&BtfFeatures::default()).unwrap(); + let btf = obj + .fixup_and_sanitize_btf(&BtfFeatures::default(), &std::collections::HashSet::new()) + .unwrap(); assert!(btf.is_none()); }