From: Dave Marchevsky <davemarchevsky@fb.com>
Date: Fri, 17 Sep 2021 11:29:07 -0700
Subject: libbpf: Use static const fmt string in __bpf_printk
Patch-mainline: v5.16-rc1
Git-commit: 6c66b0e7c91a1320c1b85ad8150bdd534eb4ddae
References: jsc#PED-1377
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 <davemarchevsky@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210917182911.2426606-6-davemarchevsky@fb.com
Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
---
tools/lib/bpf/bpf_helpers.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
--- 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__); \
})