Skip to contentSkip to conversation

tools/headers: Sync stddef.h with include/uapi to fix BPF

PATCH New Mikhail Zaslonko 1 participant 1 message Apr 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/headers: Sync stddef.h with include/uapi to fix BPF

tools/include/uapi/linux/stddef.h is a copy of include/uapi/linux/stddef.h
used by the tools build. But it occurred to be an older snapshot, what
causes the BPF selftests build failures in manual selftests builds:
In file included from test_tag.c:18:
/usr/include/linux/if_alg.h:45:22: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘__counted_by’

     45 |         __u8    iv[] __counted_by(ivlen);
        |                      ^~~~~~~~~~~~

Commit dacbfc167808 ("crypto: af_alg - Annotate struct af_alg_iv with __counted_by") added __counted_by() to a uapi header (include/uapi/linux/if_alg.h), but tools/include/uapi/linux/stddef.h was not updated.

Sync tools/include/uapi/linux/stddef.h with include/uapi/linux/stddef.h to fix selftests/bpf build.

Fixes dacbfc167808 ("crypto: af_alg - Annotate struct af_alg_iv with __counted_by")
---
 tools/include/uapi/linux/stddef.h | 39 +++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)
tools/include/uapi/linux/stddef.h +35 -4
index c53cde425406..111b097ec00b 100644
@@ -1,11 +1,13 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _LINUX_STDDEF_H
-#define _LINUX_STDDEF_H
-
+#ifndef _UAPI_LINUX_STDDEF_H
+#define _UAPI_LINUX_STDDEF_H
 
+#ifdef __KERNEL__
+#include <linux/compiler_types.h>
+#endif
 
 #ifndef __always_inline
-#define __always_inline __inline__
+#define __always_inline inline
 #endif
 
 /* Not all C++ standards support type declarations inside an anonymous union */
@@ -36,6 +38,11 @@
 		struct __struct_group_tag(TAG) { MEMBERS } ATTRS NAME; \
 	} ATTRS
 
+#ifdef __cplusplus
+/* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */
+#define __DECLARE_FLEX_ARRAY(T, member)	\
+	T member[0]
+#else
 /**
  * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
  *
@@ -52,3 +59,27 @@
 		TYPE NAME[]; \
 	}
 #endif
+
+#ifndef __counted_by
+#define __counted_by(m)
+#endif
+
+#ifndef __counted_by_le
+#define __counted_by_le(m)
+#endif
+
+#ifndef __counted_by_be
+#define __counted_by_be(m)
+#endif
+
+#ifndef __counted_by_ptr
+#define __counted_by_ptr(m)
+#endif
+
+#ifdef __KERNEL__
+#define __kernel_nonstring	__nonstring
+#else
+#define __kernel_nonstring
+#endif
+
+#endif /* _UAPI_LINUX_STDDEF_H */
Signature · 1 line
2.53.0