Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1327793
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 04/54] perf tools: Adjust symbol for shared objects |
| Date | 2016-02-05 15:30 +0100 |
| Message-ID | <qYPyy-1p9-31@gated-at.bofh.it> (permalink) |
| References | <qYPfb-1gO-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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.
Now nearly all type of ELF file should adjust symbols. Makes
ss->adjust_symbols default to true.
Steps to reproduce the problem:
$ cat ./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
$ cat ./buggy.c
int fib(int x)
{
return (x == 0) ? 1 : (x == 1) ? 1 : fib(x - 1) + fib(x - 2);
}
$ cat ./main.c
#include <stdio.h>
extern int fib(int x);
int main()
{
int i;
for (i = 0; i < 40; i++)
printf("%d\n", fib(i));
return 0;
}
$ 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 | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 5227186..6a9a53a 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -708,17 +708,10 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
if (ss->opdshdr.sh_type != SHT_PROGBITS)
ss->opdsec = NULL;
- if (dso->kernel == DSO_TYPE_USER) {
- GElf_Shdr shdr;
- ss->adjust_symbols = (ehdr.e_type == ET_EXEC ||
- ehdr.e_type == ET_REL ||
- dso__is_vdso(dso) ||
- elf_section_by_name(elf, &ehdr, &shdr,
- ".gnu.prelink_undo",
- NULL) != NULL);
- } else {
+ if (dso->kernel == DSO_TYPE_USER)
+ ss->adjust_symbols = true;
+ else
ss->adjust_symbols = elf__needs_adjust_symbols(ehdr);
- }
ss->name = strdup(name);
if (!ss->name) {
--
1.8.3.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/54] perf tools: Bugfix, BPF improvements and overwrite ring buffer support Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:20 +0100 [PATCH 08/54] perf record: Apply config to BPF objects before recording Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:30 +0100 [PATCH 19/54] perf core: Introduce new ioctl options to pause and resume ring buffer Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:30 +0100 [PATCH 09/54] perf tools: Enable passing event to BPF object Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:30 +0100 [PATCH 21/54] perf core: Prepare writing into ring buffer from end Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:30 +0100 [PATCH 05/54] perf data: Fix releasing event_class Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:30 +0100 [PATCH 02/54] perf tools: Fix symbols searching for offline module in buildid-cache Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:30 +0100 [PATCH 04/54] perf tools: Adjust symbol for shared objects Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:30 +0100 [PATCH 01/54] perf tools: Fix dangling pointers in parse_events__free_terms Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:30 +0100 [PATCH 03/54] perf tools: Record text offset in dso to calculate objdump address Wang Nan <wangnan0@huawei.com> - 2016-02-05 15:30 +0100
csiph-web