Linux Perf Users
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@linaro.org>
To: Fangrui Song <maskray@google.com>
Cc: Ian Rogers <irogers@google.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chang Rui <changruinj@gmail.com>
Subject: Re: [RFC PATCH v1] perf symbol: Correct address for bss symbols
Date: Sun, 24 Jul 2022 10:38:40 +0800	[thread overview]
Message-ID: <20220724023840.GA82137@leoy-ThinkPad-X240s> (raw)
In-Reply-To: <CAFP8O3+dQi8b6C_f9bTb0TFpEmNjsroBv4agUpRKps2p3hpP+A@mail.gmail.com>

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

      reply	other threads:[~2022-07-24  2:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-10  1:22 [RFC PATCH v1] perf symbol: Correct address for bss symbols Leo Yan
2022-07-11 16:09 ` Ian Rogers
2022-07-11 17:27   ` Fangrui Song
2022-07-12  4:05     ` Leo Yan
2022-07-13  3:29       ` Fangrui Song
2022-07-24  2:38         ` Leo Yan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220724023840.GA82137@leoy-ThinkPad-X240s \
    --to=leo.yan@linaro.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=changruinj@gmail.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maskray@google.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox