[PATCH v20] eal: add may_alias to unaligned typedefs
Scott Mitchell
scott.k.mitch1 at gmail.com
Tue Dec 1 21:18:01 CET 2026
The unaligned_uint{16,32,64}_t types are used to read memory that was
written through other types, e.g. checksumming a packet header that was
just filled in field by field. Without may_alias, type-based alias
analysis may assume those reads do not alias the preceding stores and
move them ahead of the stores. clang 22 does this to a raw checksum
loop reading through unaligned_uint16_t, producing TCP checksums over
stale header bytes.
Add may_alias to the non-MSVC typedefs, as a leading attribute so the
existing __rte_aligned(1) declarations are unchanged. The attribute is
spelled out because __rte_may_alias is defined later in rte_common.h.
MSVC keeps __unaligned and has no type-based alias analysis to disable.
Fixes: 7621d6a8d0bd ("eal: add and use unaligned integer types")
Cc: Cyril Chemparathy <cchemparathy at ezchip.com>
Cc: stable at dpdk.org
Signed-off-by: Scott Mitchell <scott.k.mitch1 at gmail.com>
---
v20:
- rebase on "eal: make unaligned types really unaligned", which already
made the types __rte_aligned(1); only may_alias is added now
- add may_alias as a leading attribute so the existing __rte_aligned(1)
declarations are unchanged (no __rte_aligned outside struct/union)
- drop "net: __rte_raw_cksum pointers enable compiler optimizations":
"eal: improve pointer add/sub/align macros" already lets compilers
vectorize __rte_raw_cksum
- drop the test_hash_functions change, fixed upstream by
"test/hash: fix jhash 32-bit key type"
---
lib/eal/include/rte_common.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index fed373f412..026eeab02e 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -151,14 +151,21 @@ extern "C" {
/**
* Integer types with no alignment requirement.
+ *
+ * may_alias - Prevents strict-aliasing optimization bugs where
+ * compilers may incorrectly elide memory operations
+ * when casting between pointer types.
*/
#ifdef RTE_TOOLCHAIN_MSVC
typedef __unaligned uint64_t unaligned_uint64_t;
typedef __unaligned uint32_t unaligned_uint32_t;
typedef __unaligned uint16_t unaligned_uint16_t;
#else
+__attribute__((__may_alias__))
typedef uint64_t unaligned_uint64_t __rte_aligned(1);
+__attribute__((__may_alias__))
typedef uint32_t unaligned_uint32_t __rte_aligned(1);
+__attribute__((__may_alias__))
typedef uint16_t unaligned_uint16_t __rte_aligned(1);
#endif
--
2.54.0 (Apple Git-157)
More information about the stable
mailing list