diff options
| author | Dave Marchevsky <[email protected]> | 2021-09-17 18:29:07 +0000 |
|---|---|---|
| committer | Alexei Starovoitov <[email protected]> | 2021-09-17 21:02:05 +0000 |
| commit | 6c66b0e7c91a1320c1b85ad8150bdd534eb4ddae (patch) | |
| tree | fe11dc67b044b33bb16b5603bfe14652594fcc7e /tools/lib/bpf/bpf_helpers.h | |
| parent | libbpf: Modify bpf_printk to choose helper based on arg count (diff) | |
| download | kernel-6c66b0e7c91a1320c1b85ad8150bdd534eb4ddae.tar.gz kernel-6c66b0e7c91a1320c1b85ad8150bdd534eb4ddae.zip | |
libbpf: Use static const fmt string in __bpf_printk
The __bpf_printk convenience macro was using a 'char' fmt string holder
as it predates support for globals in libbpf. Move to more efficient
'static const char', but provide a fallback to the old way via
BPF_NO_GLOBAL_DATA so users on old kernels can still use the macro.
Signed-off-by: Dave Marchevsky <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Acked-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 | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h index 55a308796625..963b1060d944 100644 --- a/tools/lib/bpf/bpf_helpers.h +++ b/tools/lib/bpf/bpf_helpers.h @@ -216,9 +216,15 @@ enum libbpf_tristate { ___param, sizeof(___param)); \ }) +#ifdef BPF_NO_GLOBAL_DATA +#define BPF_PRINTK_FMT_MOD +#else +#define BPF_PRINTK_FMT_MOD static const +#endif + #define __bpf_printk(fmt, ...) \ ({ \ - char ____fmt[] = fmt; \ + BPF_PRINTK_FMT_MOD char ____fmt[] = fmt; \ bpf_trace_printk(____fmt, sizeof(____fmt), \ ##__VA_ARGS__); \ }) |
