[v2,01/15] eal: provide pack start macro for MSVC

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

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff March 27, 2024, 11:09 p.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(-)
  

Patch

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
  */
 #ifdef RTE_TOOLCHAIN_MSVC
-#define __rte_packed
+#define __rte_msvc_pack __pragma(pack(push, 1))
+#define __rte_packed __pragma(pack(pop))
 #else
+#define __rte_msvc_pack
 #define __rte_packed __attribute__((__packed__))
 #endif