aya: Fix (func|line)_info multiple progs in section

This commit fixes the (func|line)_info when we have multiple programs in
the same section. The integration test reloc.bpf.c serves as our test
case here. This required filtering down the (func|line)_info to only
that in scope of the current symbol + then adjusting the offets to
appease the kernel.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
reviewable/pr721/r1
Dave Tucker 2 years ago
parent cca9b8f1a7
commit 64d6e3e3b6

@ -614,10 +614,26 @@ impl Object {
name: String, name: String,
symbol: &Symbol, symbol: &Symbol,
) -> Result<(Program, Function), ParseError> { ) -> Result<(Program, Function), ParseError> {
let offset = symbol.address as usize - section.address as usize;
let (func_info, line_info, func_info_rec_size, line_info_rec_size) = let (func_info, line_info, func_info_rec_size, line_info_rec_size) =
if let Some(btf_ext) = &self.btf_ext { if let Some(btf_ext) = &self.btf_ext {
let func_info = btf_ext.func_info.get(section.name); let bytes_offset = offset as u32 / INS_SIZE as u32;
let line_info = btf_ext.line_info.get(section.name); let section_size_bytes = symbol.size as u32 / INS_SIZE as u32;
let mut func_info = btf_ext.func_info.get(section.name);
func_info.func_info.retain(|f| f.insn_off == bytes_offset);
func_info.func_info.iter_mut().for_each(|f| {
f.insn_off -= bytes_offset;
});
let mut line_info = btf_ext.line_info.get(section.name);
line_info.line_info.retain(|l| {
l.insn_off >= bytes_offset && l.insn_off < (bytes_offset + section_size_bytes)
});
line_info.line_info.iter_mut().for_each(|f| {
f.insn_off -= bytes_offset;
});
( (
func_info, func_info,
line_info, line_info,

@ -29,9 +29,7 @@ __attribute__((noinline)) int field_global() {
return set_output(__builtin_preserve_access_index(s.b)); return set_output(__builtin_preserve_access_index(s.b));
} }
SEC("uprobe/field") int field(void *ctx) { SEC("uprobe") int field(void *ctx) { return field_global(); }
return field_global();
}
struct relocated_struct_with_pointer { struct relocated_struct_with_pointer {
struct relocated_struct_with_pointer *first; struct relocated_struct_with_pointer *first;
@ -46,9 +44,7 @@ __attribute__((noinline)) int pointer_global() {
return set_output((__u64)__builtin_preserve_access_index(s.first)); return set_output((__u64)__builtin_preserve_access_index(s.first));
} }
SEC("uprobe/pointer") int pointer(void *ctx) { SEC("uprobe") int pointer(void *ctx) { return pointer_global(); }
return pointer_global();
}
__attribute__((noinline)) int struct_flavors_global() { __attribute__((noinline)) int struct_flavors_global() {
struct relocated_struct_with_scalars s = {1, 2, 3}; struct relocated_struct_with_scalars s = {1, 2, 3};
@ -59,9 +55,7 @@ __attribute__((noinline)) int struct_flavors_global() {
} }
} }
SEC("uprobe/struct_flavors") int struct_flavors(void *ctx) { SEC("uprobe") int struct_flavors(void *ctx) { return struct_flavors_global(); }
return struct_flavors_global();
}
enum relocated_enum_unsigned_32 { U32 = 0xAAAAAAAA }; enum relocated_enum_unsigned_32 { U32 = 0xAAAAAAAA };
@ -69,8 +63,7 @@ __attribute__((noinline)) int enum_unsigned_32_global() {
return set_output(bpf_core_enum_value(enum relocated_enum_unsigned_32, U32)); return set_output(bpf_core_enum_value(enum relocated_enum_unsigned_32, U32));
} }
SEC("uprobe/enum_unsigned_32") SEC("uprobe") int enum_unsigned_32(void *ctx) {
int enum_unsigned_32(void *ctx) {
return enum_unsigned_32_global(); return enum_unsigned_32_global();
} }
@ -80,9 +73,7 @@ __attribute__((noinline)) int enum_signed_32_global() {
return set_output(bpf_core_enum_value(enum relocated_enum_signed_32, S32)); return set_output(bpf_core_enum_value(enum relocated_enum_signed_32, S32));
} }
SEC("uprobe/enum_signed_32") int enum_signed_32(void *ctx) { SEC("uprobe") int enum_signed_32(void *ctx) { return enum_signed_32_global(); }
return enum_signed_32_global();
}
enum relocated_enum_unsigned_64 { U64 = 0xAAAAAAAABBBBBBBB }; enum relocated_enum_unsigned_64 { U64 = 0xAAAAAAAABBBBBBBB };
@ -90,8 +81,7 @@ __attribute__((noinline)) int enum_unsigned_64_global() {
return set_output(bpf_core_enum_value(enum relocated_enum_unsigned_64, U64)); return set_output(bpf_core_enum_value(enum relocated_enum_unsigned_64, U64));
} }
SEC("uprobe/enum_unsigned_64") SEC("uprobe") int enum_unsigned_64(void *ctx) {
int enum_unsigned_64(void *ctx) {
return enum_unsigned_64_global(); return enum_unsigned_64_global();
} }
@ -101,6 +91,4 @@ __attribute__((noinline)) int enum_signed_64_global() {
return set_output(bpf_core_enum_value(enum relocated_enum_signed_64, u64)); return set_output(bpf_core_enum_value(enum relocated_enum_signed_64, u64));
} }
SEC("uprobe/enum_signed_64") int enum_signed_64(void *ctx) { SEC("uprobe") int enum_signed_64(void *ctx) { return enum_signed_64_global(); }
return enum_signed_64_global();
}

Loading…
Cancel
Save