Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Lin <glin@suse.com>2019-11-06 17:49:33 +0800
committerGary Lin <glin@suse.com>2019-11-06 17:49:38 +0800
commitee39cd0578a5d09027c26a90bb91db262a38f504 (patch)
tree2e739a54cabfb8b6a15bcd37a3a13f17994f6205
parent69b6cc62374d7a41ffa09a281e149907ad50f766 (diff)
tools: bpftool: move "__printf()" attributes to header file
(bsc#1155518).
-rw-r--r--patches.suse/tools-bpftool-move-__printf-attributes-to-header-fil.patch132
-rw-r--r--series.conf1
2 files changed, 133 insertions, 0 deletions
diff --git a/patches.suse/tools-bpftool-move-__printf-attributes-to-header-fil.patch b/patches.suse/tools-bpftool-move-__printf-attributes-to-header-fil.patch
new file mode 100644
index 0000000000..585a97a61b
--- /dev/null
+++ b/patches.suse/tools-bpftool-move-__printf-attributes-to-header-fil.patch
@@ -0,0 +1,132 @@
+From: Quentin Monnet <quentin.monnet@netronome.com>
+Date: Thu, 15 Aug 2019 15:32:20 +0100
+Subject: tools: bpftool: move "__printf()" attributes to header file
+Patch-mainline: v5.4-rc1
+Git-commit: 8918dc42dc85ba6981028f65a989c478eb80bc02
+References: bsc#1155518
+
+Some functions in bpftool have a "__printf()" format attributes to tell
+the compiler they should expect printf()-like arguments. But because
+these attributes are not used for the function prototypes in the header
+files, the compiler does not run the checks everywhere the functions are
+used, and some mistakes on format string and corresponding arguments
+slipped in over time.
+
+Let's move the __printf() attributes to the correct places.
+
+Note: We add guards around the definition of GCC_VERSION in
+tools/include/linux/compiler-gcc.h to prevent a conflict in jit_disasm.c
+on GCC_VERSION from headers pulled via libbfd.
+
+Fixes: c101189bc968 ("tools: bpftool: fix -Wmissing declaration warnings")
+Reported-by: Jakub Kicinski <jakub.kicinski@netronome.com>
+Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
+Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
+Signed-off-by: Alexei Starovoitov <ast@kernel.org>
+Acked-by: Gary Lin <glin@suse.com>
+---
+ tools/bpf/bpftool/common.c | 4 ++--
+ tools/bpf/bpftool/json_writer.c | 6 ++----
+ tools/bpf/bpftool/json_writer.h | 6 ++++--
+ tools/bpf/bpftool/main.h | 4 ++--
+ tools/include/linux/compiler-gcc.h | 2 ++
+ 5 files changed, 12 insertions(+), 10 deletions(-)
+
+--- a/tools/bpf/bpftool/common.c
++++ b/tools/bpf/bpftool/common.c
+@@ -29,7 +29,7 @@
+ #define BPF_FS_MAGIC 0xcafe4a11
+ #endif
+
+-void __printf(1, 2) p_err(const char *fmt, ...)
++void p_err(const char *fmt, ...)
+ {
+ va_list ap;
+
+@@ -47,7 +47,7 @@ void __printf(1, 2) p_err(const char *fm
+ va_end(ap);
+ }
+
+-void __printf(1, 2) p_info(const char *fmt, ...)
++void p_info(const char *fmt, ...)
+ {
+ va_list ap;
+
+--- a/tools/bpf/bpftool/json_writer.c
++++ b/tools/bpf/bpftool/json_writer.c
+@@ -15,7 +15,6 @@
+ #include <malloc.h>
+ #include <inttypes.h>
+ #include <stdint.h>
+-#include <linux/compiler.h>
+
+ #include "json_writer.h"
+
+@@ -153,8 +152,7 @@ void jsonw_name(json_writer_t *self, con
+ putc(' ', self->out);
+ }
+
+-void __printf(2, 0)
+-jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
++void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
+ {
+ jsonw_eor(self);
+ putc('"', self->out);
+@@ -162,7 +160,7 @@ jsonw_vprintf_enquote(json_writer_t *sel
+ putc('"', self->out);
+ }
+
+-void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...)
++void jsonw_printf(json_writer_t *self, const char *fmt, ...)
+ {
+ va_list ap;
+
+--- a/tools/bpf/bpftool/json_writer.h
++++ b/tools/bpf/bpftool/json_writer.h
+@@ -14,6 +14,7 @@
+ #include <stdbool.h>
+ #include <stdint.h>
+ #include <stdarg.h>
++#include <linux/compiler.h>
+
+ /* Opaque class structure */
+ typedef struct json_writer json_writer_t;
+@@ -30,8 +31,9 @@ void jsonw_pretty(json_writer_t *self, b
+ void jsonw_name(json_writer_t *self, const char *name);
+
+ /* Add value */
+-void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap);
+-void jsonw_printf(json_writer_t *self, const char *fmt, ...);
++void __printf(2, 0) jsonw_vprintf_enquote(json_writer_t *self, const char *fmt,
++ va_list ap);
++void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...);
+ void jsonw_string(json_writer_t *self, const char *value);
+ void jsonw_bool(json_writer_t *self, bool value);
+ void jsonw_float(json_writer_t *self, double number);
+--- a/tools/bpf/bpftool/main.h
++++ b/tools/bpf/bpftool/main.h
+@@ -98,8 +98,8 @@ extern int bpf_flags;
+ extern struct pinned_obj_table prog_table;
+ extern struct pinned_obj_table map_table;
+
+-void p_err(const char *fmt, ...);
+-void p_info(const char *fmt, ...);
++void __printf(1, 2) p_err(const char *fmt, ...);
++void __printf(1, 2) p_info(const char *fmt, ...);
+
+ bool is_prefix(const char *pfx, const char *str);
+ int detect_common_prefix(const char *arg, ...);
+--- a/tools/include/linux/compiler-gcc.h
++++ b/tools/include/linux/compiler-gcc.h
+@@ -6,9 +6,11 @@
+ /*
+ * Common definitions for all gcc versions go here.
+ */
++#ifndef GCC_VERSION
+ #define GCC_VERSION (__GNUC__ * 10000 \
+ + __GNUC_MINOR__ * 100 \
+ + __GNUC_PATCHLEVEL__)
++#endif
+
+ #if GCC_VERSION >= 70000 && !defined(__CHECKER__)
+ # define __fallthrough __attribute__ ((fallthrough))
diff --git a/series.conf b/series.conf
index f68540abca..bc37788aa8 100644
--- a/series.conf
+++ b/series.conf
@@ -1093,6 +1093,7 @@
patches.suse/tools-bpftool-fix-argument-for-p_err-in-BTF-do_dump.patch
patches.suse/tools-bpftool-fix-format-string-for-p_err-in-query_f.patch
patches.suse/tools-bpftool-fix-format-string-for-p_err-in-detect_.patch
+ patches.suse/tools-bpftool-move-__printf-attributes-to-header-fil.patch
patches.suse/btf-fix-return-value-check-in-btf_vmlinux_init.patch
patches.suse/xsk-replace-ndo_xsk_async_xmit-with-ndo_xsk_wakeup.patch
patches.suse/xsk-add-support-for-need_wakeup-flag-in-AF_XDP-rings.patch