From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EB57643B19; Thu, 15 Feb 2024 23:20:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 73B2C42C24; Thu, 15 Feb 2024 23:20:24 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 6270F40276 for ; Thu, 15 Feb 2024 23:20:21 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id AABA3207F234; Thu, 15 Feb 2024 14:20:20 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AABA3207F234 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1708035620; bh=J+CLgHv1q8DS6fqaWmEzuktrtecRYq4Voeb79SZ75lg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B0DOVTNDQtK8We0QmzrCu9unCc3QFJA9AKPhMRaq3uMSLA6+taY21C7h+xHK9pA0w mmpWjLi741BnbCzbsEyU9TBUeSFg3oXz0i8BD5u7x9ZyW1kbWfetU532dqKibACmJ+ +jY0xZBWlWOVoWDVvVDvUaRAHDBm9vt63/9lnBBQ= From: Tyler Retzlaff To: dev@dpdk.org Cc: Tyler Retzlaff Subject: [PATCH] eal: provide rte attribute macro for GCC attribute Date: Thu, 15 Feb 2024 14:20:18 -0800 Message-Id: <1708035618-14090-2-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1708035618-14090-1-git-send-email-roretzla@linux.microsoft.com> References: <1708035618-14090-1-git-send-email-roretzla@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Provide a new macro __rte_attribute(a) that when directly used compiles to empty for MSVC and to __attribute__(a) when using GCC/LLVM. Replace direct use of __attribute__ in __rte_xxx macros where there is existing empty expansion of the macro for MSVC allowing removal of repeated #ifdef RTE_TOOLCHAIN_MSVC per macro to expand empty. Signed-off-by: Tyler Retzlaff --- lib/eal/include/rte_common.h | 77 ++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 56 deletions(-) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index d7d6390..e582f99 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -24,6 +24,12 @@ /* OS specific include */ #include +#ifdef RTE_TOOLCHAIN_MSVC +#define __rte_attribute(a) +#else +#define __rte_attribute(a) __attribute__(a) +#endif + #ifndef RTE_TOOLCHAIN_MSVC #ifndef typeof #define typeof __typeof__ @@ -83,29 +89,16 @@ /** * Force a structure to be packed */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_packed -#else -#define __rte_packed __attribute__((__packed__)) -#endif +#define __rte_packed __rte_attribute((__packed__)) /** * Macro to mark a type that is not subject to type-based aliasing rules */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_may_alias -#else -#define __rte_may_alias __attribute__((__may_alias__)) -#endif +#define __rte_may_alias __rte_attribute((__may_alias__)) /******* Macro to mark functions and fields scheduled for removal *****/ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_deprecated -#define __rte_deprecated_msg(msg) -#else -#define __rte_deprecated __attribute__((__deprecated__)) -#define __rte_deprecated_msg(msg) __attribute__((__deprecated__(msg))) -#endif +#define __rte_deprecated __rte_attribute((__deprecated__)) +#define __rte_deprecated_msg(msg) __rte_attribute((__deprecated__(msg))) /** * Macro to mark macros and defines scheduled for removal @@ -121,27 +114,19 @@ /** * Mark a function or variable to a weak reference. */ -#define __rte_weak __attribute__((__weak__)) +#define __rte_weak __rte_attribute((__weak__)) /** * Force symbol to be generated even if it appears to be unused. */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_used -#else -#define __rte_used __attribute__((used)) -#endif +#define __rte_used __rte_attribute((used)) /*********** Macros to eliminate unused variable warnings ********/ /** * short definition to mark a function parameter unused */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_unused -#else -#define __rte_unused __attribute__((__unused__)) -#endif +#define __rte_unused __rte_attribute((__unused__)) /** * Mark pointer as restricted with regard to pointer aliasing. @@ -165,16 +150,12 @@ * even if the underlying stdio implementation is ANSI-compliant, * so this must be overridden. */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_format_printf(format_index, first_arg) -#else #if RTE_CC_IS_GNU #define __rte_format_printf(format_index, first_arg) \ - __attribute__((format(gnu_printf, format_index, first_arg))) + __rte_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 + __rte_attribute((format(printf, format_index, first_arg))) #endif /** @@ -298,11 +279,7 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) /** * Hint never returning function */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_noreturn -#else -#define __rte_noreturn __attribute__((noreturn)) -#endif +#define __rte_noreturn __rte_attribute((noreturn)) /** * Issue a warning in case the function's return value is ignored. @@ -327,39 +304,27 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) * } * @endcode */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_warn_unused_result -#else -#define __rte_warn_unused_result __attribute__((warn_unused_result)) -#endif +#define __rte_warn_unused_result __rte_attribute((warn_unused_result)) /** * Force a function to be inlined */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_always_inline -#else -#define __rte_always_inline inline __attribute__((always_inline)) -#endif +#define __rte_always_inline inline __rte_attribute((always_inline)) /** * Force a function to be noinlined */ -#define __rte_noinline __attribute__((noinline)) +#define __rte_noinline __rte_attribute((noinline)) /** * Hint function in the hot path */ -#define __rte_hot __attribute__((hot)) +#define __rte_hot __rte_attribute((hot)) /** * Hint function in the cold path */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_cold -#else -#define __rte_cold __attribute__((cold)) -#endif +#define __rte_cold __rte_attribute((cold)) /** * Disable AddressSanitizer on some code -- 1.8.3.1