tools/perf: Fix dso kernel load and symbol process to correctly map dso to its long_name, type and adjust_symbols
PATCH 1/1 tools/perf: Fix dso kernel load and symbol process to correctly map dso to its long_name, type and adjust_symbols
Test "object cocde 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 the 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 is:
- dso long_name is set to [kernel.kallsyms]. This file is not present and hence returns error
- DSO binary type is set to DSO_BINARY_TYPE__NOT_FOUND
- dso adjust_symbols 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 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 r10Fix the dso__process_kernel_symbol function to set the binary_type and adjust_symbols. adjust_symbols is used by function "map__rip_2objdump" which converts symbol start address to objdump address. Also set the dso long_name during dso__load_vmlinux function.
---
Note: Found similar discussion here in thread:
https://www.spinics.net/lists/linux-perf-users/msg06337.html
where Adrian proposed the fix, but looks like this was not added to the perf. Hence addeed Suggested-by from Adrian.
Additional to the fix proposed by Adrian, the patch also adds setting of adjust_symbols which is needed for map__rip_2objdump to convert symbol start to objdump address.
tools/perf/util/symbol-elf.c | 2 ++ tools/perf/util/symbol.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-)
tools/perf/util/symbol-elf.c +2 -0
@@ -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 )
tools/perf/util/symbol.c +10 -5
@@ -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); }
Signature · 1 line
2.31.1
Quoted 38 lines · Athira Rajeev
Test "object cocde reading" fails sometimes for kernel address as below:
Reading object code for memory address:
0xc000000000004c3cFile is: [kernel.kallsyms]
On file address is:0x14c3cdso__data_read_offsetfailed
test child finished with -1
---- end ----
Object code reading: FAILED!Here the
dso__data_read_offsetfails for symbol address0xc000000000004c3c. This is because, the dsolong_namehere is [kernel.kallsyms] and henceopen_dsofails to open this file. There is an incorrect dso to map handling here. The key points here is:
- dsolong_nameis set to [kernel.kallsyms]. This file is not present and hence returns error
- DSO binary type is set toDSO_BINARY_TYPE__NOT_FOUND
- dsoadjust_symbolsis set to zeroIn the end
dso__data_read_offset()returns -1 and the address0x14c3ccan not be resolved. Hence the test fails. But the address actually maps to 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
Quoted 8 lines
Fix the
dso__process_kernel_symbolfunction to set thebinary_typeandadjust_symbols.adjust_symbolsis used by function "map__rip_2objdump" which converts symbol start address to objdump address. Also set the dsolong_nameduringdso__load_vmlinuxfunction.Suggested-by Adrian Hunter <[email protected]>Signed-off-by Athira Rajeev <[email protected]>
Quoted 57 lines
---
Note: Found similar discussion here in thread:
https://www.spinics.net/lists/linux-perf-users/msg06337.html
where Adrian proposed the fix, but looks like this was not added to the perf. Hence addeed Suggested-by from Adrian.Additional to the fix proposed by Adrian, the patch also adds setting of
adjust_symbolswhich is needed formap__rip_2objdumpto convert symbol start to objdump address.tools/perf/util/symbol-elf.c | 2 ++ tools/perf/util/symbol.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-)tools/perf/util/symbol-elf.c +2
-0@@ -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 )tools/perf/util/symbol.c +10
-5@@ -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); }
Em Fri, Aug 11, 2023 at 12:49:35PM +0300, Adrian Hunter escreveu:
Quoted 45 lines · Athira Rajeev
Quoted 44 lines
Test "object cocde reading" fails sometimes for kernel address as below:
Reading object code for memory address:
0xc000000000004c3cFile is: [kernel.kallsyms]
On file address is:0x14c3cdso__data_read_offsetfailed
test child finished with -1
---- end ----
Object code reading: FAILED!Here the
dso__data_read_offsetfails for symbol address0xc000000000004c3c. This is because, the dsolong_namehere is [kernel.kallsyms] and henceopen_dsofails to open this file. There is an incorrect dso to map handling here. The key points here is:
- dsolong_nameis set to [kernel.kallsyms]. This file is not present and hence returns error
- DSO binary type is set toDSO_BINARY_TYPE__NOT_FOUND
- dsoadjust_symbolsis set to zeroIn the end
dso__data_read_offset()returns -1 and the address0x14c3ccan not be resolved. Hence the test fails. But the address actually maps to 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 r10Fix the
dso__process_kernel_symbolfunction to set thebinary_typeandadjust_symbols.adjust_symbolsis used by function "map__rip_2objdump" which converts symbol start address to objdump address. Also set the dsolong_nameduringdso__load_vmlinuxfunction.
Quoted 4 lines
Quoted 2 lines
Suggested-by Adrian Hunter <[email protected]>Signed-off-by Athira Rajeev <[email protected]>Acked-by Adrian Hunter <[email protected]>
Thanks, applied.
- Arnaldo
Quoted 58 lines
Quoted 57 lines
---
Note: Found similar discussion here in thread:
https://www.spinics.net/lists/linux-perf-users/msg06337.html
where Adrian proposed the fix, but looks like this was not added to the perf. Hence addeed Suggested-by from Adrian.Additional to the fix proposed by Adrian, the patch also adds setting of
adjust_symbolswhich is needed formap__rip_2objdumpto convert symbol start to objdump address.tools/perf/util/symbol-elf.c | 2 ++ tools/perf/util/symbol.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-)tools/perf/util/symbol-elf.c +2
-0@@ -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 )tools/perf/util/symbol.c +10
-5@@ -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); }
Signature · 1 line
- Arnaldo