mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/3] perf dso: Move dso__read_build_id() from perf inject to dso.c
Date: Fri, 16 Oct 2026 17:01:52 -0700	[thread overview]
Message-ID: <20261017000158.1178269-2-thepacketgeek@gmail.com> (raw)
In-Reply-To: <20261017000158.1178269-1-thepacketgeek@gmail.com>

dso__read_build_id() reads a DSO's build-id from inside its mount
namespace when it isn't known yet. The libdw unwinder is going to need
it, so move it out of builtin-inject.c and make it available to the rest
of perf.

No functional change.

Signed-off-by: Matthew Wood <thepacketgeek@gmail.com>
---
 tools/perf/builtin-inject.c | 25 -------------------------
 tools/perf/util/dso.c       | 29 +++++++++++++++++++++++++++++
 tools/perf/util/dso.h       |  1 +
 3 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 70bbfad5653e..7e4b45a5062c 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -892,31 +892,6 @@ static int perf_event__repipe_tracing_data(const struct perf_tool *tool,
 }
 #endif
 
-static int dso__read_build_id(struct dso *dso)
-{
-	struct nscookie nsc;
-	struct build_id bid = { .size = 0, };
-
-	if (dso__has_build_id(dso))
-		return 0;
-
-	mutex_lock(dso__lock(dso));
-	nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
-	if (filename__read_build_id(dso__long_name(dso), &bid) > 0)
-		dso__set_build_id(dso, &bid);
-	else if (dso__nsinfo(dso)) {
-		char *new_name = dso__filename_with_chroot(dso, dso__long_name(dso));
-
-		if (new_name && filename__read_build_id(new_name, &bid) > 0)
-			dso__set_build_id(dso, &bid);
-		free(new_name);
-	}
-	nsinfo__mountns_exit(&nsc);
-	mutex_unlock(dso__lock(dso));
-
-	return dso__has_build_id(dso) ? 0 : -1;
-}
-
 static struct strlist *perf_inject__parse_known_build_ids(
 	const char *known_build_ids_string)
 {
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 42bfe30a3b51..e03e2cb9212b 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -569,6 +569,35 @@ char *dso__filename_with_chroot(const struct dso *dso, const char *filename)
 	return filename_with_chroot(nsinfo__pid(dso__nsinfo_const(dso)), filename);
 }
 
+/*
+ * Read the build-id from the DSO's file, inside its mount namespace, if it
+ * isn't known yet.
+ */
+int dso__read_build_id(struct dso *dso)
+{
+	struct nscookie nsc;
+	struct build_id bid = { .size = 0, };
+
+	if (dso__has_build_id(dso))
+		return 0;
+
+	mutex_lock(dso__lock(dso));
+	nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
+	if (filename__read_build_id(dso__long_name(dso), &bid) > 0)
+		dso__set_build_id(dso, &bid);
+	else if (dso__nsinfo(dso)) {
+		char *new_name = dso__filename_with_chroot(dso, dso__long_name(dso));
+
+		if (new_name && filename__read_build_id(new_name, &bid) > 0)
+			dso__set_build_id(dso, &bid);
+		free(new_name);
+	}
+	nsinfo__mountns_exit(&nsc);
+	mutex_unlock(dso__lock(dso));
+
+	return dso__has_build_id(dso) ? 0 : -1;
+}
+
 static char *dso__get_filename(struct dso *dso, const char *root_dir,
 			       bool *decomp)
 {
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 55c4aaa53c38..ece54b9b8552 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -805,6 +805,7 @@ static inline bool dso__has_symbols(const struct dso *dso)
 }
 
 char *dso__filename_with_chroot(const struct dso *dso, const char *filename);
+int dso__read_build_id(struct dso *dso);
 
 bool dso__sorted_by_name(const struct dso *dso);
 void dso__set_sorted_by_name(struct dso *dso);
-- 
2.53.0-Meta


  reply	other threads:[~2026-10-17  0:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17  0:01 [PATCH v2 0/3] perf unwind: Don't load symbols when the caller doesn't need them Matthew Wood
2026-10-17  0:01 ` Matthew Wood [this message]
2026-10-17  0:01 ` [PATCH v2 2/3] perf unwind: Find separate debuginfo without loading symbols Matthew Wood
2026-10-17  0:01 ` [PATCH v2 3/3] perf unwind: Don't look up symbols when the caller doesn't want them Matthew Wood

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=20261017000158.1178269-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

all inboxes | Powered by JetHome®