BPF List
 help / color / mirror / Atom feed
* Question: fentry on kernel func optimized by compiler
@ 2025-03-27 16:03 Tao Chen
  2025-03-27 17:19 ` Song Liu
  2025-03-28 17:21 ` Andrii Nakryiko
  0 siblings, 2 replies; 9+ messages in thread
From: Tao Chen @ 2025-03-27 16:03 UTC (permalink / raw)
  To: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, Jiri Olsa,
	Song Liu, Yonghong Song
  Cc: bpf

Hi,

I recently encountered a problem when using fentry to trace kernel 
functions optimized by compiler, the specific situation is as follows:
https://github.com/bpftrace/bpftrace/issues/3940

Simply put, some functions have been optimized by the compiler. The 
original function names are found through BTF, but the optimized 
functions are the ones that exist in kallsyms_lookup_name. Therefore, 
the two do not match.

         func_proto = btf_type_by_id(desc_btf, func->type);
         if (!func_proto || !btf_type_is_func_proto(func_proto)) {
                 verbose(env, "kernel function btf_id %u does not have a 
valid func_proto\n",
                         func_id);
                 return -EINVAL;
         }

         func_name = btf_name_by_offset(desc_btf, func->name_off);
         addr = kallsyms_lookup_name(func_name);
         if (!addr) {
                 verbose(env, "cannot find address for kernel function 
%s\n",
                         func_name);
                 return -EINVAL;
         }

I have made a simple statistics and there are approximately more than 
2,000 functions in Ubuntu 24.04.

dylane@2404:~$ cat /proc/kallsyms | grep isra | wc -l
2324

So can we add a judgment from libbpf. If it is an optimized function, 
pass the suffix of the optimized function from the user space to the 
kernel, and then perform a function name concatenation, like:

         func_name = btf_name_by_offset(desc_btf, func->name_off);
	if (optimize) {
		func_name = func_name + ".isra.0"
	}
         addr = kallsyms_lookup_name(func_name);

-- 
Best Regards
Tao Chen


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-04-17 12:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-27 16:03 Question: fentry on kernel func optimized by compiler Tao Chen
2025-03-27 17:19 ` Song Liu
2025-03-28 15:19   ` Tao Chen
2025-03-28 17:21 ` Andrii Nakryiko
2025-03-31  9:54   ` Tao Chen
2025-03-31 10:13   ` Alan Maguire
2025-04-15 12:10     ` Tao Chen
2025-04-15 19:21       ` Jiri Olsa
2025-04-17 12:55         ` Tao Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox