Skip to contentSkip to conversation

eal: add rte_counted_by attribute

RFC New Stephen Hemminger 1 participant 1 message Mar 12, 2024

lore
Share & tools
lore
#0 lore raw

RFC 1/1 eal: add rte_counted_by attribute

Both Gcc 14 and clang support this in latest versions. Add to EAL first, then instrument flexible arrays.

[1] https://reviews.llvm.org/D148381
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896

---
 lib/eal/include/rte_compat.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/eal/include/rte_compat.h +10 -0
index 716bc0361640..6bf6b0baaccf 100644
@@ -68,6 +68,16 @@ _Pragma("GCC diagnostic pop")
 __attribute__((section(".text.internal")))
 #endif
 
+/*
+ * Used to by ASAN bounds checker for flexible arrays
+ * Supported by Gcc >= 14 and clang >=18
+ */
+#if __has_attribute(__element_count__)
+# define __rte_counted_by(member)	__attribute__((__element_count__(member)))
+#else
+# define __rte_counted_by(member)
+#endif
+
 #endif
 
 #ifdef __cplusplus
Signature · 1 line
2.43.0