From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EA94EA055A; Thu, 27 Feb 2020 05:25:57 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 127391BFC8; Thu, 27 Feb 2020 05:25:52 +0100 (CET) Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by dpdk.org (Postfix) with ESMTP id 37E1C1BF8D for ; Thu, 27 Feb 2020 05:25:50 +0100 (CET) Received: by mail-lf1-f68.google.com with SMTP id r14so1009959lfm.5 for ; Wed, 26 Feb 2020 20:25:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XwxpU67dFdFosV05TbGYMhklbSndu2oWkeA7Knzj6iE=; b=Yhyd88dpnVfL6/MR8BTcqmrjtWlmE2CwsnQ+JaCx/bCMzqxaff7oXVk5JA236Fjzje X8GQci0RCSWlmj/b6zSftWWsp4EbbJJzDH9XCXmSIhjEhdaDlxR133DZott/rFfkZ1NH oM8opCYm2tImBNPaulAq8EhxjBJMAxVatdTyL+MuRsp0m1V0PSUYtiMfuPwQhc5uMRbS pigGs5qye5J1twoV3oA6dOCMi18FPu0jqJbJNiLzAtc5fcp/jwQ9BwS/idkz8Gm24/a+ bU38to4jnPVpmemi+C0ciulSV3iALa7hCWTV4HVfMTZjm+XKxP6kRztkLfCFAjsZhy2Y NGTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XwxpU67dFdFosV05TbGYMhklbSndu2oWkeA7Knzj6iE=; b=Pc01V9cs+K5E5OoI5/+0oV9qKX1DYp28MbmfxjlrHWcMLeBWD0cXUOaZglmbB1EQtJ f6D/Xc+0vHnY2xsDLNas84dJPnp23KIPt7Z8E1YiGoNam2nR8YCySfV/eXLTIgwqWX54 zJ3xfnPEH37NC8kw9sOytFwrl2XjsxJi9zgCR3AsPIa4Mu18CVJwfL7QBd5LDL2sqBP5 7HS5wRFgjsK/5Xfe/TrGips02G2yazPyybd1ME8bEPbF6ZP6MqWOcUnEZLGIXHV0+ShN XgeP0D/vnyP807Nuxw9bczqaixGoDGEEVttEVU4Ma317dlL/MJMv/NQXrp41od0mYaNy qLMg== X-Gm-Message-State: ANhLgQ3CtqPJ5qQ+Ag5D1kMROG81vkl/ri+HGeIlkpkb6DWLbe58c3eB kt30V6LVcQ3SFa5KHGzzccOZ2TNUK/U= X-Google-Smtp-Source: ADFU+vv43BFK1UoHobUV0o4zt5jD5elg0ThcGzgNWWIFekmng4bX3UTNwEkjr78MWkGQQ2rRqtsWjA== X-Received: by 2002:a19:dcd:: with SMTP id 196mr1036709lfn.199.1582777549287; Wed, 26 Feb 2020 20:25:49 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.googlemail.com with ESMTPSA id g21sm2224350ljj.53.2020.02.26.20.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 20:25:48 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , Olivier Matz Date: Thu, 27 Feb 2020 07:25:31 +0300 Message-Id: <20200227042537.187459-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227042537.187459-1-dmitry.kozliuk@gmail.com> References: <20200218000229.86621-1-dmitry.kozliuk@gmail.com> <20200227042537.187459-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v4 1/7] eal: introduce portable format attribute X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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 + #include #include #include @@ -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.1