Re: [PATCH] perf symbol: correction while adjusting symbol

From: Leo Yan
Date: Thu Nov 24 2022 - 04:50:41 EST


Hi Ajay,

On Wed, Nov 23, 2022 at 03:48:16PM +0530, Ajay Kaher wrote:
> perf doesn't provide proper symbol information for specially crafted
> .debug files.
>
> Sometimes .debug file may not have similar program header as runtime
> ELF file. For example if we generate .debug file using objcopy
> --only-keep-debug resulting file will not contain .text, .data and
> other runtime sections. That means corresponding program headers will
> have zero FileSiz and modified Offset.
>
> Example: program header of text section of libxxx.so:
>
> Type Offset VirtAddr PhysAddr
> FileSiz MemSiz Flags Align
> LOAD 0x00000000003d3000 0x00000000003d3000 0x00000000003d3000
> 0x000000000055ae80 0x000000000055ae80 R E 0x1000
>
> Same program header after executing:
> objcopy --only-keep-debug libxxx.so libxxx.so.debug
>
> LOAD 0x0000000000001000 0x00000000003d3000 0x00000000003d3000
> 0x0000000000000000 0x000000000055ae80 R E 0x1000
>
> Offset and FileSiz have been changed.
>
> Following formula will not provide correct value, if program header
> taken from .debug file (syms_ss):
>
> sym.st_value -= phdr.p_vaddr - phdr.p_offset;
>
> Correct program header information is located inside runtime ELF
> file (runtime_ss).
>
> Fixes: 2d86612aacb7 ("perf symbol: Correct address for bss symbols")
> Signed-off-by: Ajay Kaher <akaher@xxxxxxxxxx>


Just curious how you can produce this issue? IIUC, the runtime symbol
files are copied into .debug folder and they can be found by perf tool
by matching build ID. Seems to me, you manully use
"objcopy --only-keep-debug" command to strip runtime info from elf files
under .debug folder. Do I understand correctly?

Though I have above question, this patch itself looks good to me,
thanks for the fixing!

Reviewed-by: Leo Yan <leo.yan@xxxxxxxxxx>