thread__find_symbol(thread, PERF_RECORD_MISC_USER, ip, &al);
 
        if (al.map)
-               dso = al.map->dso;
+               dso = map__dso(al.map);
 
        if (!dso) {
                pr_debug("%" PRIx64 " dso is NULL\n", ip);
 
 
        lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
 
-       if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
+       if (map__dso(map)->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
                tev->point.offset += PPC64LE_LEP_OFFSET;
        else if (lep_offset) {
                if (pev->uprobes)
 
                return 0;
 
        if (a.map != NULL)
-               a.map->dso->hit = 1;
+               map__dso(a.map)->hit = 1;
 
        hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
 
                 * the DSO?
                 */
                if (al->sym != NULL) {
-                       rb_erase_cached(&al->sym->rb_node,
-                                &al->map->dso->symbols);
+                       struct dso *dso = map__dso(al->map);
+
+                       rb_erase_cached(&al->sym->rb_node, &dso->symbols);
                        symbol__delete(al->sym);
-                       dso__reset_find_symbol_cache(al->map->dso);
+                       dso__reset_find_symbol_cache(dso);
                }
                return 0;
        }
                struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
                struct annotation *notes;
 
-               if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
+               if (he->ms.sym == NULL || map__dso(he->ms.map)->annotate_warned)
                        goto find_next;
 
                if (ann->sym_hist_filter &&
 
 
 static int buildid__map_cb(struct map *map, void *arg __maybe_unused)
 {
-       const struct dso *dso = map->dso;
+       const struct dso *dso = map__dso(map);
        char bid_buf[SBUILD_ID_SIZE];
 
        memset(bid_buf, 0, sizeof(bid_buf));
 
        }
 
        if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
-               if (!al.map->dso->hit) {
-                       al.map->dso->hit = 1;
-                       dso__inject_build_id(al.map->dso, tool, machine,
+               struct dso *dso = map__dso(al.map);
+
+               if (!dso->hit) {
+                       dso->hit = 1;
+                       dso__inject_build_id(dso, tool, machine,
                                             sample->cpumode, al.map->flags);
                }
        }
 
 
        for (i = 0; i < argc; ++i) {
                struct map *map;
+               const struct dso *dso;
                struct symbol *symbol = machine__find_kernel_symbol_by_name(machine, argv[i], &map);
 
                if (symbol == NULL) {
                        continue;
                }
 
+               dso = map__dso(map);
                printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
-                       symbol->name, map->dso->short_name, map->dso->long_name,
+                       symbol->name, dso->short_name, dso->long_name,
                        map->unmap_ip(map, symbol->start), map->unmap_ip(map, symbol->end),
                        symbol->start, symbol->end);
        }
 
        struct addr_location al;
        const char *fmt, *field_sep;
        char str[PAGE_SIZE_NAME_LEN];
+       struct dso *dso = NULL;
 
        if (machine__resolve(machine, &al, sample) < 0) {
                fprintf(stderr, "problem processing %d event, skipping it.\n",
        if (al.filtered || (mem->hide_unresolved && al.sym == NULL))
                goto out_put;
 
-       if (al.map != NULL)
-               al.map->dso->hit = 1;
+       if (al.map != NULL) {
+               dso = map__dso(al.map);
+               if (dso)
+                       dso->hit = 1;
+       }
 
        field_sep = symbol_conf.field_sep;
        if (field_sep) {
                symbol_conf.field_sep,
                sample->data_src,
                symbol_conf.field_sep,
-               al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
+               dso ? dso->long_name : "???",
                al.sym ? al.sym->name : "???");
 out_put:
        addr_location__put(&al);
 
        }
 
        if (al.map != NULL)
-               al.map->dso->hit = 1;
+               map__dso(al.map)->hit = 1;
 
        if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) {
                hist__account_cycles(sample->branch_stack, &al, sample,
                return;
 
        if (kernel_map == NULL ||
-           (kernel_map->dso->hit &&
+            (map__dso(kernel_map)->hit &&
             (kernel_kmap->ref_reloc_sym == NULL ||
              kernel_kmap->ref_reloc_sym->addr == 0))) {
                const char *desc =
 
        maps__for_each_entry(maps, rb_node) {
                struct map *map = rb_node->map;
+               const struct dso *dso = map__dso(map);
 
                printed += fprintf(fp, "%*s  %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
                                   indent, "", map->start, map->end,
                                   map->prot & PROT_EXEC ? 'x' : '-',
                                   map->flags & MAP_SHARED ? 's' : 'p',
                                   map->pgoff,
-                                  map->dso->id.ino, map->dso->name);
+                                  dso->id.ino, dso->name);
        }
 
        return printed;
 
                to   = entries[i].to;
 
                if (thread__find_map_fb(thread, sample->cpumode, from, &alf) &&
-                   !alf.map->dso->adjust_symbols)
+                   !map__dso(alf.map)->adjust_symbols)
                        from = map__map_ip(alf.map, from);
 
                if (thread__find_map_fb(thread, sample->cpumode, to, &alt) &&
-                   !alt.map->dso->adjust_symbols)
+                   !map__dso(alt.map)->adjust_symbols)
                        to = map__map_ip(alt.map, to);
 
                printed += fprintf(fp, " 0x%"PRIx64, from);
        long offset, len;
        struct addr_location al;
        bool kernel;
+       struct dso *dso;
 
        if (!start || !end)
                return 0;
                return 0;
        }
 
-       if (!thread__find_map(thread, *cpumode, start, &al) || !al.map->dso) {
+       dso = map__dso(al.map);
+       if (!thread__find_map(thread, *cpumode, start, &al) || !dso) {
                pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
                return 0;
        }
-       if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) {
+       if (dso->data.status == DSO_DATA_STATUS_ERROR) {
                pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
                return 0;
        }
        map__load(al.map);
 
        offset = al.map->map_ip(al.map, start);
-       len = dso__data_read_offset(al.map->dso, machine, offset, (u8 *)buffer,
+       len = dso__data_read_offset(dso, machine, offset, (u8 *)buffer,
                                    end - start + MAXINSN);
 
-       *is64bit = al.map->dso->is_64_bit;
+       *is64bit = dso->is_64_bit;
        if (len <= 0)
                pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n",
                        start, end);
        unsigned line;
        int len;
        char *srccode;
+       struct dso *dso = map__dso(map);
 
-       if (!map || !map->dso)
+       if (!map || !dso)
                return 0;
-       srcfile = get_srcline_split(map->dso,
+       srcfile = get_srcline_split(dso,
                                    map__rip_2objdump(map, addr),
                                    &line);
        if (!srcfile)
 
        struct symbol *sym;
        struct annotation *notes;
        struct map *map;
+       struct dso *dso;
        int err = -1;
 
        if (!he || !he->ms.sym)
 
        sym = he->ms.sym;
        map = he->ms.map;
+       dso = map__dso(map);
 
        /*
         * We can't annotate with just /proc/kallsyms
         */
-       if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-           !dso__is_kcore(map->dso)) {
+       if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(dso)) {
                pr_err("Can't annotate %s: No vmlinux file was found in the "
                       "path\n", sym->name);
                sleep(1);
 {
        struct utsname uts;
        int err = uname(&uts);
+       struct dso *dso = map__dso(map);
 
        ui__warning("Out of bounds address found:\n\n"
                    "Addr:   %" PRIx64 "\n"
                    "Tools:  %s\n\n"
                    "Not all samples will be on the annotation output.\n\n"
                    "Please report to linux-kernel@vger.kernel.org\n",
-                   ip, map->dso->long_name, dso__symtab_origin(map->dso),
+                   ip, dso->long_name, dso__symtab_origin(dso),
                    map->start, map->end, sym->start, sym->end,
                    sym->binding == STB_GLOBAL ? 'g' :
                    sym->binding == STB_LOCAL  ? 'l' : 'w', sym->name,
                    __map__is_kernel(al.map) && map__has_symbols(al.map)) {
                        if (symbol_conf.vmlinux_name) {
                                char serr[256];
-                               dso__strerror_load(al.map->dso, serr, sizeof(serr));
+
+                               dso__strerror_load(map__dso(al.map), serr, sizeof(serr));
                                ui__warning("The %s file can't be used: %s\n%s",
                                            symbol_conf.vmlinux_name, serr, msg);
                        } else {
 
 {
 
        if ((verbose > 0 || print_dso) && al->map)
-               fprintf(f, "%s@", al->map->dso->long_name);
+               fprintf(f, "%s@", map__dso(al->map)->long_name);
 
        if ((verbose > 0 || print_sym) && al->sym)
                fprintf(f, "%s+0x%" PRIx64, al->sym->name,
 
        char *srccode = NULL;
        PyObject *result;
        struct map *map;
+       struct dso *dso;
        int len = 0;
        u64 addr;
 
 
        map = c->al->map;
        addr = c->al->addr;
+       dso = map ? map__dso(map) : NULL;
 
-       if (map && map->dso)
-               srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
+       if (dso)
+               srcfile = get_srcline_split(dso, map__rip_2objdump(map, addr), &line);
 
        if (get_srccode) {
                if (srcfile)
 
        char decomp_name[KMOD_DECOMP_LEN];
        bool decomp = false;
        int ret, err = 0;
+       struct dso *dso;
 
        pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
 
-       if (!thread__find_map(thread, cpumode, addr, &al) || !al.map->dso) {
+       if (!thread__find_map(thread, cpumode, addr, &al) || !map__dso(al.map)) {
                if (cpumode == PERF_RECORD_MISC_HYPERVISOR) {
                        pr_debug("Hypervisor address can not be resolved - skipping\n");
                        goto out;
                err = -1;
                goto out;
        }
+       dso = map__dso(al.map);
+       pr_debug("File is: %s\n", dso->long_name);
 
-       pr_debug("File is: %s\n", al.map->dso->long_name);
-
-       if (al.map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
-           !dso__is_kcore(al.map->dso)) {
+       if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(dso)) {
                pr_debug("Unexpected kernel address - skipping\n");
                goto out;
        }
                len = al.map->end - addr;
 
        /* Read the object code using perf */
-       ret_len = dso__data_read_offset(al.map->dso, maps__machine(thread->maps),
+       ret_len = dso__data_read_offset(dso, maps__machine(thread->maps),
                                        al.addr, buf1, len);
        if (ret_len != len) {
                pr_debug("dso__data_read_offset failed\n");
        }
 
        /* objdump struggles with kcore - try each map only once */
-       if (dso__is_kcore(al.map->dso)) {
+       if (dso__is_kcore(dso)) {
                size_t d;
 
                for (d = 0; d < state->done_cnt; d++) {
                state->done[state->done_cnt++] = al.map->start;
        }
 
-       objdump_name = al.map->dso->long_name;
-       if (dso__needs_decompress(al.map->dso)) {
-               if (dso__decompress_kmodule_path(al.map->dso, objdump_name,
+       objdump_name = dso->long_name;
+       if (dso__needs_decompress(dso)) {
+               if (dso__decompress_kmodule_path(dso, objdump_name,
                                                 decomp_name,
                                                 sizeof(decomp_name)) < 0) {
                        pr_debug("decompression failed\n");
                        len -= ret;
                        if (len) {
                                pr_debug("Reducing len to %zu\n", len);
-                       } else if (dso__is_kcore(al.map->dso)) {
+                       } else if (dso__is_kcore(dso)) {
                                /*
                                 * objdump cannot handle very large segments
                                 * that may be found in kcore.
        pid_t pid;
        struct map *map;
        bool have_vmlinux, have_kcore, excl_kernel = false;
+       struct dso *dso;
 
        pid = getpid();
 
                pr_debug("map__load failed\n");
                goto out_err;
        }
-       have_vmlinux = dso__is_vmlinux(map->dso);
-       have_kcore = dso__is_kcore(map->dso);
+       dso = map__dso(map);
+       have_vmlinux = dso__is_vmlinux(dso);
+       have_kcore = dso__is_kcore(dso);
 
        /* 2nd time through we just try kcore */
        if (try_kcore && !have_kcore)
 
                he = rb_entry(node, struct hist_entry, rb_node_in);
 
                if (!he->filtered) {
+                       struct dso *dso = map__dso(he->ms.map);
+
                        pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64"\n",
                                i, thread__comm_str(he->thread),
-                               he->ms.map->dso->short_name,
+                               dso->short_name,
                                he->ms.sym->name, he->stat.period);
                }
 
                he = rb_entry(node, struct hist_entry, rb_node);
 
                if (!he->filtered) {
+                       struct dso *dso = map__dso(he->ms.map);
+
                        pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64"/%"PRIu64"\n",
                                i, thread__comm_str(he->thread), he->thread->tid,
-                               he->ms.map->dso->short_name,
+                               dso->short_name,
                                he->ms.sym->name, he->stat.period,
                                he->stat_acc ? he->stat_acc->period : 0);
                }
 
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
 #define DEPTH(he) (he->callchain->max_depth)
-#define CDSO(cl)  (cl->ms.map->dso->short_name)
+#define CDSO(cl)  (map__dso(cl->ms.map)->short_name)
 #define CSYM(cl)  (cl->ms.sym->name)
 
 struct result {
 
                hists__filter_by_thread(hists);
 
                /* now applying dso filter for 'kernel' */
-               hists->dso_filter = fake_samples[0].map->dso;
+               hists->dso_filter = map__dso(fake_samples[0].map);
                hists__filter_by_dso(hists);
 
                if (verbose > 2) {
 
                /* now applying all filters at once. */
                hists->thread_filter = fake_samples[1].thread;
-               hists->dso_filter = fake_samples[1].map->dso;
+               hists->dso_filter = map__dso(fake_samples[1].map);
                hists__filter_by_thread(hists);
                hists__filter_by_dso(hists);
 
 
 typedef int (*test_fn_t)(struct evsel *, struct machine *);
 
 #define COMM(he)  (thread__comm_str(he->thread))
-#define DSO(he)   (he->ms.map->dso->short_name)
+#define DSO(he)   (map__dso(he->ms.map)->short_name)
 #define SYM(he)   (he->ms.sym->name)
 #define CPU(he)   (he->cpu)
 #define PID(he)   (he->thread->tid)
 
 
                TEST_ASSERT_VAL("wrong map start",  map->start == merged[i].start);
                TEST_ASSERT_VAL("wrong map end",    map->end == merged[i].end);
-               TEST_ASSERT_VAL("wrong map name",  !strcmp(map->dso->name, merged[i].name));
+               TEST_ASSERT_VAL("wrong map name",  !strcmp(map__dso(map)->name, merged[i].name));
                TEST_ASSERT_VAL("wrong map refcnt", refcount_read(&map->refcnt) == 1);
 
                i++;
 
 {
        struct map *map = NULL;
        int ret, nr;
+       struct dso *dso;
 
        pr_debug("Testing %s\n", filename);
 
        if (ret != TEST_OK)
                return ret;
 
-       nr = dso__load(map->dso, map);
+       dso = map__dso(map);
+       nr = dso__load(dso, map);
        if (nr < 0) {
                pr_debug("dso__load() failed!\n");
                ret = TEST_FAIL;
                goto out_put;
        }
 
-       ret = test_dso(map->dso);
+       ret = test_dso(dso);
 out_put:
        map__put(map);
 
 
 
        maps__for_each_entry(maps, rb_node) {
                struct map *map = rb_node->map;
+               struct dso *dso = map__dso(map);
                /*
                 * If it is the kernel, kallsyms is always "[kernel.kallsyms]", while
                 * the kernel will have the path for the vmlinux file being used,
                 * so use the short name, less descriptive but the same ("[kernel]" in
                 * both cases.
                 */
-               struct map *pair = maps__find_by_name(kallsyms.kmaps, (map->dso->kernel ?
-                                                               map->dso->short_name :
-                                                               map->dso->name));
+               struct map *pair = maps__find_by_name(kallsyms.kmaps, (dso->kernel ?
+                                                               dso->short_name :
+                                                               dso->name));
                if (pair) {
                        pair->priv = 1;
                } else {
                        continue;
 
                if (pair->start == mem_start) {
+                       struct dso *dso = map__dso(map);
+
                        if (!header_printed) {
                                pr_info("WARN: Maps in vmlinux with a different name in kallsyms:\n");
                                header_printed = true;
                        }
 
                        pr_info("WARN: %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
-                               map->start, map->end, map->pgoff, map->dso->name);
+                               map->start, map->end, map->pgoff, dso->name);
                        if (mem_end != pair->end)
                                pr_info(":\nWARN: *%" PRIx64 "-%" PRIx64 " %" PRIx64,
                                        pair->start, pair->end, pair->pgoff);
-                       pr_info(" %s\n", pair->dso->name);
+                       pr_info(" %s\n", dso->name);
                        pair->priv = 1;
                }
        }
 
 static int sym_title(struct symbol *sym, struct map *map, char *title,
                     size_t sz, int percent_type)
 {
-       return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name, map->dso->long_name,
+       return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name,
+                       map__dso(map)->long_name,
                        percent_type_str(percent_type));
 }
 
                },
                .opts = opts,
        };
+       struct dso *dso;
        int ret = -1, err;
        int not_annotated = list_empty(¬es->src->source);
 
        if (sym == NULL)
                return -1;
 
-       if (ms->map->dso->annotate_warned)
+       dso = map__dso(ms->map);
+       if (dso->annotate_warned)
                return -1;
 
        if (not_annotated) {
                err = symbol__annotate2(ms, evsel, opts, &browser.arch);
                if (err) {
                        char msg[BUFSIZ];
-                       ms->map->dso->annotate_warned = true;
+                       dso->annotate_warned = true;
                        symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
                        ui__error("Couldn't annotate %s:\n%s", sym->name, msg);
                        goto out_free_offsets;
 
                        return NULL;
                }
 
-               dso__insert_symbol(map->dso, sym);
+               dso__insert_symbol(map__dso(map), sym);
        }
 
        return sym;
                 struct map_symbol *ms,
                 u64 addr)
 {
-       if (!ms->map || !ms->map->dso || ms->map->dso->annotate_warned)
+       struct dso *dso = map__dso(ms->map);
+
+       if (!ms->map || !dso || dso->annotate_warned)
                return 0;
 
        if (!ms->sym)
                browser->hists->dso_filter = NULL;
                ui_helpline__pop();
        } else {
+               struct dso *dso = map__dso(map);
                ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"",
-                                  __map__is_kernel(map) ? "the Kernel" : map->dso->short_name);
-               browser->hists->dso_filter = map->dso;
+                                  __map__is_kernel(map) ? "the Kernel" : dso->short_name);
+               browser->hists->dso_filter = dso;
                perf_hpp__set_elide(HISTC_DSO, true);
                pstack__push(browser->pstack, &browser->hists->dso_filter);
        }
 
        if (asprintf(optstr, "Zoom %s %s DSO (use the 'k' hotkey to zoom directly into the kernel)",
                     browser->hists->dso_filter ? "out of" : "into",
-                    __map__is_kernel(map) ? "the Kernel" : map->dso->short_name) < 0)
+                    __map__is_kernel(map) ? "the Kernel" : map__dso(map)->short_name) < 0)
                return 0;
 
        act->ms.map = map;
 
                        if (!browser->selection ||
                            !browser->selection->map ||
-                           !browser->selection->map->dso ||
-                           browser->selection->map->dso->annotate_warned) {
+                           !map__dso(browser->selection->map) ||
+                           map__dso(browser->selection->map)->annotate_warned) {
                                continue;
                        }
 
 
 {
        int key;
 
-       if (ui_browser__show(&browser->b, browser->map->dso->long_name,
+       if (ui_browser__show(&browser->b, map__dso(browser->map)->long_name,
                             "Press ESC to exit, %s / to search",
                             verbose > 0 ? "" : "restart with -v to use") < 0)
                return -1;
 {
        struct map_browser mb = {
                .b = {
-                       .entries = &map->dso->symbols,
+                       .entries = &map__dso(map)->symbols,
                        .refresh = ui_browser__rb_tree_refresh,
                        .seek    = ui_browser__rb_tree_seek,
                        .write   = map_browser__write,
 
                                struct annotation_options *options,
                                struct hist_browser_timer *hbt)
 {
+       struct dso *dso = map__dso(ms->map);
        struct symbol *sym = ms->sym;
        GtkWidget *window;
        GtkWidget *notebook;
        GtkWidget *tab_label;
        int err;
 
-       if (ms->map->dso->annotate_warned)
+       if (dso->annotate_warned)
                return -1;
 
        err = symbol__annotate(ms, evsel, options, NULL);
        if (err) {
                char msg[BUFSIZ];
-               ms->map->dso->annotate_warned = true;
+               dso->annotate_warned = true;
                symbol__strerror_disassemble(ms, err, msg, sizeof(msg));
                ui__error("Couldn't annotate %s: %s\n", sym->name, msg);
                return -1;
 
 
 int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, size_t buflen)
 {
-       struct dso *dso = ms->map->dso;
+       struct dso *dso = map__dso(ms->map);
 
        BUG_ON(buflen == 0);
 
        struct map *map = args->ms.map;
        struct perf_bpil *info_linear;
        struct disassemble_info info;
-       struct dso *dso = map->dso;
+       struct dso *dso = map__dso(map);
        int pc = 0, count, sub_id;
        struct btf *btf = NULL;
        char tpath[PATH_MAX];
 {
        struct annotation_options *opts = args->options;
        struct map *map = args->ms.map;
-       struct dso *dso = map->dso;
+       struct dso *dso = map__dso(map);
        char *command;
        FILE *file;
        char symfs_filename[PATH_MAX];
 {
        struct map *map = ms->map;
        struct symbol *sym = ms->sym;
-       struct dso *dso = map->dso;
+       struct dso *dso = map__dso(map);
        char *filename;
        const char *d_filename;
        const char *evsel_name = evsel__name(evsel);
        }
 
        fprintf(fp, "%s() %s\nEvent: %s\n\n",
-               ms->sym->name, ms->map->dso->long_name, ev_name);
+               ms->sym->name, map__dso(ms->map)->long_name, ev_name);
        symbol__annotate_fprintf2(ms->sym, fp, opts);
 
        fclose(fp);
                if (percent_max <= 0.5)
                        continue;
 
-               al->path = get_srcline(map->dso, notes->start + al->offset, NULL,
+               al->path = get_srcline(map__dso(map), notes->start + al->offset, NULL,
                                       false, true, notes->start + al->offset);
                insert_source_line(&tmp_root, al, opts);
        }
 int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel,
                          struct annotation_options *opts)
 {
-       struct dso *dso = ms->map->dso;
+       struct dso *dso = map__dso(ms->map);
        struct symbol *sym = ms->sym;
        struct rb_root source_line = RB_ROOT;
        struct hists *hists = evsel__hists(evsel);
 int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel,
                         struct annotation_options *opts)
 {
-       struct dso *dso = ms->map->dso;
+       struct dso *dso = map__dso(ms->map);
        struct symbol *sym = ms->sym;
        struct rb_root source_line = RB_ROOT;
        int err;
 
        if (map__load(map) < 0)
                pr_err("File '%s' not found or has no symbols.\n", name);
 
-       dso = dso__get(map->dso);
+       dso = dso__get(map__dso(map));
 
        map__put(map);
 
 
        struct block_fmt *block_fmt = container_of(fmt, struct block_fmt, fmt);
        struct map *map = he->ms.map;
 
-       if (map && map->dso) {
+       if (map && map__dso(map)) {
                return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
-                                map->dso->short_name);
+                                map__dso(map)->short_name);
        }
 
        return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width,
 
                struct map *map = maps__find(machine__kernel_maps(machine), addr);
 
                if (map) {
-                       map->dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
-                       map->dso->bpf_prog.id = id;
-                       map->dso->bpf_prog.sub_id = i;
-                       map->dso->bpf_prog.env = env;
+                       struct dso *dso = map__dso(map);
+
+                       dso->binary_type = DSO_BINARY_TYPE__BPF_PROG_INFO;
+                       dso->bpf_prog.id = id;
+                       dso->bpf_prog.sub_id = i;
+                       dso->bpf_prog.env = env;
                }
        }
        return 0;
 
        }
 
        if (thread__find_map(thread, sample->cpumode, sample->ip, &al))
-               al.map->dso->hit = 1;
+               map__dso(al.map)->hit = 1;
 
        thread__put(thread);
        return 0;
 
 static enum match_result match_chain_dso_addresses(struct map *left_map, u64 left_ip,
                                                   struct map *right_map, u64 right_ip)
 {
-       struct dso *left_dso = left_map ? left_map->dso : NULL;
-       struct dso *right_dso = right_map ? right_map->dso : NULL;
+       struct dso *left_dso = left_map ? map__dso(left_map) : NULL;
+       struct dso *right_dso = right_map ? map__dso(right_map) : NULL;
 
        if (left_dso != right_dso)
                return left_dso < right_dso ? MATCH_LT : MATCH_GT;
        if (show_dso)
                scnprintf(bf + printed, bfsize - printed, " %s",
                          cl->ms.map ?
-                         cl->ms.map->dso->short_name :
+                         map__dso(cl->ms.map)->short_name :
                          "unknown");
 
        return bf;
 
        struct thread *thread;
        struct machine *machine;
        struct addr_location al;
+       struct dso *dso;
        struct cs_etm_traceid_queue *tidq;
 
        if (!etmq)
                thread = etmq->etm->unknown_thread;
        }
 
-       if (!thread__find_map(thread, cpumode, address, &al) || !al.map->dso)
+       dso = map__dso(al.map);
+
+       if (!thread__find_map(thread, cpumode, address, &al) || !dso)
                return 0;
 
-       if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
-           dso__data_status_seen(al.map->dso, DSO_DATA_STATUS_SEEN_ITRACE))
+       if (dso->data.status == DSO_DATA_STATUS_ERROR &&
+           dso__data_status_seen(dso, DSO_DATA_STATUS_SEEN_ITRACE))
                return 0;
 
        offset = al.map->map_ip(al.map, address);
 
        map__load(al.map);
 
-       len = dso__data_read_offset(al.map->dso, machine, offset, buffer, size);
+       len = dso__data_read_offset(dso, machine, offset, buffer, size);
 
        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 (!al.map->dso->auxtrace_warned) {
+               if (!dso->auxtrace_warned) {
                        pr_err("CS ETM Trace: Debug data not found for address %#"PRIx64" in %s\n",
                                    address,
-                                   al.map->dso->long_name ? al.map->dso->long_name : "Unknown");
-                       al.map->dso->auxtrace_warned = true;
+                                   dso->long_name ? dso->long_name : "Unknown");
+                       dso->auxtrace_warned = true;
                }
                return 0;
        }
 
        output_json_key_format(out, false, 5, "ip", "\"0x%" PRIx64 "\"", ip);
 
        if (al && al->sym && al->sym->namelen) {
+               struct dso *dso = al->map ? map__dso(al->map) : NULL;
+
                fputc(',', out);
                output_json_key_string(out, false, 5, "symbol", al->sym->name);
 
-               if (al->map && al->map->dso) {
-                       const char *dso = al->map->dso->short_name;
+               if (dso) {
+                       const char *dso_name = dso->short_name;
 
-                       if (dso && strlen(dso) > 0) {
+                       if (dso_name && strlen(dso_name) > 0) {
                                fputc(',', out);
-                               output_json_key_string(out, false, 5, "dso", dso);
+                               output_json_key_string(out, false, 5, "dso", dso_name);
                        }
                }
        }
 
        int err;
 
        if (al->map) {
-               struct dso *dso = al->map->dso;
+               struct dso *dso = map__dso(al->map);
 
                err = db_export__dso(dbe, dso, maps__machine(al->maps));
                if (err)
                al.addr = node->ip;
 
                if (al.map && !al.sym)
-                       al.sym = dso__find_symbol(al.map->dso, al.addr);
+                       al.sym = dso__find_symbol(map__dso(al.map), al.addr);
 
                db_ids_from_al(dbe, &al, &dso_db_id, &sym_db_id, &offset);
 
 
 
        d_al->size = sizeof(*d_al);
        if (al->map) {
-               struct dso *dso = al->map->dso;
+               struct dso *dso = map__dso(al->map);
 
                if (symbol_conf.show_kernel_path && dso->long_name)
                        d_al->dso = dso->long_name;
        unsigned int line = 0;
        char *srcfile = NULL;
        struct map *map;
+       struct dso *dso;
        u64 addr;
 
        if (!d->ctx_valid || !line_no)
 
        map = al->map;
        addr = al->addr;
+       dso = map ? map__dso(map) : NULL;
 
-       if (map && map->dso)
-               srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
+       if (dso)
+               srcfile = get_srcline_split(dso, map__rip_2objdump(map, addr), &line);
 
        *line_no = line;
        return srcfile;
        offset = map->map_ip(map, ip);
        if (ip + len >= map->end)
                len = map->end - ip;
-       return dso__data_read_offset(map->dso, d->machine, offset, buf, len);
+       return dso__data_read_offset(map__dso(map), d->machine, offset, buf, len);
 }
 
 static const struct perf_dlfilter_fns perf_dlfilter_fns = {
 
                     struct perf_sample *sample)
 {
        struct thread *thread;
+       struct dso *dso;
 
        if (symbol_conf.guest_code && !machine__is_host(machine))
                thread = machine__findnew_guest_code(machine, sample->pid);
 
        dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
        thread__find_map(thread, sample->cpumode, sample->ip, al);
+       dso = al->map ? map__dso(al->map) : NULL;
        dump_printf(" ...... dso: %s\n",
-                   al->map ? al->map->dso->long_name :
-                       al->level == 'H' ? "[hypervisor]" : "<not found>");
+               dso
+               ? dso->long_name
+               : (al->level == 'H' ? "[hypervisor]" : "<not found>"));
 
        if (thread__is_filtered(thread))
                al->filtered |= (1 << HIST_FILTER__THREAD);
        }
 
        if (al->map) {
-               struct dso *dso = al->map->dso;
-
                if (symbol_conf.dso_list &&
                    (!dso || !(strlist__has_entry(symbol_conf.dso_list,
                                                  dso->short_name) ||
 
 
                        if (print_ip) {
                                /* Show binary offset for userspace addr */
-                               if (map && !map->dso->kernel)
+                               if (map && !map__dso(map)->kernel)
                                        printed += fprintf(fp, "%c%16" PRIx64, s, addr);
                                else
                                        printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
 
                hists__set_col_len(hists, HISTC_THREAD, len + 8);
 
        if (h->ms.map) {
-               len = dso__name_len(h->ms.map->dso);
+               len = dso__name_len(map__dso(h->ms.map));
                hists__new_col_len(hists, HISTC_DSO, len);
        }
 
                                symlen += BITS_PER_LONG / 4 + 2 + 3;
                        hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
 
-                       symlen = dso__name_len(h->branch_info->from.ms.map->dso);
+                       symlen = dso__name_len(map__dso(h->branch_info->from.ms.map));
                        hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
                } else {
                        symlen = unresolved_col_width + 4 + 2;
                                symlen += BITS_PER_LONG / 4 + 2 + 3;
                        hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
 
-                       symlen = dso__name_len(h->branch_info->to.ms.map->dso);
+                       symlen = dso__name_len(map__dso(h->branch_info->to.ms.map));
                        hists__new_col_len(hists, HISTC_DSO_TO, symlen);
                } else {
                        symlen = unresolved_col_width + 4 + 2;
                }
 
                if (h->mem_info->daddr.ms.map) {
-                       symlen = dso__name_len(h->mem_info->daddr.ms.map->dso);
+                       symlen = dso__name_len(map__dso(h->mem_info->daddr.ms.map));
                        hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,
                                           symlen);
                } else {
                                       struct hist_entry *he)
 {
        if (hists->dso_filter != NULL &&
-           (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
+           (he->ms.map == NULL || map__dso(he->ms.map) != hists->dso_filter)) {
                he->filtered |= (1 << HIST_FILTER__DSO);
                return true;
        }
 
        }
 
        while (1) {
-               if (!thread__find_map(thread, cpumode, *ip, &al) || !al.map->dso) {
+               struct dso *dso;
+
+               if (!thread__find_map(thread, cpumode, *ip, &al) || !map__dso(al.map)) {
                        if (al.map)
                                intel_pt_log("ERROR: thread has no dso for %#" PRIx64 "\n", *ip);
                        else
                                intel_pt_log("ERROR: thread has no map for %#" PRIx64 "\n", *ip);
                        return -EINVAL;
                }
+               dso = map__dso(al.map);
 
-               if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
-                   dso__data_status_seen(al.map->dso,
-                                         DSO_DATA_STATUS_SEEN_ITRACE))
+               if (dso->data.status == DSO_DATA_STATUS_ERROR &&
+                   dso__data_status_seen(dso, DSO_DATA_STATUS_SEEN_ITRACE))
                        return -ENOENT;
 
                offset = al.map->map_ip(al.map, *ip);
                if (!to_ip && one_map) {
                        struct intel_pt_cache_entry *e;
 
-                       e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+                       e = intel_pt_cache_lookup(dso, machine, offset);
                        if (e &&
                            (!max_insn_cnt || e->insn_cnt <= max_insn_cnt)) {
                                *insn_cnt_ptr = e->insn_cnt;
                                intel_pt_insn->emulated_ptwrite = e->emulated_ptwrite;
                                intel_pt_insn->length = e->length;
                                intel_pt_insn->rel = e->rel;
-                               memcpy(intel_pt_insn->buf, e->insn,
-                                      INTEL_PT_INSN_BUF_SZ);
+                               memcpy(intel_pt_insn->buf, e->insn, INTEL_PT_INSN_BUF_SZ);
                                intel_pt_log_insn_no_data(intel_pt_insn, *ip);
                                return 0;
                        }
                /* Load maps to ensure dso->is_64_bit has been updated */
                map__load(al.map);
 
-               x86_64 = al.map->dso->is_64_bit;
+               x86_64 = dso->is_64_bit;
 
                while (1) {
-                       len = dso__data_read_offset(al.map->dso, machine,
+                       len = dso__data_read_offset(dso, machine,
                                                    offset, buf,
                                                    INTEL_PT_INSN_BUF_SZ);
                        if (len <= 0) {
                                intel_pt_log("ERROR: failed to read at offset %#" PRIx64 " ",
                                             offset);
                                if (intel_pt_enable_logging)
-                                       dso__fprintf(al.map->dso, intel_pt_log_fp());
+                                       dso__fprintf(dso, intel_pt_log_fp());
                                return -EINVAL;
                        }
 
                                        goto out;
                                /* Check for emulated ptwrite */
                                offs = offset + intel_pt_insn->length;
-                               eptw = intel_pt_emulated_ptwrite(al.map->dso, machine, offs);
+                               eptw = intel_pt_emulated_ptwrite(dso, machine, offs);
                                intel_pt_insn->emulated_ptwrite = eptw;
                                goto out;
                        }
        if (to_ip) {
                struct intel_pt_cache_entry *e;
 
-               e = intel_pt_cache_lookup(al.map->dso, machine, start_offset);
+               e = intel_pt_cache_lookup(map__dso(al.map), machine, start_offset);
                if (e)
                        return 0;
        }
 
        /* Ignore cache errors */
-       intel_pt_cache_add(al.map->dso, machine, start_offset, insn_cnt,
+       intel_pt_cache_add(map__dso(al.map), machine, start_offset, insn_cnt,
                           *ip - start_ip, intel_pt_insn);
 
        return 0;
        if (!thread)
                return -EINVAL;
 
-       if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso)
+       if (!thread__find_map(thread, cpumode, ip, &al) || !map__dso(al.map))
                return -EINVAL;
 
        offset = al.map->map_ip(al.map, ip);
 
-       return intel_pt_match_pgd_ip(ptq->pt, ip, offset,
-                                    al.map->dso->long_name);
+       return intel_pt_match_pgd_ip(ptq->pt, ip, offset, map__dso(al.map)->long_name);
 }
 
 static bool intel_pt_pgd_ip(uint64_t ip, void *data)
        if (map__load(map))
                return 0;
 
-       start = dso__first_symbol(map->dso);
+       start = dso__first_symbol(map__dso(map));
 
        for (sym = start; sym; sym = dso__next_symbol(sym)) {
                if (sym->binding == STB_GLOBAL &&
                return 0;
 
        for (; cnt; cnt--, addr--) {
+               struct dso *dso;
+
                if (intel_pt_find_map(thread, cpumode, addr, &al)) {
                        if (addr < event->text_poke.addr)
                                return 0;
                        continue;
                }
 
-               if (!al.map->dso || !al.map->dso->auxtrace_cache)
+               dso = map__dso(al.map);
+               if (!dso || !dso->auxtrace_cache)
                        continue;
 
                offset = al.map->map_ip(al.map, addr);
 
-               e = intel_pt_cache_lookup(al.map->dso, machine, offset);
+               e = intel_pt_cache_lookup(dso, machine, offset);
                if (!e)
                        continue;
 
                        if (e->branch != INTEL_PT_BR_NO_BRANCH)
                                return 0;
                } else {
-                       intel_pt_cache_invalidate(al.map->dso, machine, offset);
+                       intel_pt_cache_invalidate(dso, machine, offset);
                        intel_pt_log("Invalidated instruction cache for %s at %#"PRIx64"\n",
-                                    al.map->dso->long_name, addr);
+                                    dso->long_name, addr);
                }
        }
 
 
 
 static struct dso *machine__kernel_dso(struct machine *machine)
 {
-       return machine->vmlinux_map->dso;
+       return map__dso(machine->vmlinux_map);
 }
 
 static void dsos__init(struct dsos *dsos)
                                             struct perf_sample *sample __maybe_unused)
 {
        struct symbol *sym;
+       struct dso *dso;
        struct map *map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
 
        if (!map) {
-               struct dso *dso = dso__new(event->ksymbol.name);
                int err;
 
+               dso = dso__new(event->ksymbol.name);
                if (dso) {
                        dso->kernel = DSO_SPACE__KERNEL;
                        map = map__new2(0, dso);
                }
 
                if (event->ksymbol.ksym_type == PERF_RECORD_KSYMBOL_TYPE_OOL) {
-                       map->dso->binary_type = DSO_BINARY_TYPE__OOL;
-                       map->dso->data.file_size = event->ksymbol.len;
-                       dso__set_loaded(map->dso);
+                       dso->binary_type = DSO_BINARY_TYPE__OOL;
+                       dso->data.file_size = event->ksymbol.len;
+                       dso__set_loaded(dso);
                }
 
                map->start = event->ksymbol.addr;
                        dso->binary_type = DSO_BINARY_TYPE__BPF_IMAGE;
                        dso__set_long_name(dso, "", false);
                }
+       } else {
+               dso = map__dso(map);
        }
 
        sym = symbol__new(map->map_ip(map, map->start),
                          0, 0, event->ksymbol.name);
        if (!sym)
                return -ENOMEM;
-       dso__insert_symbol(map->dso, sym);
+       dso__insert_symbol(dso, sym);
        return 0;
 }
 
        if (map != machine->vmlinux_map)
                maps__remove(machine__kernel_maps(machine), map);
        else {
-               sym = dso__find_symbol(map->dso, map->map_ip(map, map->start));
+               struct dso *dso = map__dso(map);
+
+               sym = dso__find_symbol(dso, map->map_ip(map, map->start));
                if (sym)
-                       dso__delete_symbol(map->dso, sym);
+                       dso__delete_symbol(dso, sym);
        }
 
        return 0;
 {
        struct map *map = maps__find(machine__kernel_maps(machine), event->text_poke.addr);
        u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
+       struct dso *dso = map ? map__dso(map) : NULL;
 
        if (dump_trace)
                perf_event__fprintf_text_poke(event, machine, stdout);
                return 0;
        }
 
-       if (map && map->dso) {
+       if (dso) {
                u8 *new_bytes = event->text_poke.bytes + event->text_poke.old_len;
                int ret;
 
                 * must be done prior to using kernel maps.
                 */
                map__load(map);
-               ret = dso__data_write_cache_addr(map->dso, map, machine,
+               ret = dso__data_write_cache_addr(dso, map, machine,
                                                 event->text_poke.addr,
                                                 new_bytes,
                                                 event->text_poke.new_len);
 int machine__load_kallsyms(struct machine *machine, const char *filename)
 {
        struct map *map = machine__kernel_map(machine);
-       int ret = __dso__load_kallsyms(map->dso, filename, map, true);
+       struct dso *dso = map__dso(map);
+       int ret = __dso__load_kallsyms(dso, filename, map, true);
 
        if (ret > 0) {
-               dso__set_loaded(map->dso);
+               dso__set_loaded(dso);
                /*
                 * Since /proc/kallsyms will have multiple sessions for the
                 * kernel, with modules between them, fixup the end of all
 int machine__load_vmlinux_path(struct machine *machine)
 {
        struct map *map = machine__kernel_map(machine);
-       int ret = dso__load_vmlinux_path(map->dso, map);
+       struct dso *dso = map__dso(map);
+       int ret = dso__load_vmlinux_path(dso, map);
 
        if (ret > 0)
-               dso__set_loaded(map->dso);
+               dso__set_loaded(dso);
 
        return ret;
 }
 static int maps__set_module_path(struct maps *maps, const char *path, struct kmod_path *m)
 {
        char *long_name;
+       struct dso *dso;
        struct map *map = maps__find_by_name(maps, m->name);
 
        if (map == NULL)
        if (long_name == NULL)
                return -ENOMEM;
 
-       dso__set_long_name(map->dso, long_name, true);
-       dso__kernel_module_get_build_id(map->dso, "");
+       dso = map__dso(map);
+       dso__set_long_name(dso, long_name, true);
+       dso__kernel_module_get_build_id(dso, "");
 
        /*
         * Full name could reveal us kmod compression, so
         * we need to update the symtab_type if needed.
         */
-       if (m->comp && is_kmod_dso(map->dso)) {
-               map->dso->symtab_type++;
-               map->dso->comp = m->comp;
+       if (m->comp && is_kmod_dso(dso)) {
+               dso->symtab_type++;
+               dso->comp = m->comp;
        }
 
        return 0;
                return -1;
        map->end = start + size;
 
-       dso__kernel_module_get_build_id(map->dso, machine->root_dir);
+       dso__kernel_module_get_build_id(map__dso(map), machine->root_dir);
 
        return 0;
 }
                map->end = map->start + xm->end - xm->start;
 
                if (build_id__is_defined(bid))
-                       dso__set_build_id(map->dso, bid);
+                       dso__set_build_id(map__dso(map), bid);
 
        } else if (is_kernel_mmap) {
                const char *symbol_name = xm->name + strlen(mmap_name);
 {
        struct map *map = ms->map;
        char *srcline = NULL;
+       struct dso *dso;
 
        if (!map || callchain_param.key == CCKEY_FUNCTION)
                return srcline;
 
-       srcline = srcline__tree_find(&map->dso->srclines, ip);
+       dso = map__dso(map);
+       srcline = srcline__tree_find(&dso->srclines, ip);
        if (!srcline) {
                bool show_sym = false;
                bool show_addr = callchain_param.key == CCKEY_ADDRESS;
 
-               srcline = get_srcline(map->dso, map__rip_2objdump(map, ip),
+               srcline = get_srcline(dso, map__rip_2objdump(map, ip),
                                      ms->sym, show_sym, show_addr, ip);
-               srcline__tree_insert(&map->dso->srclines, ip, srcline);
+               srcline__tree_insert(&dso->srclines, ip, srcline);
        }
 
        return srcline;
        struct map *map = ms->map;
        struct inline_node *inline_node;
        struct inline_list *ilist;
+       struct dso *dso;
        u64 addr;
        int ret = 1;
 
 
        addr = map__map_ip(map, ip);
        addr = map__rip_2objdump(map, addr);
+       dso = map__dso(map);
 
-       inline_node = inlines__tree_find(&map->dso->inlined_nodes, addr);
+       inline_node = inlines__tree_find(&dso->inlined_nodes, addr);
        if (!inline_node) {
-               inline_node = dso__parse_addr_inlines(map->dso, addr, sym);
+               inline_node = dso__parse_addr_inlines(dso, addr, sym);
                if (!inline_node)
                        return ret;
-               inlines__tree_insert(&map->dso->inlined_nodes, inline_node);
+               inlines__tree_insert(&dso->inlined_nodes, inline_node);
        }
 
        list_for_each_entry(ilist, &inline_node->val, list) {
        if (sym == NULL)
                return NULL;
 
-       *modp = __map__is_kmodule(map) ? (char *)map->dso->short_name : NULL;
+       *modp = __map__is_kmodule(map) ? (char *)map__dso(map)->short_name : NULL;
        *addrp = map->unmap_ip(map, sym->start);
        return sym->name;
 }
 
 
 bool __map__is_kernel(const struct map *map)
 {
-       if (!map->dso->kernel)
+       if (!map__dso(map)->kernel)
                return false;
        return machine__kernel_map(maps__machine(map__kmaps((struct map *)map))) == map;
 }
 bool __map__is_bpf_prog(const struct map *map)
 {
        const char *name;
+       struct dso *dso = map__dso(map);
 
-       if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
+       if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
                return true;
 
        /*
         * type of DSO_BINARY_TYPE__BPF_PROG_INFO. In such cases, we can
         * guess the type based on name.
         */
-       name = map->dso->short_name;
+       name = dso->short_name;
        return name && (strstr(name, "bpf_prog_") == name);
 }
 
 bool __map__is_bpf_image(const struct map *map)
 {
        const char *name;
+       struct dso *dso = map__dso(map);
 
-       if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
+       if (dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
                return true;
 
        /*
         * type of DSO_BINARY_TYPE__BPF_IMAGE. In such cases, we can
         * guess the type based on name.
         */
-       name = map->dso->short_name;
+       name = dso->short_name;
        return name && is_bpf_image(name);
 }
 
 bool __map__is_ool(const struct map *map)
 {
-       return map->dso && map->dso->binary_type == DSO_BINARY_TYPE__OOL;
+       const struct dso *dso = map__dso(map);
+
+       return dso && dso->binary_type == DSO_BINARY_TYPE__OOL;
 }
 
 bool map__has_symbols(const struct map *map)
 {
-       return dso__has_symbols(map->dso);
+       return dso__has_symbols(map__dso(map));
 }
 
 static void map__exit(struct map *map)
 
 void map__fixup_start(struct map *map)
 {
-       struct rb_root_cached *symbols = &map->dso->symbols;
+       struct dso *dso = map__dso(map);
+       struct rb_root_cached *symbols = &dso->symbols;
        struct rb_node *nd = rb_first_cached(symbols);
+
        if (nd != NULL) {
                struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
+
                map->start = sym->start;
        }
 }
 
 void map__fixup_end(struct map *map)
 {
-       struct rb_root_cached *symbols = &map->dso->symbols;
+       struct dso *dso = map__dso(map);
+       struct rb_root_cached *symbols = &dso->symbols;
        struct rb_node *nd = rb_last(&symbols->rb_root);
+
        if (nd != NULL) {
                struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
                map->end = sym->end;
 
 int map__load(struct map *map)
 {
-       const char *name = map->dso->long_name;
+       struct dso *dso = map__dso(map);
+       const char *name = dso->long_name;
        int nr;
 
-       if (dso__loaded(map->dso))
+       if (dso__loaded(dso))
                return 0;
 
-       nr = dso__load(map->dso, map);
+       nr = dso__load(dso, map);
        if (nr < 0) {
-               if (map->dso->has_build_id) {
+               if (dso->has_build_id) {
                        char sbuild_id[SBUILD_ID_SIZE];
 
-                       build_id__sprintf(&map->dso->bid, sbuild_id);
+                       build_id__sprintf(&dso->bid, sbuild_id);
                        pr_debug("%s with build id %s not found", name, sbuild_id);
                } else
                        pr_debug("Failed to open %s", name);
        if (map__load(map) < 0)
                return NULL;
 
-       return dso__find_symbol(map->dso, addr);
+       return dso__find_symbol(map__dso(map), addr);
 }
 
 struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
 {
+       struct dso *dso;
+
        if (map__load(map) < 0)
                return NULL;
 
-       if (!dso__sorted_by_name(map->dso))
-               dso__sort_by_name(map->dso);
+       dso = map__dso(map);
+       if (!dso__sorted_by_name(dso))
+               dso__sort_by_name(dso);
 
-       return dso__find_symbol_by_name(map->dso, name);
+       return dso__find_symbol_by_name(dso, name);
 }
 
 struct map *map__clone(struct map *from)
 {
        size_t size = sizeof(struct map);
        struct map *map;
+       struct dso *dso = map__dso(from);
 
-       if (from->dso && from->dso->kernel)
+       if (dso && dso->kernel)
                size += sizeof(struct kmap);
 
        map = memdup(from, size);
        if (map != NULL) {
                refcount_set(&map->refcnt, 1);
-               dso__get(map->dso);
+               dso__get(dso);
        }
 
        return map;
 
 size_t map__fprintf(struct map *map, FILE *fp)
 {
+       const struct dso *dso = map__dso(map);
+
        return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n",
-                      map->start, map->end, map->pgoff, map->dso->name);
+                      map->start, map->end, map->pgoff, dso->name);
 }
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 {
        char buf[symbol_conf.pad_output_len_dso + 1];
        const char *dsoname = "[unknown]";
+       const struct dso *dso = map ? map__dso(map) : NULL;
 
-       if (map && map->dso) {
-               if (symbol_conf.show_kernel_path && map->dso->long_name)
-                       dsoname = map->dso->long_name;
+       if (dso) {
+               if (symbol_conf.show_kernel_path && dso->long_name)
+                       dsoname = dso->long_name;
                else
-                       dsoname = map->dso->name;
+                       dsoname = dso->name;
        }
 
        if (symbol_conf.pad_output_len_dso) {
 {
        if (map == NULL)
                return SRCLINE_UNKNOWN;
-       return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
+
+       return get_srcline(map__dso(map), map__rip_2objdump(map, addr), sym, true, true, addr);
 }
 
 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
                         FILE *fp)
 {
+       const struct dso *dso = map ? map__dso(map) : NULL;
        int ret = 0;
 
-       if (map && map->dso) {
+       if (dso) {
                char *srcline = map__srcline(map, addr, NULL);
                if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)
                        ret = fprintf(fp, "%s%s", prefix, srcline);
 u64 map__rip_2objdump(struct map *map, u64 rip)
 {
        struct kmap *kmap = __map__kmap(map);
+       const struct dso *dso = map__dso(map);
 
        /*
         * vmlinux does not have program headers for PTI entry trampolines and
                }
        }
 
-       if (!map->dso->adjust_symbols)
+       if (!dso->adjust_symbols)
                return rip;
 
-       if (map->dso->rel)
+       if (dso->rel)
                return rip - map->pgoff;
 
        /*
         * kernel modules also have DSO_TYPE_USER in dso->kernel,
         * but all kernel modules are ET_REL, so won't get here.
         */
-       if (map->dso->kernel == DSO_SPACE__USER)
-               return rip + map->dso->text_offset;
+       if (dso->kernel == DSO_SPACE__USER)
+               return rip + dso->text_offset;
 
        return map->unmap_ip(map, rip) - map->reloc;
 }
  */
 u64 map__objdump_2mem(struct map *map, u64 ip)
 {
-       if (!map->dso->adjust_symbols)
+       const struct dso *dso = map__dso(map);
+
+       if (!dso->adjust_symbols)
                return map->unmap_ip(map, ip);
 
-       if (map->dso->rel)
+       if (dso->rel)
                return map->unmap_ip(map, ip + map->pgoff);
 
        /*
         * kernel modules also have DSO_TYPE_USER in dso->kernel,
         * but all kernel modules are ET_REL, so won't get here.
         */
-       if (map->dso->kernel == DSO_SPACE__USER)
-               return map->unmap_ip(map, ip - map->dso->text_offset);
+       if (dso->kernel == DSO_SPACE__USER)
+               return map->unmap_ip(map, ip - dso->text_offset);
 
        return ip + map->reloc;
 }
 
 struct kmap *__map__kmap(struct map *map)
 {
-       if (!map->dso || !map->dso->kernel)
+       const struct dso *dso = map__dso(map);
+
+       if (!dso || !dso->kernel)
                return NULL;
        return (struct kmap *)(map + 1);
 }
 
 /* Returns ip */
 u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip);
 
+static inline struct dso *map__dso(const struct map *map)
+{
+       return map->dso;
+}
+
 static inline size_t map__size(const struct map *map)
 {
        return map->end - map->start;
  * Note: caller must ensure map->dso is not NULL (map is loaded).
  */
 #define map__for_each_symbol(map, pos, n)      \
-       dso__for_each_symbol(map->dso, pos, n)
+       dso__for_each_symbol(map__dso(map), pos, n)
 
 /* map__for_each_symbol_with_name - iterate over the symbols in the given map
  *                                  that have the given name
 
 int maps__insert(struct maps *maps, struct map *map)
 {
        int err;
+       const struct dso *dso = map__dso(map);
 
        down_write(maps__lock(maps));
        err = __maps__insert(maps, map);
 
        ++maps->nr_maps;
 
-       if (map->dso && map->dso->kernel) {
+       if (dso && dso->kernel) {
                struct kmap *kmap = map__kmap(map);
 
                if (kmap)
                printed += fprintf(fp, "Map:");
                printed += map__fprintf(pos->map, fp);
                if (verbose > 2) {
-                       printed += dso__fprintf(pos->map->dso, fp);
+                       printed += dso__fprintf(map__dso(pos->map), fp);
                        printed += fprintf(fp, "--\n");
                }
        }
 
                        if (use_browser) {
                                pr_debug("overlapping maps in %s (disable tui for more info)\n",
-                                          map->dso->name);
+                                        map__dso(map)->name);
                        } else {
                                fputs("overlapping maps:\n", fp);
                                map__fprintf(map, fp);
 
 
        maps__for_each_entry(maps, pos) {
                /* short_name is "[module]" */
-               const char *short_name = pos->map->dso->short_name;
-               u16 short_name_len =  pos->map->dso->short_name_len;
+               struct dso *dso = map__dso(pos->map);
+               const char *short_name = dso->short_name;
+               u16 short_name_len =  dso->short_name_len;
 
                if (strncmp(short_name + 1, module,
                            short_name_len - 2) == 0 &&
        /* Init maps of given executable or kernel */
        if (user) {
                struct map *map;
+               struct dso *dso;
 
                map = dso__new_map(target);
-               if (map && map->dso) {
-                       mutex_lock(&map->dso->lock);
-                       nsinfo__put(map->dso->nsinfo);
-                       map->dso->nsinfo = nsinfo__get(nsi);
-                       mutex_unlock(&map->dso->lock);
+               dso = map ? map__dso(map) : NULL;
+               if (dso) {
+                       mutex_lock(&dso->lock);
+                       nsinfo__put(dso->nsinfo);
+                       dso->nsinfo = nsinfo__get(nsi);
+                       mutex_unlock(&dso->lock);
                }
                return map;
        } else {
                snprintf(module_name, sizeof(module_name), "[%s]", module);
                map = maps__find_by_name(machine__kernel_maps(host_machine), module_name);
                if (map) {
-                       dso = map->dso;
+                       dso = map__dso(map);
                        goto found;
                }
                pr_debug("Failed to find module %s.\n", module);
        }
 
        map = machine__kernel_map(host_machine);
-       dso = map->dso;
+       dso = map__dso(map);
        if (!dso->has_build_id)
                dso__read_running_kernel_build_id(dso, host_machine);
 
 {
         struct rb_node *nd;
        struct map *map;
+       struct dso *dso;
        int ret;
 
        ret = init_probe_symbol_maps(user);
                               (target) ? : "kernel");
                goto end;
        }
-       if (!dso__sorted_by_name(map->dso))
-               dso__sort_by_name(map->dso);
+       dso = map__dso(map);
+       if (!dso__sorted_by_name(dso))
+               dso__sort_by_name(dso);
 
        /* Show all (filtered) symbols */
        setup_pager();
 
-       for (nd = rb_first_cached(&map->dso->symbol_names); nd;
-            nd = rb_next(nd)) {
+       for (nd = rb_first_cached(&dso->symbol_names); nd; nd = rb_next(nd)) {
                struct symbol_name_rb_node *pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
 
                if (strfilter__compare(_filter, pos->sym.name))
 
 
                if (node->ms.map) {
                        struct map *map = node->ms.map;
+                       struct dso *dso = map ? map__dso(map) : NULL;
                        const char *dsoname = "[unknown]";
-                       if (map && map->dso) {
-                               if (symbol_conf.show_kernel_path && map->dso->long_name)
-                                       dsoname = map->dso->long_name;
+
+                       if (dso) {
+                               if (symbol_conf.show_kernel_path && dso->long_name)
+                                       dsoname = dso->long_name;
                                else
-                                       dsoname = map->dso->name;
+                                       dsoname = dso->name;
                        }
                        if (!hv_stores(elem, "dso", newSVpv(dsoname,0))) {
                                hv_undef(elem);
 
 static const char *get_dsoname(struct map *map)
 {
        const char *dsoname = "[unknown]";
+       struct dso *dso = map ? map__dso(map) : NULL;
 
-       if (map && map->dso) {
-               if (symbol_conf.show_kernel_path && map->dso->long_name)
-                       dsoname = map->dso->long_name;
+       if (dso) {
+               if (symbol_conf.show_kernel_path && dso->long_name)
+                       dsoname = dso->long_name;
                else
-                       dsoname = map->dso->name;
+                       dsoname = dso->name;
        }
 
        return dsoname;
        char sbuild_id[SBUILD_ID_SIZE];
 
        if (al->map) {
-               pydict_set_item_string_decref(dict, dso_field,
-                       _PyUnicode_FromString(al->map->dso->name));
-               build_id__sprintf(&al->map->dso->bid, sbuild_id);
+               struct dso *dso = map__dso(al->map);
+
+               pydict_set_item_string_decref(dict, dso_field, _PyUnicode_FromString(dso->name));
+               build_id__sprintf(&dso->bid, sbuild_id);
                pydict_set_item_string_decref(dict, dso_bid_field,
                        _PyUnicode_FromString(sbuild_id));
                pydict_set_item_string_decref(dict, dso_map_start,
 
 
 static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r)
 {
-       struct dso *dso_l = map_l ? map_l->dso : NULL;
-       struct dso *dso_r = map_r ? map_r->dso : NULL;
+       struct dso *dso_l = map_l ? map__dso(map_l) : NULL;
+       struct dso *dso_r = map_r ? map__dso(map_r) : NULL;
        const char *dso_name_l, *dso_name_r;
 
        if (!dso_l || !dso_r)
 static int _hist_entry__dso_snprintf(struct map *map, char *bf,
                                     size_t size, unsigned int width)
 {
-       if (map && map->dso) {
-               const char *dso_name = verbose > 0 ? map->dso->long_name :
-                       map->dso->short_name;
-               return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name);
-       }
+       const struct dso *dso = map ? map__dso(map) : NULL;
+       const char *dso_name = "[unknown]";
+
+       if (dso)
+               dso_name = verbose > 0 ? dso->long_name : dso->short_name;
 
-       return repsep_snprintf(bf, size, "%-*.*s", width, width, "[unknown]");
+       return repsep_snprintf(bf, size, "%-*.*s", width, width, dso_name);
 }
 
 static int hist_entry__dso_snprintf(struct hist_entry *he, char *bf,
        if (type != HIST_FILTER__DSO)
                return -1;
 
-       return dso && (!he->ms.map || he->ms.map->dso != dso);
+       return dso && (!he->ms.map || map__dso(he->ms.map) != dso);
 }
 
 struct sort_entry sort_dso = {
        size_t ret = 0;
 
        if (verbose > 0) {
-               char o = map ? dso__symtab_origin(map->dso) : '!';
+               struct dso *dso = map ? map__dso(map) : NULL;
+               char o = dso ? dso__symtab_origin(dso) : '!';
                u64 rip = ip;
 
-               if (map && map->dso && map->dso->kernel
-                   && map->dso->adjust_symbols)
+               if (dso && dso->kernel && dso->adjust_symbols)
                        rip = map->unmap_ip(map, ip);
 
                ret += repsep_snprintf(bf, size, "%-#*llx %c ",
        if (!map)
                return no_srcfile;
 
-       sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip),
+       sf = __get_srcline(map__dso(map), map__rip_2objdump(map, e->ip),
                         e->ms.sym, false, true, true, e->ip);
        if (!strcmp(sf, SRCLINE_UNKNOWN))
                return no_srcfile;
                return -1;
 
        return dso && (!he->branch_info || !he->branch_info->from.ms.map ||
-                      he->branch_info->from.ms.map->dso != dso);
+               map__dso(he->branch_info->from.ms.map) != dso);
 }
 
 static int64_t
                return -1;
 
        return dso && (!he->branch_info || !he->branch_info->to.ms.map ||
-                      he->branch_info->to.ms.map->dso != dso);
+               map__dso(he->branch_info->to.ms.map) != dso);
 }
 
 static int64_t
 {
        u64 l, r;
        struct map *l_map, *r_map;
+       struct dso *l_dso, *r_dso;
        int rc;
 
        if (!left->mem_info)  return -1;
        if (!l_map) return -1;
        if (!r_map) return 1;
 
-       rc = dso__cmp_id(l_map->dso, r_map->dso);
+       l_dso = map__dso(l_map);
+       r_dso = map__dso(r_map);
+       rc = dso__cmp_id(l_dso, r_dso);
        if (rc)
                return rc;
        /*
         */
 
        if ((left->cpumode != PERF_RECORD_MISC_KERNEL) &&
-           (!(l_map->flags & MAP_SHARED)) &&
-           !l_map->dso->id.maj && !l_map->dso->id.min &&
-           !l_map->dso->id.ino && !l_map->dso->id.ino_generation) {
+           (!(l_map->flags & MAP_SHARED)) && !l_dso->id.maj && !l_dso->id.min &&
+           !l_dso->id.ino && !l_dso->id.ino_generation) {
                /* userspace anonymous */
 
                if (left->thread->pid_ > right->thread->pid_) return -1;
 
        if (he->mem_info) {
                struct map *map = he->mem_info->daddr.ms.map;
+               struct dso *dso = map__dso(map);
 
                addr = cl_address(he->mem_info->daddr.al_addr, chk_double_cl);
                ms = &he->mem_info->daddr.ms;
                if ((he->cpumode != PERF_RECORD_MISC_KERNEL) &&
                     map && !(map->prot & PROT_EXEC) &&
                    (map->flags & MAP_SHARED) &&
-                   (map->dso->id.maj || map->dso->id.min ||
-                    map->dso->id.ino || map->dso->id.ino_generation))
+                   (dso->id.maj || dso->id.min || dso->id.ino || dso->id.ino_generation))
                        level = 's';
                else if (!map)
                        level = 'X';
 static int _hist_entry__dso_size_snprintf(struct map *map, char *bf,
                                          size_t bf_size, unsigned int width)
 {
-       if (map && map->dso)
-               return repsep_snprintf(bf, bf_size, "%*d", width,
-                                      map__size(map));
+       if (map && map__dso(map))
+               return repsep_snprintf(bf, bf_size, "%*d", width, map__size(map));
 
        return repsep_snprintf(bf, bf_size, "%*s", width, "unknown");
 }
 
                *curr_mapp = curr_map;
                *curr_dsop = curr_dso;
        } else
-               *curr_dsop = curr_map->dso;
+               *curr_dsop = map__dso(curr_map);
 
        return 0;
 }
 
        *root = RB_ROOT_CACHED;
 
        while (next) {
+               struct dso *curr_map_dso;
                char *module;
 
                pos = rb_entry(next, struct symbol, rb_node);
                        symbol__delete(pos);
                        continue;
                }
-
+               curr_map_dso = map__dso(curr_map);
                pos->start -= curr_map->start - curr_map->pgoff;
                if (pos->end > curr_map->end)
                        pos->end = curr_map->end;
                if (pos->end)
                        pos->end -= curr_map->start - curr_map->pgoff;
-               symbols__insert(&curr_map->dso->symbols, pos);
+               symbols__insert(&curr_map_dso->symbols, pos);
                ++count;
        }
 
 
                module = strchr(pos->name, '\t');
                if (module) {
+                       struct dso *curr_map_dso;
+
                        if (!symbol_conf.use_modules)
                                goto discard_symbol;
 
                        *module++ = '\0';
-
-                       if (strcmp(curr_map->dso->short_name, module)) {
+                       curr_map_dso = map__dso(curr_map);
+                       if (strcmp(curr_map_dso->short_name, module)) {
                                if (curr_map != initial_map &&
                                    dso->kernel == DSO_SPACE__KERNEL_GUEST &&
                                    machine__is_default_guest(machine)) {
                                         * symbols are in its kmap. Mark it as
                                         * loaded.
                                         */
-                                       dso__set_loaded(curr_map->dso);
+                                       dso__set_loaded(curr_map_dso);
                                }
 
                                curr_map = maps__find_by_name(kmaps, module);
                                        curr_map = initial_map;
                                        goto discard_symbol;
                                }
-
-                               if (curr_map->dso->loaded &&
+                               curr_map_dso = map__dso(curr_map);
+                               if (curr_map_dso->loaded &&
                                    !machine__is_default_guest(machine))
                                        goto discard_symbol;
                        }
                }
 add_symbol:
                if (curr_map != initial_map) {
+                       struct dso *curr_map_dso = map__dso(curr_map);
+
                        rb_erase_cached(&pos->rb_node, root);
-                       symbols__insert(&curr_map->dso->symbols, pos);
+                       symbols__insert(&curr_map_dso->symbols, pos);
                        ++moved;
                } else
                        ++count;
        if (curr_map != initial_map &&
            dso->kernel == DSO_SPACE__KERNEL_GUEST &&
            machine__is_default_guest(maps__machine(kmaps))) {
-               dso__set_loaded(curr_map->dso);
+               dso__set_loaded(map__dso(curr_map));
        }
 
        return count + moved;
        maps__for_each_entry(kmaps, old_node) {
                struct map *old_map = old_node->map;
                struct module_info *mi;
+               struct dso *dso;
 
                if (!__map__is_kmodule(old_map)) {
                        continue;
                }
-
+               dso = map__dso(old_map);
                /* Module must be in memory at the same address */
-               mi = find_module(old_map->dso->short_name, &modules);
+               mi = find_module(dso->short_name, &modules);
                if (!mi || mi->start != old_map->start) {
                        err = -EINVAL;
                        goto out;
 
 static int map__strcmp(const void *a, const void *b)
 {
-       const struct map *ma = *(const struct map **)a, *mb = *(const struct map **)b;
-       return strcmp(ma->dso->short_name, mb->dso->short_name);
+       const struct dso *dso_a = map__dso(*(const struct map **)a);
+       const struct dso *dso_b = map__dso(*(const struct map **)b);
+
+       return strcmp(dso_a->short_name, dso_b->short_name);
 }
 
 static int map__strcmp_name(const void *name, const void *b)
 {
-       const struct map *map = *(const struct map **)b;
-       return strcmp(name, map->dso->short_name);
+       const struct dso *dso = map__dso(*(const struct map **)b);
+
+       return strcmp(name, dso->short_name);
 }
 
 void __maps__sort_by_name(struct maps *maps)
 
        down_read(maps__lock(maps));
 
-       if (maps->last_search_by_name &&
-           strcmp(maps->last_search_by_name->dso->short_name, name) == 0) {
-               map = maps->last_search_by_name;
-               goto out_unlock;
+       if (maps->last_search_by_name) {
+               const struct dso *dso = map__dso(maps->last_search_by_name);
+
+               if (strcmp(dso->short_name, name) == 0) {
+                       map = maps->last_search_by_name;
+                       goto out_unlock;
+               }
        }
        /*
         * If we have maps->maps_by_name, then the name isn't in the rbtree,
 
        /* Fallback to traversing the rbtree... */
        maps__for_each_entry(maps, rb_node) {
+               struct dso *dso;
+
                map = rb_node->map;
-               if (strcmp(map->dso->short_name, name) == 0) {
+               dso = map__dso(map);
+               if (strcmp(dso->short_name, name) == 0) {
                        maps->last_search_by_name = map;
                        goto out_unlock;
                }
 
 
        maps__for_each_entry(maps, pos) {
                struct map *map = pos->map;
+               struct dso *dso;
 
                if (!__map__is_kmodule(map))
                        continue;
 
+               dso = map__dso(map);
                if (symbol_conf.buildid_mmap2) {
-                       size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+                       size = PERF_ALIGN(dso->long_name_len + 1, sizeof(u64));
                        event->mmap2.header.type = PERF_RECORD_MMAP2;
                        event->mmap2.header.size = (sizeof(event->mmap2) -
                                                (sizeof(event->mmap2.filename) - size));
                        event->mmap2.len   = map->end - map->start;
                        event->mmap2.pid   = machine->pid;
 
-                       memcpy(event->mmap2.filename, map->dso->long_name,
-                              map->dso->long_name_len + 1);
+                       memcpy(event->mmap2.filename, dso->long_name, dso->long_name_len + 1);
 
                        perf_record_mmap2__read_build_id(&event->mmap2, machine, false);
                } else {
-                       size = PERF_ALIGN(map->dso->long_name_len + 1, sizeof(u64));
+                       size = PERF_ALIGN(dso->long_name_len + 1, sizeof(u64));
                        event->mmap.header.type = PERF_RECORD_MMAP;
                        event->mmap.header.size = (sizeof(event->mmap) -
                                                (sizeof(event->mmap.filename) - size));
                        event->mmap.len   = map->end - map->start;
                        event->mmap.pid   = machine->pid;
 
-                       memcpy(event->mmap.filename, map->dso->long_name,
-                              map->dso->long_name_len + 1);
+                       memcpy(event->mmap.filename, dso->long_name, dso->long_name_len + 1);
                }
 
                if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
 
 int thread__memcpy(struct thread *thread, struct machine *machine,
                   void *buf, u64 ip, int len, bool *is64bit)
 {
-       u8 cpumode = PERF_RECORD_MISC_USER;
-       struct addr_location al;
-       long offset;
+       u8 cpumode = PERF_RECORD_MISC_USER;
+       struct addr_location al;
+       struct dso *dso;
+       long offset;
 
-       if (machine__kernel_ip(machine, ip))
-               cpumode = PERF_RECORD_MISC_KERNEL;
+       if (machine__kernel_ip(machine, ip))
+               cpumode = PERF_RECORD_MISC_KERNEL;
 
-       if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso ||
-          al.map->dso->data.status == DSO_DATA_STATUS_ERROR ||
-          map__load(al.map) < 0)
-               return -1;
+       if (!thread__find_map(thread, cpumode, ip, &al))
+              return -1;
 
-       offset = al.map->map_ip(al.map, ip);
-       if (is64bit)
-               *is64bit = al.map->dso->is_64_bit;
+       dso = map__dso(al.map);
 
-       return dso__data_read_offset(al.map->dso, machine, offset, buf, len);
+       if( !dso || dso->data.status == DSO_DATA_STATUS_ERROR || map__load(al.map) < 0)
+               return -1;
+
+       offset = al.map->map_ip(al.map, ip);
+       if (is64bit)
+               *is64bit = dso->is_64_bit;
+
+       return dso__data_read_offset(dso, machine, offset, buf, len);
 }
 
 void thread__free_stitch_list(struct thread *thread)
 
        thread__find_symbol(ui->thread, PERF_RECORD_MISC_USER, ip, al);
 
        if (al->map)
-               dso = al->map->dso;
+               dso = map__dso(al->map);
 
        if (!dso)
                return 0;
 {
        struct addr_location al;
        ssize_t size;
+       struct dso *dso;
 
        if (!thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al)) {
                pr_debug("unwind: no map for %lx\n", (unsigned long)addr);
                return -1;
        }
-
-       if (!al.map->dso)
+       dso = map__dso(al.map);
+       if (!dso)
                return -1;
 
-       size = dso__data_read_addr(al.map->dso, al.map, ui->machine,
-                                  addr, (u8 *) data, sizeof(*data));
+       size = dso__data_read_addr(dso, al.map, ui->machine, addr, (u8 *) data, sizeof(*data));
 
        return !(size == sizeof(*data));
 }
 
        maps__for_each_entry(ui->thread->maps, map_node) {
                struct map *map = map_node->map;
 
-               if (map->dso == dso && map->start < base_addr)
+               if (map__dso(map) == dso && map->start < base_addr)
                        base_addr = map->start;
        }
        base_addr -= dso->data.elf_base_addr;
 {
        struct unwind_info *ui = arg;
        struct map *map;
+       struct dso *dso;
        unw_dyn_info_t di;
        u64 table_data, segbase, fde_count;
        int ret = -EINVAL;
 
        map = find_map(ip, ui);
-       if (!map || !map->dso)
+       if (!map)
                return -EINVAL;
 
-       pr_debug("unwind: find_proc_info dso %s\n", map->dso->name);
+       dso = map__dso(map);
+       if (!dso)
+               return -EINVAL;
+
+       pr_debug("unwind: find_proc_info dso %s\n", dso->name);
 
        /* Check the .eh_frame section for unwinding info */
-       if (!read_unwind_spec_eh_frame(map->dso, ui,
-                                      &table_data, &segbase, &fde_count)) {
+       if (!read_unwind_spec_eh_frame(dso, ui, &table_data, &segbase, &fde_count)) {
                memset(&di, 0, sizeof(di));
                di.format   = UNW_INFO_FORMAT_REMOTE_TABLE;
                di.start_ip = map->start;
 #ifndef NO_LIBUNWIND_DEBUG_FRAME
        /* Check the .debug_frame section for unwinding info */
        if (ret < 0 &&
-           !read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {
-               int fd = dso__data_get_fd(map->dso, ui->machine);
-               int is_exec = elf_is_exec(fd, map->dso->name);
+           !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);
                unw_word_t base = is_exec ? 0 : map->start;
                const char *symfile;
 
                if (fd >= 0)
-                       dso__data_put_fd(map->dso);
+                       dso__data_put_fd(dso);
 
-               symfile = map->dso->symsrc_filename ?: map->dso->name;
+               symfile = dso->symsrc_filename ?: dso->name;
 
                memset(&di, 0, sizeof(di));
                if (dwarf_find_debug_frame(0, &di, ip, base, symfile,
                          unw_word_t *data)
 {
        struct map *map;
+       struct dso *dso;
        ssize_t size;
 
        map = find_map(addr, ui);
                return -1;
        }
 
-       if (!map->dso)
+       dso = map__dso(map);
+
+       if (!dso)
                return -1;
 
-       size = dso__data_read_addr(map->dso, map, ui->machine,
+       size = dso__data_read_addr(dso, map, ui->machine,
                                   addr, (u8 *) data, sizeof(*data));
 
        return !(size == sizeof(*data));
 
        const char *arch;
        enum dso_type dso_type;
        struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops;
+       struct dso *dso = map__dso(map);
        struct machine *machine;
        int err;
 
                return 0;
 
        if (maps__addr_space(maps)) {
-               pr_debug("unwind: thread map already set, dso=%s\n",
-                        map->dso->name);
+               pr_debug("unwind: thread map already set, dso=%s\n", dso->name);
                if (initialized)
                        *initialized = true;
                return 0;
        if (!machine->env || !machine->env->arch)
                goto out_register;
 
-       dso_type = dso__type(map->dso, machine);
+       dso_type = dso__type(dso, machine);
        if (dso_type == DSO__TYPE_UNKNOWN)
                return 0;
 
 
        struct map_rb_node *rb_node;
 
        maps__for_each_entry(thread->maps, rb_node) {
-               struct dso *dso = rb_node->map->dso;
+               struct dso *dso = map__dso(rb_node->map);
 
                if (!dso || dso->long_name[0] != '/')
                        continue;