tmp: hack for btf verifier error

Signed-off-by: astoycos <astoycos@redhat.com>
fix-verifier-blixt
astoycos 11 months ago
parent 8154fb79d3
commit a381022fca

@ -22,7 +22,7 @@ use crate::{
}, },
generated::{btf_ext_header, btf_header}, generated::{btf_ext_header, btf_header},
util::{bytes_of, HashMap}, util::{bytes_of, HashMap},
Object, Object, Program,
}; };
pub(crate) const MAX_RESOLVE_DEPTH: u8 = 32; 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. // for Aya programs. These fixups are gradually moving into bpf-linker itself.
pub(crate) fn fixup_and_sanitize( pub(crate) fn fixup_and_sanitize(
&mut self, &mut self,
programs: &HashMap<String, Program>,
section_infos: &HashMap<String, (SectionIndex, u64)>, section_infos: &HashMap<String, (SectionIndex, u64)>,
symbol_offsets: &HashMap<String, u64>, symbol_offsets: &HashMap<String, u64>,
features: &BtfFeatures, features: &BtfFeatures,
@ -676,6 +677,11 @@ impl Btf {
} }
ty.set_linkage(FuncLinkage::Static); 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. // Sanitize FLOAT.
@ -743,6 +749,7 @@ impl Object {
} }
// fixup btf // fixup btf
obj_btf.fixup_and_sanitize( obj_btf.fixup_and_sanitize(
&self.programs,
&self.section_infos, &self.section_infos,
&self.symbol_offset_by_name, &self.symbol_offset_by_name,
features, features,
@ -1238,7 +1245,7 @@ mod tests {
let features = Default::default(); 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(); .unwrap();
assert_matches!(btf.type_by_id(ptr_type_id).unwrap(), BtfType::Ptr(fixed) => { assert_matches!(btf.type_by_id(ptr_type_id).unwrap(), BtfType::Ptr(fixed) => {
assert_eq!(fixed.name_offset, 0); assert_eq!(fixed.name_offset, 0);
@ -1271,7 +1278,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(var_type_id).unwrap(), BtfType::Int(fixed) => { assert_matches!(btf.type_by_id(var_type_id).unwrap(), BtfType::Int(fixed) => {
assert_eq!(fixed.name_offset, name_offset); assert_eq!(fixed.name_offset, name_offset);
@ -1313,7 +1320,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(datasec_type_id).unwrap(), BtfType::Struct(fixed) => { assert_matches!(btf.type_by_id(datasec_type_id).unwrap(), BtfType::Struct(fixed) => {
assert_eq!(fixed.name_offset , name_offset); assert_eq!(fixed.name_offset , name_offset);
@ -1366,6 +1373,7 @@ mod tests {
}; };
btf.fixup_and_sanitize( btf.fixup_and_sanitize(
&HashMap::new(),
&HashMap::from([(".data/foo".to_owned(), (SectionIndex(0), 32u64))]), &HashMap::from([(".data/foo".to_owned(), (SectionIndex(0), 32u64))]),
&HashMap::from([("foo".to_owned(), 64u64)]), &HashMap::from([("foo".to_owned(), 64u64)]),
&features, &features,
@ -1429,7 +1437,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(func_proto_type_id).unwrap(), BtfType::Enum(fixed) => { assert_matches!(btf.type_by_id(func_proto_type_id).unwrap(), BtfType::Enum(fixed) => {
assert_eq!(fixed.name_offset, 0); assert_eq!(fixed.name_offset, 0);
@ -1486,7 +1494,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(func_proto_type_id).unwrap(), BtfType::FuncProto(fixed) => { assert_matches!(btf.type_by_id(func_proto_type_id).unwrap(), BtfType::FuncProto(fixed) => {
@ -1549,7 +1557,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(func_type_id).unwrap(), BtfType::Func(fixed) => { assert_matches!(btf.type_by_id(func_type_id).unwrap(), BtfType::Func(fixed) => {
@ -1600,7 +1608,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(func_type_id).unwrap(), BtfType::Func(fixed) => { assert_matches!(btf.type_by_id(func_type_id).unwrap(), BtfType::Func(fixed) => {
@ -1624,7 +1632,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(float_type_id).unwrap(), BtfType::Struct(fixed) => { assert_matches!(btf.type_by_id(float_type_id).unwrap(), BtfType::Struct(fixed) => {
assert_eq!(fixed.name_offset, 0); assert_eq!(fixed.name_offset, 0);
@ -1663,7 +1671,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(decl_tag_type_id).unwrap(), BtfType::Int(fixed) => { assert_matches!(btf.type_by_id(decl_tag_type_id).unwrap(), BtfType::Int(fixed) => {
assert_eq!(fixed.name_offset, name_offset); assert_eq!(fixed.name_offset, name_offset);
@ -1690,7 +1698,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(type_tag_type).unwrap(), BtfType::Const(fixed) => { assert_matches!(btf.type_by_id(type_tag_type).unwrap(), BtfType::Const(fixed) => {
assert_eq!(fixed.btf_type, int_type_id); assert_eq!(fixed.btf_type, int_type_id);
@ -1750,7 +1758,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(enum_type_id).unwrap(), BtfType::Enum(fixed) => { assert_matches!(btf.type_by_id(enum_type_id).unwrap(), BtfType::Enum(fixed) => {
@ -1794,7 +1802,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &HashMap::new(), &features)
.unwrap(); .unwrap();
assert_matches!(btf.type_by_id(enum_type_id).unwrap(), BtfType::Union(fixed) => { assert_matches!(btf.type_by_id(enum_type_id).unwrap(), BtfType::Union(fixed) => {

@ -1616,7 +1616,9 @@ mod tests {
)) ))
.unwrap(); .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()); assert!(btf.is_none());
} }

Loading…
Cancel
Save