public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH dwarves 0/3] pahole: Replace or add functions with true signatures in btf
@ 2025-11-11 17:04 Yonghong Song
  2025-11-11 17:04 ` [PATCH dwarves 1/3] btf_encoder: Refactor elf_functions__new() with struct btf_encoder as argument Yonghong Song
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Yonghong Song @ 2025-11-11 17:04 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 uattr__coerce1) { ... }
  
In the above, uattr__coerce1 corresponds to 'is_kernel' field in sockptr_t.
Here, the suffix '__coerce1' refers to the second 64bit value in
sockptr_t. The first 64bit value will be '__coerce0' if that value
is used instead.

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/2 are refactor patches. Patch 3 has the detailed explanation
in commit message and implements the logic to encode replaced or new
signatures to vmlinux BTF. Please see Patch 3 for details.

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

Yonghong Song (3):
  btf_encoder: Refactor elf_functions__new() with struct btf_encoder as
    argument
  bpf_encoder: Refactor a helper elf_function__check_and_push_sym()
  pahole: Replace or add functions with true signatures in btf

 btf_encoder.c  | 79 +++++++++++++++++++++++++++++++++++---------
 dwarf_loader.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++
 dwarves.h      |  4 +++
 pahole.c       |  9 +++++
 4 files changed, 165 insertions(+), 16 deletions(-)

-- 
2.47.3


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

end of thread, other threads:[~2025-11-14 20:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-11 17:04 [PATCH dwarves 0/3] pahole: Replace or add functions with true signatures in btf Yonghong Song
2025-11-11 17:04 ` [PATCH dwarves 1/3] btf_encoder: Refactor elf_functions__new() with struct btf_encoder as argument Yonghong Song
2025-11-11 17:04 ` [PATCH dwarves 2/3] bpf_encoder: Refactor a helper elf_function__check_and_push_sym() Yonghong Song
2025-11-11 17:04 ` [PATCH dwarves 3/3] pahole: Replace or add functions with true signatures in btf Yonghong Song
2025-11-13 16:45 ` [PATCH dwarves 0/3] " Alan Maguire
2025-11-13 17:36   ` Alexei Starovoitov
2025-11-14 15:57     ` Alan Maguire
2025-11-14 20:11       ` Alexei Starovoitov

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