Add a test_ksyms_strong_typeless light skeleton and a ksyms_btf/strong_typeless_lskel subtest referencing a nonexistent strong typeless ksym. Light skeleton generation succeeds at build time even though the symbol does not exist on the build host, and loading the generated skeleton fails with -ENOENT on the target kernel. Signed-off-by: ThiƩbaud Weksteen --- tools/testing/selftests/bpf/Makefile.skel | 3 ++- .../selftests/bpf/prog_tests/ksyms_btf.c | 19 +++++++++++++++++++ .../bpf/progs/test_ksyms_strong_typeless.c | 16 ++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/bpf/progs/test_ksyms_strong_typeless.c diff --git a/tools/testing/selftests/bpf/Makefile.skel b/tools/testing/selftests/bpf/Makefile.skel index 334342928d01..1c639b089c99 100644 --- a/tools/testing/selftests/bpf/Makefile.skel +++ b/tools/testing/selftests/bpf/Makefile.skel @@ -35,7 +35,8 @@ LSKELS := fexit_sleep.c trace_printk.c trace_vprintk.c map_ptr_kern.c \ core_kern.c core_kern_overflow.c test_ringbuf.c \ test_ringbuf_n.c test_ringbuf_map_key.c test_ringbuf_write.c \ test_ringbuf_overwrite.c callx_rodata.c many_progs.c \ - struct_ops_vmlinux.c struct_ops_mod.c + struct_ops_vmlinux.c struct_ops_mod.c \ + test_ksyms_strong_typeless.c LSKELS_SIGNED := fentry_test.c fexit_test.c atomics.c diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c b/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c index 1d7a2f1e0731..1bc3089f10fc 100644 --- a/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c +++ b/tools/testing/selftests/bpf/prog_tests/ksyms_btf.c @@ -9,6 +9,7 @@ #include "test_ksyms_weak.skel.h" #include "test_ksyms_weak.lskel.h" #include "test_ksyms_btf_write_check.skel.h" +#include "test_ksyms_strong_typeless.lskel.h" static int duration; @@ -138,6 +139,21 @@ static void test_weak_syms_lskel(void) test_ksyms_weak_lskel__destroy(skel); } +static void test_strong_typeless_lskel(void) +{ + struct test_ksyms_strong_typeless_lskel *skel; + int err; + + skel = test_ksyms_strong_typeless_lskel__open(); + if (!ASSERT_OK_PTR(skel, "test_ksyms_strong_typeless_lskel__open")) + return; + + err = test_ksyms_strong_typeless_lskel__load(skel); + ASSERT_EQ(err, -ENOENT, "strong_missing_ksym_load"); + + test_ksyms_strong_typeless_lskel__destroy(skel); +} + static void test_write_check(bool test_handler1) { struct test_ksyms_btf_write_check *skel; @@ -183,6 +199,9 @@ void test_ksyms_btf(void) if (test__start_subtest("weak_ksyms_lskel")) test_weak_syms_lskel(); + if (test__start_subtest("strong_typeless_lskel")) + test_strong_typeless_lskel(); + if (test__start_subtest("write_check1")) test_write_check(true); diff --git a/tools/testing/selftests/bpf/progs/test_ksyms_strong_typeless.c b/tools/testing/selftests/bpf/progs/test_ksyms_strong_typeless.c new file mode 100644 index 000000000000..e7f20cd34f0d --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_ksyms_strong_typeless.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2026 Google */ + +#include +#include + +/* Strong typeless ksym that does not exist in the kernel. */ +extern const void bpf_nonexistent_strong_ksym __ksym; + +SEC("raw_tp/sys_enter") +int handler(const void *ctx) +{ + return (int)(__u64)&bpf_nonexistent_strong_ksym; +} + +char _license[] SEC("license") = "GPL"; -- 2.56.1.987.g2ec0ab4260-goog