bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH dwarves v2 0/2] pahole: Replace or add functions with true signatures in btf
@ 2025-11-30  4:03 Yonghong Song
  2025-11-30  4:03 ` [PATCH dwarves v2 1/2] btf_encoder: Refactor elf_functions__new() with struct btf_encoder as argument Yonghong Song
  2025-11-30  4:03 ` [PATCH dwarves v2 2/2] pahole: Replace or add functions with true signatures in btf Yonghong Song
  0 siblings, 2 replies; 5+ messages in thread
From: Yonghong Song @ 2025-11-30  4:03 UTC (permalink / raw)
  To: Alan Maguire, Arnaldo Carvalho de Melo, dwarves
  Cc: Alexei Starovoitov, Andrii Nakryiko, bpf, David Faust,
	Jose E . Marchesi, kernel-team

Current vmlinux BTF encoding is based on the source level signatures.
But the compiler may do some optimization and changed the signature.
If the user tried with source level signature, their initial implementation
may have wrong results and then the user need to check what is the
problem and work around it, e.g. through kprobe since kprobe does not
need vmlinux BTF.

The following is a concrete example for [1].
The original source signature:
  typedef struct {
        union {
                void            *kernel;
                void __user     *user;
        };
        bool            is_kernel : 1;
  } sockptr_t;
  typedef sockptr_t bpfptr_t;
  static int map_create(union bpf_attr *attr, bpfptr_t uattr) { ... }
After compiler optimization, the signature becomes:
  static int map_create(union bpf_attr *attr, bool is_kernel) { ... }

To do proper tracing, it would be good for the users to know the
changed signature. With the actual signature, both kprobe and fentry
should work as usual. This can avoid user surprise and improve
developer productivity.

The llvm compiler patch [1] collects true signature and encoded those
functions in dwarf. pahole will process these functions and
replace old signtures with true signatures. Additionally,
new functions (e.g., foo.llvm.<hash>) can be encoded in
vmlinux BTF as well.

Patches 1 is a refactor change. Patch 2 has the detailed explanation
in commit message and implements the logic to encode replaced or new
signatures to vmlinux BTF. Please see Patch 2 for details.

  [1] https://github.com/llvm/llvm-project/pull/165310

Changelogs:
  v1 -> v2:
   - v1: https://lore.kernel.org/bpf/20251111170424.286892-1-yonghong.song@linux.dev/
   - For functions like <foo>.llvm.<hash>() where the function <foo> is promoted
     to <foo>.llvm.<hash>(). Previous llvm ([1]) allows to have new-signature dwarf
     entries for both <foo> and <foo>.llvm.<hash> and pahole will generate two
     new functions. Now, llvm will only generate one entry with name <foo>.llvm.<hash>
     so pahole will generate one entry for <foo>.llvm.<hash>.
   - Since v2 approach intends to generate functions with name in kallsyms,
     removing function suffix is avoided.

Yonghong Song (2):
  btf_encoder: Refactor elf_functions__new() with struct btf_encoder as
    argument
  pahole: Replace or add functions with true signatures in btf

 btf_encoder.c  | 52 +++++++++++++++++++++++++-------
 dwarf_loader.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 dwarves.h      |  4 +++
 pahole.c       |  9 ++++++
 4 files changed, 136 insertions(+), 10 deletions(-)

-- 
2.47.3


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

end of thread, other threads:[~2025-12-09 12:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-30  4:03 [PATCH dwarves v2 0/2] pahole: Replace or add functions with true signatures in btf Yonghong Song
2025-11-30  4:03 ` [PATCH dwarves v2 1/2] btf_encoder: Refactor elf_functions__new() with struct btf_encoder as argument Yonghong Song
2025-11-30  4:03 ` [PATCH dwarves v2 2/2] pahole: Replace or add functions with true signatures in btf Yonghong Song
2025-12-08 16:22   ` Alan Maguire
2025-12-09 12:05     ` Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).