1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _LINUX_BTF_IDS_H
4 #define _LINUX_BTF_IDS_H
11 #ifdef CONFIG_DEBUG_INFO_BTF
13 #include <linux/compiler.h> /* for __PASTE */
16 * Following macros help to define lists of BTF IDs placed
17 * in .BTF_ids section. They are initially filled with zeros
18 * (during compilation) and resolved later during the
19 * linking phase by resolve_btfids tool.
21 * Any change in list layout must be reflected in resolve_btfids
25 #define BTF_IDS_SECTION ".BTF_ids"
27 #define ____BTF_ID(symbol) \
29 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
30 ".local " #symbol " ; \n" \
31 ".type " #symbol ", STT_OBJECT; \n" \
32 ".size " #symbol ", 4; \n" \
37 #define __BTF_ID(symbol) \
40 #define __ID(prefix) \
41 __PASTE(__PASTE(prefix, __COUNTER__), __LINE__)
44 * The BTF_ID defines unique symbol for each ID pointing
47 #define BTF_ID(prefix, name) \
48 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__))
51 * The BTF_ID_LIST macro defines pure (unsorted) list
52 * of BTF IDs, with following layout:
55 * BTF_ID(type1, name1)
56 * BTF_ID(type2, name2)
59 * __BTF_ID__type1__name1__1:
61 * __BTF_ID__type2__name2__2:
65 #define __BTF_ID_LIST(name, scope) \
67 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
68 "." #scope " " #name "; \n" \
72 #define BTF_ID_LIST(name) \
73 __BTF_ID_LIST(name, local) \
76 #define BTF_ID_LIST_GLOBAL(name, n) \
77 __BTF_ID_LIST(name, globl)
79 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
82 #define BTF_ID_LIST_SINGLE(name, prefix, typename) \
84 BTF_ID(prefix, typename)
85 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
86 BTF_ID_LIST_GLOBAL(name, 1) \
87 BTF_ID(prefix, typename)
90 * The BTF_ID_UNUSED macro defines 4 zero bytes.
91 * It's used when we want to define 'unused' entry
92 * in BTF_ID_LIST, like:
94 * BTF_ID_LIST(bpf_skb_output_btf_ids)
95 * BTF_ID(struct, sk_buff)
97 * BTF_ID(struct, task_struct)
100 #define BTF_ID_UNUSED \
102 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
107 * The BTF_SET_START/END macros pair defines sorted list of
108 * BTF IDs plus its members count, with following layout:
110 * BTF_SET_START(list)
111 * BTF_ID(type1, name1)
112 * BTF_ID(type2, name2)
115 * __BTF_ID__set__list:
118 * __BTF_ID__type1__name1__3:
120 * __BTF_ID__type2__name2__4:
124 #define __BTF_SET_START(name, scope) \
126 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
127 "." #scope " __BTF_ID__set__" #name "; \n" \
128 "__BTF_ID__set__" #name ":; \n" \
132 #define BTF_SET_START(name) \
133 __BTF_ID_LIST(name, local) \
134 __BTF_SET_START(name, local)
136 #define BTF_SET_START_GLOBAL(name) \
137 __BTF_ID_LIST(name, globl) \
138 __BTF_SET_START(name, globl)
140 #define BTF_SET_END(name) \
142 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
143 ".size __BTF_ID__set__" #name ", .-" #name " \n" \
144 ".popsection; \n"); \
145 extern struct btf_id_set name;
149 #define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
150 #define BTF_ID(prefix, name)
151 #define BTF_ID_UNUSED
152 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
153 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
154 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
155 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
156 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
157 #define BTF_SET_END(name)
159 #endif /* CONFIG_DEBUG_INFO_BTF */
162 /* Define a list of socket types which can be the argument for
163 * skc_to_*_sock() helpers. All these sockets should have
164 * sock_common as the first argument in its memory layout.
166 #define BTF_SOCK_TYPE_xxx \
167 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
168 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
169 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
170 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
171 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
172 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
173 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
174 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
175 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
176 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
177 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
178 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
179 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \
180 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \
181 BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \
182 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
185 #define BTF_SOCK_TYPE(name, str) name,
191 extern u32 btf_sock_ids[];
194 #define BTF_TRACING_TYPE_xxx \
195 BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \
196 BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \
197 BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
200 #define BTF_TRACING_TYPE(name, type) name,
202 #undef BTF_TRACING_TYPE
203 MAX_BTF_TRACING_TYPE,
206 extern u32 btf_tracing_ids[];