* [PATCH] perf dwarf-aux: Check .eh_frame section for CFA
@ 2026-10-02 22:42 Namhyung Kim
2026-10-03 1:34 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Namhyung Kim @ 2026-10-02 22:42 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark, Peter Zijlstra,
Ingo Molnar, LKML, linux-perf-users, Masami Hiramatsu
The die_get_cfa() only calls dwarf_getcfi() which handles .debug_frame
section. But most binaries have .eh_frame instead so it would fail.
Let's call dwarf_getcfi_elf() first to try .eh_frame section and then
fallback to .debug_frame.
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/dwarf-aux.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index 54f8b5ec74a2fe70..af3913e661fce79e 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -1886,9 +1886,14 @@ int die_get_cfa(Dwarf *dwarf, u64 pc, int *preg, int *poffset)
Dwarf_Op *ops = NULL;
size_t nops;
- cfi = dwarf_getcfi(dwarf);
- if (cfi == NULL)
- return -1;
+ /* try to get .eh_frame section */
+ cfi = dwarf_getcfi_elf(dwarf_getelf(dwarf));
+ if (cfi == NULL) {
+ /* and then try .debug_frame section */
+ cfi = dwarf_getcfi(dwarf);
+ if (cfi == NULL)
+ return -1;
+ }
if (!dwarf_cfi_addrframe(cfi, pc, &frame) &&
!dwarf_frame_cfa(frame, &ops, &nops) &&
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] perf dwarf-aux: Check .eh_frame section for CFA
2026-10-02 22:42 [PATCH] perf dwarf-aux: Check .eh_frame section for CFA Namhyung Kim
@ 2026-10-03 1:34 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-10-03 1:34 UTC (permalink / raw)
To: Namhyung Kim; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] perf: memory leak of Dwarf_CFI handle in die_get_cfa()
- [Medium] perf: severe performance degradation from repeatedly parsing .eh_frame
--
commit 63cd38e63157cedd873e0aa6adbf63746489d27e
Author: Namhyung Kim <namhyung@kernel.org>
perf dwarf-aux: Check .eh_frame section for CFA
This commit modifies die_get_cfa() to first attempt to retrieve the
.eh_frame section using dwarf_getcfi_elf() before falling back to the
.debug_frame section.
[Severity: Medium]
Does this code leak the dynamically allocated Dwarf_CFI object?
In tools/perf/util/dwarf-aux.c within die_get_cfa(), dwarf_getcfi_elf() is
called to get the .eh_frame section. Unlike dwarf_getcfi(), which returns a
structure owned by the Dwarf context, dwarf_getcfi_elf() allocates a new
Dwarf_CFI object that the caller must free using dwarf_cfi_end().
However, die_get_cfa() returns without freeing the cfi pointer on both the
success path and the error path. Since this function is called repeatedly
during data annotation, could this lead to rapid memory consumption?
[Severity: Medium]
Is there a risk of severe performance degradation here?
Calling dwarf_getcfi_elf() reads and parses the .eh_frame section to
dynamically build a search index for the module. Because die_get_cfa() is a
heavily utilized helper function often called repeatedly, rebuilding this
index and allocating the structures from scratch on every single invocation
could cause massive CPU overhead.
Would it be possible to cache the .eh_frame Dwarf_CFI object to avoid
rebuilding it on every call?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261002224242.396135-1-namhyung@kernel.org?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-03 1:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-02 22:42 [PATCH] perf dwarf-aux: Check .eh_frame section for CFA Namhyung Kim
2026-10-03 1:34 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox