Fwd: Inaccurate unwinding/symbol resolution in `perf report/script`?

From: Tabby

Date: Thu Nov 26 2026 - 13:29:50 EST


Hi,

While using perf for userspace time-based profiling
(speedscope/Firefox Profiler stack charts), I noticed an issue where
`perf record -g` traces have incorrectly reconstructed stack traces
when I run `perf script` and import the profiling trace into a
time-axis viewer.

For instance, when I run `perf record -e sched:sched_switch -e
cycles/freq=99/ -g htop`, I get extra and missing stack frames when
viewing the trace with `perf script` or `perf report`. Interestingly
the perf.data file *does* have enough information to reconstruct
proper call stacks, and `samply import` performs this but `perf
report/script` does not.

## Debugging

I initially suspected that perf failed to query all necessary debug
info. Running `DEBUGINFOD_VERBOSE=1 perf script` shows that perf is
querying debuginfod for every build ID found in `perf buildid-list`,
but still outputs inaccurate frames from `-g/--call-graph fp` stacks.
I do not know if perf can't find downloaded debug info, can't find
on-disk binaries, or has an algorithmic deficiency.

I took a look at the call stack captured by `sched:sched_switch`,
where htop blocks on user input within wgetch.

- `perf script` reports the blocking call stack as `_start >
__libc_start_main > call_init > unknown > CommandLine_run >
Platform_done > LibSensors_cleanup > ScreenManager_run > wgetch >
[unknown] > __poll > syscall_cancel > internal_syscall_cancel.` This
has both missing and incorrect stack frames; notably in the source
code, `CommandLine_run()` directly calls `ScreenManager_run()` without
the intermediate frames.

- If I run `perf report` and view the call chain from `_start`, it
reports the extraneous stack frames as `Platform_done (inlined)` and
`LibSensors_cleanup (inlined)`. Expanding further, it reports that
`wgetch` calls an unbranched chain of `0x7ffb69c4ada2 > __poll >
syscall_cancel (inlined) > internal_syscall_cancel (inlined)`. Here it
fails to resolve wgetch's function calls (whereas gdb and `layout src`
reports that wgetch calls _nc_wgetch > check_mouse_activity >
_nc_timed_wait > poll`.

- If I run `samply import perf.data` on the same capture, and load the
trace in Firefox Profiler, I see `start > _libc_start_main_impl >
_libc_start_call_main > CommandLine_run > ScreenManager_run > wgetch >
nc_wgetch > check_mouse_activity > _GI___poll > syscall_cancel >
internal_syscall_cancel`. This shows that `samply import` and the
Firefox Profiler it spawns knows to omit the false frames between
CommandLine_run and ScreenManager_run, and properly resolves the
frames between wgetch and ...poll... This call stack is also
comparable to what gdb reports.

- - Unfortunately samply is not a full replacement as-is, because it
only includes the first `-e` (I've reported to Samply and not heard
back yet) and doesn't symbolize in-kernel stack frames.

Is there an explanation or possible solution for this issue?

Kernel: 7.3.5-arch1-1 (64-bit)

## Prior art

It does seem that perf unwinding is a subject in flux.
https://lore.kernel.org/linux-perf-users/CAP-5=fWkUW787c4dGx9rccucqD67dfRgwBB_SoCxFnfZXtXP-w@xxxxxxxxxxxxxx/T/#t
indicates that in-kernel DWARF unwinding is being proposed, but it
presumably will not be ready for some months.