linux-stable/tools/build
Jiri Olsa 5c83eff381 perf build: Stop using __weak bpf_prog_load() to handle older libbpf versions
By adding a feature test for bpf_prog_load() and providing a fallback if
it isn't present in older versions of libbpf.

Committer testing:

  $ rpm -q libbpf-devel
  libbpf-devel-0.4.0-2.fc35.x86_64
  $ make -C tools/perf LIBBPF_DYNAMIC=1 O=/tmp/build/perf install-bin
  $ cat /tmp/build/perf/feature/test-libbpf-bpf_prog_load.make.output
  test-libbpf-bpf_prog_load.c: In function ‘main’:
  test-libbpf-bpf_prog_load.c:6:16: error: implicit declaration of function ‘bpf_prog_load’ [-Werror=implicit-function-declaration]
      6 |         return bpf_prog_load(0 /* prog_type */, NULL /* prog_name */,
        |                ^~~~~~~~~~~~~
  cc1: all warnings being treated as errors
  $

  $ objdump -dS /tmp/build/perf/perf | grep '<bpf_prog_load>:' -A20
  00000000005b2d70 <bpf_prog_load>:
  {
    5b2d70:	55                   	push   %rbp
    5b2d71:	48 89 ce             	mov    %rcx,%rsi
    5b2d74:	4c 89 c8             	mov    %r9,%rax
    5b2d77:	49 89 d2             	mov    %rdx,%r10
    5b2d7a:	4c 89 c2             	mov    %r8,%rdx
    5b2d7d:	48 89 e5             	mov    %rsp,%rbp
    5b2d80:	48 83 ec 18          	sub    $0x18,%rsp
    5b2d84:	64 48 8b 0c 25 28 00 	mov    %fs:0x28,%rcx
    5b2d8b:	00 00
    5b2d8d:	48 89 4d f8          	mov    %rcx,-0x8(%rbp)
    5b2d91:	31 c9                	xor    %ecx,%ecx
  	return bpf_load_program(prog_type, insns, insn_cnt, license,
    5b2d93:	41 8b 49 5c          	mov    0x5c(%r9),%ecx
    5b2d97:	51                   	push   %rcx
    5b2d98:	4d 8b 49 60          	mov    0x60(%r9),%r9
    5b2d9c:	4c 89 d1             	mov    %r10,%rcx
    5b2d9f:	44 8b 40 1c          	mov    0x1c(%rax),%r8d
    5b2da3:	e8 f8 aa e5 ff       	call   40d8a0 <bpf_load_program@plt>
  }
  $

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Link: http://lore.kernel.org/linux-perf-users/YozLKby7ITEtchC9@krava
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-05-26 11:02:02 -03:00
..
Documentation tools build: Add CFLAGS_REMOVE_* support 2016-11-14 11:37:25 -03:00
feature perf build: Stop using __weak bpf_prog_load() to handle older libbpf versions 2022-05-26 11:02:02 -03:00
tests License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Build tools build: Make fixdep a hostprog 2016-10-03 11:40:35 -03:00
Build.include tools build: Enable warnings through HOSTCFLAGS 2021-12-07 22:18:23 -03:00
Makefile kbuild: replace $(if A,A,B) with $(or A,B) 2022-02-15 12:25:56 +09:00
Makefile.build tools build: Fix quiet cmd indentation 2021-05-17 12:10:03 +09:00
Makefile.feature perf build: Stop using __weak bpf_prog_load() to handle older libbpf versions 2022-05-26 11:02:02 -03:00
Makefile.include treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
fixdep.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00