Skip to content

Commit e59fea4

Browse files
athira-rajeevacmel
authored andcommitted
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>
1 parent 878460e commit e59fea4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tools/perf/util/symbol-elf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,8 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
14401440
curr_dso->kernel = dso->kernel;
14411441
curr_dso->long_name = dso->long_name;
14421442
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;
14431445
curr_map = map__new2(start, curr_dso);
14441446
dso__put(curr_dso);
14451447
if (curr_map == NULL)

tools/perf/util/symbol.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,15 +2204,20 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,
22042204
if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type))
22052205
return -1;
22062206

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+
22072217
err = dso__load_sym(dso, map, &ss, &ss, 0);
22082218
symsrc__destroy(&ss);
22092219

22102220
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);
22162221
dso__set_loaded(dso);
22172222
pr_debug("Using %s for symbols\n", symfs_vmlinux);
22182223
}

0 commit comments

Comments
 (0)