linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: "Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
	"Jiri Olsa" <jolsa@kernel.org>, "Ian Rogers" <irogers@google.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"Suzuki K Poulose" <suzuki.poulose@arm.com>,
	"Mike Leach" <mike.leach@linaro.org>,
	"James Clark" <james.clark@linaro.org>,
	"John Garry" <john.g.garry@oracle.com>,
	"Will Deacon" <will@kernel.org>, "Leo Yan" <leo.yan@linux.dev>,
	"Athira Rajeev" <atrajeev@linux.ibm.com>,
	tanze <tanze@kylinos.cn>,
	"Aditya Bodkhe" <aditya.b1@linux.ibm.com>,
	"Stephen Brennan" <stephen.s.brennan@oracle.com>,
	"Andi Kleen" <ak@linux.intel.com>,
	"Chun-Tse Shao" <ctshao@google.com>,
	"Thomas Falcon" <thomas.falcon@intel.com>,
	"Dapeng Mi" <dapeng1.mi@linux.intel.com>,
	"Dr. David Alan Gilbert" <linux@treblig.org>,
	"Christophe Leroy" <christophe.leroy@csgroup.eu>,
	"Krzysztof Łopatowski" <krzysztof.m.lopatowski@gmail.com>,
	"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	"Alexandre Ghiti" <alexghiti@rivosinc.com>,
	"Haibo Xu" <haibo1.xu@intel.com>,
	"Sergei Trofimovich" <slyich@gmail.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v1 0/9] perf: Refactor/add fallbacks for reading build-id and debuglink
Date: Sat, 22 Nov 2025 18:32:16 -0800	[thread overview]
Message-ID: <20251123023225.8069-1-irogers@google.com> (raw)

This cleans up some tech debt mentioned in the thread:
https://lore.kernel.org/lkml/aQt66zhfxSA80xwt@gentoo.org/

The perf tool has fallbacks for objdump but not in the case of
build-id and debuglink reading. Refactor the code so that in the case
of read_build_id it now looks like:

```
int filename__read_build_id(const char *filename, struct build_id *bid, bool block)
{
        struct kmod_path m = { .name = NULL, };
        char path[PATH_MAX];
        int err, fd;

        if (!filename)
                return -EFAULT;

        err = kmod_path__parse(&m, filename);
        if (err)
                return -1;

        if (m.comp) {
                int error = 0;

                fd = filename__decompress(filename, path, sizeof(path), m.comp, &error);
                if (fd < 0) {
                        pr_debug("Failed to decompress (error %d) %s\n",
                                 error, filename);
                        return -1;
                }
                lseek(fd, 0, SEEK_SET);
                filename = path;
                block = true;
        } else {
                fd = open(filename, block ? O_RDONLY : (O_RDONLY | O_NONBLOCK));
                if (fd < 0) {
                        pr_debug("Failed to open %s\n", filename);
                        return -1;
                }
        }

        err = libbfd__read_build_id(fd, filename, bid);
        if (err == 0)
                goto out;

        err = libelf__read_build_id(fd, filename, bid);
        if (err == 0)
                goto out;

        err = sym_min__read_build_id(fd, filename, bid);
...
```

That is what was previously symbol-elf decompression code is now made
common for all cases of reading. The handling of the block argument is
now common. There is a clear fallback from libbfd to libelf to the
symbol-minimal (sym_min) versions of the functions.

To support this there is refactoring of code into a perf-libelf.c
file, to follow patterns established for the capstone, LLVM and libbfd
code.

These changes conflict with James' removal of the block argument:
https://lore.kernel.org/lkml/20251121-james-perf-non-block-v1-1-6ab2702ab573@linaro.org/
I think we should do that change. It would be easy to apply that
change on these changes as rather than updating 3 functions, only 1
function needs updating.

Ian Rogers (9):
  perf symbol: Reduce scope of elf__needs_adjust_symbols
  perf symbol: Reduce scope of arch__sym_update
  perf symbol: Move libelf code to its own file/header
  perf symbol: Remove unused includes
  perf symbol: Move dso__load_bfd_symbols out of symbol.h
  perf symbol: Use fallbacks with filename__read_build_id
  perf symbol: Use fallbacks for filename__read_debuglink
  perf symbol: Use fallbacks for sysfs__read_build_id
  perf dso: Move type helpers out of symbol and use fallbacks

 tools/perf/arch/powerpc/util/sym-handling.c   |   7 -
 tools/perf/builtin-annotate.c                 |  47 +--
 tools/perf/builtin-c2c.c                      |  58 +--
 tools/perf/builtin-diff.c                     |  22 +-
 tools/perf/builtin-inject.c                   |  19 +-
 tools/perf/builtin-kmem.c                     |  41 ++-
 tools/perf/builtin-kwork.c                    |   9 +-
 tools/perf/builtin-mem.c                      |  16 +-
 tools/perf/builtin-report.c                   |  76 ++--
 tools/perf/builtin-sched.c                    |  50 ++-
 tools/perf/builtin-script.c                   |  89 ++---
 tools/perf/builtin-timechart.c                |  34 +-
 tools/perf/builtin-top.c                      |  85 +++--
 tools/perf/builtin-trace.c                    |  82 ++---
 .../scripts/python/Perf-Trace-Util/Context.c  |  11 +-
 tools/perf/tests/code-reading.c               |   1 +
 tools/perf/tests/hists_cumulate.c             |   1 +
 tools/perf/tests/hists_filter.c               |   1 +
 tools/perf/tests/hists_link.c                 |   1 +
 tools/perf/tests/hists_output.c               |   1 +
 tools/perf/tests/mmap-thread-lookup.c         |   1 +
 tools/perf/tests/pe-file-parsing.c            |   5 +-
 tools/perf/util/Build                         |   6 +-
 tools/perf/util/annotate-data.c               |   7 +-
 tools/perf/util/auxtrace.h                    |   1 +
 tools/perf/util/block-info.c                  |  11 +-
 tools/perf/util/build-id.c                    |  28 +-
 tools/perf/util/callchain.c                   |   1 +
 tools/perf/util/cs-etm.c                      |   1 +
 tools/perf/util/data-convert-json.c           |  30 +-
 tools/perf/util/db-export.c                   |  16 +-
 tools/perf/util/dlfilter.c                    |  11 +-
 tools/perf/util/dlfilter.h                    |   1 +
 tools/perf/util/dso.c                         |  57 +--
 tools/perf/util/event.c                       |  41 ++-
 tools/perf/util/evsel_fprintf.c               |  14 +-
 tools/perf/util/hist.c                        |  29 +-
 tools/perf/util/intel-pt.c                    |  35 +-
 tools/perf/util/kvm-stat.h                    |   5 +-
 tools/perf/util/libbfd.c                      |   4 +-
 tools/perf/util/libbfd.h                      |  15 +-
 tools/perf/util/machine.c                     |  34 +-
 tools/perf/util/perf-libelf.c                 | 286 +++++++++++++++
 tools/perf/util/perf-libelf.h                 |  65 ++++
 tools/perf/util/print_insn.c                  |  14 +-
 tools/perf/util/probe-event.c                 |   1 +
 tools/perf/util/probe-finder.c                |   1 +
 .../util/scripting-engines/trace-event-perl.c |   1 +
 .../scripting-engines/trace-event-python.c    |   1 +
 tools/perf/util/symbol-elf.c                  | 337 +-----------------
 tools/perf/util/symbol-minimal.c              |  95 +++--
 tools/perf/util/symbol-minimal.h              |  13 +
 tools/perf/util/symbol.c                      | 108 +++++-
 tools/perf/util/symbol.h                      |  44 +--
 tools/perf/util/symbol_fprintf.c              |   1 +
 tools/perf/util/thread-stack.c                |  12 +-
 tools/perf/util/thread.c                      |  18 +-
 tools/perf/util/unwind-libdw.c                |  15 +-
 58 files changed, 1085 insertions(+), 931 deletions(-)
 create mode 100644 tools/perf/util/perf-libelf.c
 create mode 100644 tools/perf/util/perf-libelf.h
 create mode 100644 tools/perf/util/symbol-minimal.h

-- 
2.52.0.rc2.455.g230fcf2819-goog


             reply	other threads:[~2025-11-23  2:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-23  2:32 Ian Rogers [this message]
2025-11-23  2:32 ` [PATCH v1 1/9] perf symbol: Reduce scope of elf__needs_adjust_symbols Ian Rogers
2025-11-23  2:32 ` [PATCH v1 2/9] perf symbol: Reduce scope of arch__sym_update Ian Rogers
2025-11-23  2:32 ` [PATCH v1 3/9] perf symbol: Move libelf code to its own file/header Ian Rogers
2025-11-23  2:32 ` [PATCH v1 4/9] perf symbol: Remove unused includes Ian Rogers
2025-11-23  2:32 ` [PATCH v1 5/9] perf symbol: Move dso__load_bfd_symbols out of symbol.h Ian Rogers
2025-11-23  2:32 ` [PATCH v1 6/9] perf symbol: Use fallbacks with filename__read_build_id Ian Rogers
2025-11-23  2:32 ` [PATCH v1 7/9] perf symbol: Use fallbacks for filename__read_debuglink Ian Rogers
2025-11-23  2:32 ` [PATCH v1 8/9] perf symbol: Use fallbacks for sysfs__read_build_id Ian Rogers
2025-11-23  2:32 ` [PATCH v1 9/9] perf dso: Move type helpers out of symbol and use fallbacks 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=20251123023225.8069-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=aditya.b1@linux.ibm.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexghiti@rivosinc.com \
    --cc=atrajeev@linux.ibm.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=ctshao@google.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=haibo1.xu@intel.com \
    --cc=james.clark@linaro.org \
    --cc=john.g.garry@oracle.com \
    --cc=jolsa@kernel.org \
    --cc=krzysztof.m.lopatowski@gmail.com \
    --cc=leo.yan@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux@treblig.org \
    --cc=mhiramat@kernel.org \
    --cc=mike.leach@linaro.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=slyich@gmail.com \
    --cc=stephen.s.brennan@oracle.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tanze@kylinos.cn \
    --cc=thomas.falcon@intel.com \
    --cc=will@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).