From b85e63cb65f96df373b034cc347b0e18231cb0d5 Mon Sep 17 00:00:00 2001 From: "Ricardo B. Marlière" Date: Tue, 2 Jun 2026 10:02:59 -0300 Subject: selftests/bpf: Provide weak definitions for cross-test functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some test files reference functions defined in other translation units that may not be compiled when skeletons are missing. Replace forward declarations of uprobe_multi_func_{1,2,3}() with weak no-op stubs so the linker resolves them regardless of which objects are present. The stub bodies are `asm volatile ("")` rather than empty, matching the shape of the strong definitions in prog_tests/uprobe_multi_test.c. This keeps the weak and strong sides on the same footing for the optimiser (noinline + asm-barrier), which is the form upstream already relies on for these functions. Move stack_mprotect() from test_lsm.c into testing_helpers.c so it is always available. The previous weak-stub approach returned 0, which would cause callers expecting -1/EPERM to fail their assertions deterministically. Having the real implementation in a shared utility avoids this problem entirely. Include for alloca() so the build does not rely on glibc's implicit declaration via . Signed-off-by: Ricardo B. Marlière Link: https://lore.kernel.org/r/20260602-selftests-bpf_misconfig-v12-10-27f898b3ba26@suse.com Signed-off-by: Alexei Starovoitov --- tools/testing/selftests/bpf/testing_helpers.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tools/testing/selftests/bpf/testing_helpers.c') diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c index 6fbe1e995660..c970e7793dfc 100644 --- a/tools/testing/selftests/bpf/testing_helpers.c +++ b/tools/testing/selftests/bpf/testing_helpers.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include #include "disasm.h" @@ -516,3 +518,19 @@ bool is_jit_enabled(void) return enabled; } + +int stack_mprotect(void) +{ + void *buf; + long sz; + int ret; + + sz = sysconf(_SC_PAGESIZE); + if (sz < 0) + return sz; + + buf = alloca(sz * 3); + ret = mprotect((void *)(((unsigned long)(buf + sz)) & ~(sz - 1)), sz, + PROT_READ | PROT_WRITE | PROT_EXEC); + return ret; +} -- cgit v1.2.3