From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: dev@dpdk.org
Cc: Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH] eal: provide rte attribute macro for GCC attribute
Date: Thu, 15 Feb 2024 14:20:18 -0800 [thread overview]
Message-ID: <1708035618-14090-2-git-send-email-roretzla@linux.microsoft.com> (raw)
In-Reply-To: <1708035618-14090-1-git-send-email-roretzla@linux.microsoft.com>
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 <roretzla@linux.microsoft.com>
---
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 <rte_os.h>
+#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
next prev parent reply other threads:[~2024-02-15 22:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-15 22:20 [PATCH] remove some MSVC conditional compile to empty Tyler Retzlaff
2024-02-15 22:20 ` Tyler Retzlaff [this message]
2024-02-18 12:24 ` [PATCH] eal: provide rte attribute macro for GCC attribute Thomas Monjalon
2024-02-18 12:53 ` Morten Brørup
2024-02-18 15:34 ` Thomas Monjalon
2024-02-18 16:38 ` Morten Brørup
2024-02-18 16:44 ` Thomas Monjalon
2024-02-20 17:50 ` Tyler Retzlaff
2024-02-18 14:51 ` Mattias Rönnblom
2024-02-18 15:31 ` Thomas Monjalon
2024-02-20 18:06 ` Tyler Retzlaff
2024-02-20 18:27 ` Thomas Monjalon
2024-02-27 22:45 ` [PATCH] remove some MSVC conditional compile to empty Tyler Retzlaff
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=1708035618-14090-2-git-send-email-roretzla@linux.microsoft.com \
--to=roretzla@linux.microsoft.com \
--cc=dev@dpdk.org \
/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).