Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf symbols: Fix DSO kernel load and symbol process to correctly map DSO to its long_name, type and adjust_symbols

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>

authored by

Athira Rajeev and committed by
Arnaldo Carvalho de Melo
e59fea47 878460e8

+12 -5
+2
tools/perf/util/symbol-elf.c
··· 1440 1440 curr_dso->kernel = dso->kernel; 1441 1441 curr_dso->long_name = dso->long_name; 1442 1442 curr_dso->long_name_len = dso->long_name_len; 1443 + curr_dso->binary_type = dso->binary_type; 1444 + curr_dso->adjust_symbols = dso->adjust_symbols; 1443 1445 curr_map = map__new2(start, curr_dso); 1444 1446 dso__put(curr_dso); 1445 1447 if (curr_map == NULL)
+10 -5
tools/perf/util/symbol.c
··· 2204 2204 if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type)) 2205 2205 return -1; 2206 2206 2207 + /* 2208 + * dso__load_sym() may copy 'dso' which will result in the copies having 2209 + * an incorrect long name unless we set it here first. 2210 + */ 2211 + dso__set_long_name(dso, vmlinux, vmlinux_allocated); 2212 + if (dso->kernel == DSO_SPACE__KERNEL_GUEST) 2213 + dso->binary_type = DSO_BINARY_TYPE__GUEST_VMLINUX; 2214 + else 2215 + dso->binary_type = DSO_BINARY_TYPE__VMLINUX; 2216 + 2207 2217 err = dso__load_sym(dso, map, &ss, &ss, 0); 2208 2218 symsrc__destroy(&ss); 2209 2219 2210 2220 if (err > 0) { 2211 - if (dso->kernel == DSO_SPACE__KERNEL_GUEST) 2212 - dso->binary_type = DSO_BINARY_TYPE__GUEST_VMLINUX; 2213 - else 2214 - dso->binary_type = DSO_BINARY_TYPE__VMLINUX; 2215 - dso__set_long_name(dso, vmlinux, vmlinux_allocated); 2216 2221 dso__set_loaded(dso); 2217 2222 pr_debug("Using %s for symbols\n", symfs_vmlinux); 2218 2223 }