1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _LINUX_BTF_IDS_H
4 #define _LINUX_BTF_IDS_H
20 #ifdef CONFIG_DEBUG_INFO_BTF
22 #include <linux/compiler.h> /* for __PASTE */
25 * Following macros help to define lists of BTF IDs placed
26 * in .BTF_ids section. They are initially filled with zeros
27 * (during compilation) and resolved later during the
28 * linking phase by resolve_btfids tool.
30 * Any change in list layout must be reflected in resolve_btfids
34 #define BTF_IDS_SECTION ".BTF_ids"
36 #define ____BTF_ID(symbol) \
38 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
39 ".local " #symbol " ; \n" \
40 ".type " #symbol ", STT_OBJECT; \n" \
41 ".size " #symbol ", 4; \n" \
46 #define __BTF_ID(symbol) \
49 #define __ID(prefix) \
50 __PASTE(__PASTE(prefix, __COUNTER__), __LINE__)
53 * The BTF_ID defines unique symbol for each ID pointing
56 #define BTF_ID(prefix, name) \
57 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__))
60 * The BTF_ID_LIST macro defines pure (unsorted) list
61 * of BTF IDs, with following layout:
64 * BTF_ID(type1, name1)
65 * BTF_ID(type2, name2)
68 * __BTF_ID__type1__name1__1:
70 * __BTF_ID__type2__name2__2:
74 #define __BTF_ID_LIST(name, scope) \
76 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
77 "." #scope " " #name "; \n" \
81 #define BTF_ID_LIST(name) \
82 __BTF_ID_LIST(name, local) \
85 #define BTF_ID_LIST_GLOBAL(name, n) \
86 __BTF_ID_LIST(name, globl)
88 /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
91 #define BTF_ID_LIST_SINGLE(name, prefix, typename) \
93 BTF_ID(prefix, typename)
94 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
95 BTF_ID_LIST_GLOBAL(name, 1) \
96 BTF_ID(prefix, typename)
99 * The BTF_ID_UNUSED macro defines 4 zero bytes.
100 * It's used when we want to define 'unused' entry
101 * in BTF_ID_LIST, like:
103 * BTF_ID_LIST(bpf_skb_output_btf_ids)
104 * BTF_ID(struct, sk_buff)
106 * BTF_ID(struct, task_struct)
109 #define BTF_ID_UNUSED \
111 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
116 * The BTF_SET_START/END macros pair defines sorted list of
117 * BTF IDs plus its members count, with following layout:
119 * BTF_SET_START(list)
120 * BTF_ID(type1, name1)
121 * BTF_ID(type2, name2)
124 * __BTF_ID__set__list:
127 * __BTF_ID__type1__name1__3:
129 * __BTF_ID__type2__name2__4:
133 #define __BTF_SET_START(name, scope) \
135 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
136 "." #scope " __BTF_ID__set__" #name "; \n" \
137 "__BTF_ID__set__" #name ":; \n" \
141 #define BTF_SET_START(name) \
142 __BTF_ID_LIST(name, local) \
143 __BTF_SET_START(name, local)
145 #define BTF_SET_START_GLOBAL(name) \
146 __BTF_ID_LIST(name, globl) \
147 __BTF_SET_START(name, globl)
149 #define BTF_SET_END(name) \
151 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
152 ".size __BTF_ID__set__" #name ", .-" #name " \n" \
153 ".popsection; \n"); \
154 extern struct btf_id_set name;
158 #define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
159 #define BTF_ID(prefix, name)
160 #define BTF_ID_UNUSED
161 #define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
162 #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
163 #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
164 #define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
165 #define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
166 #define BTF_SET_END(name)
168 #endif /* CONFIG_DEBUG_INFO_BTF */
171 /* Define a list of socket types which can be the argument for
172 * skc_to_*_sock() helpers. All these sockets should have
173 * sock_common as the first argument in its memory layout.
175 #define BTF_SOCK_TYPE_xxx \
176 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
177 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
178 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
179 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
180 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
181 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
182 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
183 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
184 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
185 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
186 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
187 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
188 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \
189 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \
190 BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) \
191 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCKET, socket)
194 #define BTF_SOCK_TYPE(name, str) name,
200 extern u32 btf_sock_ids[];
203 #define BTF_TRACING_TYPE_xxx \
204 BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \
205 BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \
206 BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
209 #define BTF_TRACING_TYPE(name, type) name,
211 #undef BTF_TRACING_TYPE
212 MAX_BTF_TRACING_TYPE,
215 extern u32 btf_tracing_ids[];