[PATCH 04/34] perf libdw: Don't look up the module by ELF address

From: James Clark

Date: Wed Nov 18 2026 - 11:30:06 EST


libdw__addr2line() finds the module with dwfl_addrmodule() using the ELF
address. However, libdw reports modules loaded from disk at a fixed bias
of 0x10000, so any ELF address below that isn't considered to be in the
module. This means that source lines for very small binaries and JIT
files can't be found by libdw.

This used to be hidden by falling back to the next addr2line style, but
now missing information stops the fallback since commit (62d7cdc8d587
"perf libdw: Optimize fallback logic for missing DWARF"). So perf script
fails to show source line for these addresses.

Perf creates a separate Dwfl session for each DSO and only loads that
DSO's file into it, so take the session's only module instead of looking
it up by address to fix the issue.

Fixes: 88c51002d06f ("perf addr2line: Add a libdw implementation")
Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
---
tools/perf/util/libdw.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/libdw.c b/tools/perf/util/libdw.c
index 90767361f485..4f472ff9f1bf 100644
--- a/tools/perf/util/libdw.c
+++ b/tools/perf/util/libdw.c
@@ -164,6 +164,14 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args)
return DWARF_CB_ABORT;
}

+static int libdw__get_module(Dwfl_Module *mod, void **userdata __maybe_unused,
+ const char *name __maybe_unused,
+ Dwarf_Addr base __maybe_unused, void *arg)
+{
+ *(Dwfl_Module **)arg = mod;
+ return DWARF_CB_ABORT;
+}
+
int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr,
struct dso *dso, bool unwind_inlines,
struct inline_node *node, struct symbol *sym)
@@ -188,7 +196,13 @@ int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr,
goto out;
}

- mod = dwfl_addrmodule(dwfl, addr);
+ /*
+ * The session only contains this DSO, but libdw places offline modules
+ * away from address 0. Take the module directly rather than looking it
+ * up by an ELF address, which isn't a module address.
+ */
+ mod = NULL;
+ dwfl_getmodules(dwfl, libdw__get_module, &mod, 0);
if (!mod) {
ret = 0;
goto out;

--
2.43.0