All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
	lkml <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Michael Petlan <mpetlan@redhat.com>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 6/9] perf tools: Pass build_id object to dso__build_id_equal
Date: Tue, 13 Oct 2020 21:24:38 +0200	[thread overview]
Message-ID: <20201013192441.1299447-7-jolsa@kernel.org> (raw)
In-Reply-To: <20201013192441.1299447-1-jolsa@kernel.org>

Passing build_id object to dso__build_id_equal, so we can
properly check build id with different size than sha1.

Acked-by: Ian Rogers <irogers@google.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/dso.c        | 5 +++--
 tools/perf/util/dso.h        | 2 +-
 tools/perf/util/symbol-elf.c | 8 ++++++--
 tools/perf/util/symbol.c     | 2 +-
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 4415ce83150b..ca965845b35e 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1332,9 +1332,10 @@ void dso__set_build_id(struct dso *dso, struct build_id *bid)
 	dso->has_build_id = 1;
 }
 
-bool dso__build_id_equal(const struct dso *dso, u8 *build_id)
+bool dso__build_id_equal(const struct dso *dso, struct build_id *bid)
 {
-	return memcmp(dso->bid.data, build_id, sizeof(dso->bid.data)) == 0;
+	return dso->bid.size == bid->size &&
+	       memcmp(dso->bid.data, bid->data, dso->bid.size) == 0;
 }
 
 void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 5a5678dbdaa5..f926c96bf230 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -261,7 +261,7 @@ void dso__set_sorted_by_name(struct dso *dso);
 void dso__sort_by_name(struct dso *dso);
 
 void dso__set_build_id(struct dso *dso, struct build_id *bid);
-bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
+bool dso__build_id_equal(const struct dso *dso, struct build_id *bid);
 void dso__read_running_kernel_build_id(struct dso *dso,
 				       struct machine *machine);
 int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 97a55f162ea5..44dd86a4f25f 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -834,13 +834,17 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
 	/* Always reject images with a mismatched build-id: */
 	if (dso->has_build_id && !symbol_conf.ignore_vmlinux_buildid) {
 		u8 build_id[BUILD_ID_SIZE];
+		struct build_id bid;
+		int size;
 
-		if (elf_read_build_id(elf, build_id, BUILD_ID_SIZE) < 0) {
+		size = elf_read_build_id(elf, build_id, BUILD_ID_SIZE);
+		if (size <= 0) {
 			dso->load_errno = DSO_LOAD_ERRNO__CANNOT_READ_BUILDID;
 			goto out_elf_end;
 		}
 
-		if (!dso__build_id_equal(dso, build_id)) {
+		build_id__init(&bid, build_id, size);
+		if (!dso__build_id_equal(dso, &bid)) {
 			pr_debug("%s: build id mismatch for %s.\n", __func__, name);
 			dso->load_errno = DSO_LOAD_ERRNO__MISMATCHING_BUILDID;
 			goto out_elf_end;
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 976632d0baa0..6138866665df 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2136,7 +2136,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
 	}
 
 	if (sysfs__read_build_id("/sys/kernel/notes", &bid) == 0)
-		is_host = dso__build_id_equal(dso, bid.data);
+		is_host = dso__build_id_equal(dso, &bid);
 
 	/* Try a fast path for /proc/kallsyms if possible */
 	if (is_host) {
-- 
2.26.2


  parent reply	other threads:[~2020-10-13 19:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-13 19:24 [PATCHv2 0/9] perf tools: Add support for build id with different sizes Jiri Olsa
2020-10-13 19:24 ` [PATCH 1/9] perf tools: Use build_id object in dso Jiri Olsa
2020-10-13 19:24 ` [PATCH 2/9] perf tools: Pass build_id object to filename__read_build_id Jiri Olsa
2020-10-13 19:24 ` [PATCH 3/9] perf tools: Pass build id object to sysfs__read_build_id Jiri Olsa
2020-10-13 19:24 ` [PATCH 4/9] perf tools: Pass build_id object to build_id__sprintf Jiri Olsa
2020-10-13 19:24 ` [PATCH 5/9] perf tools: Pass build_id object to dso__set_build_id Jiri Olsa
2020-10-14 11:51   ` Arnaldo Carvalho de Melo
2020-10-14 11:59     ` Jiri Olsa
2020-10-13 19:24 ` Jiri Olsa [this message]
2020-10-13 19:24 ` [PATCH 7/9] perf tools: Add size to struct perf_record_header_build_id Jiri Olsa
2020-10-14 11:59   ` Arnaldo Carvalho de Melo
2020-10-14 13:21     ` Jiri Olsa
2020-10-14 15:32       ` Arnaldo Carvalho de Melo
2020-10-14 14:24   ` Arnaldo Carvalho de Melo
2020-10-13 19:24 ` [PATCH 8/9] perf tools: Align buildid list output for short build ids Jiri Olsa
2020-10-13 19:24 ` [PATCH 9/9] perf tools: Add build id shell test Jiri Olsa

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=20201013192441.1299447-7-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.org \
    --subject='Re: [PATCH 6/9] perf tools: Pass build_id object to dso__build_id_equal' \
    /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

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.