From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org
Subject: [PATCH v4 09/10] perf annotate: Simplify symbol__disassemble() with dso binary_type
Date: Mon, 12 Oct 2026 16:46:53 -0700 [thread overview]
Message-ID: <20261012234654.60666-10-namhyung@kernel.org> (raw)
In-Reply-To: <20261012234654.60666-1-namhyung@kernel.org>
Now it should set the binary type of a DSO properly. No need to figure
out a filename suitable for disassembly.
Just call dso__find_binary_type() and dso__get_filename() for that type.
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/disasm.c | 124 ++++++++-------------------------------
1 file changed, 24 insertions(+), 100 deletions(-)
diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index 5478c134e7e3b8df..7c289b67b5bde899 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -1176,84 +1176,6 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, s
return 0;
}
-static int dso__disassemble_filename(struct dso *dso, char *filename, size_t filename_size)
-{
- char linkname[PATH_MAX];
- char *build_id_filename;
- char *build_id_path = NULL;
- char *pos;
- int len;
-
- if (dso__symtab_type(dso) == DSO_BINARY_TYPE__KALLSYMS &&
- !dso__is_kcore(dso))
- return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX;
-
- build_id_filename = dso__build_id_filename(dso, NULL, 0, false);
- if (build_id_filename) {
- /*
- * This is a path in perf's own build id cache, not a path on
- * the profiled system, so the symfs layout does not apply.
- */
- path__join(filename, filename_size, symbol_conf.symfs,
- build_id_filename);
- free(build_id_filename);
- } else {
- if (dso__has_build_id(dso))
- return ENOMEM;
- goto fallback;
- }
-
- build_id_path = strdup(filename);
- if (!build_id_path)
- return ENOMEM;
-
- /*
- * old style build-id cache has name of XX/XXXXXXX.. while
- * new style has XX/XXXXXXX../{elf,kallsyms,vdso}.
- * extract the build-id part of dirname in the new style only.
- */
- pos = strrchr(build_id_path, '/');
- if (pos && strlen(pos) < SBUILD_ID_SIZE - 2)
- dirname(build_id_path);
-
- if (dso__is_kcore(dso))
- goto fallback;
-
- len = readlink(build_id_path, linkname, sizeof(linkname) - 1);
- if (len < 0)
- goto fallback;
-
- linkname[len] = '\0';
- if (strstr(linkname, DSO__NAME_KALLSYMS) ||
- access(filename, R_OK)) {
-fallback:
- /*
- * If we don't have build-ids or the build-id file isn't in the
- * cache, or is just a kallsyms file, well, lets hope that this
- * DSO is the same as when 'perf record' ran.
- */
- if (dso__kernel(dso) && dso__long_name(dso)[0] == '/')
- snprintf(filename, filename_size, "%s", dso__long_name(dso));
- else
- __symbol__join_symfs(filename, filename_size, dso__long_name(dso));
-
- mutex_lock(dso__lock(dso));
- if (access(filename, R_OK) && errno == ENOENT && dso__nsinfo(dso)) {
- char *new_name = dso__filename_with_chroot(dso, filename);
- if (new_name) {
- strlcpy(filename, new_name, filename_size);
- free(new_name);
- }
- }
- mutex_unlock(dso__lock(dso));
- } else if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) {
- dso__set_binary_type(dso, DSO_BINARY_TYPE__BUILD_ID_CACHE);
- }
-
- free(build_id_path);
- return 0;
-}
-
static int symbol__disassemble_raw(char *filename, struct symbol *sym,
struct annotate_args *args)
{
@@ -1566,14 +1488,29 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
struct annotation_options *options = args->options;
struct map *map = args->ms->map;
struct dso *dso = map__dso(map);
- char symfs_filename[PATH_MAX];
+ char *symfs_filename;
bool delete_extract = false;
struct kcore_extract kce;
+ enum dso_binary_type dbt;
bool decomp = false;
- int err = dso__disassemble_filename(dso, symfs_filename, sizeof(symfs_filename));
+ int err;
- if (err)
- return err;
+ dbt = dso__find_binary_type(dso);
+
+ if (dbt == DSO_BINARY_TYPE__KALLSYMS)
+ return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX;
+
+ mutex_lock(dso__lock(dso));
+ symfs_filename = dso__get_filename(dso, "", &decomp, dbt);
+ mutex_unlock(dso__lock(dso));
+
+ if (symfs_filename == NULL) {
+ if (dbt == DSO_BINARY_TYPE__BPF_PROG_INFO ||
+ dbt == DSO_BINARY_TYPE__BPF_IMAGE)
+ symfs_filename = (char *)dso__long_name(dso);
+ else
+ return SYMBOL_ANNOTATE_ERRNO__COULDNT_DETERMINE_FILE_TYPE;
+ }
pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
symfs_filename, sym->name, map__unmap_ip(map, sym->start),
@@ -1581,9 +1518,7 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
pr_debug("annotating [%p] %30s : [%p] %30s\n", dso, dso__long_name(dso), sym, sym->name);
- if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) {
- return SYMBOL_ANNOTATE_ERRNO__COULDNT_DETERMINE_FILE_TYPE;
- } else if (dso__is_kcore(dso)) {
+ if (dso__is_kcore(dso)) {
kce.addr = map__rip_2objdump(map, sym->start);
kce.kcore_filename = symfs_filename;
kce.len = sym->end - sym->start;
@@ -1591,18 +1526,8 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
if (!kcore_extract__create(&kce)) {
delete_extract = true;
- strlcpy(symfs_filename, kce.extract_filename, sizeof(symfs_filename));
- }
- } else if (dso__needs_decompress(dso)) {
- char tmp[KMOD_DECOMP_LEN];
-
- if (dso__decompress_kmodule_path(dso, symfs_filename, tmp, sizeof(tmp)) < 0)
- return -1;
-
- /* empty pathname means file wasn't actually compressed */
- if (tmp[0] != '\0') {
- decomp = true;
- strcpy(symfs_filename, tmp);
+ dso__put_filename(dso, symfs_filename, decomp);
+ symfs_filename = kce.extract_filename;
}
}
@@ -1660,11 +1585,10 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
pr_debug("Disassembled with %s\n", perf_disassembler__strs[dis]);
}
out_remove_tmp:
- if (decomp)
- unlink(symfs_filename);
-
if (delete_extract)
kcore_extract__delete(&kce);
+ else if (dbt != DSO_BINARY_TYPE__BPF_PROG_INFO && dbt != DSO_BINARY_TYPE__BPF_IMAGE)
+ dso__put_filename(dso, symfs_filename, decomp);
return err;
}
--
2.56.0.385.gd3acb90ef8-goog
next prev parent reply other threads:[~2026-10-12 23:47 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 23:46 [PATCH v4 00/10] perf symbol: Properly seto DSO binary/symtab types Namhyung Kim
2026-10-12 23:46 ` [PATCH v4 01/10] perf tools: Remove redundant dso data init Namhyung Kim
2026-10-12 23:50 ` sashiko-bot
2026-10-12 23:46 ` [PATCH v4 02/10] perf tools: Try linked debug files for DSO debug info Namhyung Kim
2026-10-12 23:56 ` sashiko-bot
2026-10-13 6:08 ` Namhyung Kim
2026-10-12 23:46 ` [PATCH v4 03/10] perf symbol: Update symtab type of vmlinux from build-id cache Namhyung Kim
2026-10-12 23:52 ` sashiko-bot
2026-10-12 23:46 ` [PATCH v4 04/10] perf symbol: Set binary/symtab type for split kallsyms Namhyung Kim
2026-10-12 23:53 ` sashiko-bot
2026-10-12 23:46 ` [PATCH v4 05/10] perf symbol: Get rid of machine_or_dso_e_machine() Namhyung Kim
2026-10-13 0:03 ` sashiko-bot
2026-10-12 23:46 ` [PATCH v4 06/10] perf tools: Factor out dso__find_binary_type() Namhyung Kim
2026-10-12 23:58 ` sashiko-bot
2026-10-13 6:11 ` Namhyung Kim
2026-10-12 23:46 ` [PATCH v4 07/10] perf symbol: Set binary type for JIT map DSOs Namhyung Kim
2026-10-12 23:59 ` sashiko-bot
2026-10-12 23:46 ` [PATCH v4 08/10] perf symbol: Do not set binary type from symtab type Namhyung Kim
2026-10-13 0:08 ` sashiko-bot
2026-10-13 6:18 ` Namhyung Kim
2026-10-12 23:46 ` Namhyung Kim [this message]
2026-10-13 0:06 ` [PATCH v4 09/10] perf annotate: Simplify symbol__disassemble() with dso binary_type sashiko-bot
2026-10-12 23:46 ` [PATCH v4 10/10] perf test: Fix dso data tests Namhyung Kim
2026-10-13 0:06 ` sashiko-bot
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=20261012234654.60666-10-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.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@kernel.org \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.