DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: dev@dpdk.org
Cc: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
	Olivier Matz <olivier.matz@6wind.com>
Subject: [dpdk-dev] [PATCH v3 1/7] eal: introduce portable format attribute
Date: Tue, 18 Feb 2020 03:02:23 +0300	[thread overview]
Message-ID: <20200218000229.86621-2-dmitry.kozliuk@gmail.com> (raw)
In-Reply-To: <20200218000229.86621-1-dmitry.kozliuk@gmail.com>

When using __attribute__((format(...)) on functions, GCC on Windows
assumes MS-specific format string by default, even if the underlying
stdio implementation is ANSI-compliant (either MS Unicersal CRT
or MinGW implementation). Wrap attribute into a macro that forces
GNU-specific format string when using GCC.

Use this new attribute for logging and panic messages in EAL
and for output strings in cmdline library.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_cmdline/cmdline.h                |  4 +++-
 lib/librte_eal/common/include/rte_common.h  | 17 ++++++++++++++++-
 lib/librte_eal/common/include/rte_debug.h   |  2 +-
 lib/librte_eal/common/include/rte_devargs.h |  2 +-
 lib/librte_eal/common/include/rte_log.h     |  4 ++--
 5 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/lib/librte_cmdline/cmdline.h b/lib/librte_cmdline/cmdline.h
index 27d2effdf..243f99d20 100644
--- a/lib/librte_cmdline/cmdline.h
+++ b/lib/librte_cmdline/cmdline.h
@@ -7,6 +7,8 @@
 #ifndef _CMDLINE_H_
 #define _CMDLINE_H_
 
+#include <rte_common.h>
+
 #include <termios.h>
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
@@ -34,7 +36,7 @@ struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
 void cmdline_printf(const struct cmdline *cl, const char *fmt, ...)
-	__attribute__((format(printf,2,3)));
+	__rte_format_printf(2, 3);
 int cmdline_in(struct cmdline *cl, const char *buf, int size);
 int cmdline_write_char(struct rdline *rdl, char c);
 
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 4b5f3a31f..226c1a011 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -89,6 +89,21 @@ typedef uint16_t unaligned_uint16_t;
  */
 #define RTE_SET_USED(x) (void)(x)
 
+/**
+ * Check format string and its arguments at compile-time.
+ *
+ * GCC on Windows assumes MS-specific format string by default,
+ * even if the underlying stdio implementation is ANSI-compliant,
+ * so this must be overridden.
+ */
+#if defined(RTE_TOOLCHAIN_GCC)
+#define __rte_format_printf(format_index, first_arg) \
+	__attribute__((format(gnu_printf, format_index, first_arg)))
+#else
+#define __rte_format_printf(format_index, first_arg) \
+	__attribute__((format(printf, format_index, first_arg)))
+#endif
+
 #define RTE_PRIORITY_LOG 101
 #define RTE_PRIORITY_BUS 110
 #define RTE_PRIORITY_CLASS 120
@@ -784,7 +799,7 @@ rte_str_to_size(const char *str)
 void
 rte_exit(int exit_code, const char *format, ...)
 	__attribute__((noreturn))
-	__attribute__((format(printf, 2, 3)));
+	__rte_format_printf(2, 3);
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_eal/common/include/rte_debug.h b/lib/librte_eal/common/include/rte_debug.h
index 748d32c80..7edd4b89c 100644
--- a/lib/librte_eal/common/include/rte_debug.h
+++ b/lib/librte_eal/common/include/rte_debug.h
@@ -73,7 +73,7 @@ void __rte_panic(const char *funcname , const char *format, ...)
 #endif
 #endif
 	__attribute__((noreturn))
-	__attribute__((format(printf, 2, 3)));
+	__rte_format_printf(2, 3);
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 882dfa0ab..898efa0d6 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -137,7 +137,7 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev);
 int
 rte_devargs_parsef(struct rte_devargs *da,
 		   const char *format, ...)
-__attribute__((format(printf, 2, 0)));
+__rte_format_printf(2, 0);
 
 /**
  * Insert an rte_devargs in the global list.
diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h
index 1bb0e6694..a0d1f4837 100644
--- a/lib/librte_eal/common/include/rte_log.h
+++ b/lib/librte_eal/common/include/rte_log.h
@@ -282,7 +282,7 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
 	__attribute__((cold))
 #endif
 #endif
-	__attribute__((format(printf, 3, 4)));
+	__rte_format_printf(3, 4);
 
 /**
  * Generates a log message.
@@ -311,7 +311,7 @@ int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
  *   - Negative on error.
  */
 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
-	__attribute__((format(printf,3,0)));
+	__rte_format_printf(3, 0);
 
 /**
  * Generates a log message.
-- 
2.25.0


  reply	other threads:[~2020-02-18  0:02 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-18  0:02 [dpdk-dev] [PATCH v3 0/7] MinGW-w64 support Dmitry Kozlyuk
2020-02-18  0:02 ` Dmitry Kozlyuk [this message]
2020-02-18  0:02 ` [dpdk-dev] [PATCH v3 2/7] eal/windows: use lowercase filenames for system headers Dmitry Kozlyuk
2020-02-18  0:02 ` [dpdk-dev] [PATCH v3 3/7] eal/windows: support builing with MinGW-w64 Dmitry Kozlyuk
2020-02-18  0:02 ` [dpdk-dev] [PATCH v3 4/7] build: MinGW-w64 support for Meson Dmitry Kozlyuk
2020-02-18 14:26   ` Thomas Monjalon
2020-02-18 14:54     ` Bruce Richardson
2020-02-18  0:02 ` [dpdk-dev] [PATCH v3 5/7] build: add cross-file for MinGW-w64 Dmitry Kozlyuk
2020-02-18  0:02 ` [dpdk-dev] [PATCH v3 6/7] doc: guide for Windows build using MinGW-w64 Dmitry Kozlyuk
2020-02-18 21:27   ` William Tu
2020-02-18  0:02 ` [dpdk-dev] [PATCH v3 7/7] build: fix linker warnings with Clang on Windows Dmitry Kozlyuk
2020-02-18 21:16 ` [dpdk-dev] [PATCH v3 0/7] MinGW-w64 support William Tu
2020-02-27  4:25 ` [dpdk-dev] [PATCH v4 " Dmitry Kozlyuk
2020-02-27  4:25   ` [dpdk-dev] [PATCH v4 1/7] eal: introduce portable format attribute Dmitry Kozlyuk
2020-03-12 22:33     ` Thomas Monjalon
2020-03-13 23:38       ` Dmitry Kozlyuk
2020-03-15  8:36         ` Thomas Monjalon
2020-03-16 10:54           ` Bruce Richardson
2020-03-16 11:02             ` Bruce Richardson
2020-03-16 11:14               ` Thomas Monjalon
2020-03-16 11:18                 ` Bruce Richardson
2020-03-16 11:35                 ` Bruce Richardson
2020-03-16 14:27         ` Thomas Monjalon
2020-02-27  4:25   ` [dpdk-dev] [PATCH v4 2/7] eal/windows: use lowercase filenames for system headers Dmitry Kozlyuk
2020-02-27  4:25   ` [dpdk-dev] [PATCH v4 3/7] eal/windows: support builing with MinGW-w64 Dmitry Kozlyuk
2020-02-27  4:25   ` [dpdk-dev] [PATCH v4 4/7] build: MinGW-w64 support for Meson Dmitry Kozlyuk
2020-02-27  4:25   ` [dpdk-dev] [PATCH v4 5/7] build: add cross-file for MinGW-w64 Dmitry Kozlyuk
2020-02-27  4:25   ` [dpdk-dev] [PATCH v4 6/7] doc: guide for Windows build using MinGW-w64 Dmitry Kozlyuk
2020-02-27  4:25   ` [dpdk-dev] [PATCH v4 7/7] build: fix linker warnings with Clang on Windows Dmitry Kozlyuk
2020-03-11 17:22   ` [dpdk-dev] [PATCH v4 0/7] MinGW-w64 support William Tu
2020-03-18  0:24     ` Thomas Monjalon
2020-03-11 22:36   ` Kadam, Pallavi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200218000229.86621-2-dmitry.kozliuk@gmail.com \
    --to=dmitry.kozliuk@gmail.com \
    --cc=dev@dpdk.org \
    --cc=olivier.matz@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).