All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Wangnan (F)" <wangnan0@huawei.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: <acme@kernel.org>, <adrian.hunter@intel.com>, <dev@codyps.com>,
	<hekuang@huawei.com>, <kirr@nexedi.com>,
	<linux-kernel@vger.kernel.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Li Zefan <lizefan@huawei.com>, <pi3orama@163.com>
Subject: Re: [PATCH 2/2] perf tools: Adjust symbol for shared objects
Date: Wed, 3 Feb 2016 10:12:43 +0800	[thread overview]
Message-ID: <56B1621B.9070100@huawei.com> (raw)
In-Reply-To: <20160202151814.GD4627@danjae.kornet>



On 2016/2/2 23:18, Namhyung Kim wrote:
> On Tue, Feb 02, 2016 at 08:56:06AM +0000, Wang Nan wrote:
>> He Kuang reported a problem that perf fails to get correct symbol on
>> Android platform in [1]. The problem can be reproduced on normal x86_64
>> platform. I will describe the reproducing steps in detail at the end of
>> commit message.
>>
>> The reason of this problem is the missing of symbol adjustment for normal
>> shared objects. In most of the cases it works correctly, but when
>> '.text' section have different 'address' and 'offset' the result is
>> wrong. I checked all shared objects in my working platform, only wine
>> dll objects and debug objects (in .debug) have this problem. However,
>> it is common on Android. For example:
>>
>>   $ readelf -S ./libsurfaceflinger.so | grep \.text
>>     [10] .text             PROGBITS         0000000000029030  00012030
>>
>> This patch enables symbol adjustment for dynamic objects so the symbol
>> address got from elfutils would be adjusted correctly.
>>
>> Steps to reproduce the problem:
>>
>>   $ cat << EOF > ./Makefile
>> PWD := $(shell pwd)
>> LDFLAGS += "-Wl,-rpath=$(PWD)"
>> CFLAGS += -g
>> main: main.c libbuggy.so
>> libbuggy.so: buggy.c
>> 	gcc -g -shared -fPIC -Wl,-Ttext-segment=0x200000 $< -o $@
>> clean:
>> 	rm -rf main libbuggy.so *.o
>> EOF
>>
>>   $ cat << EOF > ./buggy.c
>> int fib(int x)
>> {
>> 	return (x == 0) ? 1 : (x == 1) ? 1 : fib(x - 1) + fib(x - 2);
>> }
>> EOF
>>
>>   $ cat << EOF > ./main.c
>>   #include <stdio.h>
>>
>> extern int fix(int x);
> s/fix/fib/ ?

Thank you. Have you really tested this program?

>> int main()
>> {
>> 	int i;
>>
>> 	for (i = 0; i < 40; i++)
>> 		printf("%d\n", fib(i));
>> 	return 0;
>> }
>> EOF
>>
>>   $ make
>>   $ perf record ./main
>>   ...
>>   $ perf report --stdio
>>   # Overhead  Command  Shared Object      Symbol
>>   # ........  .......  .................  ...............................
>>   #
>>       14.97%  main     libbuggy.so        [.] 0x000000000000066c
>>        8.68%  main     libbuggy.so        [.] 0x00000000000006aa
>>        8.52%  main     libbuggy.so        [.] fib@plt
>>        7.95%  main     libbuggy.so        [.] 0x0000000000000664
>>        5.94%  main     libbuggy.so        [.] 0x00000000000006a9
>>        5.35%  main     libbuggy.so        [.] 0x0000000000000678
>>   ...
>>
>> The correct result should be (after this patch):
>>
>>   # Overhead  Command  Shared Object      Symbol
>>   # ........  .......  .................  ...............................
>>   #
>>       91.47%  main     libbuggy.so        [.] fib
>>        8.52%  main     libbuggy.so        [.] fib@plt
>>        0.00%  main     [kernel.kallsyms]  [k] kmem_cache_free
>>
>> [1] http://lkml.kernel.org/g/1452567507-54013-1-git-send-email-hekuang@huawei.com
>>
>> Signed-off-by: Wang Nan <wangnan0@huawei.com>
>> Cc: Adrian Hunter <adrian.hunter@intel.com>
>> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
>> Cc: Cody P Schafer <dev@codyps.com>
>> Cc: He Kuang <hekuang@huawei.com>
>> Cc: Jiri Olsa <jolsa@kernel.org>
>> Cc: Kirill Smelkov <kirr@nexedi.com>
>> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
>> Cc: Namhyung Kim <namhyung@kernel.org>
>> Cc: Li Zefan <lizefan@huawei.com>
>> Cc: pi3orama@163.com
>> ---
>>   tools/perf/util/symbol-elf.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
>> index 5227186..d4e59dd 100644
>> --- a/tools/perf/util/symbol-elf.c
>> +++ b/tools/perf/util/symbol-elf.c
>> @@ -712,6 +712,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
>>   		GElf_Shdr shdr;
>>   		ss->adjust_symbols = (ehdr.e_type == ET_EXEC ||
>>   				ehdr.e_type == ET_REL ||
>> +				ehdr.e_type == ET_DYN ||
> It seems there's no need to check the e_type anymore..

OK. Let's make adjust_symbols the default choice.

Thank you.

> Thanks,
> Namhyung
>
>
>>   				dso__is_vdso(dso) ||
>>   				elf_section_by_name(elf, &ehdr, &shdr,
>>   						     ".gnu.prelink_undo",
>> -- 
>> 1.8.3.4
>>

  reply	other threads:[~2016-02-03  2:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-02  8:56 [PATCH 0/2] perf tools: Fix symbol error on ARM64 Wang Nan
2016-02-02  8:56 ` [PATCH 1/2] perf tools: Record text offset in dso to calculate objdump address Wang Nan
2016-02-02  8:56 ` [PATCH 2/2] perf tools: Adjust symbol for shared objects Wang Nan
2016-02-02 15:18   ` Namhyung Kim
2016-02-03  2:12     ` Wangnan (F) [this message]
2016-02-03 13:55       ` Namhyung Kim

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=56B1621B.9070100@huawei.com \
    --to=wangnan0@huawei.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dev@codyps.com \
    --cc=hekuang@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=kirr@nexedi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=namhyung@kernel.org \
    --cc=pi3orama@163.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.