perf tools: Pass build id object to sysfs__read_build_id()
authorJiri Olsa <jolsa@kernel.org>
Tue, 13 Oct 2020 19:24:35 +0000 (21:24 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Oct 2020 11:46:02 +0000 (08:46 -0300)
Passing build id object to sysfs__read_build_id function, so it can
populate the size of the build_id object.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20201013192441.1299447-4-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/build-id.c
tools/perf/util/dso.c
tools/perf/util/symbol-elf.c
tools/perf/util/symbol-minimal.c
tools/perf/util/symbol.c
tools/perf/util/symbol.h

index 62b258a..1c332e7 100644 (file)
@@ -113,7 +113,7 @@ int build_id__sprintf(const u8 *build_id, int len, char *bf)
 int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
 {
        char notes[PATH_MAX];
-       u8 build_id[BUILD_ID_SIZE];
+       struct build_id bid;
        int ret;
 
        if (!root_dir)
@@ -121,11 +121,11 @@ int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
 
        scnprintf(notes, sizeof(notes), "%s/sys/kernel/notes", root_dir);
 
-       ret = sysfs__read_build_id(notes, build_id, sizeof(build_id));
+       ret = sysfs__read_build_id(notes, &bid);
        if (ret < 0)
                return ret;
 
-       return build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
+       return build_id__sprintf(bid.data, sizeof(bid.data), sbuild_id);
 }
 
 int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
index d2c1ed0..e87fa9a 100644 (file)
@@ -1346,8 +1346,7 @@ void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
        if (machine__is_default_guest(machine))
                return;
        sprintf(path, "%s/sys/kernel/notes", machine->root_dir);
-       if (sysfs__read_build_id(path, dso->bid.data,
-                                sizeof(dso->bid.data)) == 0)
+       if (sysfs__read_build_id(path, &dso->bid) == 0)
                dso->has_build_id = true;
 }
 
@@ -1365,8 +1364,7 @@ int dso__kernel_module_get_build_id(struct dso *dso,
                 "%s/sys/module/%.*s/notes/.note.gnu.build-id",
                 root_dir, (int)strlen(name) - 1, name);
 
-       if (sysfs__read_build_id(filename, dso->bid.data,
-                                sizeof(dso->bid.data)) == 0)
+       if (sysfs__read_build_id(filename, &dso->bid) == 0)
                dso->has_build_id = true;
 
        return 0;
index 61d7c44..97a55f1 100644 (file)
@@ -595,13 +595,11 @@ out:
 
 #endif // HAVE_LIBBFD_BUILDID_SUPPORT
 
-int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
+int sysfs__read_build_id(const char *filename, struct build_id *bid)
 {
+       size_t size = sizeof(bid->data);
        int fd, err = -1;
 
-       if (size < BUILD_ID_SIZE)
-               goto out;
-
        fd = open(filename, O_RDONLY);
        if (fd < 0)
                goto out;
@@ -622,8 +620,9 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
                                break;
                        if (memcmp(bf, "GNU", sizeof("GNU")) == 0) {
                                size_t sz = min(descsz, size);
-                               if (read(fd, build_id, sz) == (ssize_t)sz) {
-                                       memset(build_id + sz, 0, size - sz);
+                               if (read(fd, bid->data, sz) == (ssize_t)sz) {
+                                       memset(bid->data + sz, 0, size - sz);
+                                       bid->size = sz;
                                        err = 0;
                                        break;
                                }
index 5173331..dba6b9e 100644 (file)
@@ -222,9 +222,8 @@ out:
        return ret;
 }
 
-int sysfs__read_build_id(const char *filename, void *build_id, size_t size __maybe_unused)
+int sysfs__read_build_id(const char *filename, struct build_id *bid)
 {
-       struct build_id bid;
        int fd;
        int ret = -1;
        struct stat stbuf;
@@ -246,9 +245,7 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size __may
        if (read(fd, buf, buf_size) != (ssize_t) buf_size)
                goto out_free;
 
-       ret = read_build_id(buf, buf_size, &bid, false);
-       if (ret > 0)
-               memcpy(build_id, bid.data, bid.size);
+       ret = read_build_id(buf, buf_size, bid, false);
 out_free:
        free(buf);
 out:
index 4c43bb9..dd1cf91 100644 (file)
@@ -2122,7 +2122,7 @@ static bool filename__readable(const char *file)
 
 static char *dso__find_kallsyms(struct dso *dso, struct map *map)
 {
-       u8 host_build_id[BUILD_ID_SIZE];
+       struct build_id bid;
        char sbuild_id[SBUILD_ID_SIZE];
        bool is_host = false;
        char path[PATH_MAX];
@@ -2135,9 +2135,8 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
                goto proc_kallsyms;
        }
 
-       if (sysfs__read_build_id("/sys/kernel/notes", host_build_id,
-                                sizeof(host_build_id)) == 0)
-               is_host = dso__build_id_equal(dso, host_build_id);
+       if (sysfs__read_build_id("/sys/kernel/notes", &bid) == 0)
+               is_host = dso__build_id_equal(dso, bid.data);
 
        /* Try a fast path for /proc/kallsyms if possible */
        if (is_host) {
index 98908fa..70b3874 100644 (file)
@@ -144,7 +144,7 @@ struct symbol *dso__next_symbol(struct symbol *sym);
 enum dso_type dso__type_fd(int fd);
 
 int filename__read_build_id(const char *filename, struct build_id *id);
-int sysfs__read_build_id(const char *filename, void *bf, size_t size);
+int sysfs__read_build_id(const char *filename, struct build_id *bid);
 int modules__parse(const char *filename, void *arg,
                   int (*process_module)(void *arg, const char *name,
                                         u64 start, u64 size));