Recover true signatures in pahole
Yonghong Song
reviewerPeople often trace kernel functions in order to get some insight in kernel from corresponding bpf progs. But if the kernel function signature has changed due to compiler optimization, users may be confused about why their prog won't work.
In LPC2025, Alan Maguire and myself presented some ideas about how to get true signature from llvm and gcc perspective ([1]). From llvm side, llvm can get functions true signatures and those updated functions will emit into dwarf with a special format. Unfortunately, upstream llvm and dwarf community does not like this format ([2]). So we decided to recover true signatures in pahole through parsing dwarf locations.
Alan did some initial work from gcc side in pahole ([3]). In gcc, func signature change will trigger func name change (e.g., from <foo> to <foo>.constprop.<n>). Alan's work is able to identify functions with dead arguments and these functions can be added to vmlinux BTF if the feature is enabled.
I did some initial hacking. The case for functions with dead arguments can be relatively easily handled in llvm side as well.
Currently, dwarf cannot know whether function return value is changed or not. Dwarf 6 standard seems solving this problem ([4]).
There are more complicated cases beyond simple dead arguments. For those cases, parsing dwarf location(s) is necessary. But dwarf location is really for debugger, so sometimes those locations could be really complicated. So we will try the following:
- Analyze locations to recover true signatures.
- In some cases, compiler may not generate dwarf locations if the argument transformation is too complicated. Or the location list is unnecessarily complex (gcc vs. clang). Such information can feed back to compiler folks and hopefully compiler can fix these issues.
- There are some dwarf differences between clang and gcc which impacts implementation. We will elaborate more.
- Need some mechanisms to relate the new argument with original argument so developers know what semantics changed for the argument. Maybe declaration tags?
Similar to recovering true signatures with location parsing, location parsing is also needed for those inlined functions ([5]). Furthermore, for llvm thinLTO mode, it is possible that inlined functions may have changed signature as well ([1]), although the chance is very low. For these inlined functions, we need a way to alert users about the potential signature change.
References:
[1] https://lpc.events/event/19/contributions/2169/
[2] https://lists.dwarfstd.org/pipermail/dwarf-discuss/2026-January/thread.html
[3] https://lore.kernel.org/bpf/[email protected]/
[4] https://dwarfstd.org/issues/221105.1.html
[5] https://lore.kernel.org/bpf/[email protected]/
Quoted 5 lines · Yonghong Song
People often trace kernel functions in order to get some insight in kernel from corresponding bpf progs. But if the kernel function signature has changed due to compiler optimization, users may be confused about why their prog won't work.
This is all good, but what is the status of recording inlined and partially inlined in BTF ?
I think it's a higher priority.
I'm talking about this patch set:
https://lore.kernel.org/bpf/[email protected]/
I think it should be finished first.
Quoted 7 lines · Alexei Starovoitov
Quoted 5 lines · Yonghong Song
People often trace kernel functions in order to get some insight in kernel from corresponding bpf progs. But if the kernel function signature has changed due to compiler optimization, users may be confused about why their prog won't work.
Quoted 6 lines
This is all good, but what is the status of recording inlined and partially inlined in BTF ?
I think it's a higher priority.
I'm talking about this patch set:
https://lore.kernel.org/bpf/[email protected]/
I think it should be finished first.
Right; that's the aim. That series however depends on the BTF kind layout work since we are introducing new kinds to support inline info; I'm hoping to get the next revision of the kind layout series out this week, I'm working on it now. That would clear the way for the inline work; I think we're reasonably agreed on the rough shape of the inline stuff so hopefully won't take too long to work through.
By the way, I was wondering if there's a way to get AI review bot feedback from a pre-submission to the kernel patches CI? Would be helpful in catching issues prior to submission, but maybe it's not feasible?
Alan
Quoted 16 lines · Alan Maguire
Quoted 7 lines · Alexei Starovoitov
Quoted 5 lines · Yonghong Song
People often trace kernel functions in order to get some insight in kernel from corresponding bpf progs. But if the kernel function signature has changed due to compiler optimization, users may be confused about why their prog won't work.
Quoted 6 lines
This is all good, but what is the status of recording inlined and partially inlined in BTF ?
I think it's a higher priority.
I'm talking about this patch set:
https://lore.kernel.org/bpf/[email protected]/
I think it should be finished first.
Quoted 5 lines
Right; that's the aim. That series however depends on the BTF kind layout work since we are introducing new kinds to support inline info; I'm hoping to get the next revision of the kind layout series out this week, I'm working on it now. That would clear the way for the inline work; I think we're reasonably agreed on the rough shape of the inline stuff so hopefully won't take too long to work through.
Sounds good. Let's land it asap.
Quoted 3 lines
By the way, I was wondering if there's a way to get AI review bot feedback from a pre-submission to the kernel patches CI? Would be helpful in catching issues prior to submission, but maybe it's not feasible?
I suggest installing Chris's prompts and do claude; /kreview on patches while you're still working on them.
It's more convenient and faster, since you get instant feedback. Sometimes I do it in parallel with a build/test run, since the bot is at your fingertips. make and /kreview are equivalent.