From: Scott <[email protected]>

The optimized __rte_raw_cksum() uses unaligned_uint16_t pointer access
which triggers UBSAN alignment warnings even though the access is safe
due to the unaligned type definition.

Add __rte_no_ubsan_alignment attribute to suppress these false positive
warnings while preserving other UBSAN checks.

Signed-off-by: Scott Mitchell <[email protected]>
---
 lib/eal/include/rte_common.h | 9 +++++++++
 lib/net/rte_cksum.h          | 1 +
 2 files changed, 10 insertions(+)

diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index 9e7d84f929..00d428e295 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -546,6 +546,15 @@ static void __attribute__((destructor(RTE_PRIO(prio)), 
used)) func(void)
 #define __rte_no_asan
 #endif
 
+/**
+ * Disable UndefinedBehaviorSanitizer alignment check on some code
+ */
+#if defined(RTE_CC_CLANG) || defined(RTE_CC_GCC)
+#define __rte_no_ubsan_alignment __attribute__((no_sanitize("alignment")))
+#else
+#define __rte_no_ubsan_alignment
+#endif
+
 /*********** Macros for pointer arithmetic ********/
 
 /**
diff --git a/lib/net/rte_cksum.h b/lib/net/rte_cksum.h
index 8dbe1179e8..9a7fda563d 100644
--- a/lib/net/rte_cksum.h
+++ b/lib/net/rte_cksum.h
@@ -39,6 +39,7 @@ extern "C" {
  * @return
  *   sum += Sum of all words in the buffer.
  */
+__rte_no_ubsan_alignment
 static inline uint32_t
 __rte_raw_cksum(const void *buf, size_t len, uint32_t sum)
 {
-- 
2.39.5 (Apple Git-154)

Reply via email to