aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Monnet <quentin.monnet@netronome.com>2019-08-15 10:32:20 -0400
committerAlexei Starovoitov <ast@kernel.org>2019-08-16 01:06:46 -0400
commit8918dc42dc85ba6981028f65a989c478eb80bc02 (patch)
treefb4d3e3897a5731d4d7bf7a856eb8dc197157c62
parentb0ead6d75a5b335287337e602e6b815e1115481c (diff)
tools: bpftool: move "__printf()" attributes to header file
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>
-rw-r--r--tools/bpf/bpftool/common.c4
-rw-r--r--tools/bpf/bpftool/json_writer.c6
-rw-r--r--tools/bpf/bpftool/json_writer.h6
-rw-r--r--tools/bpf/bpftool/main.h4
-rw-r--r--tools/include/linux/compiler-gcc.h2
5 files changed, 12 insertions, 10 deletions
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index 5215e0870bcb..a7036c70db48 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -29,7 +29,7 @@
29#define BPF_FS_MAGIC 0xcafe4a11 29#define BPF_FS_MAGIC 0xcafe4a11
30#endif 30#endif
31 31
32void __printf(1, 2) p_err(const char *fmt, ...) 32void p_err(const char *fmt, ...)
33{ 33{
34 va_list ap; 34 va_list ap;
35 35
@@ -47,7 +47,7 @@ void __printf(1, 2) p_err(const char *fmt, ...)
47 va_end(ap); 47 va_end(ap);
48} 48}
49 49
50void __printf(1, 2) p_info(const char *fmt, ...) 50void p_info(const char *fmt, ...)
51{ 51{
52 va_list ap; 52 va_list ap;
53 53
diff --git a/tools/bpf/bpftool/json_writer.c b/tools/bpf/bpftool/json_writer.c
index 6046dcab51cc..86501cd3c763 100644
--- a/tools/bpf/bpftool/json_writer.c
+++ b/tools/bpf/bpftool/json_writer.c
@@ -15,7 +15,6 @@
15#include <malloc.h> 15#include <malloc.h>
16#include <inttypes.h> 16#include <inttypes.h>
17#include <stdint.h> 17#include <stdint.h>
18#include <linux/compiler.h>
19 18
20#include "json_writer.h" 19#include "json_writer.h"
21 20
@@ -153,8 +152,7 @@ void jsonw_name(json_writer_t *self, const char *name)
153 putc(' ', self->out); 152 putc(' ', self->out);
154} 153}
155 154
156void __printf(2, 0) 155void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
157jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
158{ 156{
159 jsonw_eor(self); 157 jsonw_eor(self);
160 putc('"', self->out); 158 putc('"', self->out);
@@ -162,7 +160,7 @@ jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap)
162 putc('"', self->out); 160 putc('"', self->out);
163} 161}
164 162
165void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...) 163void jsonw_printf(json_writer_t *self, const char *fmt, ...)
166{ 164{
167 va_list ap; 165 va_list ap;
168 166
diff --git a/tools/bpf/bpftool/json_writer.h b/tools/bpf/bpftool/json_writer.h
index cb9a1993681c..35cf1f00f96c 100644
--- a/tools/bpf/bpftool/json_writer.h
+++ b/tools/bpf/bpftool/json_writer.h
@@ -14,6 +14,7 @@
14#include <stdbool.h> 14#include <stdbool.h>
15#include <stdint.h> 15#include <stdint.h>
16#include <stdarg.h> 16#include <stdarg.h>
17#include <linux/compiler.h>
17 18
18/* Opaque class structure */ 19/* Opaque class structure */
19typedef struct json_writer json_writer_t; 20typedef struct json_writer json_writer_t;
@@ -30,8 +31,9 @@ void jsonw_pretty(json_writer_t *self, bool on);
30void jsonw_name(json_writer_t *self, const char *name); 31void jsonw_name(json_writer_t *self, const char *name);
31 32
32/* Add value */ 33/* Add value */
33void jsonw_vprintf_enquote(json_writer_t *self, const char *fmt, va_list ap); 34void __printf(2, 0) jsonw_vprintf_enquote(json_writer_t *self, const char *fmt,
34void jsonw_printf(json_writer_t *self, const char *fmt, ...); 35 va_list ap);
36void __printf(2, 3) jsonw_printf(json_writer_t *self, const char *fmt, ...);
35void jsonw_string(json_writer_t *self, const char *value); 37void jsonw_string(json_writer_t *self, const char *value);
36void jsonw_bool(json_writer_t *self, bool value); 38void jsonw_bool(json_writer_t *self, bool value);
37void jsonw_float(json_writer_t *self, double number); 39void jsonw_float(json_writer_t *self, double number);
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index 7031a4bf87a0..af9ad56c303a 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -98,8 +98,8 @@ extern int bpf_flags;
98extern struct pinned_obj_table prog_table; 98extern struct pinned_obj_table prog_table;
99extern struct pinned_obj_table map_table; 99extern struct pinned_obj_table map_table;
100 100
101void p_err(const char *fmt, ...); 101void __printf(1, 2) p_err(const char *fmt, ...);
102void p_info(const char *fmt, ...); 102void __printf(1, 2) p_info(const char *fmt, ...);
103 103
104bool is_prefix(const char *pfx, const char *str); 104bool is_prefix(const char *pfx, const char *str);
105int detect_common_prefix(const char *arg, ...); 105int detect_common_prefix(const char *arg, ...);
diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h
index 0d35f18006a1..95c072b70d0e 100644
--- a/tools/include/linux/compiler-gcc.h
+++ b/tools/include/linux/compiler-gcc.h
@@ -6,9 +6,11 @@
6/* 6/*
7 * Common definitions for all gcc versions go here. 7 * Common definitions for all gcc versions go here.
8 */ 8 */
9#ifndef GCC_VERSION
9#define GCC_VERSION (__GNUC__ * 10000 \ 10#define GCC_VERSION (__GNUC__ * 10000 \
10 + __GNUC_MINOR__ * 100 \ 11 + __GNUC_MINOR__ * 100 \
11 + __GNUC_PATCHLEVEL__) 12 + __GNUC_PATCHLEVEL__)
13#endif
12 14
13#if GCC_VERSION >= 70000 && !defined(__CHECKER__) 15#if GCC_VERSION >= 70000 && !defined(__CHECKER__)
14# define __fallthrough __attribute__ ((fallthrough)) 16# define __fallthrough __attribute__ ((fallthrough))