From: "Morten Brørup" <mb@smartsharesystems.com>
To: <scott.k.mitch1@gmail.com>, <dev@dpdk.org>
Cc: <stephen@networkplumber.org>
Subject: RE: [PATCH v14 1/2] eal: add __rte_may_alias to unaligned typedefs
Date: Mon, 12 Jan 2026 14:28:28 +0100 [thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35F65654@smartserver.smartshare.dk> (raw)
In-Reply-To: <20260112120411.27314-2-scott.k.mitch1@gmail.com>
> From: Scott Mitchell <scott.k.mitch1@gmail.com>
>
> Add __rte_may_alias attribute to unaligned_uint{16,32,64}_t typedefs
> to prevent GCC strict-aliasing optimization bugs. GCC has a bug where
> it incorrectly elides struct initialization when strict aliasing is
> enabled, causing reads from uninitialized memory.
>
> The __rte_may_alias attribute signals to the compiler that these types
> can alias other types, preventing the incorrect optimization.
I'm wondering if this is the right place to add __rte_may_alias, i.e. if the scope of the workaround is correct.
Are the unaligned_uintNN_t types only used in a way where they are affected by the GCC bug?
If not, adding __rte_may_alias to the types themselves may be too broad.
Does the GCC bug only affect the unaligned_uintNN_t types?
Or does it occur elsewhere or for other types too? Then this workaround only solves the problem for parts of the code.
Minor detail:
If the bug only occurs on GCC, not Clang, please make the workaround GCC-only, using the preprocessor.
>
> Signed-off-by: Scott Mitchell <scott.k.mitch1@gmail.com>
> ---
> lib/eal/include/rte_common.h | 34 +++++++++++++++++++---------------
> 1 file changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/lib/eal/include/rte_common.h
> b/lib/eal/include/rte_common.h
> index 9e7d84f929..ac70270cfb 100644
> --- a/lib/eal/include/rte_common.h
> +++ b/lib/eal/include/rte_common.h
> @@ -121,14 +121,27 @@ extern "C" {
> #define __rte_aligned(a) __attribute__((__aligned__(a)))
> #endif
>
> +/**
> + * 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
> +
> +/**
> + * __rte_may_alias avoids compiler bugs (GCC) that elide
> initialization
> + * of memory when strict-aliasing is enabled.
> + */
> #ifdef RTE_ARCH_STRICT_ALIGN
> -typedef uint64_t unaligned_uint64_t __rte_aligned(1);
> -typedef uint32_t unaligned_uint32_t __rte_aligned(1);
> -typedef uint16_t unaligned_uint16_t __rte_aligned(1);
> +typedef uint64_t unaligned_uint64_t __rte_may_alias __rte_aligned(1);
> +typedef uint32_t unaligned_uint32_t __rte_may_alias __rte_aligned(1);
> +typedef uint16_t unaligned_uint16_t __rte_may_alias __rte_aligned(1);
> #else
> -typedef uint64_t unaligned_uint64_t;
> -typedef uint32_t unaligned_uint32_t;
> -typedef uint16_t unaligned_uint16_t;
> +typedef uint64_t unaligned_uint64_t __rte_may_alias;
> +typedef uint32_t unaligned_uint32_t __rte_may_alias;
> +typedef uint16_t unaligned_uint16_t __rte_may_alias;
> #endif
>
> /**
> @@ -159,15 +172,6 @@ typedef uint16_t unaligned_uint16_t;
> #define __rte_packed_end __attribute__((__packed__))
> #endif
>
> -/**
> - * 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
> -
> /******* Macro to mark functions and fields scheduled for removal
> *****/
> #ifdef RTE_TOOLCHAIN_MSVC
> #define __rte_deprecated
> --
> 2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2026-01-12 13:28 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-12 12:04 [PATCH v14 0/2] net: optimize __rte_raw_cksum scott.k.mitch1
2026-01-12 12:04 ` [PATCH v14 1/2] eal: add __rte_may_alias to unaligned typedefs scott.k.mitch1
2026-01-12 13:28 ` Morten Brørup [this message]
2026-01-12 15:00 ` Scott Mitchell
2026-01-12 12:04 ` [PATCH v14 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-17 21:21 ` [PATCH v15 0/2] net: optimize __rte_raw_cksum scott.k.mitch1
2026-01-17 21:21 ` [PATCH v15 1/2] eal: add __rte_may_alias to unaligned typedefs scott.k.mitch1
2026-01-20 15:23 ` Morten Brørup
2026-01-23 14:34 ` Scott Mitchell
2026-01-17 21:21 ` [PATCH v15 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-17 22:08 ` [PATCH v15 0/2] net: optimize __rte_raw_cksum Stephen Hemminger
2026-01-20 12:45 ` Morten Brørup
2026-01-23 15:43 ` Scott Mitchell
2026-01-23 16:02 ` [PATCH v16 " scott.k.mitch1
2026-01-23 16:02 ` [PATCH v16 1/2] eal: add __rte_may_alias to unaligned typedefs scott.k.mitch1
2026-01-23 16:02 ` [PATCH v16 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-28 11:05 ` David Marchand
2026-01-28 17:39 ` Scott Mitchell
2026-01-24 8:23 ` [PATCH v16 0/2] net: optimize __rte_raw_cksum Morten Brørup
2026-01-28 18:05 ` [PATCH v17 " scott.k.mitch1
2026-01-28 18:05 ` [PATCH v17 1/2] eal: add __rte_may_alias and __rte_aligned to unaligned typedefs scott.k.mitch1
2026-01-28 18:05 ` [PATCH v17 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-28 19:41 ` [PATCH v18 0/2] net: optimize __rte_raw_cksum scott.k.mitch1
2026-01-28 19:41 ` [PATCH v18 1/2] eal: add __rte_may_alias and __rte_aligned to unaligned typedefs scott.k.mitch1
2026-01-29 8:28 ` Morten Brørup
2026-02-02 4:31 ` Scott Mitchell
2026-01-28 19:41 ` [PATCH v18 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-29 8:31 ` Morten Brørup
2026-02-02 4:48 ` [PATCH v19 0/2] net: optimize __rte_raw_cksum scott.k.mitch1
2026-02-02 4:48 ` [PATCH v19 1/2] eal: add __rte_may_alias and __rte_aligned to unaligned typedefs scott.k.mitch1
2026-02-03 8:18 ` Morten Brørup
2026-02-16 14:29 ` David Marchand
2026-02-16 15:00 ` Morten Brørup
2026-02-02 4:48 ` [PATCH v19 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-02-03 8:19 ` Morten Brørup
2026-02-06 14:54 ` [PATCH v19 0/2] net: optimize __rte_raw_cksum David Marchand
2026-02-07 1:29 ` Scott Mitchell
2026-02-10 11:53 ` Thomas Monjalon
2026-02-16 14:04 ` David Marchand
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=98CBD80474FA8B44BF855DF32C47DC35F65654@smartserver.smartshare.dk \
--to=mb@smartsharesystems.com \
--cc=dev@dpdk.org \
--cc=scott.k.mitch1@gmail.com \
--cc=stephen@networkplumber.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