diff options
| author | Alexei Starovoitov <[email protected]> | 2023-03-17 20:19:19 +0000 |
|---|---|---|
| committer | Andrii Nakryiko <[email protected]> | 2023-03-17 22:46:00 +0000 |
| commit | 5cbd3fe3a91df46ea201cc5d8ab4e390332ec26e (patch) | |
| tree | 0731f47023f2105efcca7be36cbacffaf5269d36 /tools/lib/bpf/bpf_helpers.h | |
| parent | libbpf: Fix relocation of kfunc ksym in ld_imm64 insn. (diff) | |
| download | kernel-5cbd3fe3a91df46ea201cc5d8ab4e390332ec26e.tar.gz kernel-5cbd3fe3a91df46ea201cc5d8ab4e390332ec26e.zip | |
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]
Diffstat (limited to 'tools/lib/bpf/bpf_helpers.h')
| -rw-r--r-- | tools/lib/bpf/bpf_helpers.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h index 7d12d3e620cc..e7e1a8acc299 100644 --- a/tools/lib/bpf/bpf_helpers.h +++ b/tools/lib/bpf/bpf_helpers.h @@ -177,6 +177,11 @@ 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 |
