Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: fix perf_snapshot_branch_stack link failure

The newly added code to handle bpf_get_branch_snapshot fails to link when
CONFIG_PERF_EVENTS is disabled:

aarch64-linux-ld: kernel/bpf/verifier.o: in function `do_misc_fixups':
verifier.c:(.text+0x1090c): undefined reference to `__SCK__perf_snapshot_branch_stack'

Add a build-time check for that Kconfig symbol around the code to
remove the link time dependency.

Fixes: 314a53623cd4 ("bpf: inline bpf_get_branch_snapshot() helper")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20240405142637.577046-1-arnd@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Arnd Bergmann and committed by
Alexei Starovoitov
58babe27 343ca813

+2 -1
+2 -1
kernel/bpf/verifier.c
··· 20191 20191 } 20192 20192 20193 20193 /* Implement bpf_get_branch_snapshot inline. */ 20194 - if (prog->jit_requested && BITS_PER_LONG == 64 && 20194 + if (IS_ENABLED(CONFIG_PERF_EVENTS) && 20195 + prog->jit_requested && BITS_PER_LONG == 64 && 20195 20196 insn->imm == BPF_FUNC_get_branch_snapshot) { 20196 20197 /* We are dealing with the following func protos: 20197 20198 * u64 bpf_get_branch_snapshot(void *buf, u32 size, u64 flags);