[PATCH] tools headers UAPI: Sync linux/stddef.h with the kernel sources

From: Yang Jihong
Date: Mon Oct 31 2022 - 05:34:22 EST


commit 036b8f5b8970 ("tools headers uapi: Update linux/in.h copy") modify
tools/include/uapi/linux/in.h, and __DECLARE_FLEX_ARRAY is introduced.
Macro is not defined in tools/include, compilation fails:

CLNG-BPF [test_maps] bind4_prog.bpf.o
In file included from progs/bind4_prog.c:7:
/root/linux-mainline-new/linux/tools/include/uapi/linux/in.h:199:3: error: type name requires a specifier or qualifier
__DECLARE_FLEX_ARRAY(__be32, imsf_slist_flex);
^
/root/linux-mainline-new/linux/tools/include/uapi/linux/in.h:199:32: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int]
__DECLARE_FLEX_ARRAY(__be32, imsf_slist_flex);
^
2 errors generated.

Synchronize include/uapi/linux/stddef.h to tools headers directory,
and delete the line "#include <linux/compiler_types.h>":

# cp ./include/uapi/linux/stddef.h tools/include/uapi/linux/stddef.h
# sed -i '/#include <linux\/compiler_types.h>/,+1d' tools/include/uapi/linux/stddef.h

And add missed <linux/stddef.h> header in tools/include/uapi/linux/in.h.

Fixes: 036b8f5b8970 (tools headers uapi: Update linux/in.h copy)
Signed-off-by: Yang Jihong <yangjihong1@xxxxxxxxxx>
---
tools/include/uapi/linux/in.h | 1 +
tools/include/uapi/linux/stddef.h | 45 +++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
create mode 100644 tools/include/uapi/linux/stddef.h

diff --git a/tools/include/uapi/linux/in.h b/tools/include/uapi/linux/in.h
index f243ce665f74..79015665daf1 100644
--- a/tools/include/uapi/linux/in.h
+++ b/tools/include/uapi/linux/in.h
@@ -22,6 +22,7 @@
#include <linux/types.h>
#include <linux/libc-compat.h>
#include <linux/socket.h>
+#include <linux/stddef.h>

#if __UAPI_DEF_IN_IPPROTO
/* Standard well-defined IP protocols. */
diff --git a/tools/include/uapi/linux/stddef.h b/tools/include/uapi/linux/stddef.h
new file mode 100644
index 000000000000..72bcdf96999f
--- /dev/null
+++ b/tools/include/uapi/linux/stddef.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_STDDEF_H
+#define _UAPI_LINUX_STDDEF_H
+
+#ifndef __always_inline
+#define __always_inline inline
+#endif
+
+/**
+ * __struct_group() - Create a mirrored named and anonyomous struct
+ *
+ * @TAG: The tag name for the named sub-struct (usually empty)
+ * @NAME: The identifier name of the mirrored sub-struct
+ * @ATTRS: Any struct attributes (usually empty)
+ * @MEMBERS: The member declarations for the mirrored structs
+ *
+ * Used to create an anonymous union of two structs with identical layout
+ * and size: one anonymous and one named. The former's members can be used
+ * normally without sub-struct naming, and the latter can be used to
+ * reason about the start, end, and size of the group of struct members.
+ * The named struct can also be explicitly tagged for layer reuse, as well
+ * as both having struct attributes appended.
+ */
+#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
+ union { \
+ struct { MEMBERS } ATTRS; \
+ struct TAG { MEMBERS } ATTRS NAME; \
+ }
+
+/**
+ * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
+ *
+ * @TYPE: The type of each flexible array element
+ * @NAME: The name of the flexible array member
+ *
+ * In order to have a flexible array member in a union or alone in a
+ * struct, it needs to be wrapped in an anonymous struct with at least 1
+ * named member, but that member can be empty.
+ */
+#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \
+ struct { \
+ struct { } __empty_ ## NAME; \
+ TYPE NAME[]; \
+ }
+#endif
--
2.30.GIT