linux-stable/tools/perf
Masami Hiramatsu 3de2bf9dfb perf probe: Warn if the target function is a GNU indirect function
Warn if the probe target function is a GNU indirect function (GNU_IFUNC)
because it may not be what the user wants to probe.

The GNU indirect function ( https://sourceware.org/glibc/wiki/GNU_IFUNC )
is the dynamic symbol solved at runtime. An IFUNC function is a selector
which is invoked from the ELF loader, but the symbol address of the
function which will be modified by the IFUNC is the same as the IFUNC in
the symbol table. This can confuse users trying to probe such functions.

For example, memcpy is an IFUNC.

  probe_libc:memcpy    (on __new_memcpy_ifunc@x86_64/multiarch/memcpy.c in /usr/lib64/libc-2.30.so)

the probe is put on an IFUNC.

  perf  1742 [000] 26201.715632: probe_libc:memcpy: (7fdaa53824c0)
              7fdaa53824c0 __new_memcpy_ifunc+0x0 (inlined)
              7fdaa5d4a980 elf_machine_rela+0x6c0 (inlined)
              7fdaa5d4a980 elf_dynamic_do_Rela+0x6c0 (inlined)
              7fdaa5d4a980 _dl_relocate_object+0x6c0 (/usr/lib64/ld-2.30.so)
              7fdaa5d42155 dl_main+0x1cc5 (/usr/lib64/ld-2.30.so)
              7fdaa5d5831a _dl_sysdep_start+0x54a (/usr/lib64/ld-2.30.so)
              7fdaa5d3ffeb _dl_start_final+0x25b (inlined)
              7fdaa5d3ffeb _dl_start+0x25b (/usr/lib64/ld-2.30.so)
              7fdaa5d3f117 .annobin_rtld.c+0x7 (inlined)

And the event is invoked from the ELF loader instead of the target
program's main code.

Moreover, at this moment, we can not probe on the function which will
be selected by the IFUNC, because it is determined at runtime. But
uprobe will be prepared before running the target binary.

Thus, I decided to warn user when 'perf probe' detects that the probe
point is on an GNU IFUNC symbol. Someone who wants to probe an IFUNC
symbol to debug the IFUNC function can ignore this warning.

Committer notes:

I.e., this warning will be emitted if the probe point is an IFUNC:

  "Warning: The probe function (%s) is a GNU indirect function.\n"
  "Consider identifying the final function used at run time and set the probe directly on that.\n"

Complete set of steps:

  # readelf -sW /lib64/libc-2.29.so  | grep IFUNC | tail
   22196: 0000000000109a80   183 IFUNC   GLOBAL DEFAULT   14 __memcpy_chk
   22214: 00000000000b7d90   191 IFUNC   GLOBAL DEFAULT   14 __gettimeofday
   22336: 000000000008b690    60 IFUNC   GLOBAL DEFAULT   14 memchr
   22350: 000000000008b9b0    89 IFUNC   GLOBAL DEFAULT   14 __stpcpy
   22420: 000000000008bb10    76 IFUNC   GLOBAL DEFAULT   14 __strcasecmp_l
   22582: 000000000008a970    60 IFUNC   GLOBAL DEFAULT   14 strlen
   22585: 00000000000a54d0    92 IFUNC   WEAK   DEFAULT   14 wmemset
   22600: 000000000010b030    92 IFUNC   GLOBAL DEFAULT   14 __wmemset_chk
   22618: 000000000008b8a0   183 IFUNC   GLOBAL DEFAULT   14 __mempcpy
   22675: 000000000008ba70    76 IFUNC   WEAK   DEFAULT   14 strcasecmp
  #
  # perf probe -x /lib64/libc-2.29.so strlen
  Warning: The probe function (strlen) is a GNU indirect function.
  Consider identifying the final function used at run time and set the probe directly on that.
  Added new event:
    probe_libc:strlen    (on strlen in /usr/lib64/libc-2.29.so)

  You can now use it in all perf tools, such as:

  	perf record -e probe_libc:strlen -aR sleep 1

  #

Reported-by: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Link: http://lore.kernel.org/lkml/159438669349.62703.5978345670436126948.stgit@devnote2
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-07-17 09:09:47 -03:00
..
arch perf intel-pt: Add support for text poke events 2020-07-10 08:31:21 -03:00
bench perf tools: Replace zero-length array with flexible-array 2020-05-28 10:03:27 -03:00
Documentation perf script: Add option --show-text-poke-events 2020-07-10 08:31:45 -03:00
examples/bpf Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next 2020-01-28 16:02:33 -08:00
include/bpf perf bpf: Remove bpf/ subdir from bpf.h headers used to build bpf events 2020-02-18 10:13:28 -03:00
jvmti perf jvmti: Remove redundant jitdump line table entries 2020-05-29 16:51:38 -03:00
pmu-events perf vendor events power9: Added nest imc metric events 2020-07-06 09:38:03 -03:00
python
scripts perf scripts python: exported-sql-viewer.py: Fix time chart call tree 2020-07-03 08:19:52 -03:00
tests perf script: Show text poke address symbol 2020-07-10 08:39:14 -03:00
trace perf beauty: Add support to STATX_MNT_ID in the 'statx' syscall 'mask' argument 2020-06-09 12:40:03 -03:00
ui Merge remote-tracking branch 'torvalds/master' into perf/core 2020-07-08 13:49:15 -03:00
util perf probe: Warn if the target function is a GNU indirect function 2020-07-17 09:09:47 -03:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Build
builtin-annotate.c perf evsel: Rename perf_evsel__resort*() to evsel__resort*() 2020-05-28 10:03:24 -03:00
builtin-bench.c tools feature: Rename HAVE_EVENTFD to HAVE_EVENTFD_SUPPORT 2020-05-28 10:03:26 -03:00
builtin-buildid-cache.c perf session: Return error code for perf_session__new() function on failure 2019-09-20 15:58:11 -03:00
builtin-buildid-list.c perf session: Return error code for perf_session__new() function on failure 2019-09-20 15:58:11 -03:00
builtin-c2c.c perf evlist: Fix the class prefix for 'struct evlist' sample_type methods 2020-06-22 16:28:09 -03:00
builtin-config.c perf tools: Remove util.h from where it is not needed 2019-09-20 09:19:20 -03:00
builtin-data.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
builtin-diff.c perf evsel: Rename perf_evsel__is_*() to evsel__is*() 2020-05-05 16:35:31 -03:00
builtin-evlist.c perf evsel: Rename perf_evsel__fprintf() to evsel__fprintf() 2020-05-28 10:03:24 -03:00
builtin-ftrace.c perf ftrace: Detect workload failure 2020-05-28 10:03:27 -03:00
builtin-help.c perf debug: Remove needless include directives from debug.h 2019-08-31 19:10:19 -03:00
builtin-inject.c perf inject jit: Remove //anon mmap events 2020-07-08 13:51:12 -03:00
builtin-kallsyms.c perf dsos: Move the dsos struct and its methods to separate source files 2019-08-31 22:24:10 -03:00
builtin-kmem.c perf kmem: Pass additional arguments to 'perf record' 2020-07-10 09:37:55 -03:00
builtin-kvm.c perf evlist: Fix the class prefix for 'struct evlist' 'add' evsel methods 2020-06-22 16:28:09 -03:00
builtin-list.c perf list: Add metrics to command line usage 2020-05-28 10:03:28 -03:00
builtin-lock.c perf lock: Rename perf_evsel__*() operating on 'struct evsel *' to evsel__*() 2020-05-05 16:35:31 -03:00
builtin-mem.c perf c2c: Fix 'perf c2c record -e list' to show the default events used 2020-05-28 10:03:25 -03:00
builtin-probe.c perf probe: Do not show the skipped events 2020-05-28 10:03:24 -03:00
builtin-record.c perf tools: Add support for PERF_RECORD_TEXT_POKE 2020-07-10 08:20:01 -03:00
builtin-report.c perf evlist: Fix the class prefix for 'struct evlist' branch_type methods 2020-06-22 16:28:10 -03:00
builtin-sched.c perf sched: Rename perf_evsel__*() operating on 'struct evsel *' to evsel__*() 2020-05-05 16:35:31 -03:00
builtin-script.c perf script: Show text poke address symbol 2020-07-10 08:39:14 -03:00
builtin-stat.c perf evlist: Fix the class prefix for 'struct evlist' 'add' evsel methods 2020-06-22 16:28:09 -03:00
builtin-timechart.c perf tools: Replace zero-length array with flexible-array 2020-05-28 10:03:27 -03:00
builtin-top.c perf evlist: Fix the class prefix for 'struct evlist' 'add' evsel methods 2020-06-22 16:28:09 -03:00
builtin-trace.c perf evlist: Fix the class prefix for 'struct evlist' strerror methods 2020-06-22 16:28:09 -03:00
builtin-version.c perf symbols: Move mem_info and branch_info out of symbol.h 2019-08-31 22:27:48 -03:00
builtin.h perf tools: Remove needless util.h include from builtin.h 2019-08-28 17:19:34 -03:00
check-headers.sh perf tools: Grab a copy of libbpf's hashmap 2020-05-28 10:03:26 -03:00
command-list.txt
CREDITS
design.txt perf tools: Support CAP_PERFMON capability 2020-04-16 12:19:08 -03:00
Makefile tools: Let O= makes handle a relative path with -C option 2020-03-06 17:08:28 -03:00
Makefile.config perf build: Fix error message when asking for -fsanitize=address without required libraries 2020-06-18 10:34:31 -03:00
Makefile.perf perf tools: Add optional support for libpfm4 2020-05-29 16:51:38 -03:00
MANIFEST libperf: Move to tools/lib/perf 2020-01-06 11:46:09 -03:00
perf-archive.sh
perf-completion.sh
perf-read-vdso.c
perf-sys.h perf tools: Make usage of test_attr__* optional for perf-sys.h 2019-10-31 21:38:41 +01:00
perf-with-kcore.sh
perf.c libperf: Merge libperf_set_print() into libperf_init() 2019-09-25 09:51:49 -03:00
perf.h perf time-utils: Adopt rdclock() from perf.h 2019-08-29 17:38:32 -03:00