From: Matthew Wood <thepacketgeek@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH v3 1/2] perf symbol: Add dso__load_symsrc()
Date: Fri, 30 Oct 2026 12:32:33 -0700 [thread overview]
Message-ID: <20261030193237.1440673-2-thepacketgeek@gmail.com> (raw)
In-Reply-To: <20261030193237.1440673-1-thepacketgeek@gmail.com>
dso__load() goes through the candidate files for a DSO, such as the DSO
itself, separate debuginfo found through .gnu_debuglink, the build-id
cache and /usr/lib/debug, checks their build-ids, records the one with a
symbol table in dso__symsrc_filename(), and then reads and demangles
that symbol table.
The DWARF unwinders depend on the first part. dso__symsrc_filename() is
how they find a separate debuginfo file, for instance to use its
.debug_frame, and libdw's build-id cache fallback needs the build-id
that dso__load() reads when the DSO doesn't have one yet. They get both
today as a side effect of loading the symbols of every frame they visit.
Add dso__load_symsrc(), which does the same search, inside the DSO's
mount namespace and honouring --symfs but stops before reading any
symbols. A new symsrc_loaded flag records that it ran, so the search is
done once per DSO, and the DSO's symbols stay unloaded, so dso__load()
still loads them when they are wanted. Kernel and perf map DSOs are
skipped, as the unwinders only handle user space ELF images.
No functional change on its own; the next patch uses it.
Signed-off-by: Matthew Wood <thepacketgeek@gmail.com>
---
tools/perf/util/dso.h | 11 +++++++++++
tools/perf/util/symbol.c | 40 ++++++++++++++++++++++++++++++++++++----
tools/perf/util/symbol.h | 1 +
3 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 55c4aaa53c38..fcf235186978 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -340,6 +340,7 @@ DECLARE_RC_STRUCT(dso) {
u8 is_64_bit:1;
bool sorted_by_name;
bool loaded;
+ bool symsrc_loaded;
u8 rel;
char name[];
};
@@ -603,6 +604,16 @@ static inline void dso__set_loaded(struct dso *dso)
RC_CHK_ACCESS(dso)->loaded = true;
}
+static inline bool dso__symsrc_loaded(const struct dso *dso)
+{
+ return RC_CHK_ACCESS(dso)->symsrc_loaded;
+}
+
+static inline void dso__set_symsrc_loaded(struct dso *dso)
+{
+ RC_CHK_ACCESS(dso)->symsrc_loaded = true;
+}
+
static inline struct mutex *dso__lock(struct dso *dso)
{
return &RC_CHK_ACCESS(dso)->lock;
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 3587ad243159..ed2f8e89b191 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1798,7 +1798,7 @@ static int dso__find_perf_map(char *filebuf, size_t bufsz,
return rc;
}
-int dso__load(struct dso *dso, struct map *map)
+static int __dso__load(struct dso *dso, struct map *map, bool symbols)
{
char *name;
int ret = -1;
@@ -1828,11 +1828,17 @@ int dso__load(struct dso *dso, struct map *map)
nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
/* check again under the dso->lock */
- if (dso__loaded(dso)) {
+ if (dso__loaded(dso) || (!symbols && dso__symsrc_loaded(dso))) {
ret = 1;
goto out;
}
+ /* Unwinders only need ELF images, not kernel or perf map symbols. */
+ if (!symbols && (dso__kernel(dso) || perfmap)) {
+ ret = 0;
+ goto out;
+ }
+
kmod = dso__is_kmod(dso);
if (dso__kernel(dso) && !kmod) {
@@ -1915,7 +1921,7 @@ int dso__load(struct dso *dso, struct map *map)
}
#ifdef HAVE_LIBBFD_SUPPORT
- if (is_reg)
+ if (is_reg && symbols)
bfdrc = dso__load_bfd_symbols(dso, name);
#endif
if (is_reg && bfdrc < 0)
@@ -1978,6 +1984,11 @@ int dso__load(struct dso *dso, struct map *map)
if (!runtime_ss && syms_ss)
runtime_ss = syms_ss;
+ if (!symbols) {
+ ret = 0;
+ goto out_destroy;
+ }
+
if (syms_ss)
ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod);
else
@@ -1991,6 +2002,7 @@ int dso__load(struct dso *dso, struct map *map)
ret += nr_plt;
}
+out_destroy:
for (; ss_pos > 0; ss_pos--)
symsrc__destroy(&ss_[ss_pos - 1]);
out_free:
@@ -1998,13 +2010,33 @@ int dso__load(struct dso *dso, struct map *map)
if (ret < 0 && strstr(dso__name(dso), " (deleted)") != NULL)
ret = 0;
out:
- dso__set_loaded(dso);
+ if (symbols)
+ dso__set_loaded(dso);
+ dso__set_symsrc_loaded(dso);
mutex_unlock(dso__lock(dso));
nsinfo__mountns_exit(&nsc);
return ret;
}
+int dso__load(struct dso *dso, struct map *map)
+{
+ return __dso__load(dso, map, /*symbols=*/true);
+}
+
+/*
+ * Discover the same debug images as symbol loading, since they may contain
+ * unwind information. Do not read symbol tables, demangle names, synthesize
+ * PLT symbols, or mark the DSO's symbols as loaded.
+ */
+int dso__load_symsrc(struct dso *dso)
+{
+ if (dso__loaded(dso) || dso__symsrc_loaded(dso))
+ return 1;
+
+ return __dso__load(dso, NULL, /*symbols=*/false);
+}
+
/*
* Always takes ownership of vmlinux when vmlinux_allocated == true, even if
* it returns an error.
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index d0bac824c79c..7dd7924a098d 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -196,6 +196,7 @@ struct ref_reloc_sym {
};
int dso__load(struct dso *dso, struct map *map);
+int dso__load_symsrc(struct dso *dso);
int dso__load_vmlinux(struct dso *dso, struct map *map,
const char *vmlinux, bool vmlinux_allocated);
int dso__load_vmlinux_path(struct dso *dso, struct map *map);
--
2.53.0-Meta
next prev parent reply other threads:[~2026-10-30 19:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 19:32 [PATCH v3 0/2] perf unwind: Don't load symbols when the caller doesn't need them Matthew Wood
2026-10-30 19:32 ` Matthew Wood [this message]
2026-10-30 19:40 ` [PATCH v3 1/2] perf symbol: Add dso__load_symsrc() sashiko-bot
2026-10-30 19:32 ` [PATCH v3 2/2] perf unwind: Don't look up symbols when the caller doesn't want them Matthew Wood
2026-10-30 19:51 ` 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=20261030193237.1440673-2-thepacketgeek@gmail.com \
--to=thepacketgeek@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.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=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox