All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] perf tools: Fix symbol error on ARM64
@ 2016-02-02  8:56 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
  0 siblings, 2 replies; 6+ messages in thread
From: Wang Nan @ 2016-02-02  8:56 UTC (permalink / raw)
  To: acme, adrian.hunter, dev, hekuang, kirr
  Cc: linux-kernel, Wang Nan, Arnaldo Carvalho de Melo, Jiri Olsa,
	Masami Hiramatsu, Namhyung Kim, Li Zefan, pi3orama

He Kuang has described this problem at [1] that, on ARM64, perf report
output wrong symbol for a shared object.

These two patches solve this problem. The key is patch 2/2: force
adjust symbol for shared object. However, after setting
dso->adjust_symbols, map__rip_2objdump() also need to be adjust, or
perf annotate reports incorrect result. Patch 1/1 prepare this change.

[1] http://lkml.kernel.org/g/1452567507-54013-1-git-send-email-hekuang@huawei.com

Wang Nan (2):
  perf tools: Record text offset in dso to calculate objdump address
  perf tools: Adjust symbol for shared objects

 tools/perf/util/dso.h        |  1 +
 tools/perf/util/map.c        | 14 ++++++++++++++
 tools/perf/util/symbol-elf.c | 13 +++++++------
 3 files changed, 22 insertions(+), 6 deletions(-)

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.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

-- 
1.8.3.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] perf tools: Record text offset in dso to calculate objdump address
  2016-02-02  8:56 [PATCH 0/2] perf tools: Fix symbol error on ARM64 Wang Nan
@ 2016-02-02  8:56 ` Wang Nan
  2016-02-02  8:56 ` [PATCH 2/2] perf tools: Adjust symbol for shared objects Wang Nan
  1 sibling, 0 replies; 6+ messages in thread
From: Wang Nan @ 2016-02-02  8:56 UTC (permalink / raw)
  To: acme, adrian.hunter, dev, hekuang, kirr
  Cc: linux-kernel, Wang Nan, Arnaldo Carvalho de Melo, Jiri Olsa,
	Masami Hiramatsu, Namhyung Kim, Li Zefan, pi3orama

In this patch, the offset of '.text' section is stored into dso
and used here to re-calculate address to objdump.

In most of the cases, executable code is in '.text' section, so the
adjustment made to a symbol in dso__load_sym (using
sym.st_value -= shdr.sh_addr - shdr.sh_offset) should equal to
'sym.st_value -= dso->text_offset'. Therefore, adding text_offset back
get objdump address from symbol address (rip). However, it is not true
for kernel and kernel module since there could be multiple executable
sections with different offset. Exclude kernel for this reason.

After this patch, even dso->adjust_symbols is set to true for shared
objects, map__rip_2objdump() and map__objdump_2mem() would return
correct result, so perf behavior of annotate won't be changed.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.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/dso.h        |  1 +
 tools/perf/util/map.c        | 14 ++++++++++++++
 tools/perf/util/symbol-elf.c | 12 ++++++------
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 45ec4d0..ef3dbc9 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -162,6 +162,7 @@ struct dso {
 	u8		 loaded;
 	u8		 rel;
 	u8		 build_id[BUILD_ID_SIZE];
+	u64		 text_offset;
 	const char	 *short_name;
 	const char	 *long_name;
 	u16		 long_name_len;
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 171b6d1..02c3186 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -431,6 +431,13 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
 	if (map->dso->rel)
 		return rip - map->pgoff;
 
+	/*
+	 * kernel modules also have DSO_TYPE_USER in dso->kernel,
+	 * but all kernel modules are ET_REL, so won't get here.
+	 */
+	if (map->dso->kernel == DSO_TYPE_USER)
+		return rip + map->dso->text_offset;
+
 	return map->unmap_ip(map, rip) - map->reloc;
 }
 
@@ -454,6 +461,13 @@ u64 map__objdump_2mem(struct map *map, u64 ip)
 	if (map->dso->rel)
 		return map->unmap_ip(map, ip + map->pgoff);
 
+	/*
+	 * kernel modules also have DSO_TYPE_USER in dso->kernel,
+	 * but all kernel modules are ET_REL, so won't get here.
+	 */
+	if (map->dso->kernel == DSO_TYPE_USER)
+		return map->unmap_ip(map, ip - map->dso->text_offset);
+
 	return ip + map->reloc;
 }
 
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 562b8eb..5227186 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -792,6 +792,7 @@ int dso__load_sym(struct dso *dso, struct map *map,
 	uint32_t idx;
 	GElf_Ehdr ehdr;
 	GElf_Shdr shdr;
+	GElf_Shdr tshdr;
 	Elf_Data *syms, *opddata = NULL;
 	GElf_Sym sym;
 	Elf_Scn *sec, *sec_strndx;
@@ -831,6 +832,9 @@ int dso__load_sym(struct dso *dso, struct map *map,
 	sec = syms_ss->symtab;
 	shdr = syms_ss->symshdr;
 
+	if (elf_section_by_name(elf, &ehdr, &tshdr, ".text", NULL))
+		dso->text_offset = tshdr.sh_addr - tshdr.sh_offset;
+
 	if (runtime_ss->opdsec)
 		opddata = elf_rawdata(runtime_ss->opdsec, NULL);
 
@@ -879,12 +883,8 @@ int dso__load_sym(struct dso *dso, struct map *map,
 	 * Handle any relocation of vdso necessary because older kernels
 	 * attempted to prelink vdso to its virtual address.
 	 */
-	if (dso__is_vdso(dso)) {
-		GElf_Shdr tshdr;
-
-		if (elf_section_by_name(elf, &ehdr, &tshdr, ".text", NULL))
-			map->reloc = map->start - tshdr.sh_addr + tshdr.sh_offset;
-	}
+	if (dso__is_vdso(dso))
+		map->reloc = map->start - dso->text_offset;
 
 	dso->adjust_symbols = runtime_ss->adjust_symbols || ref_reloc(kmap);
 	/*
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] perf tools: Adjust symbol for shared objects
  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 ` Wang Nan
  2016-02-02 15:18   ` Namhyung Kim
  1 sibling, 1 reply; 6+ messages in thread
From: Wang Nan @ 2016-02-02  8:56 UTC (permalink / raw)
  To: acme, adrian.hunter, dev, hekuang, kirr
  Cc: linux-kernel, Wang Nan, Arnaldo Carvalho de Melo, Jiri Olsa,
	Masami Hiramatsu, Namhyung Kim, Li Zefan, pi3orama

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);
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 ||
 				dso__is_vdso(dso) ||
 				elf_section_by_name(elf, &ehdr, &shdr,
 						     ".gnu.prelink_undo",
-- 
1.8.3.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] perf tools: Adjust symbol for shared objects
  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)
  0 siblings, 1 reply; 6+ messages in thread
From: Namhyung Kim @ 2016-02-02 15:18 UTC (permalink / raw)
  To: Wang Nan
  Cc: acme, adrian.hunter, dev, hekuang, kirr, linux-kernel,
	Arnaldo Carvalho de Melo, Jiri Olsa, Masami Hiramatsu, Li Zefan,
	pi3orama

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/ ?

> 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..

Thanks,
Namhyung


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] perf tools: Adjust symbol for shared objects
  2016-02-02 15:18   ` Namhyung Kim
@ 2016-02-03  2:12     ` Wangnan (F)
  2016-02-03 13:55       ` Namhyung Kim
  0 siblings, 1 reply; 6+ messages in thread
From: Wangnan (F) @ 2016-02-03  2:12 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: acme, adrian.hunter, dev, hekuang, kirr, linux-kernel,
	Arnaldo Carvalho de Melo, Jiri Olsa, Masami Hiramatsu, Li Zefan,
	pi3orama



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
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] perf tools: Adjust symbol for shared objects
  2016-02-03  2:12     ` Wangnan (F)
@ 2016-02-03 13:55       ` Namhyung Kim
  0 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2016-02-03 13:55 UTC (permalink / raw)
  To: Wangnan (F)
  Cc: acme, adrian.hunter, dev, hekuang, kirr, linux-kernel,
	Arnaldo Carvalho de Melo, Jiri Olsa, Masami Hiramatsu, Li Zefan,
	pi3orama

Hi,

On Wed, Feb 03, 2016 at 10:12:43AM +0800, Wangnan (F) wrote:
> 
> 
> 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?

Nope, but I've been thinking that the symbol resolution code needs to
be updated or fixed.

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-03 13:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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)
2016-02-03 13:55       ` Namhyung Kim

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.