Skip to content

Commit d3379ab

Browse files
acmelIngo Molnar
authored andcommitted
perf symbols: Fix comparision of build_ids
When we read the build_id from the DSO name to then index into /usr/lib/debug/.buildid/DSO_BUILD_ID[0:2]/DSO_BUILD_ID[2:], we were jumping directly to the comparision with the buildid we already have in dso->build_id (that came from the perf.data build_id section, collected at perf record time) unconditionally, even if we didn't had recorded it, and furthermore, comparing a formatted buildid with a rawbuildid, yikes. Fix it by deleting the dso__read_build_id() function, that was really misdesigned anyway, and do the necessary checks and correct comparison of raw buildids. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1258582853-8579-1-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent b269876 commit d3379ab

1 file changed

Lines changed: 16 additions & 36 deletions

File tree

‎tools/perf/util/symbol.c‎

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -962,25 +962,6 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
962962
return err;
963963
}
964964

965-
static char *dso__read_build_id(struct dso *self)
966-
{
967-
int len;
968-
char *build_id = NULL;
969-
unsigned char rawbf[BUILD_ID_SIZE];
970-
971-
len = filename__read_build_id(self->long_name, rawbf, sizeof(rawbf));
972-
if (len < 0)
973-
goto out;
974-
975-
build_id = malloc(len * 2 + 1);
976-
if (build_id == NULL)
977-
goto out;
978-
979-
build_id__sprintf(rawbf, len, build_id);
980-
out:
981-
return build_id;
982-
}
983-
984965
char dso__symtab_origin(const struct dso *self)
985966
{
986967
static const char origin[] = {
@@ -1001,7 +982,8 @@ char dso__symtab_origin(const struct dso *self)
1001982
int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)
1002983
{
1003984
int size = PATH_MAX;
1004-
char *name = malloc(size), *build_id = NULL;
985+
char *name = malloc(size);
986+
u8 build_id[BUILD_ID_SIZE];
1005987
int ret = -1;
1006988
int fd;
1007989

@@ -1023,8 +1005,6 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)
10231005

10241006
more:
10251007
do {
1026-
int berr = 0;
1027-
10281008
self->origin++;
10291009
switch (self->origin) {
10301010
case DSO__ORIG_FEDORA:
@@ -1036,12 +1016,18 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)
10361016
self->long_name);
10371017
break;
10381018
case DSO__ORIG_BUILDID:
1039-
build_id = dso__read_build_id(self);
1040-
if (build_id != NULL) {
1019+
if (filename__read_build_id(self->long_name, build_id,
1020+
sizeof(build_id))) {
1021+
char build_id_hex[BUILD_ID_SIZE * 2 + 1];
1022+
1023+
build_id__sprintf(build_id, sizeof(build_id),
1024+
build_id_hex);
10411025
snprintf(name, size,
10421026
"/usr/lib/debug/.build-id/%.2s/%s.debug",
1043-
build_id, build_id + 2);
1044-
goto compare_build_id;
1027+
build_id_hex, build_id_hex + 2);
1028+
if (self->has_build_id)
1029+
goto compare_build_id;
1030+
break;
10451031
}
10461032
self->origin++;
10471033
/* Fall thru */
@@ -1054,18 +1040,12 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)
10541040
}
10551041

10561042
if (self->has_build_id) {
1057-
bool match;
1058-
build_id = malloc(BUILD_ID_SIZE);
1059-
if (build_id == NULL)
1043+
if (filename__read_build_id(name, build_id,
1044+
sizeof(build_id)) < 0)
10601045
goto more;
1061-
berr = filename__read_build_id(name, build_id,
1062-
BUILD_ID_SIZE);
10631046
compare_build_id:
1064-
match = berr > 0 && memcmp(build_id, self->build_id,
1065-
sizeof(self->build_id)) == 0;
1066-
free(build_id);
1067-
build_id = NULL;
1068-
if (!match)
1047+
if (memcmp(build_id, self->build_id,
1048+
sizeof(self->build_id)) != 0)
10691049
goto more;
10701050
}
10711051

0 commit comments

Comments
 (0)