perf dso: Fix address sanitizer build
authorIan Rogers <irogers@google.com>
Thu, 4 Jul 2024 01:17:45 +0000 (18:17 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 12 Jul 2024 16:38:41 +0000 (09:38 -0700)
Various files had been missed from having accessor functions added for
the sake of dso reference count checking. Add the function calls and
missing dso accessor functions.

Fixes: ee756ef7491e ("perf dso: Add reference count checking and accessor functions")
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Yunseong Kim <yskelg@gmail.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: John Garry <john.g.garry@oracle.com>
Link: https://lore.kernel.org/r/20240704011745.1021288-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/arch/powerpc/util/skip-callchain-idx.c
tools/perf/ui/gtk/annotate.c
tools/perf/util/cs-etm.c
tools/perf/util/disasm.c
tools/perf/util/dso.h
tools/perf/util/srcline.c
tools/perf/util/symbol.c
tools/perf/util/unwind-libdw.c
tools/perf/util/unwind-libunwind-local.c

index 5f3edb3004d84f58ebb5c11c5814f9f3fb836989..356786432fd3cac8e3472bcf97b018a41a970515 100644 (file)
@@ -159,9 +159,9 @@ static int check_return_addr(struct dso *dso, u64 map_start, Dwarf_Addr pc)
        Dwarf_Addr      start = pc;
        Dwarf_Addr      end = pc;
        bool            signalp;
-       const char      *exec_file = dso->long_name;
+       const char      *exec_file = dso__long_name(dso);
 
-       dwfl = dso->dwfl;
+       dwfl = RC_CHK_ACCESS(dso)->dwfl;
 
        if (!dwfl) {
                dwfl = dwfl_begin(&offline_callbacks);
@@ -183,7 +183,7 @@ static int check_return_addr(struct dso *dso, u64 map_start, Dwarf_Addr pc)
                        dwfl_end(dwfl);
                        goto out;
                }
-               dso->dwfl = dwfl;
+               RC_CHK_ACCESS(dso)->dwfl = dwfl;
        }
 
        mod = dwfl_addrmodule(dwfl, pc);
@@ -267,7 +267,7 @@ int arch_skip_callchain_idx(struct thread *thread, struct ip_callchain *chain)
        rc = check_return_addr(dso, map__start(al.map), ip);
 
        pr_debug("[DSO %s, sym %s, ip 0x%" PRIx64 "] rc %d\n",
-                               dso->long_name, al.sym->name, ip, rc);
+               dso__long_name(dso), al.sym->name, ip, rc);
 
        if (rc == 0) {
                /*
index 93ce3d47e47e6c07d889d485c57597d3bfa5e489..6da24aa039ebbd0f9c8fe41156f50f98a9c74811 100644 (file)
@@ -180,13 +180,14 @@ static int symbol__gtk_annotate(struct map_symbol *ms, struct evsel *evsel,
        GtkWidget *tab_label;
        int err;
 
-       if (dso->annotate_warned)
+       if (dso__annotate_warned(dso))
                return -1;
 
        err = symbol__annotate(ms, evsel, NULL);
        if (err) {
                char msg[BUFSIZ];
-               dso->annotate_warned = true;
+
+               dso__set_annotate_warned(dso);
                symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
                ui__error("Couldn't annotate %s: %s\n", sym->name, msg);
                return -1;
index 32818bd7cd177fb6a8ba0d371cbda8149e4d0715..5e9fbcfad7d4437733c8cfc80839c40a606bbb96 100644 (file)
@@ -1013,7 +1013,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id,
        if (!dso)
                goto out;
 
-       if (dso->data.status == DSO_DATA_STATUS_ERROR &&
+       if (dso__data(dso)->status == DSO_DATA_STATUS_ERROR &&
            dso__data_status_seen(dso, DSO_DATA_STATUS_SEEN_ITRACE))
                goto out;
 
@@ -1027,11 +1027,11 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id,
        if (len <= 0) {
                ui__warning_once("CS ETM Trace: Missing DSO. Use 'perf archive' or debuginfod to export data from the traced system.\n"
                                 "              Enable CONFIG_PROC_KCORE or use option '-k /path/to/vmlinux' for kernel symbols.\n");
-               if (!dso->auxtrace_warned) {
+               if (!dso__auxtrace_warned(dso)) {
                        pr_err("CS ETM Trace: Debug data not found for address %#"PRIx64" in %s\n",
-                                   address,
-                                   dso->long_name ? dso->long_name : "Unknown");
-                       dso->auxtrace_warned = true;
+                               address,
+                               dso__long_name(dso) ? dso__long_name(dso) : "Unknown");
+                       dso__set_auxtrace_warned(dso);
                }
                goto out;
        }
index 72aec8f61b944a7ae0e0cc2fbfab081ae097809f..e10558b79504b09f654c83c4759b36a12bfda426 100644 (file)
@@ -1199,7 +1199,7 @@ static int symbol__disassemble_bpf(struct symbol *sym,
        int ret;
        FILE *s;
 
-       if (dso->binary_type != DSO_BINARY_TYPE__BPF_PROG_INFO)
+       if (dso__binary_type(dso) != DSO_BINARY_TYPE__BPF_PROG_INFO)
                return SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE;
 
        pr_debug("%s: handling sym %s addr %" PRIx64 " len %" PRIx64 "\n", __func__,
@@ -1226,14 +1226,14 @@ static int symbol__disassemble_bpf(struct symbol *sym,
        info.arch = bfd_get_arch(bfdf);
        info.mach = bfd_get_mach(bfdf);
 
-       info_node = perf_env__find_bpf_prog_info(dso->bpf_prog.env,
-                                                dso->bpf_prog.id);
+       info_node = perf_env__find_bpf_prog_info(dso__bpf_prog(dso)->env,
+                                                dso__bpf_prog(dso)->id);
        if (!info_node) {
                ret = SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF;
                goto out;
        }
        info_linear = info_node->info_linear;
-       sub_id = dso->bpf_prog.sub_id;
+       sub_id = dso__bpf_prog(dso)->sub_id;
 
        info.buffer = (void *)(uintptr_t)(info_linear->info.jited_prog_insns);
        info.buffer_length = info_linear->info.jited_prog_len;
@@ -1244,7 +1244,7 @@ static int symbol__disassemble_bpf(struct symbol *sym,
        if (info_linear->info.btf_id) {
                struct btf_node *node;
 
-               node = perf_env__find_btf(dso->bpf_prog.env,
+               node = perf_env__find_btf(dso__bpf_prog(dso)->env,
                                          info_linear->info.btf_id);
                if (node)
                        btf = btf__new((__u8 *)(node->data),
index d72f3b8c37f6ae34f48deae489a6e6adbec63098..878c1f441868b093c924c2c8e7b5971020ef23ef 100644 (file)
@@ -280,6 +280,16 @@ static inline void dso__set_annotate_warned(struct dso *dso)
        RC_CHK_ACCESS(dso)->annotate_warned = 1;
 }
 
+static inline bool dso__auxtrace_warned(const struct dso *dso)
+{
+       return RC_CHK_ACCESS(dso)->auxtrace_warned;
+}
+
+static inline void dso__set_auxtrace_warned(struct dso *dso)
+{
+       RC_CHK_ACCESS(dso)->auxtrace_warned = 1;
+}
+
 static inline struct auxtrace_cache *dso__auxtrace_cache(struct dso *dso)
 {
        return RC_CHK_ACCESS(dso)->auxtrace_cache;
index 51eb78993fe22154d00b20dedc6f2b512efa3119..760742fd4a7d0c2412d0f24f6b79db995306b331 100644 (file)
@@ -288,7 +288,7 @@ static int inline_list__append_dso_a2l(struct dso *dso,
                                       struct inline_node *node,
                                       struct symbol *sym)
 {
-       struct a2l_data *a2l = dso->a2l;
+       struct a2l_data *a2l = dso__a2l(dso);
        struct symbol *inline_sym = new_inline_sym(dso, sym, a2l->funcname);
        char *srcline = NULL;
 
@@ -304,11 +304,11 @@ static int addr2line(const char *dso_name, u64 addr,
                     struct symbol *sym)
 {
        int ret = 0;
-       struct a2l_data *a2l = dso->a2l;
+       struct a2l_data *a2l = dso__a2l(dso);
 
        if (!a2l) {
-               dso->a2l = addr2line_init(dso_name);
-               a2l = dso->a2l;
+               a2l = addr2line_init(dso_name);
+               dso__set_a2l(dso, a2l);
        }
 
        if (a2l == NULL) {
@@ -360,14 +360,14 @@ static int addr2line(const char *dso_name, u64 addr,
 
 void dso__free_a2l(struct dso *dso)
 {
-       struct a2l_data *a2l = dso->a2l;
+       struct a2l_data *a2l = dso__a2l(dso);
 
        if (!a2l)
                return;
 
        addr2line_cleanup(a2l);
 
-       dso->a2l = NULL;
+       dso__set_a2l(dso, NULL);
 }
 
 #else /* HAVE_LIBBFD_SUPPORT */
index 478e922ce6764591babd73e714b53bb67acfe901..19eb623e08266b46e808e8d9f0773c79914fc888 100644 (file)
@@ -1607,7 +1607,7 @@ int dso__load_bfd_symbols(struct dso *dso, const char *debugfile)
 
        if (!bfd_check_format(abfd, bfd_object)) {
                pr_debug2("%s: cannot read %s bfd file.\n", __func__,
-                         dso->long_name);
+                         dso__long_name(dso));
                goto out_close;
        }
 
@@ -1640,12 +1640,13 @@ int dso__load_bfd_symbols(struct dso *dso, const char *debugfile)
                }
                if (i < symbols_count) {
                        /* PE symbols can only have 4 bytes, so use .text high bits */
-                       dso->text_offset = section->vma - (u32)section->vma;
-                       dso->text_offset += (u32)bfd_asymbol_value(symbols[i]);
-                       dso->text_end = (section->vma - dso->text_offset) + section->size;
+                       u64 text_offset = (section->vma - (u32)section->vma)
+                               + (u32)bfd_asymbol_value(symbols[i]);
+                       dso__set_text_offset(dso, text_offset);
+                       dso__set_text_end(dso, (section->vma - text_offset) + section->size);
                } else {
-                       dso->text_offset = section->vma - section->filepos;
-                       dso->text_end = section->filepos + section->size;
+                       dso__set_text_offset(dso, section->vma - section->filepos);
+                       dso__set_text_end(dso, section->filepos + section->size);
                }
        }
 
@@ -1671,7 +1672,7 @@ int dso__load_bfd_symbols(struct dso *dso, const char *debugfile)
                else
                        len = section->size - sym->value;
 
-               start = bfd_asymbol_value(sym) - dso->text_offset;
+               start = bfd_asymbol_value(sym) - dso__text_offset(dso);
                symbol = symbol__new(start, len, bfd2elf_binding(sym), STT_FUNC,
                                     bfd_asymbol_name(sym));
                if (!symbol)
index b38d322734b4a7fa0b2981bfb9e90cb26284dfdd..bde216e630d29fc764fb79bc1878c73e58af35a3 100644 (file)
@@ -29,8 +29,8 @@ static int __find_debuginfo(Dwfl_Module *mod __maybe_unused, void **userdata,
        const struct dso *dso = *userdata;
 
        assert(dso);
-       if (dso->symsrc_filename && strcmp (file_name, dso->symsrc_filename))
-               *debuginfo_file_name = strdup(dso->symsrc_filename);
+       if (dso__symsrc_filename(dso) && strcmp(file_name, dso__symsrc_filename(dso)))
+               *debuginfo_file_name = strdup(dso__symsrc_filename(dso));
        return -1;
 }
 
@@ -66,7 +66,7 @@ static int __report_module(struct addr_location *al, u64 ip,
         * a different code in another DSO.  So just use the map->start
         * directly to pick the correct one.
         */
-       if (!strncmp(dso->long_name, "/tmp/jitted-", 12))
+       if (!strncmp(dso__long_name(dso), "/tmp/jitted-", 12))
                base = map__start(al->map);
        else
                base = map__start(al->map) - map__pgoff(al->map);
@@ -83,15 +83,15 @@ static int __report_module(struct addr_location *al, u64 ip,
        if (!mod) {
                char filename[PATH_MAX];
 
-               __symbol__join_symfs(filename, sizeof(filename), dso->long_name);
-               mod = dwfl_report_elf(ui->dwfl, dso->short_name, filename, -1,
+               __symbol__join_symfs(filename, sizeof(filename), dso__long_name(dso));
+               mod = dwfl_report_elf(ui->dwfl, dso__short_name(dso), filename, -1,
                                      base, false);
        }
        if (!mod) {
                char filename[PATH_MAX];
 
                if (dso__build_id_filename(dso, filename, sizeof(filename), false))
-                       mod = dwfl_report_elf(ui->dwfl, dso->short_name, filename, -1,
+                       mod = dwfl_report_elf(ui->dwfl, dso__short_name(dso), filename, -1,
                                              base, false);
        }
 
index a424eae6d3081d03faa174158da21084fa2b09ec..f6a6f6a910309eac631dd93512abca993b27404d 100644 (file)
@@ -363,7 +363,7 @@ static int read_unwind_spec_debug_frame(struct dso *dso,
                                        struct machine *machine, u64 *offset)
 {
        int fd;
-       u64 ofs = dso->data.debug_frame_offset;
+       u64 ofs = dso__data(dso)->debug_frame_offset;
 
        /* debug_frame can reside in:
         *  - dso
@@ -379,7 +379,7 @@ static int read_unwind_spec_debug_frame(struct dso *dso,
                }
 
                if (ofs <= 0) {
-                       fd = open(dso->symsrc_filename, O_RDONLY);
+                       fd = open(dso__symsrc_filename(dso), O_RDONLY);
                        if (fd >= 0) {
                                ofs = elf_section_offset(fd, ".debug_frame");
                                close(fd);
@@ -407,21 +407,21 @@ static int read_unwind_spec_debug_frame(struct dso *dso,
                                }
                        }
                        if (ofs > 0) {
-                               if (dso->symsrc_filename != NULL) {
+                               if (dso__symsrc_filename(dso) != NULL) {
                                        pr_warning(
                                                "%s: overwrite symsrc(%s,%s)\n",
                                                        __func__,
-                                                       dso->symsrc_filename,
+                                                       dso__symsrc_filename(dso),
                                                        debuglink);
-                                       zfree(&dso->symsrc_filename);
+                                       zfree(&dso__symsrc_filename(dso));
                                }
-                               dso->symsrc_filename = debuglink;
+                               dso__set_symsrc_filename(dso, debuglink);
                        } else {
                                free(debuglink);
                        }
                }
 
-               dso->data.debug_frame_offset = ofs;
+               dso__data(dso)->debug_frame_offset = ofs;
        }
 
        *offset = ofs;
@@ -486,7 +486,7 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
        if (ret < 0 &&
            !read_unwind_spec_debug_frame(dso, ui->machine, &segbase)) {
                int fd = dso__data_get_fd(dso, ui->machine);
-               int is_exec = elf_is_exec(fd, dso->name);
+               int is_exec = elf_is_exec(fd, dso__name(dso));
                u64 start = map__start(map);
                unw_word_t base = is_exec ? 0 : start;
                const char *symfile;
@@ -494,7 +494,7 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
                if (fd >= 0)
                        dso__data_put_fd(dso);
 
-               symfile = dso->symsrc_filename ?: dso->name;
+               symfile = dso__symsrc_filename(dso) ?: dso__name(dso);
 
                memset(&di, 0, sizeof(di));
                if (dwarf_find_debug_frame(0, &di, ip, base, symfile, start, map__end(map)))