Skip to content

Commit 39be8d0

Browse files
olsajiriacmel
authored andcommitted
perf tools: Pass build_id object to dso__build_id_equal()
Passing build_id object to dso__build_id_equal(), so we can properly check build id with different size than sha1. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20201013192441.1299447-7-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 8dfdf44 commit 39be8d0

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

tools/perf/util/dso.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,9 +1332,10 @@ void dso__set_build_id(struct dso *dso, struct build_id *bid)
13321332
dso->has_build_id = 1;
13331333
}
13341334

1335-
bool dso__build_id_equal(const struct dso *dso, u8 *build_id)
1335+
bool dso__build_id_equal(const struct dso *dso, struct build_id *bid)
13361336
{
1337-
return memcmp(dso->bid.data, build_id, sizeof(dso->bid.data)) == 0;
1337+
return dso->bid.size == bid->size &&
1338+
memcmp(dso->bid.data, bid->data, dso->bid.size) == 0;
13381339
}
13391340

13401341
void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)

tools/perf/util/dso.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void dso__set_sorted_by_name(struct dso *dso);
261261
void dso__sort_by_name(struct dso *dso);
262262

263263
void dso__set_build_id(struct dso *dso, struct build_id *bid);
264-
bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
264+
bool dso__build_id_equal(const struct dso *dso, struct build_id *bid);
265265
void dso__read_running_kernel_build_id(struct dso *dso,
266266
struct machine *machine);
267267
int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);

tools/perf/util/symbol-elf.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,13 +834,17 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
834834
/* Always reject images with a mismatched build-id: */
835835
if (dso->has_build_id && !symbol_conf.ignore_vmlinux_buildid) {
836836
u8 build_id[BUILD_ID_SIZE];
837+
struct build_id bid;
838+
int size;
837839

838-
if (elf_read_build_id(elf, build_id, BUILD_ID_SIZE) < 0) {
840+
size = elf_read_build_id(elf, build_id, BUILD_ID_SIZE);
841+
if (size <= 0) {
839842
dso->load_errno = DSO_LOAD_ERRNO__CANNOT_READ_BUILDID;
840843
goto out_elf_end;
841844
}
842845

843-
if (!dso__build_id_equal(dso, build_id)) {
846+
build_id__init(&bid, build_id, size);
847+
if (!dso__build_id_equal(dso, &bid)) {
844848
pr_debug("%s: build id mismatch for %s.\n", __func__, name);
845849
dso->load_errno = DSO_LOAD_ERRNO__MISMATCHING_BUILDID;
846850
goto out_elf_end;

tools/perf/util/symbol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
21362136
}
21372137

21382138
if (sysfs__read_build_id("/sys/kernel/notes", &bid) == 0)
2139-
is_host = dso__build_id_equal(dso, bid.data);
2139+
is_host = dso__build_id_equal(dso, &bid);
21402140

21412141
/* Try a fast path for /proc/kallsyms if possible */
21422142
if (is_host) {

0 commit comments

Comments
 (0)