[v4,01/16] eal: provide pack start macro for MSVC

Message ID 1713225913-20792-2-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Series fix packing of structs when building with MSVC |


Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff April 16, 2024, 12:04 a.m. UTC
  MSVC struct packing is not compatible with GCC provide a macro that can
be used to push existing pack value and sets packing to 1-byte. The
existing __rte_packed macro is then used to restore the pack value
prior to the push.

Instead of providing macros exclusively for MSVC and for GCC the
existing macro is deliberately utilized to trigger a warning if no
existing packing has been pushed allowing easy identification of
locations where the __rte_msvc_pack is missing.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
 lib/eal/include/rte_common.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index 298a5c6..44825ed 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -97,8 +97,10 @@ 
  * Force a structure to be packed
-#define __rte_packed
+#define __rte_msvc_pack __pragma(pack(push, 1))
+#define __rte_packed __pragma(pack(pop))
+#define __rte_msvc_pack
 #define __rte_packed __attribute__((__packed__))