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 838E1A0554; Tue, 18 Feb 2020 01:02:47 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A3C091DA84; Tue, 18 Feb 2020 01:02:40 +0100 (CET) Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by dpdk.org (Postfix) with ESMTP id BB26B1D989 for ; Tue, 18 Feb 2020 01:02:37 +0100 (CET) Received: by mail-lj1-f195.google.com with SMTP id x7so20801884ljc.1 for ; Mon, 17 Feb 2020 16:02:37 -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=umLQecGVt8EO5YK5gxsZYBqxfTNmrrw4MfD6KiCbGlU=; b=Yuijm3xwoyiqkcMtNN859knG0rQlR3+T8kDlYlRtdSKMkLbt2E5fIlQ7KVAlBQUQM5 VNhJHCHZk+O9L5wbRg57A3cCgFXondL+W1h4E1GxzjgTLvbZeNXpjyOG4uPMEmng0kkt TzaMebOdejexvCoAFvgA+MBxUAYoBeTrwY7sufiGfzdvfJSfENfAdRtL98yJwSXCz8ck ESiFr7JnUxvL2aEutkvHUPLyFQT+0MlnnSKUumMZuPTDrr5SlS4QQNABY9WDbp87Lnxz zvV0DKxUmBggN7aggg91rMpY8qsubEKH1xgakZV2kOeP+GE7HvoHOrAKYmmkf4ZJ0S0p csCA== 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=umLQecGVt8EO5YK5gxsZYBqxfTNmrrw4MfD6KiCbGlU=; b=qAOsVbV4CPxQLFUpv9XdxdmkgaIIRmQSKmU7LvojuSKngrqgddV53yjNfVZeAk9l9j E8G6V/4R/MyePBB8mOoG2idZiz2kZ9mcmgG9JK5xCDp7jAouyN0R3fOTd1J5rET9pv2o E6eE+d3otMxCBIvU31fYb16ePF63z15mtSp6CRyNDdUWfeJe2sroigH8qWvsci68AMiP mY5aMMMbj/sAs1C16bUGG/bLsMnyTDwvXYkcdmKxrqqypRgNGz6cf0NuLWun4VZ3avYA S/6hbyALSsbr61PhL4uxgyTnyuckXeCuc/PjAS5fNvJpSnCnHADW3I2T+xteItpbPhg8 aUJQ== X-Gm-Message-State: APjAAAU9u9cq7bkoT4n5S+fkx2JyYDD2XneP8F6W7Sj7shqg0LLw67aT 3DQCYtlaSBsIECtUm0GJtMQDw5VGjS4= X-Google-Smtp-Source: APXvYqxFyV2J3iNY2nJxqzSMCWqJH1AP2ozcBINFuf47o6Afl8084oPY3EvQNyn0qZWTOTeRvnsXhg== X-Received: by 2002:a2e:a361:: with SMTP id i1mr11102714ljn.29.1581984157014; Mon, 17 Feb 2020 16:02:37 -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 r20sm1068864lfi.91.2020.02.17.16.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 16:02:36 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , Olivier Matz Date: Tue, 18 Feb 2020 03:02:23 +0300 Message-Id: <20200218000229.86621-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200218000229.86621-1-dmitry.kozliuk@gmail.com> References: <20200218000229.86621-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 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.0