bpf: Add BTF_SET_START/END macros
[linux-2.6-microblaze.git] / tools / include / linux / btf_ids.h
index 4867d54..210b086 100644 (file)
@@ -3,6 +3,11 @@
 #ifndef _LINUX_BTF_IDS_H
 #define _LINUX_BTF_IDS_H
 
+struct btf_id_set {
+       u32 cnt;
+       u32 ids[];
+};
+
 #ifdef CONFIG_DEBUG_INFO_BTF
 
 #include <linux/compiler.h> /* for __PASTE */
@@ -62,7 +67,7 @@ asm(                                                  \
 ".pushsection " BTF_IDS_SECTION ",\"a\";       \n"     \
 "." #scope " " #name ";                        \n"     \
 #name ":;                                      \n"     \
-".popsection;                                  \n");   \
+".popsection;                                  \n");
 
 #define BTF_ID_LIST(name)                              \
 __BTF_ID_LIST(name, local)                             \
@@ -88,12 +93,56 @@ asm(                                                        \
 ".zero 4                                       \n"     \
 ".popsection;                                  \n");
 
+/*
+ * The BTF_SET_START/END macros pair defines sorted list of
+ * BTF IDs plus its members count, with following layout:
+ *
+ * BTF_SET_START(list)
+ * BTF_ID(type1, name1)
+ * BTF_ID(type2, name2)
+ * BTF_SET_END(list)
+ *
+ * __BTF_ID__set__list:
+ * .zero 4
+ * list:
+ * __BTF_ID__type1__name1__3:
+ * .zero 4
+ * __BTF_ID__type2__name2__4:
+ * .zero 4
+ *
+ */
+#define __BTF_SET_START(name, scope)                   \
+asm(                                                   \
+".pushsection " BTF_IDS_SECTION ",\"a\";       \n"     \
+"." #scope " __BTF_ID__set__" #name ";         \n"     \
+"__BTF_ID__set__" #name ":;                    \n"     \
+".zero 4                                       \n"     \
+".popsection;                                  \n");
+
+#define BTF_SET_START(name)                            \
+__BTF_ID_LIST(name, local)                             \
+__BTF_SET_START(name, local)
+
+#define BTF_SET_START_GLOBAL(name)                     \
+__BTF_ID_LIST(name, globl)                             \
+__BTF_SET_START(name, globl)
+
+#define BTF_SET_END(name)                              \
+asm(                                                   \
+".pushsection " BTF_IDS_SECTION ",\"a\";      \n"      \
+".size __BTF_ID__set__" #name ", .-" #name "  \n"      \
+".popsection;                                 \n");    \
+extern struct btf_id_set name;
+
 #else
 
 #define BTF_ID_LIST(name) static u32 name[5];
 #define BTF_ID(prefix, name)
 #define BTF_ID_UNUSED
 #define BTF_ID_LIST_GLOBAL(name) u32 name[1];
+#define BTF_SET_START(name) static struct btf_id_set name = { 0 };
+#define BTF_SET_START_GLOBAL(name) static struct btf_id_set name = { 0 };
+#define BTF_SET_END(name)
 
 #endif /* CONFIG_DEBUG_INFO_BTF */