[PATCH v5 02/16] eal: pack structures when building with MSVC

Andre Muezerie andremue at linux.microsoft.com
Tue Nov 19 05:35:27 CET 2024


From: Tyler Retzlaff <roretzla at linux.microsoft.com>

Add __rte_msvc_pack to all __rte_packed structs to cause packing
when building with MSVC.

Remove __rte_packed where it appears natural alignment without
packing would produce the same layout or the struct is internal.

Signed-off-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
---
 lib/eal/common/eal_private.h      | 2 +-
 lib/eal/include/rte_memory.h      | 1 +
 lib/eal/include/rte_memzone.h     | 1 +
 lib/eal/include/rte_trace_point.h | 2 +-
 lib/eal/x86/include/rte_memcpy.h  | 3 +++
 5 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h
index bb315dab04..3b94e01b5b 100644
--- a/lib/eal/common/eal_private.h
+++ b/lib/eal/common/eal_private.h
@@ -62,7 +62,7 @@ struct rte_config {
 	 * DPDK instances
 	 */
 	struct rte_mem_config *mem_config;
-} __rte_packed;
+};
 
 /**
  * Get the global configuration structure.
diff --git a/lib/eal/include/rte_memory.h b/lib/eal/include/rte_memory.h
index dbd0a6bedc..fffbd2ed65 100644
--- a/lib/eal/include/rte_memory.h
+++ b/lib/eal/include/rte_memory.h
@@ -46,6 +46,7 @@ extern "C" {
 /**
  * Physical memory segment descriptor.
  */
+__rte_msvc_pack
 struct rte_memseg {
 	rte_iova_t iova;            /**< Start IO address. */
 	union {
diff --git a/lib/eal/include/rte_memzone.h b/lib/eal/include/rte_memzone.h
index e1563994d5..e52bdc91b8 100644
--- a/lib/eal/include/rte_memzone.h
+++ b/lib/eal/include/rte_memzone.h
@@ -45,6 +45,7 @@ extern "C" {
  * A structure describing a memzone, which is a contiguous portion of
  * physical memory identified by a name.
  */
+__rte_msvc_pack
 struct rte_memzone {
 
 #define RTE_MEMZONE_NAMESIZE 32       /**< Maximum length of memory zone name.*/
diff --git a/lib/eal/include/rte_trace_point.h b/lib/eal/include/rte_trace_point.h
index 87b5f43c3c..b24db3b6da 100644
--- a/lib/eal/include/rte_trace_point.h
+++ b/lib/eal/include/rte_trace_point.h
@@ -298,7 +298,7 @@ struct __rte_trace_stream_header {
 	rte_uuid_t uuid;
 	uint32_t lcore_id;
 	char thread_name[__RTE_TRACE_EMIT_STRING_LEN_MAX];
-} __rte_packed;
+};
 
 struct __rte_trace_header {
 	uint32_t offset;
diff --git a/lib/eal/x86/include/rte_memcpy.h b/lib/eal/x86/include/rte_memcpy.h
index 42058e4a3f..fed715ca33 100644
--- a/lib/eal/x86/include/rte_memcpy.h
+++ b/lib/eal/x86/include/rte_memcpy.h
@@ -67,12 +67,15 @@ rte_mov15_or_less(void *dst, const void *src, size_t n)
 	 * Use the following structs to avoid violating C standard
 	 * alignment requirements and to avoid strict aliasing bugs
 	 */
+	__rte_msvc_pack
 	struct rte_uint64_alias {
 		uint64_t val;
 	} __rte_packed __rte_may_alias;
+	__rte_msvc_pack
 	struct rte_uint32_alias {
 		uint32_t val;
 	} __rte_packed __rte_may_alias;
+	__rte_msvc_pack
 	struct rte_uint16_alias {
 		uint16_t val;
 	} __rte_packed __rte_may_alias;
-- 
2.47.0.vfs.0.3



More information about the dev mailing list