[PATCH v8 02/29] eal/include: add new packing macros
Andre Muezerie
andremue at linux.microsoft.com
Tue Dec 31 19:37:44 CET 2024
MSVC struct packing is not compatible with GCC. Add macro
__rte_packed_begin which can be used to push existing pack value
and set packing to 1-byte. Add macro __rte_packed_end to restore
the pack value prior to the push.
Macro __rte_packed_end is deliberately utilized to trigger a
MSVC compiler warning if no existing packing has been pushed allowing
easy identification of locations where the __rte_packed_begin is
missing.
Macro __rte_packed was marked as deprecated.
Signed-off-by: Andre Muezerie <andremue at linux.microsoft.com>
Acked-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
---
lib/eal/include/rte_common.h | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index 4d299f2b36..40592f71b1 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -99,13 +99,32 @@ typedef uint32_t unaligned_uint32_t;
typedef uint16_t unaligned_uint16_t;
#endif
+/**
+ * @deprecated
+ * @see __rte_packed_begin
+ * @see __rte_packed_end
+ *
+ * Force a structure to be packed
+ */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_packed RTE_DEPRECATED(__rte_packed)
+#else
+#define __rte_packed (RTE_DEPRECATED(__rte_packed) __attribute__((__packed__)))
+#endif
+
/**
* Force a structure to be packed
+ * Usage:
+ * struct __rte_packed_begin mystruct { ... } __rte_packed_end;
+ * union __rte_packed_begin myunion { ... } __rte_packed_end;
+ * Note: alignment attributes when present should precede __rte_packed_begin.
*/
#ifdef RTE_TOOLCHAIN_MSVC
-#define __rte_packed
+#define __rte_packed_begin __pragma(pack(push, 1))
+#define __rte_packed_end __pragma(pack(pop))
#else
-#define __rte_packed __attribute__((__packed__))
+#define __rte_packed_begin
+#define __rte_packed_end __attribute__((__packed__))
#endif
/**
--
2.47.0.vfs.0.3
More information about the dev
mailing list