perf symbols: Fix DSO kernel load and symbol process to correctly map DSO to its...
authorAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Fri, 11 Aug 2023 05:15:46 +0000 (10:45 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 11 Aug 2023 14:27:50 +0000 (11:27 -0300)
Test "object code reading" fails sometimes for kernel address as below:

    Reading object code for memory address: 0xc000000000004c3c
    File is: [kernel.kallsyms]
    On file address is: 0x14c3c
    dso__data_read_offset failed
    test child finished with -1
    ---- end ----
    Object code reading: FAILED!

Here dso__data_read_offset() fails for symbol address
0xc000000000004c3c. This is because the DSO long_name here is
"[kernel.kallsyms]" and hence open_dso() fails to open this file. There
is an incorrect DSO to map handling here. The key points here are:

- The DSO long_name is set to "[kernel.kallsyms]". This file is
  not present and hence returns error
- The DSO binary type is set to DSO_BINARY_TYPE__NOT_FOUND
- The DSO adjust_symbols member is set to zero

In the end dso__data_read_offset() returns -1 and the address 0x14c3c
can not be resolved. Hence the test fails. But the address actually maps
to the kernel DSO

    # objdump -z -d --start-address=0xc000000000004c3c --stop-address=0xc000000000004cbc /home/athira/linux/vmlinux

    /home/athira/linux/vmlinux:     file format elf64-powerpcle

    Disassembly of section .head.text:

    c000000000004c3c <exc_virt_0x4c00_system_call+0x3c>:
    c000000000004c3c: a6 02 9b 7d  mfsrr1  r12
    c000000000004c40: 78 13 42 7c  mr      r2,r2
    c000000000004c44: 18 00 4d e9  ld      r10,24(r13)
    c000000000004c48: 60 c6 4a 61  ori     r10,r10,50784
    c000000000004c4c: a6 03 49 7d  mtctr   r10

Fix dso__process_kernel_symbol() to set the binary_type and
adjust_symbols members. dso->adjust_symbols is used by
map__rip_2objdump() which converts the symbol start address to the
objdump address. Also set dso->long_name in dso__load_vmlinux().

Suggested-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org
Link: https://lore.kernel.org/r/20230811051546.70039-1-atrajeev@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/symbol-elf.c
tools/perf/util/symbol.c

index 8bd466d..95e99c3 100644 (file)
@@ -1440,6 +1440,8 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
                curr_dso->kernel = dso->kernel;
                curr_dso->long_name = dso->long_name;
                curr_dso->long_name_len = dso->long_name_len;
+               curr_dso->binary_type = dso->binary_type;
+               curr_dso->adjust_symbols = dso->adjust_symbols;
                curr_map = map__new2(start, curr_dso);
                dso__put(curr_dso);
                if (curr_map == NULL)
index f849f9e..3f36675 100644 (file)
@@ -2204,15 +2204,20 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,
        if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type))
                return -1;
 
+       /*
+        * dso__load_sym() may copy 'dso' which will result in the copies having
+        * an incorrect long name unless we set it here first.
+        */
+       dso__set_long_name(dso, vmlinux, vmlinux_allocated);
+       if (dso->kernel == DSO_SPACE__KERNEL_GUEST)
+               dso->binary_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
+       else
+               dso->binary_type = DSO_BINARY_TYPE__VMLINUX;
+
        err = dso__load_sym(dso, map, &ss, &ss, 0);
        symsrc__destroy(&ss);
 
        if (err > 0) {
-               if (dso->kernel == DSO_SPACE__KERNEL_GUEST)
-                       dso->binary_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
-               else
-                       dso->binary_type = DSO_BINARY_TYPE__VMLINUX;
-               dso__set_long_name(dso, vmlinux, vmlinux_allocated);
                dso__set_loaded(dso);
                pr_debug("Using %s for symbols\n", symfs_vmlinux);
        }