Message ID | 20230317201920.62030-4-alexei.starovoitov@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 5cbd3fe3a91df46ea201cc5d8ab4e390332ec26e |
Delegated to: | BPF |
Headers | show |
Series | bpf: Add detection of kfuncs. | expand |
On Fri, Mar 17, 2023 at 1:19 PM Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: > > From: Alexei Starovoitov <ast@kernel.org> > > 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 <ast@kernel.org> > --- > tools/lib/bpf/bpf_helpers.h | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h > index 7d12d3e620cc..b49823117dae 100644 > --- a/tools/lib/bpf/bpf_helpers.h > +++ b/tools/lib/bpf/bpf_helpers.h > @@ -177,6 +177,9 @@ enum libbpf_tristate { > #define __kptr_untrusted __attribute__((btf_type_tag("kptr_untrusted"))) > #define __kptr __attribute__((btf_type_tag("kptr"))) > > +#define bpf_ksym_exists(sym) \ > + ({ _Static_assert(!__builtin_constant_p(!!sym), #sym " should be marked as __weak"); !!sym; }) > + I reformatted this to fit under 100 characters. -#define bpf_ksym_exists(sym) \ - ({ _Static_assert(!__builtin_constant_p(!!sym), #sym " should be marked as __weak"); !!sym; }) +#define bpf_ksym_exists(sym) ({ \ + _Static_assert(!__builtin_constant_p(!!sym), #sym " should be marked as __weak"); \ + !!sym; \ +}) Other than that, it looks great! Applied to bpf-next, thanks. > #ifndef ___bpf_concat > #define ___bpf_concat(a, b) a ## b > #endif > -- > 2.34.1 >
diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h index 7d12d3e620cc..b49823117dae 100644 --- a/tools/lib/bpf/bpf_helpers.h +++ b/tools/lib/bpf/bpf_helpers.h @@ -177,6 +177,9 @@ enum libbpf_tristate { #define __kptr_untrusted __attribute__((btf_type_tag("kptr_untrusted"))) #define __kptr __attribute__((btf_type_tag("kptr"))) +#define bpf_ksym_exists(sym) \ + ({ _Static_assert(!__builtin_constant_p(!!sym), #sym " should be marked as __weak"); !!sym; }) + #ifndef ___bpf_concat #define ___bpf_concat(a, b) a ## b #endif