|
|
@ -1,10 +1,9 @@
|
|
|
|
use core::{ffi::CStr, mem, ptr};
|
|
|
|
use core::{ffi::CStr, mem, ptr};
|
|
|
|
|
|
|
|
|
|
|
|
use alloc::{
|
|
|
|
use alloc::{
|
|
|
|
borrow::Cow,
|
|
|
|
borrow::{Cow, ToOwned as _},
|
|
|
|
ffi::CString,
|
|
|
|
|
|
|
|
format,
|
|
|
|
format,
|
|
|
|
string::{String, ToString},
|
|
|
|
string::String,
|
|
|
|
vec,
|
|
|
|
vec,
|
|
|
|
vec::Vec,
|
|
|
|
vec::Vec,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -276,10 +275,10 @@ impl Btf {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds a string to BTF metadata, returning an offset
|
|
|
|
/// Adds a string to BTF metadata, returning an offset
|
|
|
|
pub fn add_string(&mut self, name: String) -> u32 {
|
|
|
|
pub fn add_string(&mut self, name: &str) -> u32 {
|
|
|
|
let str = CString::new(name).unwrap();
|
|
|
|
let str = name.bytes().chain(std::iter::once(0));
|
|
|
|
let name_offset = self.strings.len();
|
|
|
|
let name_offset = self.strings.len();
|
|
|
|
self.strings.extend(str.as_c_str().to_bytes_with_nul());
|
|
|
|
self.strings.extend(str);
|
|
|
|
self.header.str_len = self.strings.len() as u32;
|
|
|
|
self.header.str_len = self.strings.len() as u32;
|
|
|
|
name_offset as u32
|
|
|
|
name_offset as u32
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -424,7 +423,7 @@ impl Btf {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Err(BtfError::UnknownBtfTypeName {
|
|
|
|
Err(BtfError::UnknownBtfTypeName {
|
|
|
|
type_name: name.to_string(),
|
|
|
|
type_name: name.to_owned(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -498,14 +497,13 @@ impl Btf {
|
|
|
|
|
|
|
|
|
|
|
|
// STRUCT aren't allowed to have "." in their name, fixup this if needed.
|
|
|
|
// STRUCT aren't allowed to have "." in their name, fixup this if needed.
|
|
|
|
let mut name_offset = t.name_offset();
|
|
|
|
let mut name_offset = t.name_offset();
|
|
|
|
let sec_name = self.string_at(name_offset)?;
|
|
|
|
let name = self.string_at(name_offset)?;
|
|
|
|
let name = sec_name.to_string();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle any "." characters in struct names
|
|
|
|
// Handle any "." characters in struct names
|
|
|
|
// Example: ".maps"
|
|
|
|
// Example: ".maps"
|
|
|
|
let fixed_name = name.replace('.', "_");
|
|
|
|
let fixed_name = name.replace('.', "_");
|
|
|
|
if fixed_name != name {
|
|
|
|
if fixed_name != name {
|
|
|
|
name_offset = self.add_string(fixed_name);
|
|
|
|
name_offset = self.add_string(&fixed_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut members = vec![];
|
|
|
|
let mut members = vec![];
|
|
|
@ -526,8 +524,8 @@ impl Btf {
|
|
|
|
// we need to fix them here before loading the btf to the kernel
|
|
|
|
// we need to fix them here before loading the btf to the kernel
|
|
|
|
BtfType::DataSec(d) if features.btf_datasec => {
|
|
|
|
BtfType::DataSec(d) if features.btf_datasec => {
|
|
|
|
// Start DataSec Fixups
|
|
|
|
// Start DataSec Fixups
|
|
|
|
let sec_name = self.string_at(d.name_offset)?;
|
|
|
|
let name = self.string_at(d.name_offset)?;
|
|
|
|
let name = sec_name.to_string();
|
|
|
|
let name = name.into_owned();
|
|
|
|
|
|
|
|
|
|
|
|
let mut fixed_ty = d.clone();
|
|
|
|
let mut fixed_ty = d.clone();
|
|
|
|
|
|
|
|
|
|
|
@ -535,7 +533,7 @@ impl Btf {
|
|
|
|
// Example: "maps/hashmap"
|
|
|
|
// Example: "maps/hashmap"
|
|
|
|
let fixed_name = name.replace('/', ".");
|
|
|
|
let fixed_name = name.replace('/', ".");
|
|
|
|
if fixed_name != name {
|
|
|
|
if fixed_name != name {
|
|
|
|
fixed_ty.name_offset = self.add_string(fixed_name);
|
|
|
|
fixed_ty.name_offset = self.add_string(&fixed_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// There are some cases when the compiler does indeed populate the
|
|
|
|
// There are some cases when the compiler does indeed populate the
|
|
|
@ -546,11 +544,12 @@ impl Btf {
|
|
|
|
// We need to get the size of the section from the ELF file
|
|
|
|
// We need to get the size of the section from the ELF file
|
|
|
|
// Fortunately, we cached these when parsing it initially
|
|
|
|
// Fortunately, we cached these when parsing it initially
|
|
|
|
// and we can this up by name in section_infos
|
|
|
|
// and we can this up by name in section_infos
|
|
|
|
let (_, size) = section_infos.get(&name).ok_or_else(|| {
|
|
|
|
let size = match section_infos.get(&name) {
|
|
|
|
BtfError::UnknownSectionSize {
|
|
|
|
Some((_, size)) => size,
|
|
|
|
section_name: name.clone(),
|
|
|
|
None => {
|
|
|
|
|
|
|
|
return Err(BtfError::UnknownSectionSize { section_name: name });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})?;
|
|
|
|
};
|
|
|
|
debug!("{} {}: fixup size to {}", kind, name, size);
|
|
|
|
debug!("{} {}: fixup size to {}", kind, name, size);
|
|
|
|
fixed_ty.size = *size as u32;
|
|
|
|
fixed_ty.size = *size as u32;
|
|
|
|
|
|
|
|
|
|
|
@ -563,7 +562,7 @@ impl Btf {
|
|
|
|
let var_type = types.type_by_id(d.btf_type)?;
|
|
|
|
let var_type = types.type_by_id(d.btf_type)?;
|
|
|
|
let var_kind = var_type.kind();
|
|
|
|
let var_kind = var_type.kind();
|
|
|
|
if let BtfType::Var(var) = var_type {
|
|
|
|
if let BtfType::Var(var) = var_type {
|
|
|
|
let var_name = self.string_at(var.name_offset)?.to_string();
|
|
|
|
let var_name = self.string_at(var.name_offset)?;
|
|
|
|
if var.linkage == VarLinkage::Static {
|
|
|
|
if var.linkage == VarLinkage::Static {
|
|
|
|
debug!(
|
|
|
|
debug!(
|
|
|
|
"{} {}: {} {}: fixup not required",
|
|
|
|
"{} {}: {} {}: fixup not required",
|
|
|
@ -572,11 +571,14 @@ impl Btf {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let offset = symbol_offsets.get(&var_name).ok_or(
|
|
|
|
let offset = match symbol_offsets.get(var_name.as_ref()) {
|
|
|
|
BtfError::SymbolOffsetNotFound {
|
|
|
|
Some(offset) => offset,
|
|
|
|
symbol_name: var_name.clone(),
|
|
|
|
None => {
|
|
|
|
},
|
|
|
|
return Err(BtfError::SymbolOffsetNotFound {
|
|
|
|
)?;
|
|
|
|
symbol_name: var_name.into_owned(),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
d.offset = *offset as u32;
|
|
|
|
d.offset = *offset as u32;
|
|
|
|
debug!(
|
|
|
|
debug!(
|
|
|
|
"{} {}: {} {}: fixup offset {}",
|
|
|
|
"{} {}: {} {}: fixup offset {}",
|
|
|
@ -594,7 +596,7 @@ impl Btf {
|
|
|
|
let mut ty = ty.clone();
|
|
|
|
let mut ty = ty.clone();
|
|
|
|
for (i, param) in ty.params.iter_mut().enumerate() {
|
|
|
|
for (i, param) in ty.params.iter_mut().enumerate() {
|
|
|
|
if param.name_offset == 0 && param.btf_type != 0 {
|
|
|
|
if param.name_offset == 0 && param.btf_type != 0 {
|
|
|
|
param.name_offset = self.add_string(format!("param{i}"));
|
|
|
|
param.name_offset = self.add_string(&format!("param{i}"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
types.types[i] = BtfType::FuncProto(ty);
|
|
|
|
types.types[i] = BtfType::FuncProto(ty);
|
|
|
@ -1163,11 +1165,11 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_write_btf() {
|
|
|
|
fn test_write_btf() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type = BtfType::Int(Int::new(name_offset, 4, IntEncoding::Signed, 0));
|
|
|
|
let int_type = BtfType::Int(Int::new(name_offset, 4, IntEncoding::Signed, 0));
|
|
|
|
btf.add_type(int_type);
|
|
|
|
btf.add_type(int_type);
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string("widget".to_string());
|
|
|
|
let name_offset = btf.add_string("widget");
|
|
|
|
let int_type = BtfType::Int(Int::new(name_offset, 4, IntEncoding::Signed, 0));
|
|
|
|
let int_type = BtfType::Int(Int::new(name_offset, 4, IntEncoding::Signed, 0));
|
|
|
|
btf.add_type(int_type);
|
|
|
|
btf.add_type(int_type);
|
|
|
|
|
|
|
|
|
|
|
@ -1189,7 +1191,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_fixup_ptr() {
|
|
|
|
fn test_fixup_ptr() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
@ -1197,7 +1199,7 @@ mod tests {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
)));
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string("&mut int".to_string());
|
|
|
|
let name_offset = btf.add_string("&mut int");
|
|
|
|
let ptr_type_id = btf.add_type(BtfType::Ptr(Ptr::new(name_offset, int_type_id)));
|
|
|
|
let ptr_type_id = btf.add_type(BtfType::Ptr(Ptr::new(name_offset, int_type_id)));
|
|
|
|
|
|
|
|
|
|
|
|
let features = Default::default();
|
|
|
|
let features = Default::default();
|
|
|
@ -1221,7 +1223,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_sanitize_var() {
|
|
|
|
fn test_sanitize_var() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
@ -1229,7 +1231,7 @@ mod tests {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
)));
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string("&mut int".to_string());
|
|
|
|
let name_offset = btf.add_string("&mut int");
|
|
|
|
let var_type_id = btf.add_type(BtfType::Var(Var::new(
|
|
|
|
let var_type_id = btf.add_type(BtfType::Var(Var::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
int_type_id,
|
|
|
|
int_type_id,
|
|
|
@ -1256,7 +1258,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_sanitize_datasec() {
|
|
|
|
fn test_sanitize_datasec() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
@ -1264,14 +1266,14 @@ mod tests {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
)));
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string("foo".to_string());
|
|
|
|
let name_offset = btf.add_string("foo");
|
|
|
|
let var_type_id = btf.add_type(BtfType::Var(Var::new(
|
|
|
|
let var_type_id = btf.add_type(BtfType::Var(Var::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
int_type_id,
|
|
|
|
int_type_id,
|
|
|
|
VarLinkage::Static,
|
|
|
|
VarLinkage::Static,
|
|
|
|
)));
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string("data".to_string());
|
|
|
|
let name_offset = btf.add_string("data");
|
|
|
|
let variables = vec![DataSecEntry {
|
|
|
|
let variables = vec![DataSecEntry {
|
|
|
|
btf_type: var_type_id,
|
|
|
|
btf_type: var_type_id,
|
|
|
|
offset: 0,
|
|
|
|
offset: 0,
|
|
|
@ -1303,7 +1305,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_fixup_datasec() {
|
|
|
|
fn test_fixup_datasec() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
@ -1311,14 +1313,14 @@ mod tests {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
)));
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string("foo".to_string());
|
|
|
|
let name_offset = btf.add_string("foo");
|
|
|
|
let var_type_id = btf.add_type(BtfType::Var(Var::new(
|
|
|
|
let var_type_id = btf.add_type(BtfType::Var(Var::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
int_type_id,
|
|
|
|
int_type_id,
|
|
|
|
VarLinkage::Global,
|
|
|
|
VarLinkage::Global,
|
|
|
|
)));
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string(".data/foo".to_string());
|
|
|
|
let name_offset = btf.add_string(".data/foo");
|
|
|
|
let variables = vec![DataSecEntry {
|
|
|
|
let variables = vec![DataSecEntry {
|
|
|
|
btf_type: var_type_id,
|
|
|
|
btf_type: var_type_id,
|
|
|
|
offset: 0,
|
|
|
|
offset: 0,
|
|
|
@ -1333,8 +1335,8 @@ mod tests {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
btf.fixup_and_sanitize(
|
|
|
|
btf.fixup_and_sanitize(
|
|
|
|
&HashMap::from([(".data/foo".to_string(), (SectionIndex(0), 32u64))]),
|
|
|
|
&HashMap::from([(".data/foo".to_owned(), (SectionIndex(0), 32u64))]),
|
|
|
|
&HashMap::from([("foo".to_string(), 64u64)]),
|
|
|
|
&HashMap::from([("foo".to_owned(), 64u64)]),
|
|
|
|
&features,
|
|
|
|
&features,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
@ -1361,7 +1363,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_sanitize_func_and_proto() {
|
|
|
|
fn test_sanitize_func_and_proto() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
@ -1371,17 +1373,17 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
|
|
let params = vec![
|
|
|
|
let params = vec![
|
|
|
|
BtfParam {
|
|
|
|
BtfParam {
|
|
|
|
name_offset: btf.add_string("a".to_string()),
|
|
|
|
name_offset: btf.add_string("a"),
|
|
|
|
btf_type: int_type_id,
|
|
|
|
btf_type: int_type_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
BtfParam {
|
|
|
|
BtfParam {
|
|
|
|
name_offset: btf.add_string("b".to_string()),
|
|
|
|
name_offset: btf.add_string("b"),
|
|
|
|
btf_type: int_type_id,
|
|
|
|
btf_type: int_type_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
];
|
|
|
|
let func_proto_type_id =
|
|
|
|
let func_proto_type_id =
|
|
|
|
btf.add_type(BtfType::FuncProto(FuncProto::new(params, int_type_id)));
|
|
|
|
btf.add_type(BtfType::FuncProto(FuncProto::new(params, int_type_id)));
|
|
|
|
let inc = btf.add_string("inc".to_string());
|
|
|
|
let inc = btf.add_string("inc");
|
|
|
|
let func_type_id = btf.add_type(BtfType::Func(Func::new(
|
|
|
|
let func_type_id = btf.add_type(BtfType::Func(Func::new(
|
|
|
|
inc,
|
|
|
|
inc,
|
|
|
|
func_proto_type_id,
|
|
|
|
func_proto_type_id,
|
|
|
@ -1420,7 +1422,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_fixup_func_proto() {
|
|
|
|
fn test_fixup_func_proto() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type = BtfType::Int(Int::new(name_offset, 4, IntEncoding::Signed, 0));
|
|
|
|
let int_type = BtfType::Int(Int::new(name_offset, 4, IntEncoding::Signed, 0));
|
|
|
|
let int_type_id = btf.add_type(int_type);
|
|
|
|
let int_type_id = btf.add_type(int_type);
|
|
|
|
|
|
|
|
|
|
|
@ -1459,7 +1461,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_sanitize_func_global() {
|
|
|
|
fn test_sanitize_func_global() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
@ -1469,17 +1471,17 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
|
|
let params = vec![
|
|
|
|
let params = vec![
|
|
|
|
BtfParam {
|
|
|
|
BtfParam {
|
|
|
|
name_offset: btf.add_string("a".to_string()),
|
|
|
|
name_offset: btf.add_string("a"),
|
|
|
|
btf_type: int_type_id,
|
|
|
|
btf_type: int_type_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
BtfParam {
|
|
|
|
BtfParam {
|
|
|
|
name_offset: btf.add_string("b".to_string()),
|
|
|
|
name_offset: btf.add_string("b"),
|
|
|
|
btf_type: int_type_id,
|
|
|
|
btf_type: int_type_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
];
|
|
|
|
let func_proto_type_id =
|
|
|
|
let func_proto_type_id =
|
|
|
|
btf.add_type(BtfType::FuncProto(FuncProto::new(params, int_type_id)));
|
|
|
|
btf.add_type(BtfType::FuncProto(FuncProto::new(params, int_type_id)));
|
|
|
|
let inc = btf.add_string("inc".to_string());
|
|
|
|
let inc = btf.add_string("inc");
|
|
|
|
let func_type_id = btf.add_type(BtfType::Func(Func::new(
|
|
|
|
let func_type_id = btf.add_type(BtfType::Func(Func::new(
|
|
|
|
inc,
|
|
|
|
inc,
|
|
|
|
func_proto_type_id,
|
|
|
|
func_proto_type_id,
|
|
|
@ -1508,7 +1510,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_sanitize_mem_builtins() {
|
|
|
|
fn test_sanitize_mem_builtins() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
@ -1518,11 +1520,11 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
|
|
let params = vec![
|
|
|
|
let params = vec![
|
|
|
|
BtfParam {
|
|
|
|
BtfParam {
|
|
|
|
name_offset: btf.add_string("a".to_string()),
|
|
|
|
name_offset: btf.add_string("a"),
|
|
|
|
btf_type: int_type_id,
|
|
|
|
btf_type: int_type_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
BtfParam {
|
|
|
|
BtfParam {
|
|
|
|
name_offset: btf.add_string("b".to_string()),
|
|
|
|
name_offset: btf.add_string("b"),
|
|
|
|
btf_type: int_type_id,
|
|
|
|
btf_type: int_type_id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
];
|
|
|
@ -1531,7 +1533,7 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
|
|
let builtins = ["memset", "memcpy", "memcmp", "memmove"];
|
|
|
|
let builtins = ["memset", "memcpy", "memcmp", "memmove"];
|
|
|
|
for fname in builtins {
|
|
|
|
for fname in builtins {
|
|
|
|
let func_name_offset = btf.add_string(fname.to_string());
|
|
|
|
let func_name_offset = btf.add_string(fname);
|
|
|
|
let func_type_id = btf.add_type(BtfType::Func(Func::new(
|
|
|
|
let func_type_id = btf.add_type(BtfType::Func(Func::new(
|
|
|
|
func_name_offset,
|
|
|
|
func_name_offset,
|
|
|
|
func_proto_type_id,
|
|
|
|
func_proto_type_id,
|
|
|
@ -1562,7 +1564,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_sanitize_float() {
|
|
|
|
fn test_sanitize_float() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("float".to_string());
|
|
|
|
let name_offset = btf.add_string("float");
|
|
|
|
let float_type_id = btf.add_type(BtfType::Float(Float::new(name_offset, 16)));
|
|
|
|
let float_type_id = btf.add_type(BtfType::Float(Float::new(name_offset, 16)));
|
|
|
|
|
|
|
|
|
|
|
|
let features = BtfFeatures {
|
|
|
|
let features = BtfFeatures {
|
|
|
@ -1586,7 +1588,7 @@ mod tests {
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_sanitize_decl_tag() {
|
|
|
|
fn test_sanitize_decl_tag() {
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let mut btf = Btf::new();
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
@ -1594,14 +1596,14 @@ mod tests {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
)));
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string("foo".to_string());
|
|
|
|
let name_offset = btf.add_string("foo");
|
|
|
|
let var_type_id = btf.add_type(BtfType::Var(Var::new(
|
|
|
|
let var_type_id = btf.add_type(BtfType::Var(Var::new(
|
|
|
|
name_offset,
|
|
|
|
name_offset,
|
|
|
|
int_type_id,
|
|
|
|
int_type_id,
|
|
|
|
VarLinkage::Static,
|
|
|
|
VarLinkage::Static,
|
|
|
|
)));
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string("decl_tag".to_string());
|
|
|
|
let name_offset = btf.add_string("decl_tag");
|
|
|
|
let decl_tag_type_id =
|
|
|
|
let decl_tag_type_id =
|
|
|
|
btf.add_type(BtfType::DeclTag(DeclTag::new(name_offset, var_type_id, -1)));
|
|
|
|
btf.add_type(BtfType::DeclTag(DeclTag::new(name_offset, var_type_id, -1)));
|
|
|
|
|
|
|
|
|
|
|
@ -1629,7 +1631,7 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(0, 4, IntEncoding::Signed, 0)));
|
|
|
|
let int_type_id = btf.add_type(BtfType::Int(Int::new(0, 4, IntEncoding::Signed, 0)));
|
|
|
|
|
|
|
|
|
|
|
|
let name_offset = btf.add_string("int".to_string());
|
|
|
|
let name_offset = btf.add_string("int");
|
|
|
|
let type_tag_type = btf.add_type(BtfType::TypeTag(TypeTag::new(name_offset, int_type_id)));
|
|
|
|
let type_tag_type = btf.add_type(BtfType::TypeTag(TypeTag::new(name_offset, int_type_id)));
|
|
|
|
btf.add_type(BtfType::Ptr(Ptr::new(0, type_tag_type)));
|
|
|
|
btf.add_type(BtfType::Ptr(Ptr::new(0, type_tag_type)));
|
|
|
|
|
|
|
|
|
|
|
|