Messages in this thread | | | Date | Sun, 24 Jul 2022 10:38:40 +0800 | From | Leo Yan <> | Subject | Re: [RFC PATCH v1] perf symbol: Correct address for bss symbols |
| |
Hi Fangrui,
On Tue, Jul 12, 2022 at 08:29:52PM -0700, Fangrui Song wrote:
[...]
> > We need to create symbol info for not only .text section but also for > > .data section and .bss sectionṡ. So based on the data address, we can > > know what's the symbol for the data access. > > > > But I need to correct the description for "st_value" [1]: In > > executable and shared object files, st_value holds a virtual address. > > To make these files' symbols more useful for the dynamic linker, the > > section offset (file interpretation) gives way to a virtual address > > (memory interpretation) for which the section number is irrelevant. > > > > So perf tool uses the formula "st_value - sh_addr + sh_offset" to > > convert from the memory address to file address. But it calculates > > the wrong file address because "sh_offset" doesn't respect the > > alignment. > > Thanks for the explanation. I think st_value - p_vaddr + p_offset may > be a better formula where p_vaddr/p_offset is from the PT_LOAD program > header. > > For a SHT_NOBITS section, sh_offset may not be accurate, but PT_LOAD > has precise information.
Thanks a lot for suggestion, it's very helpful and reasonable for me!
I struggled a bit for considering two things. One is how to refactor kernel symbol parsing with PT_LOAD program headers, because the kernel symbol parsing is relative complex for both kernel symbols and module symbols, this is why I didn't move furthermore for refactoring kernel symbol parsing.
The second thing is I observe there have some spurious symbols with 'st_value' are zeros. So there have an extra fixing for this case.
Welcome comments or suggestions for the new patch set: https://lore.kernel.org/lkml/20220724022857.2621520-1-leo.yan@linaro.org/T/#t
Thanks, Leo
| |