Skip to content

Commit 5cbd3fe

Browse files
Alexei Starovoitovanakryiko
authored andcommitted
libbpf: Introduce bpf_ksym_exists() macro.
Introduce bpf_ksym_exists() macro that can be used by BPF programs to detect at load time whether particular ksym (either variable or kfunc) is present in the kernel. Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 5fc13ad commit 5cbd3fe

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/lib/bpf/bpf_helpers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ enum libbpf_tristate {
177177
#define __kptr_untrusted __attribute__((btf_type_tag("kptr_untrusted")))
178178
#define __kptr __attribute__((btf_type_tag("kptr")))
179179

180+
#define bpf_ksym_exists(sym) ({ \
181+
_Static_assert(!__builtin_constant_p(!!sym), #sym " should be marked as __weak"); \
182+
!!sym; \
183+
})
184+
180185
#ifndef ___bpf_concat
181186
#define ___bpf_concat(a, b) a ## b
182187
#endif

0 commit comments

Comments
 (0)