linux/tools/perf/util
Wang Nan 99e87f7bb7 perf symbols: Adjust symbol for shared objects
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 skipping adjustment is okay. However,
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 types of ELF files 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>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: 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: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1460024671-64774-3-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-04-08 09:58:15 -03:00
..
include tools lib: Move bitmap.[ch] from tools/perf/ to tools/{lib,include}/ 2016-01-08 12:35:46 -03:00
intel-pt-decoder perf intel-pt: Make logging slightly more efficient 2015-09-28 16:45:26 -03:00
scripting-engines perf script perl: Do error checking on new backtrace routine 2016-04-06 10:44:28 -03:00
alias.c
annotate.c perf annotate: ARM support 2015-12-07 18:13:00 -03:00
annotate.h perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
auxtrace.c perf tools: Add support for skipping itrace instructions 2016-03-30 11:14:09 -03:00
auxtrace.h perf tools: Add support for skipping itrace instructions 2016-03-30 11:14:09 -03:00
bpf-loader.c perf tools: Introduce bpf-output event 2016-02-22 14:37:21 -03:00
bpf-loader.h perf tools: Support setting different slots in a BPF map separately 2016-02-22 12:48:50 -03:00
bpf-prologue.c perf bpf: Add prologue for BPF programs for fetching arguments 2015-11-18 17:51:04 -03:00
bpf-prologue.h perf bpf: Add prologue for BPF programs for fetching arguments 2015-11-18 17:51:04 -03:00
Build perf tools: Build syscall table .c header from kernel's syscall_64.tbl 2016-04-08 09:58:14 -03:00
build-id.c perf tools: Add cpumode to struct perf_sample 2016-03-23 12:03:07 -03:00
build-id.h perf symbols: Fix symbols searching for module in buildid-cache 2016-02-12 10:54:47 -03:00
cache.h perf llvm: Use realpath to canonicalize paths 2016-03-23 17:39:19 -03:00
callchain.c perf callchain: Check return value of append_chain_children() 2016-02-19 19:15:01 -03:00
callchain.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
cgroup.c perf subcmd: Create subcmd library 2015-12-17 14:27:14 -03:00
cgroup.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
cloexec.c perf bench numa: Fix to show proper convergence stats 2015-06-25 12:28:35 -03:00
cloexec.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
color.c perf config: Bring perf_default_config to the very beginning at main() 2016-02-26 19:49:16 -03:00
color.h perf tools: Remove trail argument to color vsprintf 2015-08-05 16:44:02 -03:00
comm.c perf comm: Use atomic.h for refcounting 2015-05-27 12:21:43 -03:00
comm.h
config.c perf config: Fix build with older toolchain. 2016-04-06 10:44:28 -03:00
counts.c perf stat: Move perf_counts struct and functions into separate object 2015-08-08 14:16:49 -03:00
counts.h perf stat: Move perf_counts struct and functions into separate object 2015-08-08 14:16:49 -03:00
cpumap.c perf cpumap: Auto initialize cpu__max_{node,cpu} 2016-01-26 16:08:36 -03:00
cpumap.h perf cpumap: Auto initialize cpu__max_{node,cpu} 2016-01-26 16:08:36 -03:00
ctype.c perf ui/stdio: Align column header for hierarchy output 2016-02-24 20:21:12 -03:00
data-convert-bt.c perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
data-convert-bt.h perf data: Support using -f to override perf.data file ownership for 'convert' 2015-04-02 13:18:52 -03:00
data.c
data.h
db-export.c perf thread: Rename perf_event__preprocess_sample_addr to thread__resolve 2016-03-23 12:03:08 -03:00
db-export.h perf db-export: No need to have ->thread twice in struct export_sample 2015-04-02 13:18:43 -03:00
debug.c perf tools: Make binary data printer code in trace_event public available 2016-02-24 11:38:01 -03:00
debug.h perf tools: Initialize libapi debug output 2016-02-16 17:12:59 -03:00
demangle-java.c perf symbols: add Java demangling support 2016-02-05 09:46:45 -03:00
demangle-java.h perf symbols: add Java demangling support 2016-02-05 09:46:45 -03:00
dso.c perf symbols: Do not read symbols/data from device files 2016-01-26 11:52:43 -03:00
dso.h perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
dwarf-aux.c perf probe: Check if dwarf_getlocations() is available 2016-04-06 10:44:28 -03:00
dwarf-aux.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
env.c perf tools: Add perf data cache feature 2016-02-16 17:13:00 -03:00
env.h perf tools: Add perf data cache feature 2016-02-16 17:13:00 -03:00
event.c perf tools: Add time conversion event 2016-03-31 10:52:24 -03:00
event.h perf tools: Add time conversion event 2016-03-31 10:52:24 -03:00
evlist.c perf tools: Only set filter for tracepoints events 2016-02-26 19:50:01 -03:00
evlist.h perf tools: Enable passing event to BPF object 2016-02-22 12:30:50 -03:00
evsel.c perf bpf: Add sample types for 'bpf-output' event 2016-04-01 18:46:25 -03:00
evsel.h perf tools: Fix perf script python database export crash 2016-03-09 10:31:02 -03:00
find-vdso-map.c
genelf_debug.c perf jit: add source line info support 2016-02-05 12:33:09 -03:00
genelf.c perf jit: add source line info support 2016-02-05 12:33:09 -03:00
genelf.h perf jit: genelf makes assumptions about endian 2016-03-30 18:12:06 -03:00
generate-cmdlist.sh perf tools: Do not show trace command if it's not compiled in 2016-01-08 12:46:17 -03:00
header.c perf test: Remove 'core_id' check in topo test 2016-03-11 13:45:04 -03:00
header.h perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
help-unknown-cmd.c perf config: Bring perf_default_config to the very beginning at main() 2016-02-26 19:49:16 -03:00
help-unknown-cmd.h perf tools: Move help_unknown_cmd() to its own file 2015-12-14 12:30:37 -03:00
hist.c perf tools: Make hists__collapse_insert_entry static 2016-03-30 11:14:07 -03:00
hist.h perf tools: Make hists__collapse_insert_entry static 2016-03-30 11:14:07 -03:00
intel-bts.c perf tools: Add support for skipping itrace instructions 2016-03-30 11:14:09 -03:00
intel-bts.h perf tools: Add Intel BTS support 2015-08-21 11:34:10 -03:00
intel-pt.c perf tools: Add support for skipping itrace instructions 2016-03-30 11:14:09 -03:00
intel-pt.h perf tools: Pass Intel PT information for decoding MTC and CYC 2015-08-24 17:46:43 -03:00
intlist.c
intlist.h
jit.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
jitdump.c perf jit: Add support for using TSC as a timestamp 2016-04-01 18:42:55 -03:00
jitdump.h perf jit: Add support for using TSC as a timestamp 2016-04-01 18:42:55 -03:00
kvm-stat.h perf kvm/powerpc: Port perf kvm stat to powerpc 2016-01-29 17:49:54 -03:00
levenshtein.c
levenshtein.h
llvm-utils.c perf llvm: Use strerror_r instead of the thread unsafe strerror one 2016-03-23 17:42:21 -03:00
llvm-utils.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
lzma.c perf tools: Add lzma decompression support for kernel module 2015-03-21 14:53:40 -03:00
machine.c perf tools: Add cpumode to struct perf_sample 2016-03-23 12:03:07 -03:00
machine.h perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
map.c perf symbols: Record text offset in dso to calculate objdump address 2016-04-08 09:58:14 -03:00
map.h perf maps: Introduce maps__find_symbol_by_name() 2015-09-30 18:34:25 -03:00
mem-events.c perf script: Display data_src values 2016-02-24 10:32:11 -03:00
mem-events.h perf script: Display data_src values 2016-02-24 10:32:11 -03:00
ordered-events.c perf ordered_events: Clear the progress bar at the end of a flush 2015-08-24 17:16:22 -03:00
ordered-events.h perf ordered_samples: Remove references to perf_{evlist,tool} and machines 2015-03-31 17:52:32 -03:00
parse-branch-options.c perf subcmd: Create subcmd library 2015-12-17 14:27:14 -03:00
parse-branch-options.h perf tools: Move branch option parsing to own file 2015-05-27 21:02:17 -03:00
parse-events.c perf tools: Apply tracepoint event definition options to BPF script 2016-02-22 13:02:44 -03:00
parse-events.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
parse-events.l perf tools: Introduce bpf-output event 2016-02-22 14:37:21 -03:00
parse-events.y perf tools: Explicitly declare inc_group_count as a void function 2016-03-08 10:11:16 +01:00
parse-regs-options.c perf subcmd: Create subcmd library 2015-12-17 14:27:14 -03:00
parse-regs-options.h perf record: Add ability to name registers to record 2015-08-31 18:01:33 -03:00
path.c perf tools: Remove unused perf_pathdup, xstrdup functions 2016-03-23 15:27:33 -03:00
perf_regs.c perf tools: Fix build break on powerpc due to sample_reg_masks 2015-09-30 18:34:27 -03:00
perf_regs.h perf tools: Fix build break on powerpc due to sample_reg_masks 2015-09-30 18:34:27 -03:00
PERF-VERSION-GEN
pmu.c perf tools: Fix PMU term format max value calculation 2016-04-01 18:46:24 -03:00
pmu.h perf tools: Add perf_pmu__format_bits() 2015-08-06 16:49:01 -03:00
pmu.l
pmu.y
probe-event.c perf probe: No need to use formatting strbuf method 2016-03-23 16:53:05 -03:00
probe-event.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
probe-file.c perf probe: Verify parameters in two functions 2015-11-11 18:41:32 -03:00
probe-file.h perf probe: Print deleted events in cmd_probe() 2015-09-04 12:43:44 -03:00
probe-finder.c perf probe: No need to use formatting strbuf method 2016-03-23 16:53:05 -03:00
probe-finder.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
pstack.c perf tools: Introduce pstack_peek() 2015-05-05 18:13:22 -03:00
pstack.h perf tools: Introduce pstack_peek() 2015-05-05 18:13:22 -03:00
python-ext-sources tools lib: Move bitmap.[ch] from tools/perf/ to tools/{lib,include}/ 2016-01-08 12:35:46 -03:00
python.c perf python: Support the PERF_RECORD_SWITCH event 2015-10-07 19:41:50 -03:00
quote.c
quote.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
rblist.c
rblist.h
record.c perf tools: Add a helper function to probe whether cpu-wide tracing is possible 2015-08-17 11:08:37 -03:00
session.c perf tools: Add time conversion event 2016-03-31 10:52:24 -03:00
session.h perf tools: Add time conversion event 2016-03-31 10:52:24 -03:00
setup.py perf tools: Fix python extension build 2016-02-29 11:18:25 -03:00
sort.c perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
sort.h perf tools: Add sort__has_comm variable 2016-03-10 16:47:19 -03:00
srcline.c perf tools: Always use non inlined file name for 'srcfile' sort key 2015-09-02 16:30:46 -03:00
stat-shadow.c perf tools: Remove misplaced __maybe_unused 2016-03-23 12:03:04 -03:00
stat.c Merge branch 'perf/urgent' into perf/core, to pick up fixes 2016-02-04 08:57:44 +01:00
stat.h perf stat: Check for frontend stalled for metrics 2016-03-03 11:10:40 -03:00
strbuf.c perf tools: Unexport some methods unused outside strbuf.c 2016-03-23 17:09:53 -03:00
strbuf.h perf tools: Unexport some methods unused outside strbuf.c 2016-03-23 17:09:53 -03:00
strfilter.c perf tools: Add strfilter__string to recover rules string 2015-05-04 12:43:54 -03:00
strfilter.h perf tools: Add strfilter__string to recover rules string 2015-05-04 12:43:54 -03:00
string.c tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c 2015-11-18 17:51:02 -03:00
strlist.c perf tools: Add file_only config option to strlist 2016-01-12 12:42:07 -03:00
strlist.h perf tools: Add file_only config option to strlist 2016-01-12 12:42:07 -03:00
svghelper.c perf tools: Add reference counting for cpu_map object 2015-06-25 15:15:50 -03:00
svghelper.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
symbol-elf.c perf symbols: Adjust symbol for shared objects 2016-04-08 09:58:15 -03:00
symbol-minimal.c perf symbols: Fix type error when reading a build-id 2015-10-28 10:02:00 -03:00
symbol.c perf symbols: Fix symbols searching for module in buildid-cache 2016-02-12 10:54:47 -03:00
symbol.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
syscalltbl.c perf tools: Build syscall table .c header from kernel's syscall_64.tbl 2016-04-08 09:58:14 -03:00
syscalltbl.h perf tools: Allow generating per-arch syscall table arrays 2016-04-08 09:58:14 -03:00
target.c perf target: Simplify handling of strerror_r return 2015-03-24 12:08:30 -03:00
target.h
term.c perf tools: Move term functions out of util.c 2015-12-09 13:42:02 -03:00
term.h perf tools: Move term functions out of util.c 2015-12-09 13:42:02 -03:00
thread_map.c perf thread_map: Add thread_map__new_event function 2015-12-17 14:38:16 -03:00
thread_map.h perf thread_map: Add thread_map__new_event function 2015-12-17 14:38:16 -03:00
thread-stack.c perf tools: Ensure thread-stack is flushed 2015-06-19 16:03:33 -03:00
thread-stack.h perf tools: Ensure thread-stack is flushed 2015-06-19 16:03:33 -03:00
thread.c perf thread: Fix reference count initial state 2015-12-14 12:08:55 -03:00
thread.h perf tools: Add dedicated unwind addr_space member into thread struct 2016-04-08 09:58:02 -03:00
tool.h perf tools: Add time conversion event 2016-03-31 10:52:24 -03:00
top.c
top.h
trace-event-info.c tools lib api fs: Move tracing_path interface into api/fs/tracing_path.c 2015-09-04 12:00:45 -03:00
trace-event-parse.c irq_poll: make blk-iopoll available outside the block layer 2015-12-11 11:52:24 -08:00
trace-event-read.c perf tools: Stop reading the kallsyms data from perf.data 2015-07-23 22:51:11 -03:00
trace-event-scripting.c perf scripting: No need to pass thread twice to the scripting callbacks 2015-04-02 13:18:41 -03:00
trace-event.c tools lib api fs: Adopt filename__read_str from perf 2016-02-16 17:12:56 -03:00
trace-event.h perf script: Add process_stat/process_stat_interval scripting interface 2016-01-06 20:11:15 -03:00
tsc.c perf tools: Use 64-bit shifts with (TSC) time conversion 2016-03-08 10:11:18 +01:00
tsc.h perf jit: Add support for using TSC as a timestamp 2016-04-01 18:42:55 -03:00
unwind-libdw.c perf libdw: Check for mmaps also in MAP__VARIABLE tree 2016-01-08 14:16:57 -03:00
unwind-libdw.h perf callchain: Add order support for libdw DWARF unwinder 2015-11-23 18:31:13 -03:00
unwind-libunwind.c perf tools: Add dedicated unwind addr_space member into thread struct 2016-04-08 09:58:02 -03:00
unwind.h
usage.c perf tools: Simplify die() mechanism 2016-03-23 12:32:31 -03:00
util.c perf tools: Make binary data printer code in trace_event public available 2016-02-24 11:38:01 -03:00
util.h perf tools: Introduce trim function 2016-04-07 10:21:49 -03:00
values.c
values.h
vdso.c perf tools: Fix lockup using 32-bit compat vdso 2015-07-07 11:05:08 -03:00
vdso.h perf machine: Fix up vdso methods names 2015-05-29 12:43:44 -03:00
wrapper.c perf tools: Remove unused perf_pathdup, xstrdup functions 2016-03-23 15:27:33 -03:00
xyarray.c perf tools: Introduce xyarray__reset function 2015-06-16 10:34:39 -03:00
xyarray.h perf tools: Introduce xyarray__reset function 2015-06-16 10:34:39 -03:00
zlib.c