1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef _LINUX_BTF_IDS_H 4 #define _LINUX_BTF_IDS_H 5 6 #include <linux/compiler.h> /* for __PASTE */ 7 8 /* 9 * Following macros help to define lists of BTF IDs placed 10 * in .BTF_ids section. They are initially filled with zeros 11 * (during compilation) and resolved later during the 12 * linking phase by resolve_btfids tool. 13 * 14 * Any change in list layout must be reflected in resolve_btfids 15 * tool logic. 16 */ 17 18 #define BTF_IDS_SECTION ".BTF_ids" 19 20 #define ____BTF_ID(symbol) \ 21 asm( \ 22 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 23 ".local " #symbol " ; \n" \ 24 ".type " #symbol ", @object; \n" \ 25 ".size " #symbol ", 4; \n" \ 26 #symbol ": \n" \ 27 ".zero 4 \n" \ 28 ".popsection; \n"); 29 30 #define __BTF_ID(symbol) \ 31 ____BTF_ID(symbol) 32 33 #define __ID(prefix) \ 34 __PASTE(prefix, __COUNTER__) 35 36 /* 37 * The BTF_ID defines unique symbol for each ID pointing 38 * to 4 zero bytes. 39 */ 40 #define BTF_ID(prefix, name) \ 41 __BTF_ID(__ID(__BTF_ID__##prefix##__##name##__)) 42 43 /* 44 * The BTF_ID_LIST macro defines pure (unsorted) list 45 * of BTF IDs, with following layout: 46 * 47 * BTF_ID_LIST(list1) 48 * BTF_ID(type1, name1) 49 * BTF_ID(type2, name2) 50 * 51 * list1: 52 * __BTF_ID__type1__name1__1: 53 * .zero 4 54 * __BTF_ID__type2__name2__2: 55 * .zero 4 56 * 57 */ 58 #define __BTF_ID_LIST(name) \ 59 asm( \ 60 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 61 ".local " #name "; \n" \ 62 #name ":; \n" \ 63 ".popsection; \n"); \ 64 65 #define BTF_ID_LIST(name) \ 66 __BTF_ID_LIST(name) \ 67 extern u32 name[]; 68 69 /* 70 * The BTF_ID_UNUSED macro defines 4 zero bytes. 71 * It's used when we want to define 'unused' entry 72 * in BTF_ID_LIST, like: 73 * 74 * BTF_ID_LIST(bpf_skb_output_btf_ids) 75 * BTF_ID(struct, sk_buff) 76 * BTF_ID_UNUSED 77 * BTF_ID(struct, task_struct) 78 */ 79 80 #define BTF_ID_UNUSED \ 81 asm( \ 82 ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ 83 ".zero 4 \n" \ 84 ".popsection; \n"); 85 86 87 #endif 88