Skip to content

Commit

Permalink
perf tools: Pass build_id object to dso__build_id_equal()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Oct 14, 2020
1 parent 8dfdf44 commit 39be8d0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions tools/perf/util/dso.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/dso.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions tools/perf/util/symbol-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 39be8d0

Please sign in to comment.