mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: irogers@google.com, acme@kernel.org, namhyung@kernel.org
Cc: adrian.hunter@intel.com, james.clark@linaro.org,
	jolsa@kernel.org,  linux-kernel@vger.kernel.org,
	linux-perf-users@vger.kernel.org,  mingo@redhat.com,
	peterz@infradead.org, tmricht@linux.ibm.com
Subject: [PATCH v4 0/3] perf srcline: Fix addr2line cache and fallback bugs
Date: Wed, 16 Sep 2026 22:04:47 -0700	[thread overview]
Message-ID: <20260917050450.703018-1-irogers@google.com> (raw)
In-Reply-To: <20260916234402.437113-1-irogers@google.com>

Three fixes to source line resolution, all on the addr2line paths.

1) libdw is pointed at the wrong file. dso__libdw_dwfl() opens the Dwfl
   with the name of the file the samples came from, but when the debug
   information is in a separate file, symbol loading records that as the
   dso's symsrc filename and the Dwfl is left referring to a file with
   no DWARF in it.

2) The dso addr2line cache is shared between implementations. The libbfd
   reader caches a struct a2l_data and the command line fallback caches
   a struct child_process through the same pointer, so once a dso has
   fallen back from one to the other the cached object is read back as
   the wrong type.

3) libbfd only reports success when the caller asked for a file name.
   addr2inlines() doesn't, so srcline.c treats a resolved address as a
   failure and tries the next implementation, which appends its own
   frames to the ones libbfd already appended. Every frame that isn't
   inlined is then reported twice. This is the default when perf is
   built with libbfd but without libdw:

     $ perf record --call-graph dwarf -- perf test -w inlineloop 1
     $ perf script --fields +srcline
     ...
                 56051a99503a inlineloop+0x8a (perf)
         inlineloop.c:47
                 56051a99503a inlineloop+0x8a (perf)
         inlineloop.c:47
     ...

   With addr2line.style set to "libbfd,addr2line" so the fallback is
   taken, the script output for that workload drops from 288 lines to
   176, and each repeated frame goes from appearing 16 times to 8.

Changes in v4:
 - Patch 1: add the headers that are used, rather than relying on glibc
   including them for us, since these files are rearranging their
   includes anyway: <unistd.h> in addr2line.c for write(), <stdio.h> in
   srcline.c for asprintf(), and <unistd.h> and <limits.h> in
   unwind-libunwind.c for close() and PATH_MAX. These are all
   pre-existing omissions that musl libc builds would trip over.
 - Patch 2: drop the duplicate "dso.h" that the include reordering left
   behind in the alphabetical block of dso.c, as it is already included
   at the top of the file.

Changes in v3:
 - Patch 1: re-read dso__symsrc_filename() under dso__lock() in
   libbfd__addr2line() and cmd__addr2line() before initializing the
   addr2line cache. In v2, __get_srcline() fetched dso_name before the
   lock was acquired, leaving a TOCTOU window where another thread
   calling dso__set_symsrc_filename() could invalidate the cache and
   cause the new cache to be initialized with the stale dso_name.

Changes in v2:
 - Add patch 3, so that a resolved address isn't retried by the next
   addr2line implementation and reported twice.
 - Patch 1: rewrite the commit message to describe the wrong file the
   Dwfl is opened with, which is the actual bug, rather than the cache
   teardown that follows from it, and add the Fixes tag.
 - Rebase onto perf-tools-next.

This series is independent of "perf build: Fix builds with clang and
BUILD_NONDISTRO" posted earlier and applies with or without it.

Testing:

 - "perf test addr2line" and the hists tests pass.
 - Builds in 13 configurations, including BUILD_NONDISTRO=1 where the
   libbfd reader is actually compiled, and with clang and gcc.
 - Every patch builds on its own, so the series stays bisectable.

Ian Rogers (3):
  perf libdw: Fix Dwfl discovery with split files
  perf dso: Separate libbfd and cmd addr2line caches to fix confusion
  perf libbfd: Report success when an address is found

 .../arch/powerpc/util/skip-callchain-idx.c    |  4 +-
 tools/perf/util/addr2line.c                   | 42 +++++++++---
 tools/perf/util/dso.c                         | 57 +++++++++++------
 tools/perf/util/dso.h                         | 26 ++++++--
 tools/perf/util/libbfd.c                      | 53 ++++++++++-----
 tools/perf/util/libdw.c                       | 39 +++++++----
 tools/perf/util/srcline.c                     | 64 +++++++++++++------
 tools/perf/util/unwind-libdw.c                |  2 +
 tools/perf/util/unwind-libunwind.c            | 64 ++++++++++++++-----
 9 files changed, 253 insertions(+), 98 deletions(-)


base-commit: 91b0782fc9e9d2f0a40b5256146e014802fdbb36
prerequisite-patch-id: b6fdc526887b71fb66f5fe0c0d41f7ef9493861e
prerequisite-patch-id: d47077f674c700f4f6296e9367f7ddfe004aea89
prerequisite-patch-id: ed0db23450840601762fe85ca1bef06ce6d28fe7
prerequisite-patch-id: d84e6b96d533ee6ed549e26e94216e2da60f7f74
prerequisite-patch-id: 6e8f19551d771621a5037096626cfe7e271b36f9
prerequisite-patch-id: 3768dfd588c7439deb741bce44c74763011c6be7
prerequisite-patch-id: babac99a4faa3b1525e44d3f34ab33a88103334c
prerequisite-patch-id: 5279827453fea1536abc620aa33c887c44e41ee9
prerequisite-patch-id: bdc0d648a577142b9270fb59b54496bc2bf8d5ea
-- 
2.55.0.1082.g2b9226bbc0-goog


  parent reply	other threads:[~2026-09-17  5:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 17:07 [PATCH v1 1/2] perf libdw: Fix Dwfl discovery with split files Ian Rogers
2026-09-14 17:07 ` [PATCH v1 2/2] perf dso: Separate libbfd and cmd addr2line caches to fix confusion Ian Rogers
2026-09-16  6:35 ` [PATCH v2 0/3] perf srcline: Fix addr2line cache and fallback bugs Ian Rogers
2026-09-16  6:35   ` [PATCH v2 1/3] perf libdw: Fix Dwfl discovery with split files Ian Rogers
2026-09-16  6:35   ` [PATCH v2 2/3] perf dso: Separate libbfd and cmd addr2line caches to fix confusion Ian Rogers
2026-09-16  6:35   ` [PATCH v2 3/3] perf libbfd: Report success when an address is found Ian Rogers
2026-09-16 23:43   ` [PATCH v3 0/3] perf srcline: Fix addr2line cache and fallback bugs Ian Rogers
2026-09-16 23:44     ` [PATCH v3 1/3] perf libdw: Fix Dwfl discovery with split files Ian Rogers
2026-09-16 23:44     ` [PATCH v3 2/3] perf dso: Separate libbfd and cmd addr2line caches to fix confusion Ian Rogers
2026-09-16 23:44     ` [PATCH v3 3/3] perf libbfd: Report success when an address is found Ian Rogers
2026-09-17  5:04     ` Ian Rogers [this message]
2026-09-17  5:04       ` [PATCH v4 1/3] perf libdw: Fix Dwfl discovery with split files Ian Rogers
2026-09-17  5:04       ` [PATCH v4 2/3] perf dso: Separate libbfd and cmd addr2line caches to fix confusion Ian Rogers
2026-09-17  5:04       ` [PATCH v4 3/3] perf libbfd: Report success when an address is found Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260917050450.703018-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tmricht@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®