1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _LINUX_BTF_IDS_H
4 #define _LINUX_BTF_IDS_H
6 #ifdef CONFIG_DEBUG_INFO_BTF
8 #include <linux/compiler.h> /* for __PASTE */
11 * Following macros help to define lists of BTF IDs placed
12 * in .BTF_ids section. They are initially filled with zeros
13 * (during compilation) and resolved later during the
14 * linking phase by resolve_btfids tool.
16 * Any change in list layout must be reflected in resolve_btfids
20 #define BTF_IDS_SECTION ".BTF_ids"
22 #define ____BTF_ID(symbol) \
24 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
25 ".local " #symbol " ; \n" \
26 ".type " #symbol ", STT_OBJECT; \n" \
27 ".size " #symbol ", 4; \n" \
32 #define __BTF_ID(symbol) \
35 #define __ID(prefix) \
36 __PASTE(prefix, __COUNTER__)
39 * The BTF_ID defines unique symbol for each ID pointing
42 #define BTF_ID(prefix, name) \
43 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__))
46 * The BTF_ID_LIST macro defines pure (unsorted) list
47 * of BTF IDs, with following layout:
50 * BTF_ID(type1, name1)
51 * BTF_ID(type2, name2)
54 * __BTF_ID__type1__name1__1:
56 * __BTF_ID__type2__name2__2:
60 #define __BTF_ID_LIST(name, scope) \
62 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
63 "." #scope " " #name "; \n" \
67 #define BTF_ID_LIST(name) \
68 __BTF_ID_LIST(name, local) \
71 #define BTF_ID_LIST_GLOBAL(name) \
72 __BTF_ID_LIST(name, globl)
75 * The BTF_ID_UNUSED macro defines 4 zero bytes.
76 * It's used when we want to define 'unused' entry
77 * in BTF_ID_LIST, like:
79 * BTF_ID_LIST(bpf_skb_output_btf_ids)
80 * BTF_ID(struct, sk_buff)
82 * BTF_ID(struct, task_struct)
85 #define BTF_ID_UNUSED \
87 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
93 #define BTF_ID_LIST(name) static u32 name[5];
94 #define BTF_ID(prefix, name)
96 #define BTF_ID_LIST_GLOBAL(name) u32 name[1];
98 #endif /* CONFIG_DEBUG_INFO_BTF */
101 /* Define a list of socket types which can be the argument for
102 * skc_to_*_sock() helpers. All these sockets should have
103 * sock_common as the first argument in its memory layout.
105 #define BTF_SOCK_TYPE_xxx \
106 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
107 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
108 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
109 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
110 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
111 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
112 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
113 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
114 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
115 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
116 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
117 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
118 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
121 #define BTF_SOCK_TYPE(name, str) name,
127 extern u32 btf_sock_ids[];