]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
perf tools: Use build_id object in dso
authorJiri Olsa <jolsa@kernel.org>
Tue, 13 Oct 2020 19:24:33 +0000 (21:24 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 14 Oct 2020 11:44:47 +0000 (08:44 -0300)
Replace build_id byte array with struct build_id object and all the code
that references it.

The objective is to carry size together with build id array, so it's
better to keep both together.

This is preparatory change for following patches, and there's no
functional change.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20201013192441.1299447-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
15 files changed:
tools/perf/bench/inject-buildid.c
tools/perf/builtin-buildid-cache.c
tools/perf/builtin-inject.c
tools/perf/util/annotate.c
tools/perf/util/build-id.c
tools/perf/util/build-id.h
tools/perf/util/dso.c
tools/perf/util/dso.h
tools/perf/util/dsos.c
tools/perf/util/header.c
tools/perf/util/map.c
tools/perf/util/probe-event.c
tools/perf/util/scripting-engines/trace-event-python.c
tools/perf/util/symbol.c
tools/perf/util/synthetic-events.c

index e9a11f4a11098a05c087aa35499c848ace721af5..3d048a8139a7a53653d004344e9564b768a31e25 100644 (file)
@@ -79,12 +79,12 @@ static int add_dso(const char *fpath, const struct stat *sb __maybe_unused,
                   int typeflag, struct FTW *ftwbuf __maybe_unused)
 {
        struct bench_dso *dso = &dsos[nr_dsos];
-       unsigned char build_id[BUILD_ID_SIZE];
+       struct build_id bid;
 
        if (typeflag == FTW_D || typeflag == FTW_SL)
                return 0;
 
-       if (filename__read_build_id(fpath, build_id, BUILD_ID_SIZE) < 0)
+       if (filename__read_build_id(fpath, bid.data, sizeof(bid.data)) < 0)
                return 0;
 
        dso->name = realpath(fpath, NULL);
index 39efa51d7fb3d0884b97c1a0f59b969332c69cd7..a523c629f321acb2d636db2e1a4c56e28d531d52 100644 (file)
@@ -284,7 +284,7 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
 
                pr_warning("Problems with %s file, consider removing it from the cache\n",
                           filename);
-       } else if (memcmp(dso->build_id, build_id, sizeof(dso->build_id))) {
+       } else if (memcmp(dso->bid.data, build_id, sizeof(dso->bid.data))) {
                pr_warning("Problems with %s file, consider removing it from the cache\n",
                           filename);
        }
index f3f965157d69381fe785a597e6ae51123b1f47f6..a35cdabe5bd4c666d711ca430be6093cc5cc2539 100644 (file)
@@ -522,8 +522,8 @@ static int dso__read_build_id(struct dso *dso)
                return 0;
 
        nsinfo__mountns_enter(dso->nsinfo, &nsc);
-       if (filename__read_build_id(dso->long_name, dso->build_id,
-                                   sizeof(dso->build_id)) > 0) {
+       if (filename__read_build_id(dso->long_name, dso->bid.data,
+                                   sizeof(dso->bid.data)) > 0) {
                dso->has_build_id = true;
        }
        nsinfo__mountns_exit(&nsc);
index fc17af7ba845197d596df59b6bbad18dd38a3487..a016e1bd7b8dbe0618c140567c332fe6658d7db1 100644 (file)
@@ -1578,8 +1578,8 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, s
                char *build_id_msg = NULL;
 
                if (dso->has_build_id) {
-                       build_id__sprintf(dso->build_id,
-                                         sizeof(dso->build_id), bf + 15);
+                       build_id__sprintf(dso->bid.data,
+                                         sizeof(dso->bid.data), bf + 15);
                        build_id_msg = bf;
                }
                scnprintf(buf, buflen,
index 31207b6e20667cff26c1c2c50c716c04e737a20f..7da13ddb0d508b6433bfbe9c689fe7f211532bed 100644 (file)
@@ -272,7 +272,7 @@ char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size,
        if (!dso->has_build_id)
                return NULL;
 
-       build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
+       build_id__sprintf(dso->bid.data, sizeof(dso->bid.data), sbuild_id);
        linkname = build_id_cache__linkname(sbuild_id, NULL, 0);
        if (!linkname)
                return NULL;
@@ -355,7 +355,7 @@ static int machine__write_buildid_table(struct machine *machine,
                in_kernel = pos->kernel ||
                                is_kernel_module(name,
                                        PERF_RECORD_MISC_CPUMODE_UNKNOWN);
-               err = write_buildid(name, name_len, pos->build_id, machine->pid,
+               err = write_buildid(name, name_len, pos->bid.data, machine->pid,
                                    in_kernel ? kmisc : umisc, fd);
                if (err)
                        break;
@@ -841,7 +841,7 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine)
                is_kallsyms = true;
                name = machine->mmap_name;
        }
-       return build_id_cache__add_b(dso->build_id, sizeof(dso->build_id), name,
+       return build_id_cache__add_b(dso->bid.data, sizeof(dso->bid.data), name,
                                     dso->nsinfo, is_kallsyms, is_vdso);
 }
 
index 949f7e54c9cb0045dacb4c07cc24692c6596243c..5033e96d5c9ddd922c61f14471481a033b8c0aef 100644 (file)
@@ -8,6 +8,11 @@
 #include "tool.h"
 #include <linux/types.h>
 
+struct build_id {
+       u8      data[BUILD_ID_SIZE];
+       size_t  size;
+};
+
 struct nsinfo;
 
 extern struct perf_tool build_id__mark_dso_hit_ops;
index 5a3b4755f0b3aea0997032b43c8176f351c8721a..d2c1ed08c879a05697b574adc1597bafaffffd30 100644 (file)
@@ -172,8 +172,8 @@ int dso__read_binary_type_filename(const struct dso *dso,
                        break;
                }
 
-               build_id__sprintf(dso->build_id,
-                                 sizeof(dso->build_id),
+               build_id__sprintf(dso->bid.data,
+                                 sizeof(dso->bid.data),
                                  build_id_hex);
                len = __symbol__join_symfs(filename, size, "/usr/lib/debug/.build-id/");
                snprintf(filename + len, size - len, "%.2s/%s.debug",
@@ -1330,13 +1330,13 @@ void dso__put(struct dso *dso)
 
 void dso__set_build_id(struct dso *dso, void *build_id)
 {
-       memcpy(dso->build_id, build_id, sizeof(dso->build_id));
+       memcpy(dso->bid.data, build_id, sizeof(dso->bid.data));
        dso->has_build_id = 1;
 }
 
 bool dso__build_id_equal(const struct dso *dso, u8 *build_id)
 {
-       return memcmp(dso->build_id, build_id, sizeof(dso->build_id)) == 0;
+       return memcmp(dso->bid.data, build_id, sizeof(dso->bid.data)) == 0;
 }
 
 void dso__read_running_kernel_build_id(struct dso *dso, struct machine *machine)
@@ -1346,8 +1346,8 @@ 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->build_id,
-                                sizeof(dso->build_id)) == 0)
+       if (sysfs__read_build_id(path, dso->bid.data,
+                                sizeof(dso->bid.data)) == 0)
                dso->has_build_id = true;
 }
 
@@ -1365,8 +1365,8 @@ 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->build_id,
-                                sizeof(dso->build_id)) == 0)
+       if (sysfs__read_build_id(filename, dso->bid.data,
+                                sizeof(dso->bid.data)) == 0)
                dso->has_build_id = true;
 
        return 0;
@@ -1376,7 +1376,7 @@ size_t dso__fprintf_buildid(struct dso *dso, FILE *fp)
 {
        char sbuild_id[SBUILD_ID_SIZE];
 
-       build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
+       build_id__sprintf(dso->bid.data, sizeof(dso->bid.data), sbuild_id);
        return fprintf(fp, "%s", sbuild_id);
 }
 
index 8ad17f395a197a01215a727837061c650ac7f041..eac004210b47b0818c923da72fa701125ff5577b 100644 (file)
@@ -176,7 +176,7 @@ struct dso {
        bool             sorted_by_name;
        bool             loaded;
        u8               rel;
-       u8               build_id[BUILD_ID_SIZE];
+       struct build_id  bid;
        u64              text_offset;
        const char       *short_name;
        const char       *long_name;
index 939471731ea6405f5165388f68248ec9139dbb68..e3af46e818f1603f4707451497a22ed18467f0a4 100644 (file)
@@ -73,8 +73,8 @@ bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
                        continue;
                }
                nsinfo__mountns_enter(pos->nsinfo, &nsc);
-               if (filename__read_build_id(pos->long_name, pos->build_id,
-                                           sizeof(pos->build_id)) > 0) {
+               if (filename__read_build_id(pos->long_name, pos->bid.data,
+                                           sizeof(pos->bid.data)) > 0) {
                        have_build_id     = true;
                        pos->has_build_id = true;
                }
index 9cf4efdcbbbdb4579bc275992947e0238086e5d2..cde8f6eba47924f2ea4ca3b1024a63fe27d20c90 100644 (file)
@@ -2095,7 +2095,7 @@ static int __event_process_build_id(struct perf_record_header_build_id *bev,
                        free(m.name);
                }
 
-               build_id__sprintf(dso->build_id, sizeof(dso->build_id),
+               build_id__sprintf(dso->bid.data, sizeof(dso->bid.data),
                                  sbuild_id);
                pr_debug("build id event received for %s: %s\n",
                         dso->long_name, sbuild_id);
index 8b305e6241245f43b1fbe29753aa11bda2680f5b..522df3090b1c76a251917dcea3f47046100101f1 100644 (file)
@@ -331,8 +331,8 @@ int map__load(struct map *map)
                if (map->dso->has_build_id) {
                        char sbuild_id[SBUILD_ID_SIZE];
 
-                       build_id__sprintf(map->dso->build_id,
-                                         sizeof(map->dso->build_id),
+                       build_id__sprintf(map->dso->bid.data,
+                                         sizeof(map->dso->bid.data),
                                          sbuild_id);
                        pr_debug("%s with build id %s not found", name, sbuild_id);
                } else
index 3a1b58a9267359cd36652449c81ccb29ea81afef..2041ad849851e0a5fa96126f7dbf12412f648682 100644 (file)
@@ -473,7 +473,7 @@ static struct debuginfo *open_from_debuginfod(struct dso *dso, struct nsinfo *ns
        if (!c)
                return NULL;
 
-       build_id__sprintf(dso->build_id, BUILD_ID_SIZE, sbuild_id);
+       build_id__sprintf(dso->bid.data, BUILD_ID_SIZE, sbuild_id);
        fd = debuginfod_find_debuginfo(c, (const unsigned char *)sbuild_id,
                                        0, &path);
        if (fd >= 0)
index 739516fdf6e38c16a84d7a7ce3c83543bfc61cd3..db3b1c275d8fe8f8f55a504927745cd4096a0a35 100644 (file)
@@ -1064,7 +1064,7 @@ static int python_export_dso(struct db_export *dbe, struct dso *dso,
        char sbuild_id[SBUILD_ID_SIZE];
        PyObject *t;
 
-       build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
+       build_id__sprintf(dso->bid.data, sizeof(dso->bid.data), sbuild_id);
 
        t = tuple_new(5);
 
index 5ddf76fb691c2a791ec824d01ff5e3ed35ac9286..c772c8c70db549a088854d2e8096ecf684f973a8 100644 (file)
@@ -2153,7 +2153,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
                        goto proc_kallsyms;
        }
 
-       build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
+       build_id__sprintf(dso->bid.data, sizeof(dso->bid.data), sbuild_id);
 
        /* Find kallsyms in build-id cache with kcore */
        scnprintf(path, sizeof(path), "%s/%s/%s",
index 3ca5d9399680f801ac9f204d0060ff55fde8750c..8a23391558cf6bc4f1220d8e452d69c2ad53c853 100644 (file)
@@ -1961,7 +1961,7 @@ int perf_event__synthesize_build_id(struct perf_tool *tool, struct dso *pos, u16
 
        len = pos->long_name_len + 1;
        len = PERF_ALIGN(len, NAME_ALIGN);
-       memcpy(&ev.build_id.build_id, pos->build_id, sizeof(pos->build_id));
+       memcpy(&ev.build_id.build_id, pos->bid.data, sizeof(pos->bid.data));
        ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID;
        ev.build_id.header.misc = misc;
        ev.build_id.pid = machine->pid;