linux-stable/tools/perf/tests
Wang Nan 9b57fb7e35 perf test llvm: Avoid error when PROFILE_ALL_BRANCHES is set
The 'if' keyword is a define that expands to complex code when
CONFIG_PROFILE_ALL_BRANCHES is selected, which causes a 'perf test LLVM'
failure like:

  $ ./perf test LLVM
  35: LLVM search and compile                    :
  35.1: Basic BPF llvm compile                    : Ok
  35.2: kbuild searching                          : Ok
  35.3: Compile source for BPF prologue generation: FAILED!
  35.4: Compile source for BPF relocation         : Skip

The only affected test case is bpf-script-test-prologue.c
because it uses kernel headers and has 'if' inside.

This patch undefines 'if' to make it passes perf test.

More detailed analysis from a message in this thread, also by Wang:

The problem is caused by following relocation information:

  $ readelf -a ./llvmsubtest3
  ...
     [ 5] _ftrace_branch    PROGBITS         0000000000000000  00000260
          00000000000000a0  0000000000000000  WA       0     0     4
  ...
  Relocation section '.relfunc=null_lseek file->f_mode offset orig' at
  offset 0x490 contains 4 entries:
     Offset          Info           Type           Sym. Value    Sym. Name
  000000000038  000b00000001 unrecognized: 1       0000000000000000 _ftrace_branch
  0000000000b0  000b00000001 unrecognized: 1       0000000000000000 _ftrace_branch
  000000000128  000b00000001 unrecognized: 1       0000000000000000 _ftrace_branch
  0000000001c0  000b00000001 unrecognized: 1       0000000000000000 _ftrace_branch

  Relocation section '.rel_ftrace_branch' at offset 0x4d0 contains 8 entries:
     Offset          Info           Type           Sym. Value    Sym. Name
  000000000000  000200000001 unrecognized: 1       0000000000000000 .L__func__.bpf_func__n
  000000000008  000100000001 unrecognized: 1       0000000000000015 .L.str
  000000000028  000200000001 unrecognized: 1       0000000000000000 .L__func__.bpf_func__n
  000000000030  000100000001 unrecognized: 1       0000000000000015 .L.str
  000000000050  000200000001 unrecognized: 1       0000000000000000 .L__func__.bpf_func__n
  000000000058  000100000001 unrecognized: 1       0000000000000015 .L.str
  000000000078  000200000001 unrecognized: 1       0000000000000000 .L__func__.bpf_func__n
  000000000080  000100000001 unrecognized: 1       0000000000000015 .L.str
  ...

So I think the failure is because you enabled CONFIG_PROFILE_ALL_BRANCHES.

I can reproduce your buggy result by selecting
CONFIG_PROFILE_ALL_BRANCHES in my kbuild:

  $ ./perf test LLVM
  35: LLVM search and compile                    :
  35.1: Basic BPF llvm compile                    : Ok
  35.2: kbuild searching                          : Ok
  35.3: Compile source for BPF prologue generation: FAILED!
  35.4: Compile source for BPF relocation         : Skip

Simply undef CONFIG_PROFILE_ALL_BRANCHES in clang opts not working
because it is introduced by "#include <uapi/linux/fs.h>", which override
cmdline options. So I think the best way is to undefine 'if' inside BPF
script.

Reported-and-Tested-by: Thomas-Mich Richter <tmricht@linux.vnet.ibm.com>
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Cc: Zefan Li <lizefan@huawei.com>
Link: http://lkml.kernel.org/r/20170620183203.2517-1-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-06-19 16:11:26 -03:00
..
attr perf tests: Fix attr tests 2015-04-08 10:49:53 -03:00
.gitignore perf test: Add libbpf relocation checker 2016-01-26 12:10:55 -03:00
attr.c perf tools: Remove string.h, unistd.h and sys/stat.h from util.h 2017-04-24 13:43:33 -03:00
attr.py perf tools: Remove EOL whitespaces 2015-01-21 13:24:31 -03:00
backward-ring-buffer.c perf tools: Include errno.h where needed 2017-04-19 13:01:51 -03:00
bitmap.c perf tests: Add test for bitmap_scnprintf function 2016-08-02 16:33:27 -03:00
bp_signal.c tools: Adopt noinline from kernel sources 2017-06-19 15:27:06 -03:00
bp_signal_overflow.c tools: Adopt noinline from kernel sources 2017-06-19 15:27:06 -03:00
bpf-script-example.c perf tests bpf: Use SyS_epoll_wait alias 2016-08-03 19:40:48 -03:00
bpf-script-test-kbuild.c perf test: Enhance the LLVM tests: add kbuild test 2015-11-06 17:49:50 -03:00
bpf-script-test-prologue.c perf test llvm: Avoid error when PROFILE_ALL_BRANCHES is set 2017-06-19 16:11:26 -03:00
bpf-script-test-relocation.c perf test: Add libbpf relocation checker 2016-01-26 12:10:55 -03:00
bpf.c perf tools: Remove string.h, unistd.h and sys/stat.h from util.h 2017-04-24 13:43:33 -03:00
Build perf tools: Fix build with ARCH=x86_64 2017-06-14 15:44:29 -03:00
builtin-test.c perf test: Disable breakpoint signal tests for powerpc 2017-06-05 14:18:01 -03:00
clang.c perf tools: Add include <linux/kernel.h> where ARRAY_SIZE() is used 2017-04-19 13:01:44 -03:00
code-reading.c perf tests: Decompress kernel module before objdump 2017-06-08 15:39:19 -03:00
cpumap.c perf cpumap: Convert cpu_map.refcnt from atomic_t to refcount_t 2017-03-03 19:07:14 -03:00
dso-data.c perf tools: Remove include dirent.h from util.h 2017-04-19 13:01:55 -03:00
dwarf-unwind.c tools: Adopt noinline from kernel sources 2017-06-19 15:27:06 -03:00
event-times.c perf tools: Remove poll.h and wait.h from util.h 2017-04-24 13:43:34 -03:00
event_update.c perf tests: Replace assignment with comparison on assert check 2016-04-25 20:24:26 -03:00
evsel-roundtrip-name.c perf tools: Include errno.h where needed 2017-04-19 13:01:51 -03:00
evsel-tp-sched.c perf tests: Pass the subtest index to each test routine 2015-11-19 13:19:15 -03:00
expr.c perf tools: Add a simple expression parser for JSON 2017-03-23 11:39:27 -03:00
fdarray.c perf utils: Check verbose flag properly 2017-02-20 11:35:54 -03:00
hists_common.c perf tools: Including missing inttypes.h header 2017-04-19 13:01:46 -03:00
hists_common.h perf tests: Define and use symbolic names for fake symbols 2014-06-01 14:35:11 +02:00
hists_cumulate.c perf tools: Move event prototypes from util.h to event.h 2017-04-25 15:30:47 -03:00
hists_filter.c perf tools: Move event prototypes from util.h to event.h 2017-04-25 15:30:47 -03:00
hists_link.c perf tools: Include errno.h where needed 2017-04-19 13:01:51 -03:00
hists_output.c perf tools: Move event prototypes from util.h to event.h 2017-04-25 15:30:47 -03:00
is_printable_array.c perf tools: Move print_binary definitions to separate files 2017-04-19 13:01:50 -03:00
keep-tracking.c perf evsel: Do not use globals in config() 2016-04-11 22:18:20 -03:00
kmod-path.c perf tests kmod-path: Don't fail if compressed modules aren't supported 2017-05-04 10:05:55 -03:00
llvm.c perf utils: Check verbose flag properly 2017-02-20 11:35:54 -03:00
llvm.h perf clang: Update test case to use real BPF script 2016-12-05 15:51:44 -03:00
make Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild 2016-12-17 16:24:13 -08:00
mmap-basic.c perf tools: Include errno.h where needed 2017-04-19 13:01:51 -03:00
mmap-thread-lookup.c perf tools: Move path related functions to util/path.h 2017-04-19 13:01:53 -03:00
openat-syscall-all-cpus.c perf tools: Move path related functions to util/path.h 2017-04-19 13:01:53 -03:00
openat-syscall-tp-fields.c perf tools: Include errno.h where needed 2017-04-19 13:01:51 -03:00
openat-syscall.c perf tools: Move path related functions to util/path.h 2017-04-19 13:01:53 -03:00
parse-events.c perf tools: Remove string.h, unistd.h and sys/stat.h from util.h 2017-04-24 13:43:33 -03:00
parse-no-sample-id-all.c perf tools: Add include <linux/kernel.h> where ARRAY_SIZE() is used 2017-04-19 13:01:44 -03:00
perf-hooks.c perf tools: Pass context to perf hook functions 2016-12-05 15:51:42 -03:00
perf-record.c perf tools: Include errno.h where needed 2017-04-19 13:01:51 -03:00
perf-targz-src-pkg perf tests: Fix tarpkg build test error output redirection 2016-03-24 12:26:41 -03:00
pmu.c perf tools: Include errno.h where needed 2017-04-19 13:01:51 -03:00
python-use.c perf utils: Check verbose flag properly 2017-02-20 11:35:54 -03:00
sample-parsing.c perf tools: Including missing inttypes.h header 2017-04-19 13:01:46 -03:00
sdt.c perf buildid: Move prototypes from util.h to build-id.h 2017-04-25 11:45:59 -03:00
stat.c perf tools: Add stat round event synthesize function 2015-12-17 14:55:44 -03:00
sw-clock.c perf tools: Include errno.h where needed 2017-04-19 13:01:51 -03:00
switch-tracking.c perf tools: Include errno.h where needed 2017-04-19 13:01:51 -03:00
task-exit.c perf evsel: Fix probing of precise_ip level for default cycles event 2017-06-14 15:44:29 -03:00
tests.h perf test: Disable breakpoint signal tests for powerpc 2017-06-05 14:18:01 -03:00
thread-map.c perf thread_map: Convert thread_map.refcnt from atomic_t to refcount_t 2017-03-03 19:07:16 -03:00
thread-mg-share.c perf map: Convert map_groups.refcnt from atomic_t to refcount_t 2017-03-03 19:07:15 -03:00
topology.c perf tools: Replace _SC_NPROCESSORS_CONF with max_present_cpu in cpu_topology_map 2017-02-17 12:56:35 -03:00
unit_number__scnprintf.c perf tools: Move units conversion/formatting routines to separate object 2017-04-20 13:22:44 -03:00
vmlinux-kallsyms.c perf tools: Including missing inttypes.h header 2017-04-19 13:01:46 -03:00