xref: /linux/tools/testing/selftests/bpf/prog_tests/btf.c (revision 20dfee95936413708701eb151f419597fdd9d948)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018 Facebook */
3 
4 #include <linux/bpf.h>
5 #include <linux/btf.h>
6 #include <linux/err.h>
7 #include <linux/kernel.h>
8 #include <linux/filter.h>
9 #include <linux/unistd.h>
10 #include <bpf/bpf.h>
11 #include <libelf.h>
12 #include <gelf.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <stdarg.h>
17 #include <unistd.h>
18 #include <fcntl.h>
19 #include <errno.h>
20 #include <assert.h>
21 #include <bpf/libbpf.h>
22 #include <bpf/btf.h>
23 
24 #include "bpf_util.h"
25 #include "../test_btf.h"
26 #include "test_progs.h"
27 
28 #define MAX_INSNS	512
29 #define MAX_SUBPROGS	16
30 
31 static int duration = 0;
32 static bool always_log;
33 
34 #undef CHECK
35 #define CHECK(condition, format...) _CHECK(condition, "check", duration, format)
36 
37 #define NAME_TBD 0xdeadb33f
38 
39 #define NAME_NTH(N) (0xfffe0000 | N)
40 #define IS_NAME_NTH(X) ((X & 0xffff0000) == 0xfffe0000)
41 #define GET_NAME_NTH_IDX(X) (X & 0x0000ffff)
42 
43 #define MAX_NR_RAW_U32 1024
44 #define BTF_LOG_BUF_SIZE 65535
45 
46 static char btf_log_buf[BTF_LOG_BUF_SIZE];
47 
48 static struct btf_header hdr_tmpl = {
49 	.magic = BTF_MAGIC,
50 	.version = BTF_VERSION,
51 	.hdr_len = sizeof(struct btf_header),
52 };
53 
54 /* several different mapv kinds(types) supported by pprint */
55 enum pprint_mapv_kind_t {
56 	PPRINT_MAPV_KIND_BASIC = 0,
57 	PPRINT_MAPV_KIND_INT128,
58 };
59 
60 struct btf_raw_test {
61 	const char *descr;
62 	const char *str_sec;
63 	const char *map_name;
64 	const char *err_str;
65 	__u32 raw_types[MAX_NR_RAW_U32];
66 	__u32 str_sec_size;
67 	enum bpf_map_type map_type;
68 	__u32 key_size;
69 	__u32 value_size;
70 	__u32 key_type_id;
71 	__u32 value_type_id;
72 	__u32 max_entries;
73 	bool btf_load_err;
74 	bool map_create_err;
75 	bool ordered_map;
76 	bool lossless_map;
77 	bool percpu_map;
78 	int hdr_len_delta;
79 	int type_off_delta;
80 	int str_off_delta;
81 	int str_len_delta;
82 	enum pprint_mapv_kind_t mapv_kind;
83 };
84 
85 #define BTF_STR_SEC(str) \
86 	.str_sec = str, .str_sec_size = sizeof(str)
87 
88 static struct btf_raw_test raw_tests[] = {
89 /* enum E {
90  *     E0,
91  *     E1,
92  * };
93  *
94  * struct A {
95  *	unsigned long long m;
96  *	int n;
97  *	char o;
98  *	[3 bytes hole]
99  *	int p[8];
100  *	int q[4][8];
101  *	enum E r;
102  * };
103  */
104 {
105 	.descr = "struct test #1",
106 	.raw_types = {
107 		/* int */
108 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
109 		/* unsigned long long */
110 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
111 		/* char */
112 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
113 		/* int[8] */
114 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
115 		/* struct A { */				/* [5] */
116 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 6), 180),
117 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
118 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
119 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
120 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
121 		BTF_MEMBER_ENC(NAME_TBD, 6, 384),/* int q[4][8]		*/
122 		BTF_MEMBER_ENC(NAME_TBD, 7, 1408), /* enum E r		*/
123 		/* } */
124 		/* int[4][8] */
125 		BTF_TYPE_ARRAY_ENC(4, 1, 4),			/* [6] */
126 		/* enum E */					/* [7] */
127 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), sizeof(int)),
128 		BTF_ENUM_ENC(NAME_TBD, 0),
129 		BTF_ENUM_ENC(NAME_TBD, 1),
130 		BTF_END_RAW,
131 	},
132 	.str_sec = "\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1",
133 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1"),
134 	.map_type = BPF_MAP_TYPE_ARRAY,
135 	.map_name = "struct_test1_map",
136 	.key_size = sizeof(int),
137 	.value_size = 180,
138 	.key_type_id = 1,
139 	.value_type_id = 5,
140 	.max_entries = 4,
141 },
142 
143 /* typedef struct b Struct_B;
144  *
145  * struct A {
146  *     int m;
147  *     struct b n[4];
148  *     const Struct_B o[4];
149  * };
150  *
151  * struct B {
152  *     int m;
153  *     int n;
154  * };
155  */
156 {
157 	.descr = "struct test #2",
158 	.raw_types = {
159 		/* int */					/* [1] */
160 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
161 		/* struct b [4] */				/* [2] */
162 		BTF_TYPE_ARRAY_ENC(4, 1, 4),
163 
164 		/* struct A { */				/* [3] */
165 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 3), 68),
166 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int m;		*/
167 		BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* struct B n[4]	*/
168 		BTF_MEMBER_ENC(NAME_TBD, 8, 288),/* const Struct_B o[4];*/
169 		/* } */
170 
171 		/* struct B { */				/* [4] */
172 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
173 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int m; */
174 		BTF_MEMBER_ENC(NAME_TBD, 1, 32),/* int n; */
175 		/* } */
176 
177 		/* const int */					/* [5] */
178 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 1),
179 		/* typedef struct b Struct_B */	/* [6] */
180 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 4),
181 		/* const Struct_B */				/* [7] */
182 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 6),
183 		/* const Struct_B [4] */			/* [8] */
184 		BTF_TYPE_ARRAY_ENC(7, 1, 4),
185 		BTF_END_RAW,
186 	},
187 	.str_sec = "\0A\0m\0n\0o\0B\0m\0n\0Struct_B",
188 	.str_sec_size = sizeof("\0A\0m\0n\0o\0B\0m\0n\0Struct_B"),
189 	.map_type = BPF_MAP_TYPE_ARRAY,
190 	.map_name = "struct_test2_map",
191 	.key_size = sizeof(int),
192 	.value_size = 68,
193 	.key_type_id = 1,
194 	.value_type_id = 3,
195 	.max_entries = 4,
196 },
197 {
198 	.descr = "struct test #3 Invalid member offset",
199 	.raw_types = {
200 		/* int */					/* [1] */
201 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
202 		/* int64 */					/* [2] */
203 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 64, 8),
204 
205 		/* struct A { */				/* [3] */
206 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 16),
207 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),	/* int m;		*/
208 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),		/* int64 n; */
209 		/* } */
210 		BTF_END_RAW,
211 	},
212 	.str_sec = "\0A\0m\0n\0",
213 	.str_sec_size = sizeof("\0A\0m\0n\0"),
214 	.map_type = BPF_MAP_TYPE_ARRAY,
215 	.map_name = "struct_test3_map",
216 	.key_size = sizeof(int),
217 	.value_size = 16,
218 	.key_type_id = 1,
219 	.value_type_id = 3,
220 	.max_entries = 4,
221 	.btf_load_err = true,
222 	.err_str = "Invalid member bits_offset",
223 },
224 /*
225  * struct A {
226  *	unsigned long long m;
227  *	int n;
228  *	char o;
229  *	[3 bytes hole]
230  *	int p[8];
231  * };
232  */
233 {
234 	.descr = "global data test #1",
235 	.raw_types = {
236 		/* int */
237 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
238 		/* unsigned long long */
239 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
240 		/* char */
241 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
242 		/* int[8] */
243 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
244 		/* struct A { */				/* [5] */
245 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
246 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
247 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
248 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
249 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
250 		/* } */
251 		BTF_END_RAW,
252 	},
253 	.str_sec = "\0A\0m\0n\0o\0p",
254 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p"),
255 	.map_type = BPF_MAP_TYPE_ARRAY,
256 	.map_name = "struct_test1_map",
257 	.key_size = sizeof(int),
258 	.value_size = 48,
259 	.key_type_id = 1,
260 	.value_type_id = 5,
261 	.max_entries = 4,
262 },
263 /*
264  * struct A {
265  *	unsigned long long m;
266  *	int n;
267  *	char o;
268  *	[3 bytes hole]
269  *	int p[8];
270  * };
271  * static struct A t; <- in .bss
272  */
273 {
274 	.descr = "global data test #2",
275 	.raw_types = {
276 		/* int */
277 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
278 		/* unsigned long long */
279 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
280 		/* char */
281 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
282 		/* int[8] */
283 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
284 		/* struct A { */				/* [5] */
285 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
286 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
287 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
288 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
289 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
290 		/* } */
291 		/* static struct A t */
292 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [6] */
293 		/* .bss section */				/* [7] */
294 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 48),
295 		BTF_VAR_SECINFO_ENC(6, 0, 48),
296 		BTF_END_RAW,
297 	},
298 	.str_sec = "\0A\0m\0n\0o\0p\0t\0.bss",
299 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
300 	.map_type = BPF_MAP_TYPE_ARRAY,
301 	.map_name = ".bss",
302 	.key_size = sizeof(int),
303 	.value_size = 48,
304 	.key_type_id = 0,
305 	.value_type_id = 7,
306 	.max_entries = 1,
307 },
308 {
309 	.descr = "global data test #3",
310 	.raw_types = {
311 		/* int */
312 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
313 		/* static int t */
314 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
315 		/* .bss section */				/* [3] */
316 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
317 		BTF_VAR_SECINFO_ENC(2, 0, 4),
318 		BTF_END_RAW,
319 	},
320 	.str_sec = "\0t\0.bss",
321 	.str_sec_size = sizeof("\0t\0.bss"),
322 	.map_type = BPF_MAP_TYPE_ARRAY,
323 	.map_name = ".bss",
324 	.key_size = sizeof(int),
325 	.value_size = 4,
326 	.key_type_id = 0,
327 	.value_type_id = 3,
328 	.max_entries = 1,
329 },
330 {
331 	.descr = "global data test #4, unsupported linkage",
332 	.raw_types = {
333 		/* int */
334 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
335 		/* static int t */
336 		BTF_VAR_ENC(NAME_TBD, 1, 2),			/* [2] */
337 		/* .bss section */				/* [3] */
338 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
339 		BTF_VAR_SECINFO_ENC(2, 0, 4),
340 		BTF_END_RAW,
341 	},
342 	.str_sec = "\0t\0.bss",
343 	.str_sec_size = sizeof("\0t\0.bss"),
344 	.map_type = BPF_MAP_TYPE_ARRAY,
345 	.map_name = ".bss",
346 	.key_size = sizeof(int),
347 	.value_size = 4,
348 	.key_type_id = 0,
349 	.value_type_id = 3,
350 	.max_entries = 1,
351 	.btf_load_err = true,
352 	.err_str = "Linkage not supported",
353 },
354 {
355 	.descr = "global data test #5, invalid var type",
356 	.raw_types = {
357 		/* static void t */
358 		BTF_VAR_ENC(NAME_TBD, 0, 0),			/* [1] */
359 		/* .bss section */				/* [2] */
360 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
361 		BTF_VAR_SECINFO_ENC(1, 0, 4),
362 		BTF_END_RAW,
363 	},
364 	.str_sec = "\0t\0.bss",
365 	.str_sec_size = sizeof("\0t\0.bss"),
366 	.map_type = BPF_MAP_TYPE_ARRAY,
367 	.map_name = ".bss",
368 	.key_size = sizeof(int),
369 	.value_size = 4,
370 	.key_type_id = 0,
371 	.value_type_id = 2,
372 	.max_entries = 1,
373 	.btf_load_err = true,
374 	.err_str = "Invalid type_id",
375 },
376 {
377 	.descr = "global data test #6, invalid var type (fwd type)",
378 	.raw_types = {
379 		/* union A */
380 		BTF_TYPE_ENC(NAME_TBD,
381 			     BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [1] */
382 		/* static union A t */
383 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
384 		/* .bss section */				/* [3] */
385 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
386 		BTF_VAR_SECINFO_ENC(2, 0, 4),
387 		BTF_END_RAW,
388 	},
389 	.str_sec = "\0A\0t\0.bss",
390 	.str_sec_size = sizeof("\0A\0t\0.bss"),
391 	.map_type = BPF_MAP_TYPE_ARRAY,
392 	.map_name = ".bss",
393 	.key_size = sizeof(int),
394 	.value_size = 4,
395 	.key_type_id = 0,
396 	.value_type_id = 2,
397 	.max_entries = 1,
398 	.btf_load_err = true,
399 	.err_str = "Invalid type",
400 },
401 {
402 	.descr = "global data test #7, invalid var type (fwd type)",
403 	.raw_types = {
404 		/* union A */
405 		BTF_TYPE_ENC(NAME_TBD,
406 			     BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [1] */
407 		/* static union A t */
408 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
409 		/* .bss section */				/* [3] */
410 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
411 		BTF_VAR_SECINFO_ENC(1, 0, 4),
412 		BTF_END_RAW,
413 	},
414 	.str_sec = "\0A\0t\0.bss",
415 	.str_sec_size = sizeof("\0A\0t\0.bss"),
416 	.map_type = BPF_MAP_TYPE_ARRAY,
417 	.map_name = ".bss",
418 	.key_size = sizeof(int),
419 	.value_size = 4,
420 	.key_type_id = 0,
421 	.value_type_id = 2,
422 	.max_entries = 1,
423 	.btf_load_err = true,
424 	.err_str = "Invalid type",
425 },
426 {
427 	.descr = "global data test #8, invalid var size",
428 	.raw_types = {
429 		/* int */
430 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
431 		/* unsigned long long */
432 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
433 		/* char */
434 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
435 		/* int[8] */
436 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
437 		/* struct A { */				/* [5] */
438 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
439 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
440 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
441 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
442 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
443 		/* } */
444 		/* static struct A t */
445 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [6] */
446 		/* .bss section */				/* [7] */
447 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 48),
448 		BTF_VAR_SECINFO_ENC(6, 0, 47),
449 		BTF_END_RAW,
450 	},
451 	.str_sec = "\0A\0m\0n\0o\0p\0t\0.bss",
452 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
453 	.map_type = BPF_MAP_TYPE_ARRAY,
454 	.map_name = ".bss",
455 	.key_size = sizeof(int),
456 	.value_size = 48,
457 	.key_type_id = 0,
458 	.value_type_id = 7,
459 	.max_entries = 1,
460 	.btf_load_err = true,
461 	.err_str = "Invalid size",
462 },
463 {
464 	.descr = "global data test #9, invalid var size",
465 	.raw_types = {
466 		/* int */
467 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
468 		/* unsigned long long */
469 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
470 		/* char */
471 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
472 		/* int[8] */
473 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
474 		/* struct A { */				/* [5] */
475 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
476 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
477 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
478 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
479 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
480 		/* } */
481 		/* static struct A t */
482 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [6] */
483 		/* .bss section */				/* [7] */
484 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 46),
485 		BTF_VAR_SECINFO_ENC(6, 0, 48),
486 		BTF_END_RAW,
487 	},
488 	.str_sec = "\0A\0m\0n\0o\0p\0t\0.bss",
489 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
490 	.map_type = BPF_MAP_TYPE_ARRAY,
491 	.map_name = ".bss",
492 	.key_size = sizeof(int),
493 	.value_size = 48,
494 	.key_type_id = 0,
495 	.value_type_id = 7,
496 	.max_entries = 1,
497 	.btf_load_err = true,
498 	.err_str = "Invalid size",
499 },
500 {
501 	.descr = "global data test #10, invalid var size",
502 	.raw_types = {
503 		/* int */
504 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
505 		/* unsigned long long */
506 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
507 		/* char */
508 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
509 		/* int[8] */
510 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
511 		/* struct A { */				/* [5] */
512 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
513 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
514 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
515 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
516 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
517 		/* } */
518 		/* static struct A t */
519 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [6] */
520 		/* .bss section */				/* [7] */
521 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 46),
522 		BTF_VAR_SECINFO_ENC(6, 0, 46),
523 		BTF_END_RAW,
524 	},
525 	.str_sec = "\0A\0m\0n\0o\0p\0t\0.bss",
526 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
527 	.map_type = BPF_MAP_TYPE_ARRAY,
528 	.map_name = ".bss",
529 	.key_size = sizeof(int),
530 	.value_size = 48,
531 	.key_type_id = 0,
532 	.value_type_id = 7,
533 	.max_entries = 1,
534 	.btf_load_err = true,
535 	.err_str = "Invalid size",
536 },
537 {
538 	.descr = "global data test #11, multiple section members",
539 	.raw_types = {
540 		/* int */
541 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
542 		/* unsigned long long */
543 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
544 		/* char */
545 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
546 		/* int[8] */
547 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
548 		/* struct A { */				/* [5] */
549 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
550 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
551 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
552 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
553 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
554 		/* } */
555 		/* static struct A t */
556 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [6] */
557 		/* static int u */
558 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [7] */
559 		/* .bss section */				/* [8] */
560 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2), 62),
561 		BTF_VAR_SECINFO_ENC(6, 10, 48),
562 		BTF_VAR_SECINFO_ENC(7, 58, 4),
563 		BTF_END_RAW,
564 	},
565 	.str_sec = "\0A\0m\0n\0o\0p\0t\0u\0.bss",
566 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
567 	.map_type = BPF_MAP_TYPE_ARRAY,
568 	.map_name = ".bss",
569 	.key_size = sizeof(int),
570 	.value_size = 62,
571 	.key_type_id = 0,
572 	.value_type_id = 8,
573 	.max_entries = 1,
574 },
575 {
576 	.descr = "global data test #12, invalid offset",
577 	.raw_types = {
578 		/* int */
579 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
580 		/* unsigned long long */
581 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
582 		/* char */
583 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
584 		/* int[8] */
585 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
586 		/* struct A { */				/* [5] */
587 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
588 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
589 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
590 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
591 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
592 		/* } */
593 		/* static struct A t */
594 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [6] */
595 		/* static int u */
596 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [7] */
597 		/* .bss section */				/* [8] */
598 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2), 62),
599 		BTF_VAR_SECINFO_ENC(6, 10, 48),
600 		BTF_VAR_SECINFO_ENC(7, 60, 4),
601 		BTF_END_RAW,
602 	},
603 	.str_sec = "\0A\0m\0n\0o\0p\0t\0u\0.bss",
604 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
605 	.map_type = BPF_MAP_TYPE_ARRAY,
606 	.map_name = ".bss",
607 	.key_size = sizeof(int),
608 	.value_size = 62,
609 	.key_type_id = 0,
610 	.value_type_id = 8,
611 	.max_entries = 1,
612 	.btf_load_err = true,
613 	.err_str = "Invalid offset+size",
614 },
615 {
616 	.descr = "global data test #13, invalid offset",
617 	.raw_types = {
618 		/* int */
619 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
620 		/* unsigned long long */
621 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
622 		/* char */
623 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
624 		/* int[8] */
625 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
626 		/* struct A { */				/* [5] */
627 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
628 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
629 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
630 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
631 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
632 		/* } */
633 		/* static struct A t */
634 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [6] */
635 		/* static int u */
636 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [7] */
637 		/* .bss section */				/* [8] */
638 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2), 62),
639 		BTF_VAR_SECINFO_ENC(6, 10, 48),
640 		BTF_VAR_SECINFO_ENC(7, 12, 4),
641 		BTF_END_RAW,
642 	},
643 	.str_sec = "\0A\0m\0n\0o\0p\0t\0u\0.bss",
644 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
645 	.map_type = BPF_MAP_TYPE_ARRAY,
646 	.map_name = ".bss",
647 	.key_size = sizeof(int),
648 	.value_size = 62,
649 	.key_type_id = 0,
650 	.value_type_id = 8,
651 	.max_entries = 1,
652 	.btf_load_err = true,
653 	.err_str = "Invalid offset",
654 },
655 {
656 	.descr = "global data test #14, invalid offset",
657 	.raw_types = {
658 		/* int */
659 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
660 		/* unsigned long long */
661 		BTF_TYPE_INT_ENC(0, 0, 0, 64, 8),		/* [2] */
662 		/* char */
663 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),	/* [3] */
664 		/* int[8] */
665 		BTF_TYPE_ARRAY_ENC(1, 1, 8),			/* [4] */
666 		/* struct A { */				/* [5] */
667 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
668 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* unsigned long long m;*/
669 		BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n;		*/
670 		BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o;		*/
671 		BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8]		*/
672 		/* } */
673 		/* static struct A t */
674 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [6] */
675 		/* static int u */
676 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [7] */
677 		/* .bss section */				/* [8] */
678 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2), 62),
679 		BTF_VAR_SECINFO_ENC(7, 58, 4),
680 		BTF_VAR_SECINFO_ENC(6, 10, 48),
681 		BTF_END_RAW,
682 	},
683 	.str_sec = "\0A\0m\0n\0o\0p\0t\0u\0.bss",
684 	.str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
685 	.map_type = BPF_MAP_TYPE_ARRAY,
686 	.map_name = ".bss",
687 	.key_size = sizeof(int),
688 	.value_size = 62,
689 	.key_type_id = 0,
690 	.value_type_id = 8,
691 	.max_entries = 1,
692 	.btf_load_err = true,
693 	.err_str = "Invalid offset",
694 },
695 {
696 	.descr = "global data test #15, not var kind",
697 	.raw_types = {
698 		/* int */
699 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
700 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
701 		/* .bss section */				/* [3] */
702 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
703 		BTF_VAR_SECINFO_ENC(1, 0, 4),
704 		BTF_END_RAW,
705 	},
706 	.str_sec = "\0A\0t\0.bss",
707 	.str_sec_size = sizeof("\0A\0t\0.bss"),
708 	.map_type = BPF_MAP_TYPE_ARRAY,
709 	.map_name = ".bss",
710 	.key_size = sizeof(int),
711 	.value_size = 4,
712 	.key_type_id = 0,
713 	.value_type_id = 3,
714 	.max_entries = 1,
715 	.btf_load_err = true,
716 	.err_str = "Not a VAR kind member",
717 },
718 {
719 	.descr = "global data test #16, invalid var referencing sec",
720 	.raw_types = {
721 		/* int */
722 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
723 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [2] */
724 		BTF_VAR_ENC(NAME_TBD, 2, 0),			/* [3] */
725 		/* a section */					/* [4] */
726 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
727 		BTF_VAR_SECINFO_ENC(3, 0, 4),
728 		/* a section */					/* [5] */
729 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
730 		BTF_VAR_SECINFO_ENC(6, 0, 4),
731 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [6] */
732 		BTF_END_RAW,
733 	},
734 	.str_sec = "\0A\0t\0s\0a\0a",
735 	.str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
736 	.map_type = BPF_MAP_TYPE_ARRAY,
737 	.map_name = ".bss",
738 	.key_size = sizeof(int),
739 	.value_size = 4,
740 	.key_type_id = 0,
741 	.value_type_id = 4,
742 	.max_entries = 1,
743 	.btf_load_err = true,
744 	.err_str = "Invalid type_id",
745 },
746 {
747 	.descr = "global data test #17, invalid var referencing var",
748 	.raw_types = {
749 		/* int */
750 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
751 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
752 		BTF_VAR_ENC(NAME_TBD, 2, 0),			/* [3] */
753 		/* a section */					/* [4] */
754 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
755 		BTF_VAR_SECINFO_ENC(3, 0, 4),
756 		BTF_END_RAW,
757 	},
758 	.str_sec = "\0A\0t\0s\0a\0a",
759 	.str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
760 	.map_type = BPF_MAP_TYPE_ARRAY,
761 	.map_name = ".bss",
762 	.key_size = sizeof(int),
763 	.value_size = 4,
764 	.key_type_id = 0,
765 	.value_type_id = 4,
766 	.max_entries = 1,
767 	.btf_load_err = true,
768 	.err_str = "Invalid type_id",
769 },
770 {
771 	.descr = "global data test #18, invalid var loop",
772 	.raw_types = {
773 		/* int */
774 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
775 		BTF_VAR_ENC(NAME_TBD, 2, 0),			/* [2] */
776 		/* .bss section */				/* [3] */
777 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
778 		BTF_VAR_SECINFO_ENC(2, 0, 4),
779 		BTF_END_RAW,
780 	},
781 	.str_sec = "\0A\0t\0aaa",
782 	.str_sec_size = sizeof("\0A\0t\0aaa"),
783 	.map_type = BPF_MAP_TYPE_ARRAY,
784 	.map_name = ".bss",
785 	.key_size = sizeof(int),
786 	.value_size = 4,
787 	.key_type_id = 0,
788 	.value_type_id = 4,
789 	.max_entries = 1,
790 	.btf_load_err = true,
791 	.err_str = "Invalid type_id",
792 },
793 {
794 	.descr = "global data test #19, invalid var referencing var",
795 	.raw_types = {
796 		/* int */
797 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
798 		BTF_VAR_ENC(NAME_TBD, 3, 0),			/* [2] */
799 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [3] */
800 		BTF_END_RAW,
801 	},
802 	.str_sec = "\0A\0t\0s\0a\0a",
803 	.str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
804 	.map_type = BPF_MAP_TYPE_ARRAY,
805 	.map_name = ".bss",
806 	.key_size = sizeof(int),
807 	.value_size = 4,
808 	.key_type_id = 0,
809 	.value_type_id = 4,
810 	.max_entries = 1,
811 	.btf_load_err = true,
812 	.err_str = "Invalid type_id",
813 },
814 {
815 	.descr = "global data test #20, invalid ptr referencing var",
816 	.raw_types = {
817 		/* int */
818 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
819 		/* PTR type_id=3	*/			/* [2] */
820 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 3),
821 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [3] */
822 		BTF_END_RAW,
823 	},
824 	.str_sec = "\0A\0t\0s\0a\0a",
825 	.str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
826 	.map_type = BPF_MAP_TYPE_ARRAY,
827 	.map_name = ".bss",
828 	.key_size = sizeof(int),
829 	.value_size = 4,
830 	.key_type_id = 0,
831 	.value_type_id = 4,
832 	.max_entries = 1,
833 	.btf_load_err = true,
834 	.err_str = "Invalid type_id",
835 },
836 {
837 	.descr = "global data test #21, var included in struct",
838 	.raw_types = {
839 		/* int */
840 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
841 		/* struct A { */				/* [2] */
842 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 2),
843 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int m; */
844 		BTF_MEMBER_ENC(NAME_TBD, 3, 32),/* VAR type_id=3; */
845 		/* } */
846 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [3] */
847 		BTF_END_RAW,
848 	},
849 	.str_sec = "\0A\0t\0s\0a\0a",
850 	.str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
851 	.map_type = BPF_MAP_TYPE_ARRAY,
852 	.map_name = ".bss",
853 	.key_size = sizeof(int),
854 	.value_size = 4,
855 	.key_type_id = 0,
856 	.value_type_id = 4,
857 	.max_entries = 1,
858 	.btf_load_err = true,
859 	.err_str = "Invalid member",
860 },
861 {
862 	.descr = "global data test #22, array of var",
863 	.raw_types = {
864 		/* int */
865 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
866 		BTF_TYPE_ARRAY_ENC(3, 1, 4),			/* [2] */
867 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [3] */
868 		BTF_END_RAW,
869 	},
870 	.str_sec = "\0A\0t\0s\0a\0a",
871 	.str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
872 	.map_type = BPF_MAP_TYPE_ARRAY,
873 	.map_name = ".bss",
874 	.key_size = sizeof(int),
875 	.value_size = 4,
876 	.key_type_id = 0,
877 	.value_type_id = 4,
878 	.max_entries = 1,
879 	.btf_load_err = true,
880 	.err_str = "Invalid elem",
881 },
882 {
883 	.descr = "var after datasec, ptr followed by modifier",
884 	.raw_types = {
885 		/* .bss section */				/* [1] */
886 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2),
887 			sizeof(void*)+4),
888 		BTF_VAR_SECINFO_ENC(4, 0, sizeof(void*)),
889 		BTF_VAR_SECINFO_ENC(6, sizeof(void*), 4),
890 		/* int */					/* [2] */
891 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
892 		/* int* */					/* [3] */
893 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
894 		BTF_VAR_ENC(NAME_TBD, 3, 0),			/* [4] */
895 		/* const int */					/* [5] */
896 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
897 		BTF_VAR_ENC(NAME_TBD, 5, 0),			/* [6] */
898 		BTF_END_RAW,
899 	},
900 	.str_sec = "\0a\0b\0c\0",
901 	.str_sec_size = sizeof("\0a\0b\0c\0"),
902 	.map_type = BPF_MAP_TYPE_ARRAY,
903 	.map_name = ".bss",
904 	.key_size = sizeof(int),
905 	.value_size = sizeof(void*)+4,
906 	.key_type_id = 0,
907 	.value_type_id = 1,
908 	.max_entries = 1,
909 },
910 /* Test member exceeds the size of struct.
911  *
912  * struct A {
913  *     int m;
914  *     int n;
915  * };
916  */
917 {
918 	.descr = "size check test #1",
919 	.raw_types = {
920 		/* int */					/* [1] */
921 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
922 		/* struct A { */				/* [2] */
923 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 2 -  1),
924 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int m; */
925 		BTF_MEMBER_ENC(NAME_TBD, 1, 32),/* int n; */
926 		/* } */
927 		BTF_END_RAW,
928 	},
929 	.str_sec = "\0A\0m\0n",
930 	.str_sec_size = sizeof("\0A\0m\0n"),
931 	.map_type = BPF_MAP_TYPE_ARRAY,
932 	.map_name = "size_check1_map",
933 	.key_size = sizeof(int),
934 	.value_size = 1,
935 	.key_type_id = 1,
936 	.value_type_id = 2,
937 	.max_entries = 4,
938 	.btf_load_err = true,
939 	.err_str = "Member exceeds struct_size",
940 },
941 
942 /* Test member exceeds the size of struct
943  *
944  * struct A {
945  *     int m;
946  *     int n[2];
947  * };
948  */
949 {
950 	.descr = "size check test #2",
951 	.raw_types = {
952 		/* int */					/* [1] */
953 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
954 		/* int[2] */					/* [2] */
955 		BTF_TYPE_ARRAY_ENC(1, 1, 2),
956 		/* struct A { */				/* [3] */
957 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 3 - 1),
958 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int m; */
959 		BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* int n[2]; */
960 		/* } */
961 		BTF_END_RAW,
962 	},
963 	.str_sec = "\0A\0m\0n",
964 	.str_sec_size = sizeof("\0A\0m\0n"),
965 	.map_type = BPF_MAP_TYPE_ARRAY,
966 	.map_name = "size_check2_map",
967 	.key_size = sizeof(int),
968 	.value_size = 1,
969 	.key_type_id = 1,
970 	.value_type_id = 3,
971 	.max_entries = 4,
972 	.btf_load_err = true,
973 	.err_str = "Member exceeds struct_size",
974 },
975 
976 /* Test member exceeds the size of struct
977  *
978  * struct A {
979  *     int m;
980  *     void *n;
981  * };
982  */
983 {
984 	.descr = "size check test #3",
985 	.raw_types = {
986 		/* int */					/* [1] */
987 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
988 		/* void* */					/* [2] */
989 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0),
990 		/* struct A { */				/* [3] */
991 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) + sizeof(void *) - 1),
992 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int m; */
993 		BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* void *n; */
994 		/* } */
995 		BTF_END_RAW,
996 	},
997 	.str_sec = "\0A\0m\0n",
998 	.str_sec_size = sizeof("\0A\0m\0n"),
999 	.map_type = BPF_MAP_TYPE_ARRAY,
1000 	.map_name = "size_check3_map",
1001 	.key_size = sizeof(int),
1002 	.value_size = 1,
1003 	.key_type_id = 1,
1004 	.value_type_id = 3,
1005 	.max_entries = 4,
1006 	.btf_load_err = true,
1007 	.err_str = "Member exceeds struct_size",
1008 },
1009 
1010 /* Test member exceeds the size of struct
1011  *
1012  * enum E {
1013  *     E0,
1014  *     E1,
1015  * };
1016  *
1017  * struct A {
1018  *     int m;
1019  *     enum E n;
1020  * };
1021  */
1022 {
1023 	.descr = "size check test #4",
1024 	.raw_types = {
1025 		/* int */			/* [1] */
1026 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
1027 		/* enum E { */			/* [2] */
1028 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), sizeof(int)),
1029 		BTF_ENUM_ENC(NAME_TBD, 0),
1030 		BTF_ENUM_ENC(NAME_TBD, 1),
1031 		/* } */
1032 		/* struct A { */		/* [3] */
1033 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 2 - 1),
1034 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int m; */
1035 		BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* enum E n; */
1036 		/* } */
1037 		BTF_END_RAW,
1038 	},
1039 	.str_sec = "\0E\0E0\0E1\0A\0m\0n",
1040 	.str_sec_size = sizeof("\0E\0E0\0E1\0A\0m\0n"),
1041 	.map_type = BPF_MAP_TYPE_ARRAY,
1042 	.map_name = "size_check4_map",
1043 	.key_size = sizeof(int),
1044 	.value_size = 1,
1045 	.key_type_id = 1,
1046 	.value_type_id = 3,
1047 	.max_entries = 4,
1048 	.btf_load_err = true,
1049 	.err_str = "Member exceeds struct_size",
1050 },
1051 
1052 /* Test member unexceeds the size of struct
1053  *
1054  * enum E {
1055  *     E0,
1056  *     E1,
1057  * };
1058  *
1059  * struct A {
1060  *     char m;
1061  *     enum E __attribute__((packed)) n;
1062  * };
1063  */
1064 {
1065 	.descr = "size check test #5",
1066 	.raw_types = {
1067 		/* int */			/* [1] */
1068 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
1069 		/* char */			/* [2] */
1070 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),
1071 		/* enum E { */			/* [3] */
1072 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 1),
1073 		BTF_ENUM_ENC(NAME_TBD, 0),
1074 		BTF_ENUM_ENC(NAME_TBD, 1),
1075 		/* } */
1076 		/* struct A { */		/* [4] */
1077 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 2),
1078 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),	/* char m; */
1079 		BTF_MEMBER_ENC(NAME_TBD, 3, 8),/* enum E __attribute__((packed)) n; */
1080 		/* } */
1081 		BTF_END_RAW,
1082 	},
1083 	.str_sec = "\0E\0E0\0E1\0A\0m\0n",
1084 	.str_sec_size = sizeof("\0E\0E0\0E1\0A\0m\0n"),
1085 	.map_type = BPF_MAP_TYPE_ARRAY,
1086 	.map_name = "size_check5_map",
1087 	.key_size = sizeof(int),
1088 	.value_size = 2,
1089 	.key_type_id = 1,
1090 	.value_type_id = 4,
1091 	.max_entries = 4,
1092 },
1093 
1094 /* typedef const void * const_void_ptr;
1095  * struct A {
1096  *	const_void_ptr m;
1097  * };
1098  */
1099 {
1100 	.descr = "void test #1",
1101 	.raw_types = {
1102 		/* int */		/* [1] */
1103 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1104 		/* const void */	/* [2] */
1105 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1106 		/* const void* */	/* [3] */
1107 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
1108 		/* typedef const void * const_void_ptr */
1109 		BTF_TYPEDEF_ENC(NAME_TBD, 3),	/* [4] */
1110 		/* struct A { */	/* [5] */
1111 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1112 		/* const_void_ptr m; */
1113 		BTF_MEMBER_ENC(NAME_TBD, 4, 0),
1114 		/* } */
1115 		BTF_END_RAW,
1116 	},
1117 	.str_sec = "\0const_void_ptr\0A\0m",
1118 	.str_sec_size = sizeof("\0const_void_ptr\0A\0m"),
1119 	.map_type = BPF_MAP_TYPE_ARRAY,
1120 	.map_name = "void_test1_map",
1121 	.key_size = sizeof(int),
1122 	.value_size = sizeof(void *),
1123 	.key_type_id = 1,
1124 	.value_type_id = 4,
1125 	.max_entries = 4,
1126 },
1127 
1128 /* struct A {
1129  *     const void m;
1130  * };
1131  */
1132 {
1133 	.descr = "void test #2",
1134 	.raw_types = {
1135 		/* int */		/* [1] */
1136 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1137 		/* const void */	/* [2] */
1138 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1139 		/* struct A { */	/* [3] */
1140 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 8),
1141 		/* const void m; */
1142 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),
1143 		/* } */
1144 		BTF_END_RAW,
1145 	},
1146 	.str_sec = "\0A\0m",
1147 	.str_sec_size = sizeof("\0A\0m"),
1148 	.map_type = BPF_MAP_TYPE_ARRAY,
1149 	.map_name = "void_test2_map",
1150 	.key_size = sizeof(int),
1151 	.value_size = sizeof(void *),
1152 	.key_type_id = 1,
1153 	.value_type_id = 3,
1154 	.max_entries = 4,
1155 	.btf_load_err = true,
1156 	.err_str = "Invalid member",
1157 },
1158 
1159 /* typedef const void * const_void_ptr;
1160  * const_void_ptr[4]
1161  */
1162 {
1163 	.descr = "void test #3",
1164 	.raw_types = {
1165 		/* int */		/* [1] */
1166 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1167 		/* const void */	/* [2] */
1168 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1169 		/* const void* */	/* [3] */
1170 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
1171 		/* typedef const void * const_void_ptr */
1172 		BTF_TYPEDEF_ENC(NAME_TBD, 3),	/* [4] */
1173 		/* const_void_ptr[4] */
1174 		BTF_TYPE_ARRAY_ENC(4, 1, 4),	/* [5] */
1175 		BTF_END_RAW,
1176 	},
1177 	.str_sec = "\0const_void_ptr",
1178 	.str_sec_size = sizeof("\0const_void_ptr"),
1179 	.map_type = BPF_MAP_TYPE_ARRAY,
1180 	.map_name = "void_test3_map",
1181 	.key_size = sizeof(int),
1182 	.value_size = sizeof(void *) * 4,
1183 	.key_type_id = 1,
1184 	.value_type_id = 5,
1185 	.max_entries = 4,
1186 },
1187 
1188 /* const void[4]  */
1189 {
1190 	.descr = "void test #4",
1191 	.raw_types = {
1192 		/* int */		/* [1] */
1193 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1194 		/* const void */	/* [2] */
1195 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1196 		/* const void[4] */	/* [3] */
1197 		BTF_TYPE_ARRAY_ENC(2, 1, 4),
1198 		BTF_END_RAW,
1199 	},
1200 	.str_sec = "\0A\0m",
1201 	.str_sec_size = sizeof("\0A\0m"),
1202 	.map_type = BPF_MAP_TYPE_ARRAY,
1203 	.map_name = "void_test4_map",
1204 	.key_size = sizeof(int),
1205 	.value_size = sizeof(void *) * 4,
1206 	.key_type_id = 1,
1207 	.value_type_id = 3,
1208 	.max_entries = 4,
1209 	.btf_load_err = true,
1210 	.err_str = "Invalid elem",
1211 },
1212 
1213 /* Array_A  <------------------+
1214  *     elem_type == Array_B    |
1215  *                    |        |
1216  *                    |        |
1217  * Array_B  <-------- +        |
1218  *      elem_type == Array A --+
1219  */
1220 {
1221 	.descr = "loop test #1",
1222 	.raw_types = {
1223 		/* int */			/* [1] */
1224 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1225 		/* Array_A */			/* [2] */
1226 		BTF_TYPE_ARRAY_ENC(3, 1, 8),
1227 		/* Array_B */			/* [3] */
1228 		BTF_TYPE_ARRAY_ENC(2, 1, 8),
1229 		BTF_END_RAW,
1230 	},
1231 	.str_sec = "",
1232 	.str_sec_size = sizeof(""),
1233 	.map_type = BPF_MAP_TYPE_ARRAY,
1234 	.map_name = "loop_test1_map",
1235 	.key_size = sizeof(int),
1236 	.value_size = sizeof(sizeof(int) * 8),
1237 	.key_type_id = 1,
1238 	.value_type_id = 2,
1239 	.max_entries = 4,
1240 	.btf_load_err = true,
1241 	.err_str = "Loop detected",
1242 },
1243 
1244 /* typedef is _before_ the BTF type of Array_A and Array_B
1245  *
1246  * typedef Array_B int_array;
1247  *
1248  * Array_A  <------------------+
1249  *     elem_type == int_array  |
1250  *                    |        |
1251  *                    |        |
1252  * Array_B  <-------- +        |
1253  *      elem_type == Array_A --+
1254  */
1255 {
1256 	.descr = "loop test #2",
1257 	.raw_types = {
1258 		/* int */
1259 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
1260 		/* typedef Array_B int_array */
1261 		BTF_TYPEDEF_ENC(1, 4),				/* [2] */
1262 		/* Array_A */
1263 		BTF_TYPE_ARRAY_ENC(2, 1, 8),			/* [3] */
1264 		/* Array_B */
1265 		BTF_TYPE_ARRAY_ENC(3, 1, 8),			/* [4] */
1266 		BTF_END_RAW,
1267 	},
1268 	.str_sec = "\0int_array\0",
1269 	.str_sec_size = sizeof("\0int_array"),
1270 	.map_type = BPF_MAP_TYPE_ARRAY,
1271 	.map_name = "loop_test2_map",
1272 	.key_size = sizeof(int),
1273 	.value_size = sizeof(sizeof(int) * 8),
1274 	.key_type_id = 1,
1275 	.value_type_id = 2,
1276 	.max_entries = 4,
1277 	.btf_load_err = true,
1278 	.err_str = "Loop detected",
1279 },
1280 
1281 /* Array_A  <------------------+
1282  *     elem_type == Array_B    |
1283  *                    |        |
1284  *                    |        |
1285  * Array_B  <-------- +        |
1286  *      elem_type == Array_A --+
1287  */
1288 {
1289 	.descr = "loop test #3",
1290 	.raw_types = {
1291 		/* int */				/* [1] */
1292 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1293 		/* Array_A */				/* [2] */
1294 		BTF_TYPE_ARRAY_ENC(3, 1, 8),
1295 		/* Array_B */				/* [3] */
1296 		BTF_TYPE_ARRAY_ENC(2, 1, 8),
1297 		BTF_END_RAW,
1298 	},
1299 	.str_sec = "",
1300 	.str_sec_size = sizeof(""),
1301 	.map_type = BPF_MAP_TYPE_ARRAY,
1302 	.map_name = "loop_test3_map",
1303 	.key_size = sizeof(int),
1304 	.value_size = sizeof(sizeof(int) * 8),
1305 	.key_type_id = 1,
1306 	.value_type_id = 2,
1307 	.max_entries = 4,
1308 	.btf_load_err = true,
1309 	.err_str = "Loop detected",
1310 },
1311 
1312 /* typedef is _between_ the BTF type of Array_A and Array_B
1313  *
1314  * typedef Array_B int_array;
1315  *
1316  * Array_A  <------------------+
1317  *     elem_type == int_array  |
1318  *                    |        |
1319  *                    |        |
1320  * Array_B  <-------- +        |
1321  *      elem_type == Array_A --+
1322  */
1323 {
1324 	.descr = "loop test #4",
1325 	.raw_types = {
1326 		/* int */				/* [1] */
1327 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1328 		/* Array_A */				/* [2] */
1329 		BTF_TYPE_ARRAY_ENC(3, 1, 8),
1330 		/* typedef Array_B int_array */		/* [3] */
1331 		BTF_TYPEDEF_ENC(NAME_TBD, 4),
1332 		/* Array_B */				/* [4] */
1333 		BTF_TYPE_ARRAY_ENC(2, 1, 8),
1334 		BTF_END_RAW,
1335 	},
1336 	.str_sec = "\0int_array\0",
1337 	.str_sec_size = sizeof("\0int_array"),
1338 	.map_type = BPF_MAP_TYPE_ARRAY,
1339 	.map_name = "loop_test4_map",
1340 	.key_size = sizeof(int),
1341 	.value_size = sizeof(sizeof(int) * 8),
1342 	.key_type_id = 1,
1343 	.value_type_id = 2,
1344 	.max_entries = 4,
1345 	.btf_load_err = true,
1346 	.err_str = "Loop detected",
1347 },
1348 
1349 /* typedef struct B Struct_B
1350  *
1351  * struct A {
1352  *     int x;
1353  *     Struct_B y;
1354  * };
1355  *
1356  * struct B {
1357  *     int x;
1358  *     struct A y;
1359  * };
1360  */
1361 {
1362 	.descr = "loop test #5",
1363 	.raw_types = {
1364 		/* int */
1365 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
1366 		/* struct A */					/* [2] */
1367 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
1368 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int x;	*/
1369 		BTF_MEMBER_ENC(NAME_TBD, 3, 32),/* Struct_B y;	*/
1370 		/* typedef struct B Struct_B */
1371 		BTF_TYPEDEF_ENC(NAME_TBD, 4),			/* [3] */
1372 		/* struct B */					/* [4] */
1373 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
1374 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int x;	*/
1375 		BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* struct A y;	*/
1376 		BTF_END_RAW,
1377 	},
1378 	.str_sec = "\0A\0x\0y\0Struct_B\0B\0x\0y",
1379 	.str_sec_size = sizeof("\0A\0x\0y\0Struct_B\0B\0x\0y"),
1380 	.map_type = BPF_MAP_TYPE_ARRAY,
1381 	.map_name = "loop_test5_map",
1382 	.key_size = sizeof(int),
1383 	.value_size = 8,
1384 	.key_type_id = 1,
1385 	.value_type_id = 2,
1386 	.max_entries = 4,
1387 	.btf_load_err = true,
1388 	.err_str = "Loop detected",
1389 },
1390 
1391 /* struct A {
1392  *     int x;
1393  *     struct A array_a[4];
1394  * };
1395  */
1396 {
1397 	.descr = "loop test #6",
1398 	.raw_types = {
1399 		/* int */
1400 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
1401 		BTF_TYPE_ARRAY_ENC(3, 1, 4),			/* [2] */
1402 		/* struct A */					/* [3] */
1403 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
1404 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),	/* int x;		*/
1405 		BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* struct A array_a[4];	*/
1406 		BTF_END_RAW,
1407 	},
1408 	.str_sec = "\0A\0x\0y",
1409 	.str_sec_size = sizeof("\0A\0x\0y"),
1410 	.map_type = BPF_MAP_TYPE_ARRAY,
1411 	.map_name = "loop_test6_map",
1412 	.key_size = sizeof(int),
1413 	.value_size = 8,
1414 	.key_type_id = 1,
1415 	.value_type_id = 2,
1416 	.max_entries = 4,
1417 	.btf_load_err = true,
1418 	.err_str = "Loop detected",
1419 },
1420 
1421 {
1422 	.descr = "loop test #7",
1423 	.raw_types = {
1424 		/* int */				/* [1] */
1425 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1426 		/* struct A { */			/* [2] */
1427 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1428 		/*     const void *m;	*/
1429 		BTF_MEMBER_ENC(NAME_TBD, 3, 0),
1430 		/* CONST type_id=3	*/		/* [3] */
1431 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 4),
1432 		/* PTR type_id=2	*/		/* [4] */
1433 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 3),
1434 		BTF_END_RAW,
1435 	},
1436 	.str_sec = "\0A\0m",
1437 	.str_sec_size = sizeof("\0A\0m"),
1438 	.map_type = BPF_MAP_TYPE_ARRAY,
1439 	.map_name = "loop_test7_map",
1440 	.key_size = sizeof(int),
1441 	.value_size = sizeof(void *),
1442 	.key_type_id = 1,
1443 	.value_type_id = 2,
1444 	.max_entries = 4,
1445 	.btf_load_err = true,
1446 	.err_str = "Loop detected",
1447 },
1448 
1449 {
1450 	.descr = "loop test #8",
1451 	.raw_types = {
1452 		/* int */				/* [1] */
1453 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1454 		/* struct A { */			/* [2] */
1455 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1456 		/*     const void *m;	*/
1457 		BTF_MEMBER_ENC(NAME_TBD, 4, 0),
1458 		/* struct B { */			/* [3] */
1459 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1460 		/*     const void *n;	*/
1461 		BTF_MEMBER_ENC(NAME_TBD, 6, 0),
1462 		/* CONST type_id=5	*/		/* [4] */
1463 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 5),
1464 		/* PTR type_id=6	*/		/* [5] */
1465 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 6),
1466 		/* CONST type_id=7	*/		/* [6] */
1467 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 7),
1468 		/* PTR type_id=4	*/		/* [7] */
1469 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 4),
1470 		BTF_END_RAW,
1471 	},
1472 	.str_sec = "\0A\0m\0B\0n",
1473 	.str_sec_size = sizeof("\0A\0m\0B\0n"),
1474 	.map_type = BPF_MAP_TYPE_ARRAY,
1475 	.map_name = "loop_test8_map",
1476 	.key_size = sizeof(int),
1477 	.value_size = sizeof(void *),
1478 	.key_type_id = 1,
1479 	.value_type_id = 2,
1480 	.max_entries = 4,
1481 	.btf_load_err = true,
1482 	.err_str = "Loop detected",
1483 },
1484 
1485 {
1486 	.descr = "string section does not end with null",
1487 	.raw_types = {
1488 		/* int */				/* [1] */
1489 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1490 		BTF_END_RAW,
1491 	},
1492 	.str_sec = "\0int",
1493 	.str_sec_size = sizeof("\0int") - 1,
1494 	.map_type = BPF_MAP_TYPE_ARRAY,
1495 	.map_name = "hdr_test_map",
1496 	.key_size = sizeof(int),
1497 	.value_size = sizeof(int),
1498 	.key_type_id = 1,
1499 	.value_type_id = 1,
1500 	.max_entries = 4,
1501 	.btf_load_err = true,
1502 	.err_str = "Invalid string section",
1503 },
1504 
1505 {
1506 	.descr = "empty string section",
1507 	.raw_types = {
1508 		/* int */				/* [1] */
1509 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1510 		BTF_END_RAW,
1511 	},
1512 	.str_sec = "",
1513 	.str_sec_size = 0,
1514 	.map_type = BPF_MAP_TYPE_ARRAY,
1515 	.map_name = "hdr_test_map",
1516 	.key_size = sizeof(int),
1517 	.value_size = sizeof(int),
1518 	.key_type_id = 1,
1519 	.value_type_id = 1,
1520 	.max_entries = 4,
1521 	.btf_load_err = true,
1522 	.err_str = "Invalid string section",
1523 },
1524 
1525 {
1526 	.descr = "empty type section",
1527 	.raw_types = {
1528 		BTF_END_RAW,
1529 	},
1530 	.str_sec = "\0int",
1531 	.str_sec_size = sizeof("\0int"),
1532 	.map_type = BPF_MAP_TYPE_ARRAY,
1533 	.map_name = "hdr_test_map",
1534 	.key_size = sizeof(int),
1535 	.value_size = sizeof(int),
1536 	.key_type_id = 1,
1537 	.value_type_id = 1,
1538 	.max_entries = 4,
1539 	.btf_load_err = true,
1540 	.err_str = "No type found",
1541 },
1542 
1543 {
1544 	.descr = "btf_header test. Longer hdr_len",
1545 	.raw_types = {
1546 		/* int */				/* [1] */
1547 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1548 		BTF_END_RAW,
1549 	},
1550 	.str_sec = "\0int",
1551 	.str_sec_size = sizeof("\0int"),
1552 	.map_type = BPF_MAP_TYPE_ARRAY,
1553 	.map_name = "hdr_test_map",
1554 	.key_size = sizeof(int),
1555 	.value_size = sizeof(int),
1556 	.key_type_id = 1,
1557 	.value_type_id = 1,
1558 	.max_entries = 4,
1559 	.btf_load_err = true,
1560 	.hdr_len_delta = 4,
1561 	.err_str = "Unsupported btf_header",
1562 },
1563 
1564 {
1565 	.descr = "btf_header test. Gap between hdr and type",
1566 	.raw_types = {
1567 		/* int */				/* [1] */
1568 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1569 		BTF_END_RAW,
1570 	},
1571 	.str_sec = "\0int",
1572 	.str_sec_size = sizeof("\0int"),
1573 	.map_type = BPF_MAP_TYPE_ARRAY,
1574 	.map_name = "hdr_test_map",
1575 	.key_size = sizeof(int),
1576 	.value_size = sizeof(int),
1577 	.key_type_id = 1,
1578 	.value_type_id = 1,
1579 	.max_entries = 4,
1580 	.btf_load_err = true,
1581 	.type_off_delta = 4,
1582 	.err_str = "Unsupported section found",
1583 },
1584 
1585 {
1586 	.descr = "btf_header test. Gap between type and str",
1587 	.raw_types = {
1588 		/* int */				/* [1] */
1589 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1590 		BTF_END_RAW,
1591 	},
1592 	.str_sec = "\0int",
1593 	.str_sec_size = sizeof("\0int"),
1594 	.map_type = BPF_MAP_TYPE_ARRAY,
1595 	.map_name = "hdr_test_map",
1596 	.key_size = sizeof(int),
1597 	.value_size = sizeof(int),
1598 	.key_type_id = 1,
1599 	.value_type_id = 1,
1600 	.max_entries = 4,
1601 	.btf_load_err = true,
1602 	.str_off_delta = 4,
1603 	.err_str = "Unsupported section found",
1604 },
1605 
1606 {
1607 	.descr = "btf_header test. Overlap between type and str",
1608 	.raw_types = {
1609 		/* int */				/* [1] */
1610 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1611 		BTF_END_RAW,
1612 	},
1613 	.str_sec = "\0int",
1614 	.str_sec_size = sizeof("\0int"),
1615 	.map_type = BPF_MAP_TYPE_ARRAY,
1616 	.map_name = "hdr_test_map",
1617 	.key_size = sizeof(int),
1618 	.value_size = sizeof(int),
1619 	.key_type_id = 1,
1620 	.value_type_id = 1,
1621 	.max_entries = 4,
1622 	.btf_load_err = true,
1623 	.str_off_delta = -4,
1624 	.err_str = "Section overlap found",
1625 },
1626 
1627 {
1628 	.descr = "btf_header test. Larger BTF size",
1629 	.raw_types = {
1630 		/* int */				/* [1] */
1631 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1632 		BTF_END_RAW,
1633 	},
1634 	.str_sec = "\0int",
1635 	.str_sec_size = sizeof("\0int"),
1636 	.map_type = BPF_MAP_TYPE_ARRAY,
1637 	.map_name = "hdr_test_map",
1638 	.key_size = sizeof(int),
1639 	.value_size = sizeof(int),
1640 	.key_type_id = 1,
1641 	.value_type_id = 1,
1642 	.max_entries = 4,
1643 	.btf_load_err = true,
1644 	.str_len_delta = -4,
1645 	.err_str = "Unsupported section found",
1646 },
1647 
1648 {
1649 	.descr = "btf_header test. Smaller BTF size",
1650 	.raw_types = {
1651 		/* int */				/* [1] */
1652 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1653 		BTF_END_RAW,
1654 	},
1655 	.str_sec = "\0int",
1656 	.str_sec_size = sizeof("\0int"),
1657 	.map_type = BPF_MAP_TYPE_ARRAY,
1658 	.map_name = "hdr_test_map",
1659 	.key_size = sizeof(int),
1660 	.value_size = sizeof(int),
1661 	.key_type_id = 1,
1662 	.value_type_id = 1,
1663 	.max_entries = 4,
1664 	.btf_load_err = true,
1665 	.str_len_delta = 4,
1666 	.err_str = "Total section length too long",
1667 },
1668 
1669 {
1670 	.descr = "array test. index_type/elem_type \"int\"",
1671 	.raw_types = {
1672 		/* int */				/* [1] */
1673 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1674 		/* int[16] */				/* [2] */
1675 		BTF_TYPE_ARRAY_ENC(1, 1, 16),
1676 		BTF_END_RAW,
1677 	},
1678 	.str_sec = "",
1679 	.str_sec_size = sizeof(""),
1680 	.map_type = BPF_MAP_TYPE_ARRAY,
1681 	.map_name = "array_test_map",
1682 	.key_size = sizeof(int),
1683 	.value_size = sizeof(int),
1684 	.key_type_id = 1,
1685 	.value_type_id = 1,
1686 	.max_entries = 4,
1687 },
1688 
1689 {
1690 	.descr = "array test. index_type/elem_type \"const int\"",
1691 	.raw_types = {
1692 		/* int */				/* [1] */
1693 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1694 		/* int[16] */				/* [2] */
1695 		BTF_TYPE_ARRAY_ENC(3, 3, 16),
1696 		/* CONST type_id=1 */			/* [3] */
1697 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 1),
1698 		BTF_END_RAW,
1699 	},
1700 	.str_sec = "",
1701 	.str_sec_size = sizeof(""),
1702 	.map_type = BPF_MAP_TYPE_ARRAY,
1703 	.map_name = "array_test_map",
1704 	.key_size = sizeof(int),
1705 	.value_size = sizeof(int),
1706 	.key_type_id = 1,
1707 	.value_type_id = 1,
1708 	.max_entries = 4,
1709 },
1710 
1711 {
1712 	.descr = "array test. index_type \"const int:31\"",
1713 	.raw_types = {
1714 		/* int */				/* [1] */
1715 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1716 		/* int:31 */				/* [2] */
1717 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 31, 4),
1718 		/* int[16] */				/* [3] */
1719 		BTF_TYPE_ARRAY_ENC(1, 4, 16),
1720 		/* CONST type_id=2 */			/* [4] */
1721 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
1722 		BTF_END_RAW,
1723 	},
1724 	.str_sec = "",
1725 	.str_sec_size = sizeof(""),
1726 	.map_type = BPF_MAP_TYPE_ARRAY,
1727 	.map_name = "array_test_map",
1728 	.key_size = sizeof(int),
1729 	.value_size = sizeof(int),
1730 	.key_type_id = 1,
1731 	.value_type_id = 1,
1732 	.max_entries = 4,
1733 	.btf_load_err = true,
1734 	.err_str = "Invalid index",
1735 },
1736 
1737 {
1738 	.descr = "array test. elem_type \"const int:31\"",
1739 	.raw_types = {
1740 		/* int */				/* [1] */
1741 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1742 		/* int:31 */				/* [2] */
1743 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 31, 4),
1744 		/* int[16] */				/* [3] */
1745 		BTF_TYPE_ARRAY_ENC(4, 1, 16),
1746 		/* CONST type_id=2 */			/* [4] */
1747 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
1748 		BTF_END_RAW,
1749 	},
1750 	.str_sec = "",
1751 	.str_sec_size = sizeof(""),
1752 	.map_type = BPF_MAP_TYPE_ARRAY,
1753 	.map_name = "array_test_map",
1754 	.key_size = sizeof(int),
1755 	.value_size = sizeof(int),
1756 	.key_type_id = 1,
1757 	.value_type_id = 1,
1758 	.max_entries = 4,
1759 	.btf_load_err = true,
1760 	.err_str = "Invalid array of int",
1761 },
1762 
1763 {
1764 	.descr = "array test. index_type \"void\"",
1765 	.raw_types = {
1766 		/* int */				/* [1] */
1767 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1768 		/* int[16] */				/* [2] */
1769 		BTF_TYPE_ARRAY_ENC(1, 0, 16),
1770 		BTF_END_RAW,
1771 	},
1772 	.str_sec = "",
1773 	.str_sec_size = sizeof(""),
1774 	.map_type = BPF_MAP_TYPE_ARRAY,
1775 	.map_name = "array_test_map",
1776 	.key_size = sizeof(int),
1777 	.value_size = sizeof(int),
1778 	.key_type_id = 1,
1779 	.value_type_id = 1,
1780 	.max_entries = 4,
1781 	.btf_load_err = true,
1782 	.err_str = "Invalid index",
1783 },
1784 
1785 {
1786 	.descr = "array test. index_type \"const void\"",
1787 	.raw_types = {
1788 		/* int */				/* [1] */
1789 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1790 		/* int[16] */				/* [2] */
1791 		BTF_TYPE_ARRAY_ENC(1, 3, 16),
1792 		/* CONST type_id=0 (void) */		/* [3] */
1793 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1794 		BTF_END_RAW,
1795 	},
1796 	.str_sec = "",
1797 	.str_sec_size = sizeof(""),
1798 	.map_type = BPF_MAP_TYPE_ARRAY,
1799 	.map_name = "array_test_map",
1800 	.key_size = sizeof(int),
1801 	.value_size = sizeof(int),
1802 	.key_type_id = 1,
1803 	.value_type_id = 1,
1804 	.max_entries = 4,
1805 	.btf_load_err = true,
1806 	.err_str = "Invalid index",
1807 },
1808 
1809 {
1810 	.descr = "array test. elem_type \"const void\"",
1811 	.raw_types = {
1812 		/* int */				/* [1] */
1813 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1814 		/* int[16] */				/* [2] */
1815 		BTF_TYPE_ARRAY_ENC(3, 1, 16),
1816 		/* CONST type_id=0 (void) */		/* [3] */
1817 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1818 		BTF_END_RAW,
1819 	},
1820 	.str_sec = "",
1821 	.str_sec_size = sizeof(""),
1822 	.map_type = BPF_MAP_TYPE_ARRAY,
1823 	.map_name = "array_test_map",
1824 	.key_size = sizeof(int),
1825 	.value_size = sizeof(int),
1826 	.key_type_id = 1,
1827 	.value_type_id = 1,
1828 	.max_entries = 4,
1829 	.btf_load_err = true,
1830 	.err_str = "Invalid elem",
1831 },
1832 
1833 {
1834 	.descr = "array test. elem_type \"const void *\"",
1835 	.raw_types = {
1836 		/* int */				/* [1] */
1837 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1838 		/* const void *[16] */			/* [2] */
1839 		BTF_TYPE_ARRAY_ENC(3, 1, 16),
1840 		/* CONST type_id=4 */			/* [3] */
1841 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 4),
1842 		/* void* */				/* [4] */
1843 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0),
1844 		BTF_END_RAW,
1845 	},
1846 	.str_sec = "",
1847 	.str_sec_size = sizeof(""),
1848 	.map_type = BPF_MAP_TYPE_ARRAY,
1849 	.map_name = "array_test_map",
1850 	.key_size = sizeof(int),
1851 	.value_size = sizeof(int),
1852 	.key_type_id = 1,
1853 	.value_type_id = 1,
1854 	.max_entries = 4,
1855 },
1856 
1857 {
1858 	.descr = "array test. index_type \"const void *\"",
1859 	.raw_types = {
1860 		/* int */				/* [1] */
1861 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1862 		/* const void *[16] */			/* [2] */
1863 		BTF_TYPE_ARRAY_ENC(3, 3, 16),
1864 		/* CONST type_id=4 */			/* [3] */
1865 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 4),
1866 		/* void* */				/* [4] */
1867 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0),
1868 		BTF_END_RAW,
1869 	},
1870 	.str_sec = "",
1871 	.str_sec_size = sizeof(""),
1872 	.map_type = BPF_MAP_TYPE_ARRAY,
1873 	.map_name = "array_test_map",
1874 	.key_size = sizeof(int),
1875 	.value_size = sizeof(int),
1876 	.key_type_id = 1,
1877 	.value_type_id = 1,
1878 	.max_entries = 4,
1879 	.btf_load_err = true,
1880 	.err_str = "Invalid index",
1881 },
1882 
1883 {
1884 	.descr = "array test. t->size != 0\"",
1885 	.raw_types = {
1886 		/* int */				/* [1] */
1887 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1888 		/* int[16] */				/* [2] */
1889 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY, 0, 0), 1),
1890 		BTF_ARRAY_ENC(1, 1, 16),
1891 		BTF_END_RAW,
1892 	},
1893 	.str_sec = "",
1894 	.str_sec_size = sizeof(""),
1895 	.map_type = BPF_MAP_TYPE_ARRAY,
1896 	.map_name = "array_test_map",
1897 	.key_size = sizeof(int),
1898 	.value_size = sizeof(int),
1899 	.key_type_id = 1,
1900 	.value_type_id = 1,
1901 	.max_entries = 4,
1902 	.btf_load_err = true,
1903 	.err_str = "size != 0",
1904 },
1905 
1906 {
1907 	.descr = "int test. invalid int_data",
1908 	.raw_types = {
1909 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), 4),
1910 		0x10000000,
1911 		BTF_END_RAW,
1912 	},
1913 	.str_sec = "",
1914 	.str_sec_size = sizeof(""),
1915 	.map_type = BPF_MAP_TYPE_ARRAY,
1916 	.map_name = "array_test_map",
1917 	.key_size = sizeof(int),
1918 	.value_size = sizeof(int),
1919 	.key_type_id = 1,
1920 	.value_type_id = 1,
1921 	.max_entries = 4,
1922 	.btf_load_err = true,
1923 	.err_str = "Invalid int_data",
1924 },
1925 
1926 {
1927 	.descr = "invalid BTF_INFO",
1928 	.raw_types = {
1929 		/* int */				/* [1] */
1930 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1931 		BTF_TYPE_ENC(0, 0x20000000, 4),
1932 		BTF_END_RAW,
1933 	},
1934 	.str_sec = "",
1935 	.str_sec_size = sizeof(""),
1936 	.map_type = BPF_MAP_TYPE_ARRAY,
1937 	.map_name = "array_test_map",
1938 	.key_size = sizeof(int),
1939 	.value_size = sizeof(int),
1940 	.key_type_id = 1,
1941 	.value_type_id = 1,
1942 	.max_entries = 4,
1943 	.btf_load_err = true,
1944 	.err_str = "Invalid btf_info",
1945 },
1946 
1947 {
1948 	.descr = "fwd test. t->type != 0\"",
1949 	.raw_types = {
1950 		/* int */				/* [1] */
1951 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1952 		/* fwd type */				/* [2] */
1953 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD, 0, 0), 1),
1954 		BTF_END_RAW,
1955 	},
1956 	.str_sec = "",
1957 	.str_sec_size = sizeof(""),
1958 	.map_type = BPF_MAP_TYPE_ARRAY,
1959 	.map_name = "fwd_test_map",
1960 	.key_size = sizeof(int),
1961 	.value_size = sizeof(int),
1962 	.key_type_id = 1,
1963 	.value_type_id = 1,
1964 	.max_entries = 4,
1965 	.btf_load_err = true,
1966 	.err_str = "type != 0",
1967 },
1968 
1969 {
1970 	.descr = "typedef (invalid name, name_off = 0)",
1971 	.raw_types = {
1972 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
1973 		BTF_TYPEDEF_ENC(0, 1),				/* [2] */
1974 		BTF_END_RAW,
1975 	},
1976 	.str_sec = "\0__int",
1977 	.str_sec_size = sizeof("\0__int"),
1978 	.map_type = BPF_MAP_TYPE_ARRAY,
1979 	.map_name = "typedef_check_btf",
1980 	.key_size = sizeof(int),
1981 	.value_size = sizeof(int),
1982 	.key_type_id = 1,
1983 	.value_type_id = 1,
1984 	.max_entries = 4,
1985 	.btf_load_err = true,
1986 	.err_str = "Invalid name",
1987 },
1988 
1989 {
1990 	.descr = "typedef (invalid name, invalid identifier)",
1991 	.raw_types = {
1992 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
1993 		BTF_TYPEDEF_ENC(NAME_TBD, 1),			/* [2] */
1994 		BTF_END_RAW,
1995 	},
1996 	.str_sec = "\0__!int",
1997 	.str_sec_size = sizeof("\0__!int"),
1998 	.map_type = BPF_MAP_TYPE_ARRAY,
1999 	.map_name = "typedef_check_btf",
2000 	.key_size = sizeof(int),
2001 	.value_size = sizeof(int),
2002 	.key_type_id = 1,
2003 	.value_type_id = 1,
2004 	.max_entries = 4,
2005 	.btf_load_err = true,
2006 	.err_str = "Invalid name",
2007 },
2008 
2009 {
2010 	.descr = "ptr type (invalid name, name_off <> 0)",
2011 	.raw_types = {
2012 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2013 		BTF_TYPE_ENC(NAME_TBD,
2014 			     BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 1),	/* [2] */
2015 		BTF_END_RAW,
2016 	},
2017 	.str_sec = "\0__int",
2018 	.str_sec_size = sizeof("\0__int"),
2019 	.map_type = BPF_MAP_TYPE_ARRAY,
2020 	.map_name = "ptr_type_check_btf",
2021 	.key_size = sizeof(int),
2022 	.value_size = sizeof(int),
2023 	.key_type_id = 1,
2024 	.value_type_id = 1,
2025 	.max_entries = 4,
2026 	.btf_load_err = true,
2027 	.err_str = "Invalid name",
2028 },
2029 
2030 {
2031 	.descr = "volatile type (invalid name, name_off <> 0)",
2032 	.raw_types = {
2033 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2034 		BTF_TYPE_ENC(NAME_TBD,
2035 			     BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), 1),	/* [2] */
2036 		BTF_END_RAW,
2037 	},
2038 	.str_sec = "\0__int",
2039 	.str_sec_size = sizeof("\0__int"),
2040 	.map_type = BPF_MAP_TYPE_ARRAY,
2041 	.map_name = "volatile_type_check_btf",
2042 	.key_size = sizeof(int),
2043 	.value_size = sizeof(int),
2044 	.key_type_id = 1,
2045 	.value_type_id = 1,
2046 	.max_entries = 4,
2047 	.btf_load_err = true,
2048 	.err_str = "Invalid name",
2049 },
2050 
2051 {
2052 	.descr = "const type (invalid name, name_off <> 0)",
2053 	.raw_types = {
2054 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2055 		BTF_TYPE_ENC(NAME_TBD,
2056 			     BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 1),	/* [2] */
2057 		BTF_END_RAW,
2058 	},
2059 	.str_sec = "\0__int",
2060 	.str_sec_size = sizeof("\0__int"),
2061 	.map_type = BPF_MAP_TYPE_ARRAY,
2062 	.map_name = "const_type_check_btf",
2063 	.key_size = sizeof(int),
2064 	.value_size = sizeof(int),
2065 	.key_type_id = 1,
2066 	.value_type_id = 1,
2067 	.max_entries = 4,
2068 	.btf_load_err = true,
2069 	.err_str = "Invalid name",
2070 },
2071 
2072 {
2073 	.descr = "restrict type (invalid name, name_off <> 0)",
2074 	.raw_types = {
2075 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2076 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 1),	/* [2] */
2077 		BTF_TYPE_ENC(NAME_TBD,
2078 			     BTF_INFO_ENC(BTF_KIND_RESTRICT, 0, 0), 2),	/* [3] */
2079 		BTF_END_RAW,
2080 	},
2081 	.str_sec = "\0__int",
2082 	.str_sec_size = sizeof("\0__int"),
2083 	.map_type = BPF_MAP_TYPE_ARRAY,
2084 	.map_name = "restrict_type_check_btf",
2085 	.key_size = sizeof(int),
2086 	.value_size = sizeof(int),
2087 	.key_type_id = 1,
2088 	.value_type_id = 1,
2089 	.max_entries = 4,
2090 	.btf_load_err = true,
2091 	.err_str = "Invalid name",
2092 },
2093 
2094 {
2095 	.descr = "fwd type (invalid name, name_off = 0)",
2096 	.raw_types = {
2097 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2098 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD, 0, 0), 0),	/* [2] */
2099 		BTF_END_RAW,
2100 	},
2101 	.str_sec = "\0__skb",
2102 	.str_sec_size = sizeof("\0__skb"),
2103 	.map_type = BPF_MAP_TYPE_ARRAY,
2104 	.map_name = "fwd_type_check_btf",
2105 	.key_size = sizeof(int),
2106 	.value_size = sizeof(int),
2107 	.key_type_id = 1,
2108 	.value_type_id = 1,
2109 	.max_entries = 4,
2110 	.btf_load_err = true,
2111 	.err_str = "Invalid name",
2112 },
2113 
2114 {
2115 	.descr = "fwd type (invalid name, invalid identifier)",
2116 	.raw_types = {
2117 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2118 		BTF_TYPE_ENC(NAME_TBD,
2119 			     BTF_INFO_ENC(BTF_KIND_FWD, 0, 0), 0),	/* [2] */
2120 		BTF_END_RAW,
2121 	},
2122 	.str_sec = "\0__!skb",
2123 	.str_sec_size = sizeof("\0__!skb"),
2124 	.map_type = BPF_MAP_TYPE_ARRAY,
2125 	.map_name = "fwd_type_check_btf",
2126 	.key_size = sizeof(int),
2127 	.value_size = sizeof(int),
2128 	.key_type_id = 1,
2129 	.value_type_id = 1,
2130 	.max_entries = 4,
2131 	.btf_load_err = true,
2132 	.err_str = "Invalid name",
2133 },
2134 
2135 {
2136 	.descr = "array type (invalid name, name_off <> 0)",
2137 	.raw_types = {
2138 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2139 		BTF_TYPE_ENC(NAME_TBD,
2140 			     BTF_INFO_ENC(BTF_KIND_ARRAY, 0, 0), 0),	/* [2] */
2141 		BTF_ARRAY_ENC(1, 1, 4),
2142 		BTF_END_RAW,
2143 	},
2144 	.str_sec = "\0__skb",
2145 	.str_sec_size = sizeof("\0__skb"),
2146 	.map_type = BPF_MAP_TYPE_ARRAY,
2147 	.map_name = "array_type_check_btf",
2148 	.key_size = sizeof(int),
2149 	.value_size = sizeof(int),
2150 	.key_type_id = 1,
2151 	.value_type_id = 1,
2152 	.max_entries = 4,
2153 	.btf_load_err = true,
2154 	.err_str = "Invalid name",
2155 },
2156 
2157 {
2158 	.descr = "struct type (name_off = 0)",
2159 	.raw_types = {
2160 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2161 		BTF_TYPE_ENC(0,
2162 			     BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4),	/* [2] */
2163 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2164 		BTF_END_RAW,
2165 	},
2166 	.str_sec = "\0A",
2167 	.str_sec_size = sizeof("\0A"),
2168 	.map_type = BPF_MAP_TYPE_ARRAY,
2169 	.map_name = "struct_type_check_btf",
2170 	.key_size = sizeof(int),
2171 	.value_size = sizeof(int),
2172 	.key_type_id = 1,
2173 	.value_type_id = 1,
2174 	.max_entries = 4,
2175 },
2176 
2177 {
2178 	.descr = "struct type (invalid name, invalid identifier)",
2179 	.raw_types = {
2180 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2181 		BTF_TYPE_ENC(NAME_TBD,
2182 			     BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4),	/* [2] */
2183 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2184 		BTF_END_RAW,
2185 	},
2186 	.str_sec = "\0A!\0B",
2187 	.str_sec_size = sizeof("\0A!\0B"),
2188 	.map_type = BPF_MAP_TYPE_ARRAY,
2189 	.map_name = "struct_type_check_btf",
2190 	.key_size = sizeof(int),
2191 	.value_size = sizeof(int),
2192 	.key_type_id = 1,
2193 	.value_type_id = 1,
2194 	.max_entries = 4,
2195 	.btf_load_err = true,
2196 	.err_str = "Invalid name",
2197 },
2198 
2199 {
2200 	.descr = "struct member (name_off = 0)",
2201 	.raw_types = {
2202 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2203 		BTF_TYPE_ENC(0,
2204 			     BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4),	/* [2] */
2205 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2206 		BTF_END_RAW,
2207 	},
2208 	.str_sec = "\0A",
2209 	.str_sec_size = sizeof("\0A"),
2210 	.map_type = BPF_MAP_TYPE_ARRAY,
2211 	.map_name = "struct_type_check_btf",
2212 	.key_size = sizeof(int),
2213 	.value_size = sizeof(int),
2214 	.key_type_id = 1,
2215 	.value_type_id = 1,
2216 	.max_entries = 4,
2217 },
2218 
2219 {
2220 	.descr = "struct member (invalid name, invalid identifier)",
2221 	.raw_types = {
2222 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2223 		BTF_TYPE_ENC(NAME_TBD,
2224 			     BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4),	/* [2] */
2225 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2226 		BTF_END_RAW,
2227 	},
2228 	.str_sec = "\0A\0B*",
2229 	.str_sec_size = sizeof("\0A\0B*"),
2230 	.map_type = BPF_MAP_TYPE_ARRAY,
2231 	.map_name = "struct_type_check_btf",
2232 	.key_size = sizeof(int),
2233 	.value_size = sizeof(int),
2234 	.key_type_id = 1,
2235 	.value_type_id = 1,
2236 	.max_entries = 4,
2237 	.btf_load_err = true,
2238 	.err_str = "Invalid name",
2239 },
2240 
2241 {
2242 	.descr = "enum type (name_off = 0)",
2243 	.raw_types = {
2244 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2245 		BTF_TYPE_ENC(0,
2246 			     BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2247 			     sizeof(int)),				/* [2] */
2248 		BTF_ENUM_ENC(NAME_TBD, 0),
2249 		BTF_END_RAW,
2250 	},
2251 	.str_sec = "\0A\0B",
2252 	.str_sec_size = sizeof("\0A\0B"),
2253 	.map_type = BPF_MAP_TYPE_ARRAY,
2254 	.map_name = "enum_type_check_btf",
2255 	.key_size = sizeof(int),
2256 	.value_size = sizeof(int),
2257 	.key_type_id = 1,
2258 	.value_type_id = 1,
2259 	.max_entries = 4,
2260 },
2261 
2262 {
2263 	.descr = "enum type (invalid name, invalid identifier)",
2264 	.raw_types = {
2265 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2266 		BTF_TYPE_ENC(NAME_TBD,
2267 			     BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2268 			     sizeof(int)),				/* [2] */
2269 		BTF_ENUM_ENC(NAME_TBD, 0),
2270 		BTF_END_RAW,
2271 	},
2272 	.str_sec = "\0A!\0B",
2273 	.str_sec_size = sizeof("\0A!\0B"),
2274 	.map_type = BPF_MAP_TYPE_ARRAY,
2275 	.map_name = "enum_type_check_btf",
2276 	.key_size = sizeof(int),
2277 	.value_size = sizeof(int),
2278 	.key_type_id = 1,
2279 	.value_type_id = 1,
2280 	.max_entries = 4,
2281 	.btf_load_err = true,
2282 	.err_str = "Invalid name",
2283 },
2284 
2285 {
2286 	.descr = "enum member (invalid name, name_off = 0)",
2287 	.raw_types = {
2288 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2289 		BTF_TYPE_ENC(0,
2290 			     BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2291 			     sizeof(int)),				/* [2] */
2292 		BTF_ENUM_ENC(0, 0),
2293 		BTF_END_RAW,
2294 	},
2295 	.str_sec = "",
2296 	.str_sec_size = sizeof(""),
2297 	.map_type = BPF_MAP_TYPE_ARRAY,
2298 	.map_name = "enum_type_check_btf",
2299 	.key_size = sizeof(int),
2300 	.value_size = sizeof(int),
2301 	.key_type_id = 1,
2302 	.value_type_id = 1,
2303 	.max_entries = 4,
2304 	.btf_load_err = true,
2305 	.err_str = "Invalid name",
2306 },
2307 
2308 {
2309 	.descr = "enum member (invalid name, invalid identifier)",
2310 	.raw_types = {
2311 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2312 		BTF_TYPE_ENC(0,
2313 			     BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2314 			     sizeof(int)),				/* [2] */
2315 		BTF_ENUM_ENC(NAME_TBD, 0),
2316 		BTF_END_RAW,
2317 	},
2318 	.str_sec = "\0A!",
2319 	.str_sec_size = sizeof("\0A!"),
2320 	.map_type = BPF_MAP_TYPE_ARRAY,
2321 	.map_name = "enum_type_check_btf",
2322 	.key_size = sizeof(int),
2323 	.value_size = sizeof(int),
2324 	.key_type_id = 1,
2325 	.value_type_id = 1,
2326 	.max_entries = 4,
2327 	.btf_load_err = true,
2328 	.err_str = "Invalid name",
2329 },
2330 {
2331 	.descr = "arraymap invalid btf key (a bit field)",
2332 	.raw_types = {
2333 		/* int */				/* [1] */
2334 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2335 		/* 32 bit int with 32 bit offset */	/* [2] */
2336 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 32, 32, 8),
2337 		BTF_END_RAW,
2338 	},
2339 	.str_sec = "",
2340 	.str_sec_size = sizeof(""),
2341 	.map_type = BPF_MAP_TYPE_ARRAY,
2342 	.map_name = "array_map_check_btf",
2343 	.key_size = sizeof(int),
2344 	.value_size = sizeof(int),
2345 	.key_type_id = 2,
2346 	.value_type_id = 1,
2347 	.max_entries = 4,
2348 	.map_create_err = true,
2349 },
2350 
2351 {
2352 	.descr = "arraymap invalid btf key (!= 32 bits)",
2353 	.raw_types = {
2354 		/* int */				/* [1] */
2355 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2356 		/* 16 bit int with 0 bit offset */	/* [2] */
2357 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 16, 2),
2358 		BTF_END_RAW,
2359 	},
2360 	.str_sec = "",
2361 	.str_sec_size = sizeof(""),
2362 	.map_type = BPF_MAP_TYPE_ARRAY,
2363 	.map_name = "array_map_check_btf",
2364 	.key_size = sizeof(int),
2365 	.value_size = sizeof(int),
2366 	.key_type_id = 2,
2367 	.value_type_id = 1,
2368 	.max_entries = 4,
2369 	.map_create_err = true,
2370 },
2371 
2372 {
2373 	.descr = "arraymap invalid btf value (too small)",
2374 	.raw_types = {
2375 		/* int */				/* [1] */
2376 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2377 		BTF_END_RAW,
2378 	},
2379 	.str_sec = "",
2380 	.str_sec_size = sizeof(""),
2381 	.map_type = BPF_MAP_TYPE_ARRAY,
2382 	.map_name = "array_map_check_btf",
2383 	.key_size = sizeof(int),
2384 	/* btf_value_size < map->value_size */
2385 	.value_size = sizeof(__u64),
2386 	.key_type_id = 1,
2387 	.value_type_id = 1,
2388 	.max_entries = 4,
2389 	.map_create_err = true,
2390 },
2391 
2392 {
2393 	.descr = "arraymap invalid btf value (too big)",
2394 	.raw_types = {
2395 		/* int */				/* [1] */
2396 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2397 		BTF_END_RAW,
2398 	},
2399 	.str_sec = "",
2400 	.str_sec_size = sizeof(""),
2401 	.map_type = BPF_MAP_TYPE_ARRAY,
2402 	.map_name = "array_map_check_btf",
2403 	.key_size = sizeof(int),
2404 	/* btf_value_size > map->value_size */
2405 	.value_size = sizeof(__u16),
2406 	.key_type_id = 1,
2407 	.value_type_id = 1,
2408 	.max_entries = 4,
2409 	.map_create_err = true,
2410 },
2411 
2412 {
2413 	.descr = "func proto (int (*)(int, unsigned int))",
2414 	.raw_types = {
2415 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2416 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2417 		/* int (*)(int, unsigned int) */
2418 		BTF_FUNC_PROTO_ENC(1, 2),			/* [3] */
2419 			BTF_FUNC_PROTO_ARG_ENC(0, 1),
2420 			BTF_FUNC_PROTO_ARG_ENC(0, 2),
2421 		BTF_END_RAW,
2422 	},
2423 	.str_sec = "",
2424 	.str_sec_size = sizeof(""),
2425 	.map_type = BPF_MAP_TYPE_ARRAY,
2426 	.map_name = "func_proto_type_check_btf",
2427 	.key_size = sizeof(int),
2428 	.value_size = sizeof(int),
2429 	.key_type_id = 1,
2430 	.value_type_id = 1,
2431 	.max_entries = 4,
2432 },
2433 
2434 {
2435 	.descr = "func proto (vararg)",
2436 	.raw_types = {
2437 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2438 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2439 		/* void (*)(int, unsigned int, ...) */
2440 		BTF_FUNC_PROTO_ENC(0, 3),			/* [3] */
2441 			BTF_FUNC_PROTO_ARG_ENC(0, 1),
2442 			BTF_FUNC_PROTO_ARG_ENC(0, 2),
2443 			BTF_FUNC_PROTO_ARG_ENC(0, 0),
2444 		BTF_END_RAW,
2445 	},
2446 	.str_sec = "",
2447 	.str_sec_size = sizeof(""),
2448 	.map_type = BPF_MAP_TYPE_ARRAY,
2449 	.map_name = "func_proto_type_check_btf",
2450 	.key_size = sizeof(int),
2451 	.value_size = sizeof(int),
2452 	.key_type_id = 1,
2453 	.value_type_id = 1,
2454 	.max_entries = 4,
2455 },
2456 
2457 {
2458 	.descr = "func proto (vararg with name)",
2459 	.raw_types = {
2460 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2461 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2462 		/* void (*)(int a, unsigned int b, ... c) */
2463 		BTF_FUNC_PROTO_ENC(0, 3),			/* [3] */
2464 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2465 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2466 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 0),
2467 		BTF_END_RAW,
2468 	},
2469 	.str_sec = "\0a\0b\0c",
2470 	.str_sec_size = sizeof("\0a\0b\0c"),
2471 	.map_type = BPF_MAP_TYPE_ARRAY,
2472 	.map_name = "func_proto_type_check_btf",
2473 	.key_size = sizeof(int),
2474 	.value_size = sizeof(int),
2475 	.key_type_id = 1,
2476 	.value_type_id = 1,
2477 	.max_entries = 4,
2478 	.btf_load_err = true,
2479 	.err_str = "Invalid arg#3",
2480 },
2481 
2482 {
2483 	.descr = "func proto (arg after vararg)",
2484 	.raw_types = {
2485 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2486 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2487 		/* void (*)(int a, ..., unsigned int b) */
2488 		BTF_FUNC_PROTO_ENC(0, 3),			/* [3] */
2489 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2490 			BTF_FUNC_PROTO_ARG_ENC(0, 0),
2491 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2492 		BTF_END_RAW,
2493 	},
2494 	.str_sec = "\0a\0b",
2495 	.str_sec_size = sizeof("\0a\0b"),
2496 	.map_type = BPF_MAP_TYPE_ARRAY,
2497 	.map_name = "func_proto_type_check_btf",
2498 	.key_size = sizeof(int),
2499 	.value_size = sizeof(int),
2500 	.key_type_id = 1,
2501 	.value_type_id = 1,
2502 	.max_entries = 4,
2503 	.btf_load_err = true,
2504 	.err_str = "Invalid arg#2",
2505 },
2506 
2507 {
2508 	.descr = "func proto (CONST=>TYPEDEF=>PTR=>FUNC_PROTO)",
2509 	.raw_types = {
2510 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2511 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2512 		/* typedef void (*func_ptr)(int, unsigned int) */
2513 		BTF_TYPEDEF_ENC(NAME_TBD, 5),			/* [3] */
2514 		/* const func_ptr */
2515 		BTF_CONST_ENC(3),				/* [4] */
2516 		BTF_PTR_ENC(6),					/* [5] */
2517 		BTF_FUNC_PROTO_ENC(0, 2),			/* [6] */
2518 			BTF_FUNC_PROTO_ARG_ENC(0, 1),
2519 			BTF_FUNC_PROTO_ARG_ENC(0, 2),
2520 		BTF_END_RAW,
2521 	},
2522 	.str_sec = "\0func_ptr",
2523 	.str_sec_size = sizeof("\0func_ptr"),
2524 	.map_type = BPF_MAP_TYPE_ARRAY,
2525 	.map_name = "func_proto_type_check_btf",
2526 	.key_size = sizeof(int),
2527 	.value_size = sizeof(int),
2528 	.key_type_id = 1,
2529 	.value_type_id = 1,
2530 	.max_entries = 4,
2531 },
2532 
2533 {
2534 	.descr = "func proto (TYPEDEF=>FUNC_PROTO)",
2535 	.raw_types = {
2536 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2537 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2538 		BTF_TYPEDEF_ENC(NAME_TBD, 4),			/* [3] */
2539 		BTF_FUNC_PROTO_ENC(0, 2),			/* [4] */
2540 			BTF_FUNC_PROTO_ARG_ENC(0, 1),
2541 			BTF_FUNC_PROTO_ARG_ENC(0, 2),
2542 		BTF_END_RAW,
2543 	},
2544 	.str_sec = "\0func_typedef",
2545 	.str_sec_size = sizeof("\0func_typedef"),
2546 	.map_type = BPF_MAP_TYPE_ARRAY,
2547 	.map_name = "func_proto_type_check_btf",
2548 	.key_size = sizeof(int),
2549 	.value_size = sizeof(int),
2550 	.key_type_id = 1,
2551 	.value_type_id = 1,
2552 	.max_entries = 4,
2553 },
2554 
2555 {
2556 	.descr = "func proto (btf_resolve(arg))",
2557 	.raw_types = {
2558 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2559 		/* void (*)(const void *) */
2560 		BTF_FUNC_PROTO_ENC(0, 1),			/* [2] */
2561 			BTF_FUNC_PROTO_ARG_ENC(0, 3),
2562 		BTF_CONST_ENC(4),				/* [3] */
2563 		BTF_PTR_ENC(0),					/* [4] */
2564 		BTF_END_RAW,
2565 	},
2566 	.str_sec = "",
2567 	.str_sec_size = sizeof(""),
2568 	.map_type = BPF_MAP_TYPE_ARRAY,
2569 	.map_name = "func_proto_type_check_btf",
2570 	.key_size = sizeof(int),
2571 	.value_size = sizeof(int),
2572 	.key_type_id = 1,
2573 	.value_type_id = 1,
2574 	.max_entries = 4,
2575 },
2576 
2577 {
2578 	.descr = "func proto (Not all arg has name)",
2579 	.raw_types = {
2580 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2581 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2582 		/* void (*)(int, unsigned int b) */
2583 		BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
2584 			BTF_FUNC_PROTO_ARG_ENC(0, 1),
2585 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2586 		BTF_END_RAW,
2587 	},
2588 	.str_sec = "\0b",
2589 	.str_sec_size = sizeof("\0b"),
2590 	.map_type = BPF_MAP_TYPE_ARRAY,
2591 	.map_name = "func_proto_type_check_btf",
2592 	.key_size = sizeof(int),
2593 	.value_size = sizeof(int),
2594 	.key_type_id = 1,
2595 	.value_type_id = 1,
2596 	.max_entries = 4,
2597 },
2598 
2599 {
2600 	.descr = "func proto (Bad arg name_off)",
2601 	.raw_types = {
2602 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2603 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2604 		/* void (*)(int a, unsigned int <bad_name_off>) */
2605 		BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
2606 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2607 			BTF_FUNC_PROTO_ARG_ENC(0x0fffffff, 2),
2608 		BTF_END_RAW,
2609 	},
2610 	.str_sec = "\0a",
2611 	.str_sec_size = sizeof("\0a"),
2612 	.map_type = BPF_MAP_TYPE_ARRAY,
2613 	.map_name = "func_proto_type_check_btf",
2614 	.key_size = sizeof(int),
2615 	.value_size = sizeof(int),
2616 	.key_type_id = 1,
2617 	.value_type_id = 1,
2618 	.max_entries = 4,
2619 	.btf_load_err = true,
2620 	.err_str = "Invalid arg#2",
2621 },
2622 
2623 {
2624 	.descr = "func proto (Bad arg name)",
2625 	.raw_types = {
2626 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2627 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2628 		/* void (*)(int a, unsigned int !!!) */
2629 		BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
2630 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2631 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2632 		BTF_END_RAW,
2633 	},
2634 	.str_sec = "\0a\0!!!",
2635 	.str_sec_size = sizeof("\0a\0!!!"),
2636 	.map_type = BPF_MAP_TYPE_ARRAY,
2637 	.map_name = "func_proto_type_check_btf",
2638 	.key_size = sizeof(int),
2639 	.value_size = sizeof(int),
2640 	.key_type_id = 1,
2641 	.value_type_id = 1,
2642 	.max_entries = 4,
2643 	.btf_load_err = true,
2644 	.err_str = "Invalid arg#2",
2645 },
2646 
2647 {
2648 	.descr = "func proto (Invalid return type)",
2649 	.raw_types = {
2650 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2651 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2652 		/* <bad_ret_type> (*)(int, unsigned int) */
2653 		BTF_FUNC_PROTO_ENC(100, 2),			/* [3] */
2654 			BTF_FUNC_PROTO_ARG_ENC(0, 1),
2655 			BTF_FUNC_PROTO_ARG_ENC(0, 2),
2656 		BTF_END_RAW,
2657 	},
2658 	.str_sec = "",
2659 	.str_sec_size = sizeof(""),
2660 	.map_type = BPF_MAP_TYPE_ARRAY,
2661 	.map_name = "func_proto_type_check_btf",
2662 	.key_size = sizeof(int),
2663 	.value_size = sizeof(int),
2664 	.key_type_id = 1,
2665 	.value_type_id = 1,
2666 	.max_entries = 4,
2667 	.btf_load_err = true,
2668 	.err_str = "Invalid return type",
2669 },
2670 
2671 {
2672 	.descr = "func proto (with func name)",
2673 	.raw_types = {
2674 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2675 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2676 		/* void func_proto(int, unsigned int) */
2677 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 0, 2), 0),	/* [3] */
2678 			BTF_FUNC_PROTO_ARG_ENC(0, 1),
2679 			BTF_FUNC_PROTO_ARG_ENC(0, 2),
2680 		BTF_END_RAW,
2681 	},
2682 	.str_sec = "\0func_proto",
2683 	.str_sec_size = sizeof("\0func_proto"),
2684 	.map_type = BPF_MAP_TYPE_ARRAY,
2685 	.map_name = "func_proto_type_check_btf",
2686 	.key_size = sizeof(int),
2687 	.value_size = sizeof(int),
2688 	.key_type_id = 1,
2689 	.value_type_id = 1,
2690 	.max_entries = 4,
2691 	.btf_load_err = true,
2692 	.err_str = "Invalid name",
2693 },
2694 
2695 {
2696 	.descr = "func proto (const void arg)",
2697 	.raw_types = {
2698 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2699 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2700 		/* void (*)(const void) */
2701 		BTF_FUNC_PROTO_ENC(0, 1),			/* [3] */
2702 			BTF_FUNC_PROTO_ARG_ENC(0, 4),
2703 		BTF_CONST_ENC(0),				/* [4] */
2704 		BTF_END_RAW,
2705 	},
2706 	.str_sec = "",
2707 	.str_sec_size = sizeof(""),
2708 	.map_type = BPF_MAP_TYPE_ARRAY,
2709 	.map_name = "func_proto_type_check_btf",
2710 	.key_size = sizeof(int),
2711 	.value_size = sizeof(int),
2712 	.key_type_id = 1,
2713 	.value_type_id = 1,
2714 	.max_entries = 4,
2715 	.btf_load_err = true,
2716 	.err_str = "Invalid arg#1",
2717 },
2718 
2719 {
2720 	.descr = "func (void func(int a, unsigned int b))",
2721 	.raw_types = {
2722 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2723 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2724 		/* void (*)(int a, unsigned int b) */
2725 		BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
2726 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2727 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2728 		/* void func(int a, unsigned int b) */
2729 		BTF_FUNC_ENC(NAME_TBD, 3),			/* [4] */
2730 		BTF_END_RAW,
2731 	},
2732 	.str_sec = "\0a\0b\0func",
2733 	.str_sec_size = sizeof("\0a\0b\0func"),
2734 	.map_type = BPF_MAP_TYPE_ARRAY,
2735 	.map_name = "func_type_check_btf",
2736 	.key_size = sizeof(int),
2737 	.value_size = sizeof(int),
2738 	.key_type_id = 1,
2739 	.value_type_id = 1,
2740 	.max_entries = 4,
2741 },
2742 
2743 {
2744 	.descr = "func (No func name)",
2745 	.raw_types = {
2746 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2747 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2748 		/* void (*)(int a, unsigned int b) */
2749 		BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
2750 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2751 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2752 		/* void <no_name>(int a, unsigned int b) */
2753 		BTF_FUNC_ENC(0, 3),				/* [4] */
2754 		BTF_END_RAW,
2755 	},
2756 	.str_sec = "\0a\0b",
2757 	.str_sec_size = sizeof("\0a\0b"),
2758 	.map_type = BPF_MAP_TYPE_ARRAY,
2759 	.map_name = "func_type_check_btf",
2760 	.key_size = sizeof(int),
2761 	.value_size = sizeof(int),
2762 	.key_type_id = 1,
2763 	.value_type_id = 1,
2764 	.max_entries = 4,
2765 	.btf_load_err = true,
2766 	.err_str = "Invalid name",
2767 },
2768 
2769 {
2770 	.descr = "func (Invalid func name)",
2771 	.raw_types = {
2772 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2773 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2774 		/* void (*)(int a, unsigned int b) */
2775 		BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
2776 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2777 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2778 		/* void !!!(int a, unsigned int b) */
2779 		BTF_FUNC_ENC(NAME_TBD, 3),			/* [4] */
2780 		BTF_END_RAW,
2781 	},
2782 	.str_sec = "\0a\0b\0!!!",
2783 	.str_sec_size = sizeof("\0a\0b\0!!!"),
2784 	.map_type = BPF_MAP_TYPE_ARRAY,
2785 	.map_name = "func_type_check_btf",
2786 	.key_size = sizeof(int),
2787 	.value_size = sizeof(int),
2788 	.key_type_id = 1,
2789 	.value_type_id = 1,
2790 	.max_entries = 4,
2791 	.btf_load_err = true,
2792 	.err_str = "Invalid name",
2793 },
2794 
2795 {
2796 	.descr = "func (Some arg has no name)",
2797 	.raw_types = {
2798 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2799 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2800 		/* void (*)(int a, unsigned int) */
2801 		BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
2802 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2803 			BTF_FUNC_PROTO_ARG_ENC(0, 2),
2804 		/* void func(int a, unsigned int) */
2805 		BTF_FUNC_ENC(NAME_TBD, 3),			/* [4] */
2806 		BTF_END_RAW,
2807 	},
2808 	.str_sec = "\0a\0func",
2809 	.str_sec_size = sizeof("\0a\0func"),
2810 	.map_type = BPF_MAP_TYPE_ARRAY,
2811 	.map_name = "func_type_check_btf",
2812 	.key_size = sizeof(int),
2813 	.value_size = sizeof(int),
2814 	.key_type_id = 1,
2815 	.value_type_id = 1,
2816 	.max_entries = 4,
2817 	.btf_load_err = true,
2818 	.err_str = "Invalid arg#2",
2819 },
2820 
2821 {
2822 	.descr = "func (Non zero vlen)",
2823 	.raw_types = {
2824 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2825 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),		/* [2] */
2826 		/* void (*)(int a, unsigned int b) */
2827 		BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
2828 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2829 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2830 		/* void func(int a, unsigned int b) */
2831 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FUNC, 0, 2), 3), 	/* [4] */
2832 		BTF_END_RAW,
2833 	},
2834 	.str_sec = "\0a\0b\0func",
2835 	.str_sec_size = sizeof("\0a\0b\0func"),
2836 	.map_type = BPF_MAP_TYPE_ARRAY,
2837 	.map_name = "func_type_check_btf",
2838 	.key_size = sizeof(int),
2839 	.value_size = sizeof(int),
2840 	.key_type_id = 1,
2841 	.value_type_id = 1,
2842 	.max_entries = 4,
2843 	.btf_load_err = true,
2844 	.err_str = "Invalid func linkage",
2845 },
2846 
2847 {
2848 	.descr = "func (Not referring to FUNC_PROTO)",
2849 	.raw_types = {
2850 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
2851 		BTF_FUNC_ENC(NAME_TBD, 1),			/* [2] */
2852 		BTF_END_RAW,
2853 	},
2854 	.str_sec = "\0func",
2855 	.str_sec_size = sizeof("\0func"),
2856 	.map_type = BPF_MAP_TYPE_ARRAY,
2857 	.map_name = "func_type_check_btf",
2858 	.key_size = sizeof(int),
2859 	.value_size = sizeof(int),
2860 	.key_type_id = 1,
2861 	.value_type_id = 1,
2862 	.max_entries = 4,
2863 	.btf_load_err = true,
2864 	.err_str = "Invalid type_id",
2865 },
2866 
2867 {
2868 	.descr = "invalid int kind_flag",
2869 	.raw_types = {
2870 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2871 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT, 1, 0), 4),	/* [2] */
2872 		BTF_INT_ENC(0, 0, 32),
2873 		BTF_END_RAW,
2874 	},
2875 	BTF_STR_SEC(""),
2876 	.map_type = BPF_MAP_TYPE_ARRAY,
2877 	.map_name = "int_type_check_btf",
2878 	.key_size = sizeof(int),
2879 	.value_size = sizeof(int),
2880 	.key_type_id = 1,
2881 	.value_type_id = 1,
2882 	.max_entries = 4,
2883 	.btf_load_err = true,
2884 	.err_str = "Invalid btf_info kind_flag",
2885 },
2886 
2887 {
2888 	.descr = "invalid ptr kind_flag",
2889 	.raw_types = {
2890 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2891 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 1, 0), 1),	/* [2] */
2892 		BTF_END_RAW,
2893 	},
2894 	BTF_STR_SEC(""),
2895 	.map_type = BPF_MAP_TYPE_ARRAY,
2896 	.map_name = "ptr_type_check_btf",
2897 	.key_size = sizeof(int),
2898 	.value_size = sizeof(int),
2899 	.key_type_id = 1,
2900 	.value_type_id = 1,
2901 	.max_entries = 4,
2902 	.btf_load_err = true,
2903 	.err_str = "Invalid btf_info kind_flag",
2904 },
2905 
2906 {
2907 	.descr = "invalid array kind_flag",
2908 	.raw_types = {
2909 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2910 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY, 1, 0), 0),	/* [2] */
2911 		BTF_ARRAY_ENC(1, 1, 1),
2912 		BTF_END_RAW,
2913 	},
2914 	BTF_STR_SEC(""),
2915 	.map_type = BPF_MAP_TYPE_ARRAY,
2916 	.map_name = "array_type_check_btf",
2917 	.key_size = sizeof(int),
2918 	.value_size = sizeof(int),
2919 	.key_type_id = 1,
2920 	.value_type_id = 1,
2921 	.max_entries = 4,
2922 	.btf_load_err = true,
2923 	.err_str = "Invalid btf_info kind_flag",
2924 },
2925 
2926 {
2927 	.descr = "valid fwd kind_flag",
2928 	.raw_types = {
2929 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2930 		BTF_TYPE_ENC(NAME_TBD,
2931 			     BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0),	/* [2] */
2932 		BTF_END_RAW,
2933 	},
2934 	BTF_STR_SEC("\0A"),
2935 	.map_type = BPF_MAP_TYPE_ARRAY,
2936 	.map_name = "fwd_type_check_btf",
2937 	.key_size = sizeof(int),
2938 	.value_size = sizeof(int),
2939 	.key_type_id = 1,
2940 	.value_type_id = 1,
2941 	.max_entries = 4,
2942 },
2943 
2944 {
2945 	.descr = "invalid typedef kind_flag",
2946 	.raw_types = {
2947 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2948 		BTF_TYPE_ENC(NAME_TBD,
2949 			     BTF_INFO_ENC(BTF_KIND_TYPEDEF, 1, 0), 1),	/* [2] */
2950 		BTF_END_RAW,
2951 	},
2952 	BTF_STR_SEC("\0A"),
2953 	.map_type = BPF_MAP_TYPE_ARRAY,
2954 	.map_name = "typedef_type_check_btf",
2955 	.key_size = sizeof(int),
2956 	.value_size = sizeof(int),
2957 	.key_type_id = 1,
2958 	.value_type_id = 1,
2959 	.max_entries = 4,
2960 	.btf_load_err = true,
2961 	.err_str = "Invalid btf_info kind_flag",
2962 },
2963 
2964 {
2965 	.descr = "invalid volatile kind_flag",
2966 	.raw_types = {
2967 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
2968 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 1, 0), 1),	/* [2] */
2969 		BTF_END_RAW,
2970 	},
2971 	BTF_STR_SEC(""),
2972 	.map_type = BPF_MAP_TYPE_ARRAY,
2973 	.map_name = "volatile_type_check_btf",
2974 	.key_size = sizeof(int),
2975 	.value_size = sizeof(int),
2976 	.key_type_id = 1,
2977 	.value_type_id = 1,
2978 	.max_entries = 4,
2979 	.btf_load_err = true,
2980 	.err_str = "Invalid btf_info kind_flag",
2981 },
2982 
2983 {
2984 	.descr = "invalid const kind_flag",
2985 	.raw_types = {
2986 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
2987 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 1, 0), 1),	/* [2] */
2988 		BTF_END_RAW,
2989 	},
2990 	BTF_STR_SEC(""),
2991 	.map_type = BPF_MAP_TYPE_ARRAY,
2992 	.map_name = "const_type_check_btf",
2993 	.key_size = sizeof(int),
2994 	.value_size = sizeof(int),
2995 	.key_type_id = 1,
2996 	.value_type_id = 1,
2997 	.max_entries = 4,
2998 	.btf_load_err = true,
2999 	.err_str = "Invalid btf_info kind_flag",
3000 },
3001 
3002 {
3003 	.descr = "invalid restrict kind_flag",
3004 	.raw_types = {
3005 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3006 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_RESTRICT, 1, 0), 1),	/* [2] */
3007 		BTF_END_RAW,
3008 	},
3009 	BTF_STR_SEC(""),
3010 	.map_type = BPF_MAP_TYPE_ARRAY,
3011 	.map_name = "restrict_type_check_btf",
3012 	.key_size = sizeof(int),
3013 	.value_size = sizeof(int),
3014 	.key_type_id = 1,
3015 	.value_type_id = 1,
3016 	.max_entries = 4,
3017 	.btf_load_err = true,
3018 	.err_str = "Invalid btf_info kind_flag",
3019 },
3020 
3021 {
3022 	.descr = "invalid func kind_flag",
3023 	.raw_types = {
3024 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3025 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 0, 0), 0),	/* [2] */
3026 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FUNC, 1, 0), 2),	/* [3] */
3027 		BTF_END_RAW,
3028 	},
3029 	BTF_STR_SEC("\0A"),
3030 	.map_type = BPF_MAP_TYPE_ARRAY,
3031 	.map_name = "func_type_check_btf",
3032 	.key_size = sizeof(int),
3033 	.value_size = sizeof(int),
3034 	.key_type_id = 1,
3035 	.value_type_id = 1,
3036 	.max_entries = 4,
3037 	.btf_load_err = true,
3038 	.err_str = "Invalid btf_info kind_flag",
3039 },
3040 
3041 {
3042 	.descr = "invalid func_proto kind_flag",
3043 	.raw_types = {
3044 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3045 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 1, 0), 0),	/* [2] */
3046 		BTF_END_RAW,
3047 	},
3048 	BTF_STR_SEC(""),
3049 	.map_type = BPF_MAP_TYPE_ARRAY,
3050 	.map_name = "func_proto_type_check_btf",
3051 	.key_size = sizeof(int),
3052 	.value_size = sizeof(int),
3053 	.key_type_id = 1,
3054 	.value_type_id = 1,
3055 	.max_entries = 4,
3056 	.btf_load_err = true,
3057 	.err_str = "Invalid btf_info kind_flag",
3058 },
3059 
3060 {
3061 	.descr = "valid struct, kind_flag, bitfield_size = 0",
3062 	.raw_types = {
3063 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3064 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 8),	/* [2] */
3065 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(0, 0)),
3066 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(0, 32)),
3067 		BTF_END_RAW,
3068 	},
3069 	BTF_STR_SEC("\0A\0B"),
3070 	.map_type = BPF_MAP_TYPE_ARRAY,
3071 	.map_name = "struct_type_check_btf",
3072 	.key_size = sizeof(int),
3073 	.value_size = sizeof(int),
3074 	.key_type_id = 1,
3075 	.value_type_id = 1,
3076 	.max_entries = 4,
3077 },
3078 
3079 {
3080 	.descr = "valid struct, kind_flag, int member, bitfield_size != 0",
3081 	.raw_types = {
3082 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3083 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),	/* [2] */
3084 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 0)),
3085 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 4)),
3086 		BTF_END_RAW,
3087 	},
3088 	BTF_STR_SEC("\0A\0B"),
3089 	.map_type = BPF_MAP_TYPE_ARRAY,
3090 	.map_name = "struct_type_check_btf",
3091 	.key_size = sizeof(int),
3092 	.value_size = sizeof(int),
3093 	.key_type_id = 1,
3094 	.value_type_id = 1,
3095 	.max_entries = 4,
3096 },
3097 
3098 {
3099 	.descr = "valid union, kind_flag, int member, bitfield_size != 0",
3100 	.raw_types = {
3101 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
3102 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 4),	/* [2] */
3103 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 0)),
3104 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 0)),
3105 		BTF_END_RAW,
3106 	},
3107 	BTF_STR_SEC("\0A\0B"),
3108 	.map_type = BPF_MAP_TYPE_ARRAY,
3109 	.map_name = "union_type_check_btf",
3110 	.key_size = sizeof(int),
3111 	.value_size = sizeof(int),
3112 	.key_type_id = 1,
3113 	.value_type_id = 1,
3114 	.max_entries = 4,
3115 },
3116 
3117 {
3118 	.descr = "valid struct, kind_flag, enum member, bitfield_size != 0",
3119 	.raw_types = {
3120 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
3121 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),	/* [2] */
3122 		BTF_ENUM_ENC(NAME_TBD, 0),
3123 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),/* [3] */
3124 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 0)),
3125 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 4)),
3126 		BTF_END_RAW,
3127 	},
3128 	BTF_STR_SEC("\0A\0B\0C"),
3129 	.map_type = BPF_MAP_TYPE_ARRAY,
3130 	.map_name = "struct_type_check_btf",
3131 	.key_size = sizeof(int),
3132 	.value_size = sizeof(int),
3133 	.key_type_id = 1,
3134 	.value_type_id = 1,
3135 	.max_entries = 4,
3136 },
3137 
3138 {
3139 	.descr = "valid union, kind_flag, enum member, bitfield_size != 0",
3140 	.raw_types = {
3141 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
3142 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),	/* [2] */
3143 		BTF_ENUM_ENC(NAME_TBD, 0),
3144 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 4),	/* [3] */
3145 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 0)),
3146 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 0)),
3147 		BTF_END_RAW,
3148 	},
3149 	BTF_STR_SEC("\0A\0B\0C"),
3150 	.map_type = BPF_MAP_TYPE_ARRAY,
3151 	.map_name = "union_type_check_btf",
3152 	.key_size = sizeof(int),
3153 	.value_size = sizeof(int),
3154 	.key_type_id = 1,
3155 	.value_type_id = 1,
3156 	.max_entries = 4,
3157 },
3158 
3159 {
3160 	.descr = "valid struct, kind_flag, typedef member, bitfield_size != 0",
3161 	.raw_types = {
3162 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
3163 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),	/* [2] */
3164 		BTF_ENUM_ENC(NAME_TBD, 0),
3165 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),/* [3] */
3166 		BTF_MEMBER_ENC(NAME_TBD, 4, BTF_MEMBER_OFFSET(4, 0)),
3167 		BTF_MEMBER_ENC(NAME_TBD, 5, BTF_MEMBER_OFFSET(4, 4)),
3168 		BTF_TYPEDEF_ENC(NAME_TBD, 1),				/* [4] */
3169 		BTF_TYPEDEF_ENC(NAME_TBD, 2),				/* [5] */
3170 		BTF_END_RAW,
3171 	},
3172 	BTF_STR_SEC("\0A\0B\0C\0D\0E"),
3173 	.map_type = BPF_MAP_TYPE_ARRAY,
3174 	.map_name = "struct_type_check_btf",
3175 	.key_size = sizeof(int),
3176 	.value_size = sizeof(int),
3177 	.key_type_id = 1,
3178 	.value_type_id = 1,
3179 	.max_entries = 4,
3180 },
3181 
3182 {
3183 	.descr = "valid union, kind_flag, typedef member, bitfield_size != 0",
3184 	.raw_types = {
3185 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
3186 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),	/* [2] */
3187 		BTF_ENUM_ENC(NAME_TBD, 0),
3188 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 4),	/* [3] */
3189 		BTF_MEMBER_ENC(NAME_TBD, 4, BTF_MEMBER_OFFSET(4, 0)),
3190 		BTF_MEMBER_ENC(NAME_TBD, 5, BTF_MEMBER_OFFSET(4, 0)),
3191 		BTF_TYPEDEF_ENC(NAME_TBD, 1),				/* [4] */
3192 		BTF_TYPEDEF_ENC(NAME_TBD, 2),				/* [5] */
3193 		BTF_END_RAW,
3194 	},
3195 	BTF_STR_SEC("\0A\0B\0C\0D\0E"),
3196 	.map_type = BPF_MAP_TYPE_ARRAY,
3197 	.map_name = "union_type_check_btf",
3198 	.key_size = sizeof(int),
3199 	.value_size = sizeof(int),
3200 	.key_type_id = 1,
3201 	.value_type_id = 1,
3202 	.max_entries = 4,
3203 },
3204 
3205 {
3206 	.descr = "invalid struct, kind_flag, bitfield_size greater than struct size",
3207 	.raw_types = {
3208 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3209 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),	/* [2] */
3210 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(20, 0)),
3211 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(20, 20)),
3212 		BTF_END_RAW,
3213 	},
3214 	BTF_STR_SEC("\0A\0B"),
3215 	.map_type = BPF_MAP_TYPE_ARRAY,
3216 	.map_name = "struct_type_check_btf",
3217 	.key_size = sizeof(int),
3218 	.value_size = sizeof(int),
3219 	.key_type_id = 1,
3220 	.value_type_id = 1,
3221 	.max_entries = 4,
3222 	.btf_load_err = true,
3223 	.err_str = "Member exceeds struct_size",
3224 },
3225 
3226 {
3227 	.descr = "invalid struct, kind_flag, bitfield base_type int not regular",
3228 	.raw_types = {
3229 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3230 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 20, 4),			/* [2] */
3231 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),	/* [3] */
3232 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(20, 0)),
3233 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(20, 20)),
3234 		BTF_END_RAW,
3235 	},
3236 	BTF_STR_SEC("\0A\0B"),
3237 	.map_type = BPF_MAP_TYPE_ARRAY,
3238 	.map_name = "struct_type_check_btf",
3239 	.key_size = sizeof(int),
3240 	.value_size = sizeof(int),
3241 	.key_type_id = 1,
3242 	.value_type_id = 1,
3243 	.max_entries = 4,
3244 	.btf_load_err = true,
3245 	.err_str = "Invalid member base type",
3246 },
3247 
3248 {
3249 	.descr = "invalid struct, kind_flag, base_type int not regular",
3250 	.raw_types = {
3251 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3252 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 12, 4),			/* [2] */
3253 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),	/* [3] */
3254 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(8, 0)),
3255 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(8, 8)),
3256 		BTF_END_RAW,
3257 	},
3258 	BTF_STR_SEC("\0A\0B"),
3259 	.map_type = BPF_MAP_TYPE_ARRAY,
3260 	.map_name = "struct_type_check_btf",
3261 	.key_size = sizeof(int),
3262 	.value_size = sizeof(int),
3263 	.key_type_id = 1,
3264 	.value_type_id = 1,
3265 	.max_entries = 4,
3266 	.btf_load_err = true,
3267 	.err_str = "Invalid member base type",
3268 },
3269 
3270 {
3271 	.descr = "invalid union, kind_flag, bitfield_size greater than struct size",
3272 	.raw_types = {
3273 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),		/* [1] */
3274 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 2),	/* [2] */
3275 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(8, 0)),
3276 		BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(20, 0)),
3277 		BTF_END_RAW,
3278 	},
3279 	BTF_STR_SEC("\0A\0B"),
3280 	.map_type = BPF_MAP_TYPE_ARRAY,
3281 	.map_name = "union_type_check_btf",
3282 	.key_size = sizeof(int),
3283 	.value_size = sizeof(int),
3284 	.key_type_id = 1,
3285 	.value_type_id = 1,
3286 	.max_entries = 4,
3287 	.btf_load_err = true,
3288 	.err_str = "Member exceeds struct_size",
3289 },
3290 
3291 {
3292 	.descr = "invalid struct, kind_flag, int member, bitfield_size = 0, wrong byte alignment",
3293 	.raw_types = {
3294 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3295 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [2] */
3296 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 12),	/* [3] */
3297 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),
3298 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 36)),
3299 		BTF_END_RAW,
3300 	},
3301 	BTF_STR_SEC("\0A\0B"),
3302 	.map_type = BPF_MAP_TYPE_ARRAY,
3303 	.map_name = "struct_type_check_btf",
3304 	.key_size = sizeof(int),
3305 	.value_size = sizeof(int),
3306 	.key_type_id = 1,
3307 	.value_type_id = 1,
3308 	.max_entries = 4,
3309 	.btf_load_err = true,
3310 	.err_str = "Invalid member offset",
3311 },
3312 
3313 {
3314 	.descr = "invalid struct, kind_flag, enum member, bitfield_size = 0, wrong byte alignment",
3315 	.raw_types = {
3316 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3317 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [2] */
3318 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),	/* [2] */
3319 		BTF_ENUM_ENC(NAME_TBD, 0),
3320 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 12),	/* [3] */
3321 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),
3322 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 36)),
3323 		BTF_END_RAW,
3324 	},
3325 	BTF_STR_SEC("\0A\0B\0C"),
3326 	.map_type = BPF_MAP_TYPE_ARRAY,
3327 	.map_name = "struct_type_check_btf",
3328 	.key_size = sizeof(int),
3329 	.value_size = sizeof(int),
3330 	.key_type_id = 1,
3331 	.value_type_id = 1,
3332 	.max_entries = 4,
3333 	.btf_load_err = true,
3334 	.err_str = "Invalid member offset",
3335 },
3336 
3337 {
3338 	.descr = "128-bit int",
3339 	.raw_types = {
3340 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3341 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16),		/* [2] */
3342 		BTF_END_RAW,
3343 	},
3344 	BTF_STR_SEC("\0A"),
3345 	.map_type = BPF_MAP_TYPE_ARRAY,
3346 	.map_name = "int_type_check_btf",
3347 	.key_size = sizeof(int),
3348 	.value_size = sizeof(int),
3349 	.key_type_id = 1,
3350 	.value_type_id = 1,
3351 	.max_entries = 4,
3352 },
3353 
3354 {
3355 	.descr = "struct, 128-bit int member",
3356 	.raw_types = {
3357 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3358 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16),		/* [2] */
3359 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 16),	/* [3] */
3360 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3361 		BTF_END_RAW,
3362 	},
3363 	BTF_STR_SEC("\0A"),
3364 	.map_type = BPF_MAP_TYPE_ARRAY,
3365 	.map_name = "struct_type_check_btf",
3366 	.key_size = sizeof(int),
3367 	.value_size = sizeof(int),
3368 	.key_type_id = 1,
3369 	.value_type_id = 1,
3370 	.max_entries = 4,
3371 },
3372 
3373 {
3374 	.descr = "struct, 120-bit int member bitfield",
3375 	.raw_types = {
3376 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3377 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 120, 16),		/* [2] */
3378 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 16),	/* [3] */
3379 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3380 		BTF_END_RAW,
3381 	},
3382 	BTF_STR_SEC("\0A"),
3383 	.map_type = BPF_MAP_TYPE_ARRAY,
3384 	.map_name = "struct_type_check_btf",
3385 	.key_size = sizeof(int),
3386 	.value_size = sizeof(int),
3387 	.key_type_id = 1,
3388 	.value_type_id = 1,
3389 	.max_entries = 4,
3390 },
3391 
3392 {
3393 	.descr = "struct, kind_flag, 128-bit int member",
3394 	.raw_types = {
3395 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3396 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16),		/* [2] */
3397 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 16),	/* [3] */
3398 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),
3399 		BTF_END_RAW,
3400 	},
3401 	BTF_STR_SEC("\0A"),
3402 	.map_type = BPF_MAP_TYPE_ARRAY,
3403 	.map_name = "struct_type_check_btf",
3404 	.key_size = sizeof(int),
3405 	.value_size = sizeof(int),
3406 	.key_type_id = 1,
3407 	.value_type_id = 1,
3408 	.max_entries = 4,
3409 },
3410 
3411 {
3412 	.descr = "struct, kind_flag, 120-bit int member bitfield",
3413 	.raw_types = {
3414 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
3415 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16),		/* [2] */
3416 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 16),	/* [3] */
3417 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(120, 0)),
3418 		BTF_END_RAW,
3419 	},
3420 	BTF_STR_SEC("\0A"),
3421 	.map_type = BPF_MAP_TYPE_ARRAY,
3422 	.map_name = "struct_type_check_btf",
3423 	.key_size = sizeof(int),
3424 	.value_size = sizeof(int),
3425 	.key_type_id = 1,
3426 	.value_type_id = 1,
3427 	.max_entries = 4,
3428 },
3429 /*
3430  * typedef int arr_t[16];
3431  * struct s {
3432  *	arr_t *a;
3433  * };
3434  */
3435 {
3436 	.descr = "struct->ptr->typedef->array->int size resolution",
3437 	.raw_types = {
3438 		BTF_STRUCT_ENC(NAME_TBD, 1, 8),			/* [1] */
3439 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3440 		BTF_PTR_ENC(3),					/* [2] */
3441 		BTF_TYPEDEF_ENC(NAME_TBD, 4),			/* [3] */
3442 		BTF_TYPE_ARRAY_ENC(5, 5, 16),			/* [4] */
3443 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [5] */
3444 		BTF_END_RAW,
3445 	},
3446 	BTF_STR_SEC("\0s\0a\0arr_t"),
3447 	.map_type = BPF_MAP_TYPE_ARRAY,
3448 	.map_name = "ptr_mod_chain_size_resolve_map",
3449 	.key_size = sizeof(int),
3450 	.value_size = sizeof(int) * 16,
3451 	.key_type_id = 5 /* int */,
3452 	.value_type_id = 3 /* arr_t */,
3453 	.max_entries = 4,
3454 },
3455 /*
3456  * typedef int arr_t[16][8][4];
3457  * struct s {
3458  *	arr_t *a;
3459  * };
3460  */
3461 {
3462 	.descr = "struct->ptr->typedef->multi-array->int size resolution",
3463 	.raw_types = {
3464 		BTF_STRUCT_ENC(NAME_TBD, 1, 8),			/* [1] */
3465 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3466 		BTF_PTR_ENC(3),					/* [2] */
3467 		BTF_TYPEDEF_ENC(NAME_TBD, 4),			/* [3] */
3468 		BTF_TYPE_ARRAY_ENC(5, 7, 16),			/* [4] */
3469 		BTF_TYPE_ARRAY_ENC(6, 7, 8),			/* [5] */
3470 		BTF_TYPE_ARRAY_ENC(7, 7, 4),			/* [6] */
3471 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [7] */
3472 		BTF_END_RAW,
3473 	},
3474 	BTF_STR_SEC("\0s\0a\0arr_t"),
3475 	.map_type = BPF_MAP_TYPE_ARRAY,
3476 	.map_name = "multi_arr_size_resolve_map",
3477 	.key_size = sizeof(int),
3478 	.value_size = sizeof(int) * 16 * 8 * 4,
3479 	.key_type_id = 7 /* int */,
3480 	.value_type_id = 3 /* arr_t */,
3481 	.max_entries = 4,
3482 },
3483 /*
3484  * typedef int int_t;
3485  * typedef int_t arr3_t[4];
3486  * typedef arr3_t arr2_t[8];
3487  * typedef arr2_t arr1_t[16];
3488  * struct s {
3489  *	arr1_t *a;
3490  * };
3491  */
3492 {
3493 	.descr = "typedef/multi-arr mix size resolution",
3494 	.raw_types = {
3495 		BTF_STRUCT_ENC(NAME_TBD, 1, 8),			/* [1] */
3496 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3497 		BTF_PTR_ENC(3),					/* [2] */
3498 		BTF_TYPEDEF_ENC(NAME_TBD, 4),			/* [3] */
3499 		BTF_TYPE_ARRAY_ENC(5, 10, 16),			/* [4] */
3500 		BTF_TYPEDEF_ENC(NAME_TBD, 6),			/* [5] */
3501 		BTF_TYPE_ARRAY_ENC(7, 10, 8),			/* [6] */
3502 		BTF_TYPEDEF_ENC(NAME_TBD, 8),			/* [7] */
3503 		BTF_TYPE_ARRAY_ENC(9, 10, 4),			/* [8] */
3504 		BTF_TYPEDEF_ENC(NAME_TBD, 10),			/* [9] */
3505 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [10] */
3506 		BTF_END_RAW,
3507 	},
3508 	BTF_STR_SEC("\0s\0a\0arr1_t\0arr2_t\0arr3_t\0int_t"),
3509 	.map_type = BPF_MAP_TYPE_ARRAY,
3510 	.map_name = "typedef_arra_mix_size_resolve_map",
3511 	.key_size = sizeof(int),
3512 	.value_size = sizeof(int) * 16 * 8 * 4,
3513 	.key_type_id = 10 /* int */,
3514 	.value_type_id = 3 /* arr_t */,
3515 	.max_entries = 4,
3516 },
3517 /*
3518  * elf .rodata section size 4 and btf .rodata section vlen 0.
3519  */
3520 {
3521 	.descr = "datasec: vlen == 0",
3522 	.raw_types = {
3523 		/* int */
3524 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3525 		/* .rodata section */
3526 		BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 0), 4),
3527 								 /* [2] */
3528 		BTF_END_RAW,
3529 	},
3530 	BTF_STR_SEC("\0.rodata"),
3531 	.map_type = BPF_MAP_TYPE_ARRAY,
3532 	.key_size = sizeof(int),
3533 	.value_size = sizeof(int),
3534 	.key_type_id = 1,
3535 	.value_type_id = 1,
3536 	.max_entries = 1,
3537 },
3538 {
3539 	.descr = "datasec: name '?.foo bar:buz' is ok",
3540 	.raw_types = {
3541 		/* int */
3542 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
3543 		/* VAR x */                                     /* [2] */
3544 		BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
3545 		BTF_VAR_STATIC,
3546 		/* DATASEC ?.data */                            /* [3] */
3547 		BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
3548 		BTF_VAR_SECINFO_ENC(2, 0, 4),
3549 		BTF_END_RAW,
3550 	},
3551 	BTF_STR_SEC("\0x\0?.foo bar:buz"),
3552 },
3553 {
3554 	.descr = "type name '?foo' is not ok",
3555 	.raw_types = {
3556 		/* union ?foo; */
3557 		BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [1] */
3558 		BTF_END_RAW,
3559 	},
3560 	BTF_STR_SEC("\0?foo"),
3561 	.err_str = "Invalid name",
3562 	.btf_load_err = true,
3563 },
3564 
3565 {
3566 	.descr = "float test #1, well-formed",
3567 	.raw_types = {
3568 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3569 								/* [1] */
3570 		BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),		/* [2] */
3571 		BTF_TYPE_FLOAT_ENC(NAME_TBD, 4),		/* [3] */
3572 		BTF_TYPE_FLOAT_ENC(NAME_TBD, 8),		/* [4] */
3573 		BTF_TYPE_FLOAT_ENC(NAME_TBD, 12),		/* [5] */
3574 		BTF_TYPE_FLOAT_ENC(NAME_TBD, 16),		/* [6] */
3575 		BTF_STRUCT_ENC(NAME_TBD, 5, 48),		/* [7] */
3576 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3577 		BTF_MEMBER_ENC(NAME_TBD, 3, 32),
3578 		BTF_MEMBER_ENC(NAME_TBD, 4, 64),
3579 		BTF_MEMBER_ENC(NAME_TBD, 5, 128),
3580 		BTF_MEMBER_ENC(NAME_TBD, 6, 256),
3581 		BTF_END_RAW,
3582 	},
3583 	BTF_STR_SEC("\0int\0_Float16\0float\0double\0_Float80\0long_double"
3584 		    "\0floats\0a\0b\0c\0d\0e"),
3585 	.map_type = BPF_MAP_TYPE_ARRAY,
3586 	.map_name = "float_type_check_btf",
3587 	.key_size = sizeof(int),
3588 	.value_size = 48,
3589 	.key_type_id = 1,
3590 	.value_type_id = 7,
3591 	.max_entries = 1,
3592 },
3593 {
3594 	.descr = "float test #2, invalid vlen",
3595 	.raw_types = {
3596 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3597 								/* [1] */
3598 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 1), 4),
3599 								/* [2] */
3600 		BTF_END_RAW,
3601 	},
3602 	BTF_STR_SEC("\0int\0float"),
3603 	.map_type = BPF_MAP_TYPE_ARRAY,
3604 	.map_name = "float_type_check_btf",
3605 	.key_size = sizeof(int),
3606 	.value_size = 4,
3607 	.key_type_id = 1,
3608 	.value_type_id = 2,
3609 	.max_entries = 1,
3610 	.btf_load_err = true,
3611 	.err_str = "vlen != 0",
3612 },
3613 {
3614 	.descr = "float test #3, invalid kind_flag",
3615 	.raw_types = {
3616 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3617 								/* [1] */
3618 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FLOAT, 1, 0), 4),
3619 								/* [2] */
3620 		BTF_END_RAW,
3621 	},
3622 	BTF_STR_SEC("\0int\0float"),
3623 	.map_type = BPF_MAP_TYPE_ARRAY,
3624 	.map_name = "float_type_check_btf",
3625 	.key_size = sizeof(int),
3626 	.value_size = 4,
3627 	.key_type_id = 1,
3628 	.value_type_id = 2,
3629 	.max_entries = 1,
3630 	.btf_load_err = true,
3631 	.err_str = "Invalid btf_info kind_flag",
3632 },
3633 {
3634 	.descr = "float test #4, member does not fit",
3635 	.raw_types = {
3636 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3637 								/* [1] */
3638 		BTF_TYPE_FLOAT_ENC(NAME_TBD, 4),		/* [2] */
3639 		BTF_STRUCT_ENC(NAME_TBD, 1, 2),			/* [3] */
3640 		BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3641 		BTF_END_RAW,
3642 	},
3643 	BTF_STR_SEC("\0int\0float\0floats\0x"),
3644 	.map_type = BPF_MAP_TYPE_ARRAY,
3645 	.map_name = "float_type_check_btf",
3646 	.key_size = sizeof(int),
3647 	.value_size = 4,
3648 	.key_type_id = 1,
3649 	.value_type_id = 3,
3650 	.max_entries = 1,
3651 	.btf_load_err = true,
3652 	.err_str = "Member exceeds struct_size",
3653 },
3654 {
3655 	.descr = "float test #5, member is not properly aligned",
3656 	.raw_types = {
3657 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3658 								/* [1] */
3659 		BTF_TYPE_FLOAT_ENC(NAME_TBD, 4),		/* [2] */
3660 		BTF_STRUCT_ENC(NAME_TBD, 1, 8),			/* [3] */
3661 		BTF_MEMBER_ENC(NAME_TBD, 2, 8),
3662 		BTF_END_RAW,
3663 	},
3664 	BTF_STR_SEC("\0int\0float\0floats\0x"),
3665 	.map_type = BPF_MAP_TYPE_ARRAY,
3666 	.map_name = "float_type_check_btf",
3667 	.key_size = sizeof(int),
3668 	.value_size = 4,
3669 	.key_type_id = 1,
3670 	.value_type_id = 3,
3671 	.max_entries = 1,
3672 	.btf_load_err = true,
3673 	.err_str = "Member is not properly aligned",
3674 },
3675 {
3676 	.descr = "float test #6, invalid size",
3677 	.raw_types = {
3678 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3679 								/* [1] */
3680 		BTF_TYPE_FLOAT_ENC(NAME_TBD, 6),		/* [2] */
3681 		BTF_END_RAW,
3682 	},
3683 	BTF_STR_SEC("\0int\0float"),
3684 	.map_type = BPF_MAP_TYPE_ARRAY,
3685 	.map_name = "float_type_check_btf",
3686 	.key_size = sizeof(int),
3687 	.value_size = 6,
3688 	.key_type_id = 1,
3689 	.value_type_id = 2,
3690 	.max_entries = 1,
3691 	.btf_load_err = true,
3692 	.err_str = "Invalid type_size",
3693 },
3694 
3695 {
3696 	.descr = "decl_tag test #1, struct/member, well-formed",
3697 	.raw_types = {
3698 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3699 		BTF_STRUCT_ENC(0, 2, 8),			/* [2] */
3700 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3701 		BTF_MEMBER_ENC(NAME_TBD, 1, 32),
3702 		BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3703 		BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3704 		BTF_DECL_TAG_ENC(NAME_TBD, 2, 1),
3705 		BTF_END_RAW,
3706 	},
3707 	BTF_STR_SEC("\0m1\0m2\0tag1\0tag2\0tag3"),
3708 	.map_type = BPF_MAP_TYPE_ARRAY,
3709 	.map_name = "tag_type_check_btf",
3710 	.key_size = sizeof(int),
3711 	.value_size = 8,
3712 	.key_type_id = 1,
3713 	.value_type_id = 2,
3714 	.max_entries = 1,
3715 },
3716 {
3717 	.descr = "decl_tag test #2, union/member, well-formed",
3718 	.raw_types = {
3719 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3720 		BTF_UNION_ENC(NAME_TBD, 2, 4),			/* [2] */
3721 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3722 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3723 		BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3724 		BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3725 		BTF_DECL_TAG_ENC(NAME_TBD, 2, 1),
3726 		BTF_END_RAW,
3727 	},
3728 	BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
3729 	.map_type = BPF_MAP_TYPE_ARRAY,
3730 	.map_name = "tag_type_check_btf",
3731 	.key_size = sizeof(int),
3732 	.value_size = 4,
3733 	.key_type_id = 1,
3734 	.value_type_id = 2,
3735 	.max_entries = 1,
3736 },
3737 {
3738 	.descr = "decl_tag test #3, variable, well-formed",
3739 	.raw_types = {
3740 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3741 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
3742 		BTF_VAR_ENC(NAME_TBD, 1, 1),			/* [3] */
3743 		BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3744 		BTF_DECL_TAG_ENC(NAME_TBD, 3, -1),
3745 		BTF_END_RAW,
3746 	},
3747 	BTF_STR_SEC("\0local\0global\0tag1\0tag2"),
3748 	.map_type = BPF_MAP_TYPE_ARRAY,
3749 	.map_name = "tag_type_check_btf",
3750 	.key_size = sizeof(int),
3751 	.value_size = 4,
3752 	.key_type_id = 1,
3753 	.value_type_id = 1,
3754 	.max_entries = 1,
3755 },
3756 {
3757 	.descr = "decl_tag test #4, func/parameter, well-formed",
3758 	.raw_types = {
3759 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3760 		BTF_FUNC_PROTO_ENC(0, 2),			/* [2] */
3761 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3762 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3763 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
3764 		BTF_DECL_TAG_ENC(NAME_TBD, 3, -1),
3765 		BTF_DECL_TAG_ENC(NAME_TBD, 3, 0),
3766 		BTF_DECL_TAG_ENC(NAME_TBD, 3, 1),
3767 		BTF_END_RAW,
3768 	},
3769 	BTF_STR_SEC("\0arg1\0arg2\0f\0tag1\0tag2\0tag3"),
3770 	.map_type = BPF_MAP_TYPE_ARRAY,
3771 	.map_name = "tag_type_check_btf",
3772 	.key_size = sizeof(int),
3773 	.value_size = 4,
3774 	.key_type_id = 1,
3775 	.value_type_id = 1,
3776 	.max_entries = 1,
3777 },
3778 {
3779 	.descr = "decl_tag test #5, invalid value",
3780 	.raw_types = {
3781 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3782 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
3783 		BTF_DECL_TAG_ENC(0, 2, -1),
3784 		BTF_END_RAW,
3785 	},
3786 	BTF_STR_SEC("\0local\0tag"),
3787 	.map_type = BPF_MAP_TYPE_ARRAY,
3788 	.map_name = "tag_type_check_btf",
3789 	.key_size = sizeof(int),
3790 	.value_size = 4,
3791 	.key_type_id = 1,
3792 	.value_type_id = 1,
3793 	.max_entries = 1,
3794 	.btf_load_err = true,
3795 	.err_str = "Invalid value",
3796 },
3797 {
3798 	.descr = "decl_tag test #6, invalid target type",
3799 	.raw_types = {
3800 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3801 		BTF_DECL_TAG_ENC(NAME_TBD, 1, -1),
3802 		BTF_END_RAW,
3803 	},
3804 	BTF_STR_SEC("\0tag1"),
3805 	.map_type = BPF_MAP_TYPE_ARRAY,
3806 	.map_name = "tag_type_check_btf",
3807 	.key_size = sizeof(int),
3808 	.value_size = 4,
3809 	.key_type_id = 1,
3810 	.value_type_id = 1,
3811 	.max_entries = 1,
3812 	.btf_load_err = true,
3813 	.err_str = "Invalid type",
3814 },
3815 {
3816 	.descr = "decl_tag test #7, invalid vlen",
3817 	.raw_types = {
3818 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3819 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
3820 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 1), 2), (0),
3821 		BTF_END_RAW,
3822 	},
3823 	BTF_STR_SEC("\0local\0tag1"),
3824 	.map_type = BPF_MAP_TYPE_ARRAY,
3825 	.map_name = "tag_type_check_btf",
3826 	.key_size = sizeof(int),
3827 	.value_size = 4,
3828 	.key_type_id = 1,
3829 	.value_type_id = 1,
3830 	.max_entries = 1,
3831 	.btf_load_err = true,
3832 	.err_str = "vlen != 0",
3833 },
3834 {
3835 	.descr = "decl_tag test #8, invalid kflag",
3836 	.raw_types = {
3837 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3838 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
3839 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 1, 0), 2), (-1),
3840 		BTF_END_RAW,
3841 	},
3842 	BTF_STR_SEC("\0local\0tag1"),
3843 	.map_type = BPF_MAP_TYPE_ARRAY,
3844 	.map_name = "tag_type_check_btf",
3845 	.key_size = sizeof(int),
3846 	.value_size = 4,
3847 	.key_type_id = 1,
3848 	.value_type_id = 1,
3849 	.max_entries = 1,
3850 	.btf_load_err = true,
3851 	.err_str = "Invalid btf_info kind_flag",
3852 },
3853 {
3854 	.descr = "decl_tag test #9, var, invalid component_idx",
3855 	.raw_types = {
3856 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3857 		BTF_VAR_ENC(NAME_TBD, 1, 0),			/* [2] */
3858 		BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3859 		BTF_END_RAW,
3860 	},
3861 	BTF_STR_SEC("\0local\0tag"),
3862 	.map_type = BPF_MAP_TYPE_ARRAY,
3863 	.map_name = "tag_type_check_btf",
3864 	.key_size = sizeof(int),
3865 	.value_size = 4,
3866 	.key_type_id = 1,
3867 	.value_type_id = 1,
3868 	.max_entries = 1,
3869 	.btf_load_err = true,
3870 	.err_str = "Invalid component_idx",
3871 },
3872 {
3873 	.descr = "decl_tag test #10, struct member, invalid component_idx",
3874 	.raw_types = {
3875 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3876 		BTF_STRUCT_ENC(0, 2, 8),			/* [2] */
3877 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3878 		BTF_MEMBER_ENC(NAME_TBD, 1, 32),
3879 		BTF_DECL_TAG_ENC(NAME_TBD, 2, 2),
3880 		BTF_END_RAW,
3881 	},
3882 	BTF_STR_SEC("\0m1\0m2\0tag"),
3883 	.map_type = BPF_MAP_TYPE_ARRAY,
3884 	.map_name = "tag_type_check_btf",
3885 	.key_size = sizeof(int),
3886 	.value_size = 8,
3887 	.key_type_id = 1,
3888 	.value_type_id = 2,
3889 	.max_entries = 1,
3890 	.btf_load_err = true,
3891 	.err_str = "Invalid component_idx",
3892 },
3893 {
3894 	.descr = "decl_tag test #11, func parameter, invalid component_idx",
3895 	.raw_types = {
3896 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3897 		BTF_FUNC_PROTO_ENC(0, 2),			/* [2] */
3898 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3899 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3900 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
3901 		BTF_DECL_TAG_ENC(NAME_TBD, 3, 2),
3902 		BTF_END_RAW,
3903 	},
3904 	BTF_STR_SEC("\0arg1\0arg2\0f\0tag"),
3905 	.map_type = BPF_MAP_TYPE_ARRAY,
3906 	.map_name = "tag_type_check_btf",
3907 	.key_size = sizeof(int),
3908 	.value_size = 4,
3909 	.key_type_id = 1,
3910 	.value_type_id = 1,
3911 	.max_entries = 1,
3912 	.btf_load_err = true,
3913 	.err_str = "Invalid component_idx",
3914 },
3915 {
3916 	.descr = "decl_tag test #12, < -1 component_idx",
3917 	.raw_types = {
3918 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3919 		BTF_FUNC_PROTO_ENC(0, 2),			/* [2] */
3920 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3921 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3922 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
3923 		BTF_DECL_TAG_ENC(NAME_TBD, 3, -2),
3924 		BTF_END_RAW,
3925 	},
3926 	BTF_STR_SEC("\0arg1\0arg2\0f\0tag"),
3927 	.map_type = BPF_MAP_TYPE_ARRAY,
3928 	.map_name = "tag_type_check_btf",
3929 	.key_size = sizeof(int),
3930 	.value_size = 4,
3931 	.key_type_id = 1,
3932 	.value_type_id = 1,
3933 	.max_entries = 1,
3934 	.btf_load_err = true,
3935 	.err_str = "Invalid component_idx",
3936 },
3937 {
3938 	.descr = "decl_tag test #13, typedef, well-formed",
3939 	.raw_types = {
3940 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3941 		BTF_TYPEDEF_ENC(NAME_TBD, 1),			/* [2] */
3942 		BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3943 		BTF_END_RAW,
3944 	},
3945 	BTF_STR_SEC("\0t\0tag"),
3946 	.map_type = BPF_MAP_TYPE_ARRAY,
3947 	.map_name = "tag_type_check_btf",
3948 	.key_size = sizeof(int),
3949 	.value_size = 4,
3950 	.key_type_id = 1,
3951 	.value_type_id = 1,
3952 	.max_entries = 1,
3953 },
3954 {
3955 	.descr = "decl_tag test #14, typedef, invalid component_idx",
3956 	.raw_types = {
3957 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3958 		BTF_TYPEDEF_ENC(NAME_TBD, 1),			/* [2] */
3959 		BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3960 		BTF_END_RAW,
3961 	},
3962 	BTF_STR_SEC("\0local\0tag"),
3963 	.map_type = BPF_MAP_TYPE_ARRAY,
3964 	.map_name = "tag_type_check_btf",
3965 	.key_size = sizeof(int),
3966 	.value_size = 4,
3967 	.key_type_id = 1,
3968 	.value_type_id = 1,
3969 	.max_entries = 1,
3970 	.btf_load_err = true,
3971 	.err_str = "Invalid component_idx",
3972 },
3973 {
3974 	.descr = "decl_tag test #15, func, invalid func proto",
3975 	.raw_types = {
3976 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
3977 		BTF_DECL_TAG_ENC(NAME_TBD, 3, 0),		/* [2] */
3978 		BTF_FUNC_ENC(NAME_TBD, 8),			/* [3] */
3979 		BTF_END_RAW,
3980 	},
3981 	BTF_STR_SEC("\0tag\0func"),
3982 	.map_type = BPF_MAP_TYPE_ARRAY,
3983 	.map_name = "tag_type_check_btf",
3984 	.key_size = sizeof(int),
3985 	.value_size = 4,
3986 	.key_type_id = 1,
3987 	.value_type_id = 1,
3988 	.max_entries = 1,
3989 	.btf_load_err = true,
3990 	.err_str = "Invalid type_id",
3991 },
3992 {
3993 	.descr = "decl_tag test #16, func proto, return type",
3994 	.raw_types = {
3995 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),				/* [1] */
3996 		BTF_VAR_ENC(NAME_TBD, 1, 0),						/* [2] */
3997 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), 2), (-1),	/* [3] */
3998 		BTF_FUNC_PROTO_ENC(3, 0),						/* [4] */
3999 		BTF_END_RAW,
4000 	},
4001 	BTF_STR_SEC("\0local\0tag1"),
4002 	.btf_load_err = true,
4003 	.err_str = "Invalid return type",
4004 },
4005 {
4006 	.descr = "decl_tag test #17, func proto, argument",
4007 	.raw_types = {
4008 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), 4), (-1),	/* [1] */
4009 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0), /* [2] */
4010 		BTF_FUNC_PROTO_ENC(0, 1),			/* [3] */
4011 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
4012 		BTF_VAR_ENC(NAME_TBD, 2, 0),			/* [4] */
4013 		BTF_END_RAW,
4014 	},
4015 	BTF_STR_SEC("\0local\0tag1\0var"),
4016 	.btf_load_err = true,
4017 	.err_str = "Invalid arg#1",
4018 },
4019 {
4020 	.descr = "decl_tag test #18, decl_tag as the map key type",
4021 	.raw_types = {
4022 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
4023 		BTF_STRUCT_ENC(0, 2, 8),			/* [2] */
4024 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
4025 		BTF_MEMBER_ENC(NAME_TBD, 1, 32),
4026 		BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),		/* [3] */
4027 		BTF_END_RAW,
4028 	},
4029 	BTF_STR_SEC("\0m1\0m2\0tag"),
4030 	.map_type = BPF_MAP_TYPE_HASH,
4031 	.map_name = "tag_type_check_btf",
4032 	.key_size = 8,
4033 	.value_size = 4,
4034 	.key_type_id = 3,
4035 	.value_type_id = 1,
4036 	.max_entries = 1,
4037 	.map_create_err = true,
4038 },
4039 {
4040 	.descr = "decl_tag test #19, decl_tag as the map value type",
4041 	.raw_types = {
4042 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
4043 		BTF_STRUCT_ENC(0, 2, 8),			/* [2] */
4044 		BTF_MEMBER_ENC(NAME_TBD, 1, 0),
4045 		BTF_MEMBER_ENC(NAME_TBD, 1, 32),
4046 		BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),		/* [3] */
4047 		BTF_END_RAW,
4048 	},
4049 	BTF_STR_SEC("\0m1\0m2\0tag"),
4050 	.map_type = BPF_MAP_TYPE_HASH,
4051 	.map_name = "tag_type_check_btf",
4052 	.key_size = 4,
4053 	.value_size = 8,
4054 	.key_type_id = 1,
4055 	.value_type_id = 3,
4056 	.max_entries = 1,
4057 	.map_create_err = true,
4058 },
4059 {
4060 	.descr = "type_tag test #1",
4061 	.raw_types = {
4062 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
4063 		BTF_TYPE_TAG_ENC(NAME_TBD, 1),			/* [2] */
4064 		BTF_PTR_ENC(2),					/* [3] */
4065 		BTF_END_RAW,
4066 	},
4067 	BTF_STR_SEC("\0tag"),
4068 	.map_type = BPF_MAP_TYPE_ARRAY,
4069 	.map_name = "tag_type_check_btf",
4070 	.key_size = sizeof(int),
4071 	.value_size = 4,
4072 	.key_type_id = 1,
4073 	.value_type_id = 1,
4074 	.max_entries = 1,
4075 },
4076 {
4077 	.descr = "type_tag test #2, type tag order",
4078 	.raw_types = {
4079 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
4080 		BTF_CONST_ENC(3),				/* [2] */
4081 		BTF_TYPE_TAG_ENC(NAME_TBD, 1),			/* [3] */
4082 		BTF_END_RAW,
4083 	},
4084 	BTF_STR_SEC("\0tag"),
4085 	.map_type = BPF_MAP_TYPE_ARRAY,
4086 	.map_name = "tag_type_check_btf",
4087 	.key_size = sizeof(int),
4088 	.value_size = 4,
4089 	.key_type_id = 1,
4090 	.value_type_id = 1,
4091 	.max_entries = 1,
4092 	.btf_load_err = true,
4093 	.err_str = "Type tags don't precede modifiers",
4094 },
4095 {
4096 	.descr = "type_tag test #3, type tag order",
4097 	.raw_types = {
4098 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
4099 		BTF_TYPE_TAG_ENC(NAME_TBD, 3),			/* [2] */
4100 		BTF_CONST_ENC(4),				/* [3] */
4101 		BTF_TYPE_TAG_ENC(NAME_TBD, 1),			/* [4] */
4102 		BTF_END_RAW,
4103 	},
4104 	BTF_STR_SEC("\0tag\0tag"),
4105 	.map_type = BPF_MAP_TYPE_ARRAY,
4106 	.map_name = "tag_type_check_btf",
4107 	.key_size = sizeof(int),
4108 	.value_size = 4,
4109 	.key_type_id = 1,
4110 	.value_type_id = 1,
4111 	.max_entries = 1,
4112 	.btf_load_err = true,
4113 	.err_str = "Type tags don't precede modifiers",
4114 },
4115 {
4116 	.descr = "type_tag test #4, type tag order",
4117 	.raw_types = {
4118 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
4119 		BTF_TYPEDEF_ENC(NAME_TBD, 3),			/* [2] */
4120 		BTF_CONST_ENC(4),				/* [3] */
4121 		BTF_TYPE_TAG_ENC(NAME_TBD, 1),			/* [4] */
4122 		BTF_END_RAW,
4123 	},
4124 	BTF_STR_SEC("\0tag\0tag"),
4125 	.map_type = BPF_MAP_TYPE_ARRAY,
4126 	.map_name = "tag_type_check_btf",
4127 	.key_size = sizeof(int),
4128 	.value_size = 4,
4129 	.key_type_id = 1,
4130 	.value_type_id = 1,
4131 	.max_entries = 1,
4132 	.btf_load_err = true,
4133 	.err_str = "Type tags don't precede modifiers",
4134 },
4135 {
4136 	.descr = "type_tag test #5, type tag order",
4137 	.raw_types = {
4138 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
4139 		BTF_TYPE_TAG_ENC(NAME_TBD, 3),			/* [2] */
4140 		BTF_CONST_ENC(1),				/* [3] */
4141 		BTF_TYPE_TAG_ENC(NAME_TBD, 2),			/* [4] */
4142 		BTF_END_RAW,
4143 	},
4144 	BTF_STR_SEC("\0tag\0tag"),
4145 	.map_type = BPF_MAP_TYPE_ARRAY,
4146 	.map_name = "tag_type_check_btf",
4147 	.key_size = sizeof(int),
4148 	.value_size = 4,
4149 	.key_type_id = 1,
4150 	.value_type_id = 1,
4151 	.max_entries = 1,
4152 },
4153 {
4154 	.descr = "type_tag test #6, type tag order",
4155 	.raw_types = {
4156 		BTF_PTR_ENC(2),					/* [1] */
4157 		BTF_TYPE_TAG_ENC(NAME_TBD, 3),			/* [2] */
4158 		BTF_CONST_ENC(4),				/* [3] */
4159 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [4] */
4160 		BTF_PTR_ENC(6),					/* [5] */
4161 		BTF_CONST_ENC(2),				/* [6] */
4162 		BTF_END_RAW,
4163 	},
4164 	BTF_STR_SEC("\0tag"),
4165 	.map_type = BPF_MAP_TYPE_ARRAY,
4166 	.map_name = "tag_type_check_btf",
4167 	.key_size = sizeof(int),
4168 	.value_size = 4,
4169 	.key_type_id = 1,
4170 	.value_type_id = 1,
4171 	.max_entries = 1,
4172 	.btf_load_err = true,
4173 	.err_str = "Type tags don't precede modifiers",
4174 },
4175 {
4176 	.descr = "enum64 test #1, unsigned, size 8",
4177 	.raw_types = {
4178 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
4179 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 2), 8),	/* [2] */
4180 		BTF_ENUM64_ENC(NAME_TBD, 0, 0),
4181 		BTF_ENUM64_ENC(NAME_TBD, 1, 1),
4182 		BTF_END_RAW,
4183 	},
4184 	BTF_STR_SEC("\0a\0b\0c"),
4185 	.map_type = BPF_MAP_TYPE_ARRAY,
4186 	.map_name = "tag_type_check_btf",
4187 	.key_size = sizeof(int),
4188 	.value_size = 8,
4189 	.key_type_id = 1,
4190 	.value_type_id = 2,
4191 	.max_entries = 1,
4192 },
4193 {
4194 	.descr = "enum64 test #2, signed, size 4",
4195 	.raw_types = {
4196 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),			/* [1] */
4197 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 1, 2), 4),	/* [2] */
4198 		BTF_ENUM64_ENC(NAME_TBD, -1, 0),
4199 		BTF_ENUM64_ENC(NAME_TBD, 1, 0),
4200 		BTF_END_RAW,
4201 	},
4202 	BTF_STR_SEC("\0a\0b\0c"),
4203 	.map_type = BPF_MAP_TYPE_ARRAY,
4204 	.map_name = "tag_type_check_btf",
4205 	.key_size = sizeof(int),
4206 	.value_size = 4,
4207 	.key_type_id = 1,
4208 	.value_type_id = 2,
4209 	.max_entries = 1,
4210 },
4211 
4212 }; /* struct btf_raw_test raw_tests[] */
4213 
4214 static const char *get_next_str(const char *start, const char *end)
4215 {
4216 	return start < end - 1 ? start + 1 : NULL;
4217 }
4218 
4219 static int get_raw_sec_size(const __u32 *raw_types)
4220 {
4221 	int i;
4222 
4223 	for (i = MAX_NR_RAW_U32 - 1;
4224 	     i >= 0 && raw_types[i] != BTF_END_RAW;
4225 	     i--)
4226 		;
4227 
4228 	return i < 0 ? i : i * sizeof(raw_types[0]);
4229 }
4230 
4231 static void *btf_raw_create(const struct btf_header *hdr,
4232 			    const __u32 *raw_types,
4233 			    const char *str,
4234 			    unsigned int str_sec_size,
4235 			    unsigned int *btf_size,
4236 			    const char **ret_next_str)
4237 {
4238 	const char *next_str = str, *end_str = str + str_sec_size;
4239 	const char **strs_idx = NULL, **tmp_strs_idx;
4240 	int strs_cap = 0, strs_cnt = 0, next_str_idx = 0;
4241 	unsigned int size_needed, offset;
4242 	struct btf_header *ret_hdr;
4243 	int i, type_sec_size, err = 0;
4244 	uint32_t *ret_types;
4245 	void *raw_btf = NULL;
4246 
4247 	type_sec_size = get_raw_sec_size(raw_types);
4248 	if (CHECK(type_sec_size < 0, "Cannot get nr_raw_types"))
4249 		return NULL;
4250 
4251 	size_needed = sizeof(*hdr) + type_sec_size + str_sec_size;
4252 	raw_btf = malloc(size_needed);
4253 	if (CHECK(!raw_btf, "Cannot allocate memory for raw_btf"))
4254 		return NULL;
4255 
4256 	/* Copy header */
4257 	memcpy(raw_btf, hdr, sizeof(*hdr));
4258 	offset = sizeof(*hdr);
4259 
4260 	/* Index strings */
4261 	while ((next_str = get_next_str(next_str, end_str))) {
4262 		if (strs_cnt == strs_cap) {
4263 			strs_cap += max(16, strs_cap / 2);
4264 			tmp_strs_idx = realloc(strs_idx,
4265 					       sizeof(*strs_idx) * strs_cap);
4266 			if (CHECK(!tmp_strs_idx,
4267 				  "Cannot allocate memory for strs_idx")) {
4268 				err = -1;
4269 				goto done;
4270 			}
4271 			strs_idx = tmp_strs_idx;
4272 		}
4273 		strs_idx[strs_cnt++] = next_str;
4274 		next_str += strlen(next_str);
4275 	}
4276 
4277 	/* Copy type section */
4278 	ret_types = raw_btf + offset;
4279 	for (i = 0; i < type_sec_size / sizeof(raw_types[0]); i++) {
4280 		if (raw_types[i] == NAME_TBD) {
4281 			if (CHECK(next_str_idx == strs_cnt,
4282 				  "Error in getting next_str #%d",
4283 				  next_str_idx)) {
4284 				err = -1;
4285 				goto done;
4286 			}
4287 			ret_types[i] = strs_idx[next_str_idx++] - str;
4288 		} else if (IS_NAME_NTH(raw_types[i])) {
4289 			int idx = GET_NAME_NTH_IDX(raw_types[i]);
4290 
4291 			if (CHECK(idx <= 0 || idx > strs_cnt,
4292 				  "Error getting string #%d, strs_cnt:%d",
4293 				  idx, strs_cnt)) {
4294 				err = -1;
4295 				goto done;
4296 			}
4297 			ret_types[i] = strs_idx[idx-1] - str;
4298 		} else {
4299 			ret_types[i] = raw_types[i];
4300 		}
4301 	}
4302 	offset += type_sec_size;
4303 
4304 	/* Copy string section */
4305 	memcpy(raw_btf + offset, str, str_sec_size);
4306 
4307 	ret_hdr = (struct btf_header *)raw_btf;
4308 	ret_hdr->type_len = type_sec_size;
4309 	ret_hdr->str_off = type_sec_size;
4310 	ret_hdr->str_len = str_sec_size;
4311 
4312 	*btf_size = size_needed;
4313 	if (ret_next_str)
4314 		*ret_next_str =
4315 			next_str_idx < strs_cnt ? strs_idx[next_str_idx] : NULL;
4316 
4317 done:
4318 	free(strs_idx);
4319 	if (err) {
4320 		free(raw_btf);
4321 		return NULL;
4322 	}
4323 	return raw_btf;
4324 }
4325 
4326 static int load_raw_btf(const void *raw_data, size_t raw_size)
4327 {
4328 	LIBBPF_OPTS(bpf_btf_load_opts, opts);
4329 	int btf_fd;
4330 
4331 	if (always_log) {
4332 		opts.log_buf = btf_log_buf,
4333 		opts.log_size = BTF_LOG_BUF_SIZE,
4334 		opts.log_level = 1;
4335 	}
4336 
4337 	btf_fd = bpf_btf_load(raw_data, raw_size, &opts);
4338 	if (btf_fd < 0 && !always_log) {
4339 		opts.log_buf = btf_log_buf,
4340 		opts.log_size = BTF_LOG_BUF_SIZE,
4341 		opts.log_level = 1;
4342 		btf_fd = bpf_btf_load(raw_data, raw_size, &opts);
4343 	}
4344 
4345 	return btf_fd;
4346 }
4347 
4348 static void do_test_raw(unsigned int test_num)
4349 {
4350 	struct btf_raw_test *test = &raw_tests[test_num - 1];
4351 	LIBBPF_OPTS(bpf_map_create_opts, opts);
4352 	int map_fd = -1, btf_fd = -1;
4353 	unsigned int raw_btf_size;
4354 	struct btf_header *hdr;
4355 	void *raw_btf;
4356 	int err;
4357 
4358 	if (!test__start_subtest(test->descr))
4359 		return;
4360 
4361 	raw_btf = btf_raw_create(&hdr_tmpl,
4362 				 test->raw_types,
4363 				 test->str_sec,
4364 				 test->str_sec_size,
4365 				 &raw_btf_size, NULL);
4366 	if (!raw_btf)
4367 		return;
4368 
4369 	hdr = raw_btf;
4370 
4371 	hdr->hdr_len = (int)hdr->hdr_len + test->hdr_len_delta;
4372 	hdr->type_off = (int)hdr->type_off + test->type_off_delta;
4373 	hdr->str_off = (int)hdr->str_off + test->str_off_delta;
4374 	hdr->str_len = (int)hdr->str_len + test->str_len_delta;
4375 
4376 	*btf_log_buf = '\0';
4377 	btf_fd = load_raw_btf(raw_btf, raw_btf_size);
4378 	free(raw_btf);
4379 
4380 	err = ((btf_fd < 0) != test->btf_load_err);
4381 	if (CHECK(err, "btf_fd:%d test->btf_load_err:%u",
4382 		  btf_fd, test->btf_load_err) ||
4383 	    CHECK(test->err_str && !strstr(btf_log_buf, test->err_str),
4384 		  "expected err_str:%s\n", test->err_str)) {
4385 		err = -1;
4386 		goto done;
4387 	}
4388 
4389 	if (err || btf_fd < 0)
4390 		goto done;
4391 
4392 	if (!test->map_type)
4393 		goto done;
4394 
4395 	opts.btf_fd = btf_fd;
4396 	opts.btf_key_type_id = test->key_type_id;
4397 	opts.btf_value_type_id = test->value_type_id;
4398 	map_fd = bpf_map_create(test->map_type, test->map_name,
4399 				test->key_size, test->value_size, test->max_entries, &opts);
4400 
4401 	err = ((map_fd < 0) != test->map_create_err);
4402 	CHECK(err, "map_fd:%d test->map_create_err:%u",
4403 	      map_fd, test->map_create_err);
4404 
4405 done:
4406 	if (*btf_log_buf && (err || always_log))
4407 		fprintf(stderr, "\n%s", btf_log_buf);
4408 	if (btf_fd >= 0)
4409 		close(btf_fd);
4410 	if (map_fd >= 0)
4411 		close(map_fd);
4412 }
4413 
4414 struct btf_get_info_test {
4415 	const char *descr;
4416 	const char *str_sec;
4417 	__u32 raw_types[MAX_NR_RAW_U32];
4418 	__u32 str_sec_size;
4419 	int btf_size_delta;
4420 	int (*special_test)(unsigned int test_num);
4421 };
4422 
4423 static int test_big_btf_info(unsigned int test_num);
4424 static int test_btf_id(unsigned int test_num);
4425 
4426 const struct btf_get_info_test get_info_tests[] = {
4427 {
4428 	.descr = "== raw_btf_size+1",
4429 	.raw_types = {
4430 		/* int */				/* [1] */
4431 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4432 		BTF_END_RAW,
4433 	},
4434 	.str_sec = "",
4435 	.str_sec_size = sizeof(""),
4436 	.btf_size_delta = 1,
4437 },
4438 {
4439 	.descr = "== raw_btf_size-3",
4440 	.raw_types = {
4441 		/* int */				/* [1] */
4442 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4443 		BTF_END_RAW,
4444 	},
4445 	.str_sec = "",
4446 	.str_sec_size = sizeof(""),
4447 	.btf_size_delta = -3,
4448 },
4449 {
4450 	.descr = "Large bpf_btf_info",
4451 	.raw_types = {
4452 		/* int */				/* [1] */
4453 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4454 		BTF_END_RAW,
4455 	},
4456 	.str_sec = "",
4457 	.str_sec_size = sizeof(""),
4458 	.special_test = test_big_btf_info,
4459 },
4460 {
4461 	.descr = "BTF ID",
4462 	.raw_types = {
4463 		/* int */				/* [1] */
4464 		BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4465 		/* unsigned int */			/* [2] */
4466 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),
4467 		BTF_END_RAW,
4468 	},
4469 	.str_sec = "",
4470 	.str_sec_size = sizeof(""),
4471 	.special_test = test_btf_id,
4472 },
4473 };
4474 
4475 static int test_big_btf_info(unsigned int test_num)
4476 {
4477 	const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
4478 	uint8_t *raw_btf = NULL, *user_btf = NULL;
4479 	unsigned int raw_btf_size;
4480 	struct {
4481 		struct bpf_btf_info info;
4482 		uint64_t garbage;
4483 	} info_garbage;
4484 	struct bpf_btf_info *info;
4485 	int btf_fd = -1, err;
4486 	uint32_t info_len;
4487 
4488 	raw_btf = btf_raw_create(&hdr_tmpl,
4489 				 test->raw_types,
4490 				 test->str_sec,
4491 				 test->str_sec_size,
4492 				 &raw_btf_size, NULL);
4493 
4494 	if (!raw_btf)
4495 		return -1;
4496 
4497 	*btf_log_buf = '\0';
4498 
4499 	user_btf = malloc(raw_btf_size);
4500 	if (CHECK(!user_btf, "!user_btf")) {
4501 		err = -1;
4502 		goto done;
4503 	}
4504 
4505 	btf_fd = load_raw_btf(raw_btf, raw_btf_size);
4506 	if (CHECK(btf_fd < 0, "errno:%d", errno)) {
4507 		err = -1;
4508 		goto done;
4509 	}
4510 
4511 	/*
4512 	 * GET_INFO should error out if the userspace info
4513 	 * has non zero tailing bytes.
4514 	 */
4515 	info = &info_garbage.info;
4516 	memset(info, 0, sizeof(*info));
4517 	info_garbage.garbage = 0xdeadbeef;
4518 	info_len = sizeof(info_garbage);
4519 	info->btf = ptr_to_u64(user_btf);
4520 	info->btf_size = raw_btf_size;
4521 
4522 	err = bpf_btf_get_info_by_fd(btf_fd, info, &info_len);
4523 	if (CHECK(!err, "!err")) {
4524 		err = -1;
4525 		goto done;
4526 	}
4527 
4528 	/*
4529 	 * GET_INFO should succeed even info_len is larger than
4530 	 * the kernel supported as long as tailing bytes are zero.
4531 	 * The kernel supported info len should also be returned
4532 	 * to userspace.
4533 	 */
4534 	info_garbage.garbage = 0;
4535 	err = bpf_btf_get_info_by_fd(btf_fd, info, &info_len);
4536 	if (CHECK(err || info_len != sizeof(*info),
4537 		  "err:%d errno:%d info_len:%u sizeof(*info):%zu",
4538 		  err, errno, info_len, sizeof(*info))) {
4539 		err = -1;
4540 		goto done;
4541 	}
4542 
4543 	fprintf(stderr, "OK");
4544 
4545 done:
4546 	if (*btf_log_buf && (err || always_log))
4547 		fprintf(stderr, "\n%s", btf_log_buf);
4548 
4549 	free(raw_btf);
4550 	free(user_btf);
4551 
4552 	if (btf_fd >= 0)
4553 		close(btf_fd);
4554 
4555 	return err;
4556 }
4557 
4558 static int test_btf_id(unsigned int test_num)
4559 {
4560 	const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
4561 	LIBBPF_OPTS(bpf_map_create_opts, opts);
4562 	uint8_t *raw_btf = NULL, *user_btf[2] = {};
4563 	int btf_fd[2] = {-1, -1}, map_fd = -1;
4564 	struct bpf_map_info map_info = {};
4565 	struct bpf_btf_info info[2] = {};
4566 	unsigned int raw_btf_size;
4567 	uint32_t info_len;
4568 	int err, i, ret;
4569 
4570 	raw_btf = btf_raw_create(&hdr_tmpl,
4571 				 test->raw_types,
4572 				 test->str_sec,
4573 				 test->str_sec_size,
4574 				 &raw_btf_size, NULL);
4575 
4576 	if (!raw_btf)
4577 		return -1;
4578 
4579 	*btf_log_buf = '\0';
4580 
4581 	for (i = 0; i < 2; i++) {
4582 		user_btf[i] = malloc(raw_btf_size);
4583 		if (CHECK(!user_btf[i], "!user_btf[%d]", i)) {
4584 			err = -1;
4585 			goto done;
4586 		}
4587 		info[i].btf = ptr_to_u64(user_btf[i]);
4588 		info[i].btf_size = raw_btf_size;
4589 	}
4590 
4591 	btf_fd[0] = load_raw_btf(raw_btf, raw_btf_size);
4592 	if (CHECK(btf_fd[0] < 0, "errno:%d", errno)) {
4593 		err = -1;
4594 		goto done;
4595 	}
4596 
4597 	/* Test BPF_OBJ_GET_INFO_BY_ID on btf_id */
4598 	info_len = sizeof(info[0]);
4599 	err = bpf_btf_get_info_by_fd(btf_fd[0], &info[0], &info_len);
4600 	if (CHECK(err, "errno:%d", errno)) {
4601 		err = -1;
4602 		goto done;
4603 	}
4604 
4605 	btf_fd[1] = bpf_btf_get_fd_by_id(info[0].id);
4606 	if (CHECK(btf_fd[1] < 0, "errno:%d", errno)) {
4607 		err = -1;
4608 		goto done;
4609 	}
4610 
4611 	ret = 0;
4612 	err = bpf_btf_get_info_by_fd(btf_fd[1], &info[1], &info_len);
4613 	if (CHECK(err || info[0].id != info[1].id ||
4614 		  info[0].btf_size != info[1].btf_size ||
4615 		  (ret = memcmp(user_btf[0], user_btf[1], info[0].btf_size)),
4616 		  "err:%d errno:%d id0:%u id1:%u btf_size0:%u btf_size1:%u memcmp:%d",
4617 		  err, errno, info[0].id, info[1].id,
4618 		  info[0].btf_size, info[1].btf_size, ret)) {
4619 		err = -1;
4620 		goto done;
4621 	}
4622 
4623 	/* Test btf members in struct bpf_map_info */
4624 	opts.btf_fd = btf_fd[0];
4625 	opts.btf_key_type_id = 1;
4626 	opts.btf_value_type_id = 2;
4627 	map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "test_btf_id",
4628 				sizeof(int), sizeof(int), 4, &opts);
4629 	if (CHECK(map_fd < 0, "errno:%d", errno)) {
4630 		err = -1;
4631 		goto done;
4632 	}
4633 
4634 	info_len = sizeof(map_info);
4635 	err = bpf_map_get_info_by_fd(map_fd, &map_info, &info_len);
4636 	if (CHECK(err || map_info.btf_id != info[0].id ||
4637 		  map_info.btf_key_type_id != 1 || map_info.btf_value_type_id != 2,
4638 		  "err:%d errno:%d info.id:%u btf_id:%u btf_key_type_id:%u btf_value_type_id:%u",
4639 		  err, errno, info[0].id, map_info.btf_id, map_info.btf_key_type_id,
4640 		  map_info.btf_value_type_id)) {
4641 		err = -1;
4642 		goto done;
4643 	}
4644 
4645 	for (i = 0; i < 2; i++) {
4646 		close(btf_fd[i]);
4647 		btf_fd[i] = -1;
4648 	}
4649 
4650 	/* Test BTF ID is removed from the kernel */
4651 	btf_fd[0] = bpf_btf_get_fd_by_id(map_info.btf_id);
4652 	if (CHECK(btf_fd[0] < 0, "errno:%d", errno)) {
4653 		err = -1;
4654 		goto done;
4655 	}
4656 	close(btf_fd[0]);
4657 	btf_fd[0] = -1;
4658 
4659 	/* The map holds the last ref to BTF and its btf_id */
4660 	close(map_fd);
4661 	map_fd = -1;
4662 
4663 	fprintf(stderr, "OK");
4664 
4665 done:
4666 	if (*btf_log_buf && (err || always_log))
4667 		fprintf(stderr, "\n%s", btf_log_buf);
4668 
4669 	free(raw_btf);
4670 	if (map_fd >= 0)
4671 		close(map_fd);
4672 	for (i = 0; i < 2; i++) {
4673 		free(user_btf[i]);
4674 		if (btf_fd[i] >= 0)
4675 			close(btf_fd[i]);
4676 	}
4677 
4678 	return err;
4679 }
4680 
4681 static void do_test_get_info(unsigned int test_num)
4682 {
4683 	const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
4684 	unsigned int raw_btf_size, user_btf_size, expected_nbytes;
4685 	uint8_t *raw_btf = NULL, *user_btf = NULL;
4686 	struct bpf_btf_info info = {};
4687 	int btf_fd = -1, err, ret;
4688 	uint32_t info_len;
4689 
4690 	if (!test__start_subtest(test->descr))
4691 		return;
4692 
4693 	if (test->special_test) {
4694 		err = test->special_test(test_num);
4695 		if (CHECK(err, "failed: %d\n", err))
4696 			return;
4697 	}
4698 
4699 	raw_btf = btf_raw_create(&hdr_tmpl,
4700 				 test->raw_types,
4701 				 test->str_sec,
4702 				 test->str_sec_size,
4703 				 &raw_btf_size, NULL);
4704 
4705 	if (!raw_btf)
4706 		return;
4707 
4708 	*btf_log_buf = '\0';
4709 
4710 	user_btf = malloc(raw_btf_size);
4711 	if (CHECK(!user_btf, "!user_btf")) {
4712 		err = -1;
4713 		goto done;
4714 	}
4715 
4716 	btf_fd = load_raw_btf(raw_btf, raw_btf_size);
4717 	if (CHECK(btf_fd <= 0, "errno:%d", errno)) {
4718 		err = -1;
4719 		goto done;
4720 	}
4721 
4722 	user_btf_size = (int)raw_btf_size + test->btf_size_delta;
4723 	expected_nbytes = min(raw_btf_size, user_btf_size);
4724 	if (raw_btf_size > expected_nbytes)
4725 		memset(user_btf + expected_nbytes, 0xff,
4726 		       raw_btf_size - expected_nbytes);
4727 
4728 	info_len = sizeof(info);
4729 	info.btf = ptr_to_u64(user_btf);
4730 	info.btf_size = user_btf_size;
4731 
4732 	ret = 0;
4733 	err = bpf_btf_get_info_by_fd(btf_fd, &info, &info_len);
4734 	if (CHECK(err || !info.id || info_len != sizeof(info) ||
4735 		  info.btf_size != raw_btf_size ||
4736 		  (ret = memcmp(raw_btf, user_btf, expected_nbytes)),
4737 		  "err:%d errno:%d info.id:%u info_len:%u sizeof(info):%zu raw_btf_size:%u info.btf_size:%u expected_nbytes:%u memcmp:%d",
4738 		  err, errno, info.id, info_len, sizeof(info),
4739 		  raw_btf_size, info.btf_size, expected_nbytes, ret)) {
4740 		err = -1;
4741 		goto done;
4742 	}
4743 
4744 	while (expected_nbytes < raw_btf_size) {
4745 		fprintf(stderr, "%u...", expected_nbytes);
4746 		if (CHECK(user_btf[expected_nbytes++] != 0xff,
4747 			  "user_btf[%u]:%x != 0xff", expected_nbytes - 1,
4748 			  user_btf[expected_nbytes - 1])) {
4749 			err = -1;
4750 			goto done;
4751 		}
4752 	}
4753 
4754 	fprintf(stderr, "OK");
4755 
4756 done:
4757 	if (*btf_log_buf && (err || always_log))
4758 		fprintf(stderr, "\n%s", btf_log_buf);
4759 
4760 	free(raw_btf);
4761 	free(user_btf);
4762 
4763 	if (btf_fd >= 0)
4764 		close(btf_fd);
4765 }
4766 
4767 struct btf_file_test {
4768 	const char *file;
4769 	bool btf_kv_notfound;
4770 };
4771 
4772 static struct btf_file_test file_tests[] = {
4773 	{ .file = "test_btf_newkv.bpf.o", },
4774 	{ .file = "test_btf_nokv.bpf.o", .btf_kv_notfound = true, },
4775 };
4776 
4777 static void do_test_file(unsigned int test_num)
4778 {
4779 	const struct btf_file_test *test = &file_tests[test_num - 1];
4780 	const char *expected_fnames[] = {"_dummy_tracepoint",
4781 					 "test_long_fname_1",
4782 					 "test_long_fname_2"};
4783 	struct btf_ext *btf_ext = NULL;
4784 	struct bpf_prog_info info = {};
4785 	struct bpf_object *obj = NULL;
4786 	struct bpf_func_info *finfo;
4787 	struct bpf_program *prog;
4788 	__u32 info_len, rec_size;
4789 	bool has_btf_ext = false;
4790 	struct btf *btf = NULL;
4791 	void *func_info = NULL;
4792 	struct bpf_map *map;
4793 	int i, err, prog_fd;
4794 
4795 	if (!test__start_subtest(test->file))
4796 		return;
4797 
4798 	btf = btf__parse_elf(test->file, &btf_ext);
4799 	err = libbpf_get_error(btf);
4800 	if (err) {
4801 		if (err == -ENOENT) {
4802 			printf("%s:SKIP: No ELF %s found", __func__, BTF_ELF_SEC);
4803 			test__skip();
4804 			return;
4805 		}
4806 		return;
4807 	}
4808 	btf__free(btf);
4809 
4810 	has_btf_ext = btf_ext != NULL;
4811 	btf_ext__free(btf_ext);
4812 
4813 	/* temporary disable LIBBPF_STRICT_MAP_DEFINITIONS to test legacy maps */
4814 	libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
4815 	obj = bpf_object__open(test->file);
4816 	err = libbpf_get_error(obj);
4817 	if (CHECK(err, "obj: %d", err))
4818 		return;
4819 
4820 	prog = bpf_object__next_program(obj, NULL);
4821 	if (CHECK(!prog, "Cannot find bpf_prog")) {
4822 		err = -1;
4823 		goto done;
4824 	}
4825 
4826 	bpf_program__set_type(prog, BPF_PROG_TYPE_TRACEPOINT);
4827 	err = bpf_object__load(obj);
4828 	if (CHECK(err < 0, "bpf_object__load: %d", err))
4829 		goto done;
4830 	prog_fd = bpf_program__fd(prog);
4831 
4832 	map = bpf_object__find_map_by_name(obj, "btf_map");
4833 	if (CHECK(!map, "btf_map not found")) {
4834 		err = -1;
4835 		goto done;
4836 	}
4837 
4838 	err = (bpf_map__btf_key_type_id(map) == 0 || bpf_map__btf_value_type_id(map) == 0)
4839 		!= test->btf_kv_notfound;
4840 	if (CHECK(err, "btf_key_type_id:%u btf_value_type_id:%u test->btf_kv_notfound:%u",
4841 		  bpf_map__btf_key_type_id(map), bpf_map__btf_value_type_id(map),
4842 		  test->btf_kv_notfound))
4843 		goto done;
4844 
4845 	if (!has_btf_ext)
4846 		goto skip;
4847 
4848 	/* get necessary program info */
4849 	info_len = sizeof(struct bpf_prog_info);
4850 	err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
4851 
4852 	if (CHECK(err < 0, "invalid get info (1st) errno:%d", errno)) {
4853 		fprintf(stderr, "%s\n", btf_log_buf);
4854 		err = -1;
4855 		goto done;
4856 	}
4857 	if (CHECK(info.nr_func_info != 3,
4858 		  "incorrect info.nr_func_info (1st) %d",
4859 		  info.nr_func_info)) {
4860 		err = -1;
4861 		goto done;
4862 	}
4863 	rec_size = info.func_info_rec_size;
4864 	if (CHECK(rec_size != sizeof(struct bpf_func_info),
4865 		  "incorrect info.func_info_rec_size (1st) %d\n", rec_size)) {
4866 		err = -1;
4867 		goto done;
4868 	}
4869 
4870 	func_info = malloc(info.nr_func_info * rec_size);
4871 	if (CHECK(!func_info, "out of memory")) {
4872 		err = -1;
4873 		goto done;
4874 	}
4875 
4876 	/* reset info to only retrieve func_info related data */
4877 	memset(&info, 0, sizeof(info));
4878 	info.nr_func_info = 3;
4879 	info.func_info_rec_size = rec_size;
4880 	info.func_info = ptr_to_u64(func_info);
4881 
4882 	err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
4883 
4884 	if (CHECK(err < 0, "invalid get info (2nd) errno:%d", errno)) {
4885 		fprintf(stderr, "%s\n", btf_log_buf);
4886 		err = -1;
4887 		goto done;
4888 	}
4889 	if (CHECK(info.nr_func_info != 3,
4890 		  "incorrect info.nr_func_info (2nd) %d",
4891 		  info.nr_func_info)) {
4892 		err = -1;
4893 		goto done;
4894 	}
4895 	if (CHECK(info.func_info_rec_size != rec_size,
4896 		  "incorrect info.func_info_rec_size (2nd) %d",
4897 		  info.func_info_rec_size)) {
4898 		err = -1;
4899 		goto done;
4900 	}
4901 
4902 	btf = btf__load_from_kernel_by_id(info.btf_id);
4903 	err = libbpf_get_error(btf);
4904 	if (CHECK(err, "cannot get btf from kernel, err: %d", err))
4905 		goto done;
4906 
4907 	/* check three functions */
4908 	finfo = func_info;
4909 	for (i = 0; i < 3; i++) {
4910 		const struct btf_type *t;
4911 		const char *fname;
4912 
4913 		t = btf__type_by_id(btf, finfo->type_id);
4914 		if (CHECK(!t, "btf__type_by_id failure: id %u",
4915 			  finfo->type_id)) {
4916 			err = -1;
4917 			goto done;
4918 		}
4919 
4920 		fname = btf__name_by_offset(btf, t->name_off);
4921 		err = strcmp(fname, expected_fnames[i]);
4922 		/* for the second and third functions in .text section,
4923 		 * the compiler may order them either way.
4924 		 */
4925 		if (i && err)
4926 			err = strcmp(fname, expected_fnames[3 - i]);
4927 		if (CHECK(err, "incorrect fname %s", fname ? : "")) {
4928 			err = -1;
4929 			goto done;
4930 		}
4931 
4932 		finfo = (void *)finfo + rec_size;
4933 	}
4934 
4935 skip:
4936 	fprintf(stderr, "OK");
4937 
4938 done:
4939 	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
4940 
4941 	btf__free(btf);
4942 	free(func_info);
4943 	bpf_object__close(obj);
4944 }
4945 
4946 const char *pprint_enum_str[] = {
4947 	"ENUM_ZERO",
4948 	"ENUM_ONE",
4949 	"ENUM_TWO",
4950 	"ENUM_THREE",
4951 };
4952 
4953 struct pprint_mapv {
4954 	uint32_t ui32;
4955 	uint16_t ui16;
4956 	/* 2 bytes hole */
4957 	int32_t si32;
4958 	uint32_t unused_bits2a:2,
4959 		bits28:28,
4960 		unused_bits2b:2;
4961 	union {
4962 		uint64_t ui64;
4963 		uint8_t ui8a[8];
4964 	};
4965 	enum {
4966 		ENUM_ZERO,
4967 		ENUM_ONE,
4968 		ENUM_TWO,
4969 		ENUM_THREE,
4970 	} aenum;
4971 	uint32_t ui32b;
4972 	uint32_t bits2c:2;
4973 	uint8_t si8_4[2][2];
4974 };
4975 
4976 #ifdef __SIZEOF_INT128__
4977 struct pprint_mapv_int128 {
4978 	__int128 si128a;
4979 	__int128 si128b;
4980 	unsigned __int128 bits3:3;
4981 	unsigned __int128 bits80:80;
4982 	unsigned __int128 ui128;
4983 };
4984 #endif
4985 
4986 static struct btf_raw_test pprint_test_template[] = {
4987 {
4988 	.raw_types = {
4989 		/* unsighed char */			/* [1] */
4990 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 8, 1),
4991 		/* unsigned short */			/* [2] */
4992 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 16, 2),
4993 		/* unsigned int */			/* [3] */
4994 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
4995 		/* int */				/* [4] */
4996 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
4997 		/* unsigned long long */		/* [5] */
4998 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),
4999 		/* 2 bits */				/* [6] */
5000 		BTF_TYPE_INT_ENC(0, 0, 0, 2, 2),
5001 		/* 28 bits */				/* [7] */
5002 		BTF_TYPE_INT_ENC(0, 0, 0, 28, 4),
5003 		/* uint8_t[8] */			/* [8] */
5004 		BTF_TYPE_ARRAY_ENC(9, 1, 8),
5005 		/* typedef unsigned char uint8_t */	/* [9] */
5006 		BTF_TYPEDEF_ENC(NAME_TBD, 1),
5007 		/* typedef unsigned short uint16_t */	/* [10] */
5008 		BTF_TYPEDEF_ENC(NAME_TBD, 2),
5009 		/* typedef unsigned int uint32_t */	/* [11] */
5010 		BTF_TYPEDEF_ENC(NAME_TBD, 3),
5011 		/* typedef int int32_t */		/* [12] */
5012 		BTF_TYPEDEF_ENC(NAME_TBD, 4),
5013 		/* typedef unsigned long long uint64_t *//* [13] */
5014 		BTF_TYPEDEF_ENC(NAME_TBD, 5),
5015 		/* union (anon) */			/* [14] */
5016 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 0, 2), 8),
5017 		BTF_MEMBER_ENC(NAME_TBD, 13, 0),/* uint64_t ui64; */
5018 		BTF_MEMBER_ENC(NAME_TBD, 8, 0),	/* uint8_t ui8a[8]; */
5019 		/* enum (anon) */			/* [15] */
5020 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 4), 4),
5021 		BTF_ENUM_ENC(NAME_TBD, 0),
5022 		BTF_ENUM_ENC(NAME_TBD, 1),
5023 		BTF_ENUM_ENC(NAME_TBD, 2),
5024 		BTF_ENUM_ENC(NAME_TBD, 3),
5025 		/* struct pprint_mapv */		/* [16] */
5026 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 11), 40),
5027 		BTF_MEMBER_ENC(NAME_TBD, 11, 0),	/* uint32_t ui32 */
5028 		BTF_MEMBER_ENC(NAME_TBD, 10, 32),	/* uint16_t ui16 */
5029 		BTF_MEMBER_ENC(NAME_TBD, 12, 64),	/* int32_t si32 */
5030 		BTF_MEMBER_ENC(NAME_TBD, 6, 96),	/* unused_bits2a */
5031 		BTF_MEMBER_ENC(NAME_TBD, 7, 98),	/* bits28 */
5032 		BTF_MEMBER_ENC(NAME_TBD, 6, 126),	/* unused_bits2b */
5033 		BTF_MEMBER_ENC(0, 14, 128),		/* union (anon) */
5034 		BTF_MEMBER_ENC(NAME_TBD, 15, 192),	/* aenum */
5035 		BTF_MEMBER_ENC(NAME_TBD, 11, 224),	/* uint32_t ui32b */
5036 		BTF_MEMBER_ENC(NAME_TBD, 6, 256),	/* bits2c */
5037 		BTF_MEMBER_ENC(NAME_TBD, 17, 264),	/* si8_4 */
5038 		BTF_TYPE_ARRAY_ENC(18, 1, 2),		/* [17] */
5039 		BTF_TYPE_ARRAY_ENC(1, 1, 2),		/* [18] */
5040 		BTF_END_RAW,
5041 	},
5042 	BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0ui32b\0bits2c\0si8_4"),
5043 	.key_size = sizeof(unsigned int),
5044 	.value_size = sizeof(struct pprint_mapv),
5045 	.key_type_id = 3,	/* unsigned int */
5046 	.value_type_id = 16,	/* struct pprint_mapv */
5047 	.max_entries = 128,
5048 },
5049 
5050 {
5051 	/* this type will have the same type as the
5052 	 * first .raw_types definition, but struct type will
5053 	 * be encoded with kind_flag set.
5054 	 */
5055 	.raw_types = {
5056 		/* unsighed char */			/* [1] */
5057 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 8, 1),
5058 		/* unsigned short */			/* [2] */
5059 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 16, 2),
5060 		/* unsigned int */			/* [3] */
5061 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
5062 		/* int */				/* [4] */
5063 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
5064 		/* unsigned long long */		/* [5] */
5065 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),
5066 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),	/* [6] */
5067 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),	/* [7] */
5068 		/* uint8_t[8] */			/* [8] */
5069 		BTF_TYPE_ARRAY_ENC(9, 1, 8),
5070 		/* typedef unsigned char uint8_t */	/* [9] */
5071 		BTF_TYPEDEF_ENC(NAME_TBD, 1),
5072 		/* typedef unsigned short uint16_t */	/* [10] */
5073 		BTF_TYPEDEF_ENC(NAME_TBD, 2),
5074 		/* typedef unsigned int uint32_t */	/* [11] */
5075 		BTF_TYPEDEF_ENC(NAME_TBD, 3),
5076 		/* typedef int int32_t */		/* [12] */
5077 		BTF_TYPEDEF_ENC(NAME_TBD, 4),
5078 		/* typedef unsigned long long uint64_t *//* [13] */
5079 		BTF_TYPEDEF_ENC(NAME_TBD, 5),
5080 		/* union (anon) */			/* [14] */
5081 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 0, 2), 8),
5082 		BTF_MEMBER_ENC(NAME_TBD, 13, 0),/* uint64_t ui64; */
5083 		BTF_MEMBER_ENC(NAME_TBD, 8, 0),	/* uint8_t ui8a[8]; */
5084 		/* enum (anon) */			/* [15] */
5085 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 4), 4),
5086 		BTF_ENUM_ENC(NAME_TBD, 0),
5087 		BTF_ENUM_ENC(NAME_TBD, 1),
5088 		BTF_ENUM_ENC(NAME_TBD, 2),
5089 		BTF_ENUM_ENC(NAME_TBD, 3),
5090 		/* struct pprint_mapv */		/* [16] */
5091 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 11), 40),
5092 		BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)),	/* uint32_t ui32 */
5093 		BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)),	/* uint16_t ui16 */
5094 		BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)),	/* int32_t si32 */
5095 		BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 96)),	/* unused_bits2a */
5096 		BTF_MEMBER_ENC(NAME_TBD, 7, BTF_MEMBER_OFFSET(28, 98)),	/* bits28 */
5097 		BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 126)),	/* unused_bits2b */
5098 		BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)),	/* union (anon) */
5099 		BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)),	/* aenum */
5100 		BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 224)),	/* uint32_t ui32b */
5101 		BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 256)),	/* bits2c */
5102 		BTF_MEMBER_ENC(NAME_TBD, 17, 264),	/* si8_4 */
5103 		BTF_TYPE_ARRAY_ENC(18, 1, 2),		/* [17] */
5104 		BTF_TYPE_ARRAY_ENC(1, 1, 2),		/* [18] */
5105 		BTF_END_RAW,
5106 	},
5107 	BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0ui32b\0bits2c\0si8_4"),
5108 	.key_size = sizeof(unsigned int),
5109 	.value_size = sizeof(struct pprint_mapv),
5110 	.key_type_id = 3,	/* unsigned int */
5111 	.value_type_id = 16,	/* struct pprint_mapv */
5112 	.max_entries = 128,
5113 },
5114 
5115 {
5116 	/* this type will have the same layout as the
5117 	 * first .raw_types definition. The struct type will
5118 	 * be encoded with kind_flag set, bitfield members
5119 	 * are added typedef/const/volatile, and bitfield members
5120 	 * will have both int and enum types.
5121 	 */
5122 	.raw_types = {
5123 		/* unsighed char */			/* [1] */
5124 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 8, 1),
5125 		/* unsigned short */			/* [2] */
5126 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 16, 2),
5127 		/* unsigned int */			/* [3] */
5128 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
5129 		/* int */				/* [4] */
5130 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
5131 		/* unsigned long long */		/* [5] */
5132 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),
5133 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),	/* [6] */
5134 		BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),	/* [7] */
5135 		/* uint8_t[8] */			/* [8] */
5136 		BTF_TYPE_ARRAY_ENC(9, 1, 8),
5137 		/* typedef unsigned char uint8_t */	/* [9] */
5138 		BTF_TYPEDEF_ENC(NAME_TBD, 1),
5139 		/* typedef unsigned short uint16_t */	/* [10] */
5140 		BTF_TYPEDEF_ENC(NAME_TBD, 2),
5141 		/* typedef unsigned int uint32_t */	/* [11] */
5142 		BTF_TYPEDEF_ENC(NAME_TBD, 3),
5143 		/* typedef int int32_t */		/* [12] */
5144 		BTF_TYPEDEF_ENC(NAME_TBD, 4),
5145 		/* typedef unsigned long long uint64_t *//* [13] */
5146 		BTF_TYPEDEF_ENC(NAME_TBD, 5),
5147 		/* union (anon) */			/* [14] */
5148 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 0, 2), 8),
5149 		BTF_MEMBER_ENC(NAME_TBD, 13, 0),/* uint64_t ui64; */
5150 		BTF_MEMBER_ENC(NAME_TBD, 8, 0),	/* uint8_t ui8a[8]; */
5151 		/* enum (anon) */			/* [15] */
5152 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 4), 4),
5153 		BTF_ENUM_ENC(NAME_TBD, 0),
5154 		BTF_ENUM_ENC(NAME_TBD, 1),
5155 		BTF_ENUM_ENC(NAME_TBD, 2),
5156 		BTF_ENUM_ENC(NAME_TBD, 3),
5157 		/* struct pprint_mapv */		/* [16] */
5158 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 11), 40),
5159 		BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)),	/* uint32_t ui32 */
5160 		BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)),	/* uint16_t ui16 */
5161 		BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)),	/* int32_t si32 */
5162 		BTF_MEMBER_ENC(NAME_TBD, 17, BTF_MEMBER_OFFSET(2, 96)),	/* unused_bits2a */
5163 		BTF_MEMBER_ENC(NAME_TBD, 7, BTF_MEMBER_OFFSET(28, 98)),	/* bits28 */
5164 		BTF_MEMBER_ENC(NAME_TBD, 19, BTF_MEMBER_OFFSET(2, 126)),/* unused_bits2b */
5165 		BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)),	/* union (anon) */
5166 		BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)),	/* aenum */
5167 		BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 224)),	/* uint32_t ui32b */
5168 		BTF_MEMBER_ENC(NAME_TBD, 17, BTF_MEMBER_OFFSET(2, 256)),	/* bits2c */
5169 		BTF_MEMBER_ENC(NAME_TBD, 20, BTF_MEMBER_OFFSET(0, 264)),	/* si8_4 */
5170 		/* typedef unsigned int ___int */	/* [17] */
5171 		BTF_TYPEDEF_ENC(NAME_TBD, 18),
5172 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), 6),	/* [18] */
5173 		BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 15),	/* [19] */
5174 		BTF_TYPE_ARRAY_ENC(21, 1, 2),					/* [20] */
5175 		BTF_TYPE_ARRAY_ENC(1, 1, 2),					/* [21] */
5176 		BTF_END_RAW,
5177 	},
5178 	BTF_STR_SEC("\0unsigned char\0unsigned short\0unsigned int\0int\0unsigned long long\0uint8_t\0uint16_t\0uint32_t\0int32_t\0uint64_t\0ui64\0ui8a\0ENUM_ZERO\0ENUM_ONE\0ENUM_TWO\0ENUM_THREE\0pprint_mapv\0ui32\0ui16\0si32\0unused_bits2a\0bits28\0unused_bits2b\0aenum\0ui32b\0bits2c\0___int\0si8_4"),
5179 	.key_size = sizeof(unsigned int),
5180 	.value_size = sizeof(struct pprint_mapv),
5181 	.key_type_id = 3,	/* unsigned int */
5182 	.value_type_id = 16,	/* struct pprint_mapv */
5183 	.max_entries = 128,
5184 },
5185 
5186 #ifdef __SIZEOF_INT128__
5187 {
5188 	/* test int128 */
5189 	.raw_types = {
5190 		/* unsigned int */				/* [1] */
5191 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
5192 		/* __int128 */					/* [2] */
5193 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 128, 16),
5194 		/* unsigned __int128 */				/* [3] */
5195 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 128, 16),
5196 		/* struct pprint_mapv_int128 */			/* [4] */
5197 		BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 5), 64),
5198 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),		/* si128a */
5199 		BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 128)),		/* si128b */
5200 		BTF_MEMBER_ENC(NAME_TBD, 3, BTF_MEMBER_OFFSET(3, 256)),		/* bits3 */
5201 		BTF_MEMBER_ENC(NAME_TBD, 3, BTF_MEMBER_OFFSET(80, 259)),	/* bits80 */
5202 		BTF_MEMBER_ENC(NAME_TBD, 3, BTF_MEMBER_OFFSET(0, 384)),		/* ui128 */
5203 		BTF_END_RAW,
5204 	},
5205 	BTF_STR_SEC("\0unsigned int\0__int128\0unsigned __int128\0pprint_mapv_int128\0si128a\0si128b\0bits3\0bits80\0ui128"),
5206 	.key_size = sizeof(unsigned int),
5207 	.value_size = sizeof(struct pprint_mapv_int128),
5208 	.key_type_id = 1,
5209 	.value_type_id = 4,
5210 	.max_entries = 128,
5211 	.mapv_kind = PPRINT_MAPV_KIND_INT128,
5212 },
5213 #endif
5214 
5215 };
5216 
5217 static struct btf_pprint_test_meta {
5218 	const char *descr;
5219 	enum bpf_map_type map_type;
5220 	const char *map_name;
5221 	bool ordered_map;
5222 	bool lossless_map;
5223 	bool percpu_map;
5224 } pprint_tests_meta[] = {
5225 {
5226 	.descr = "BTF pretty print array",
5227 	.map_type = BPF_MAP_TYPE_ARRAY,
5228 	.map_name = "pprint_test_array",
5229 	.ordered_map = true,
5230 	.lossless_map = true,
5231 	.percpu_map = false,
5232 },
5233 
5234 {
5235 	.descr = "BTF pretty print hash",
5236 	.map_type = BPF_MAP_TYPE_HASH,
5237 	.map_name = "pprint_test_hash",
5238 	.ordered_map = false,
5239 	.lossless_map = true,
5240 	.percpu_map = false,
5241 },
5242 
5243 {
5244 	.descr = "BTF pretty print lru hash",
5245 	.map_type = BPF_MAP_TYPE_LRU_HASH,
5246 	.map_name = "pprint_test_lru_hash",
5247 	.ordered_map = false,
5248 	.lossless_map = false,
5249 	.percpu_map = false,
5250 },
5251 
5252 {
5253 	.descr = "BTF pretty print percpu array",
5254 	.map_type = BPF_MAP_TYPE_PERCPU_ARRAY,
5255 	.map_name = "pprint_test_percpu_array",
5256 	.ordered_map = true,
5257 	.lossless_map = true,
5258 	.percpu_map = true,
5259 },
5260 
5261 {
5262 	.descr = "BTF pretty print percpu hash",
5263 	.map_type = BPF_MAP_TYPE_PERCPU_HASH,
5264 	.map_name = "pprint_test_percpu_hash",
5265 	.ordered_map = false,
5266 	.lossless_map = true,
5267 	.percpu_map = true,
5268 },
5269 
5270 {
5271 	.descr = "BTF pretty print lru percpu hash",
5272 	.map_type = BPF_MAP_TYPE_LRU_PERCPU_HASH,
5273 	.map_name = "pprint_test_lru_percpu_hash",
5274 	.ordered_map = false,
5275 	.lossless_map = false,
5276 	.percpu_map = true,
5277 },
5278 
5279 };
5280 
5281 static size_t get_pprint_mapv_size(enum pprint_mapv_kind_t mapv_kind)
5282 {
5283 	if (mapv_kind == PPRINT_MAPV_KIND_BASIC)
5284 		return sizeof(struct pprint_mapv);
5285 
5286 #ifdef __SIZEOF_INT128__
5287 	if (mapv_kind == PPRINT_MAPV_KIND_INT128)
5288 		return sizeof(struct pprint_mapv_int128);
5289 #endif
5290 
5291 	assert(0);
5292 	return 0;
5293 }
5294 
5295 static void set_pprint_mapv(enum pprint_mapv_kind_t mapv_kind,
5296 			    void *mapv, uint32_t i,
5297 			    int num_cpus, int rounded_value_size)
5298 {
5299 	int cpu;
5300 
5301 	if (mapv_kind == PPRINT_MAPV_KIND_BASIC) {
5302 		struct pprint_mapv *v = mapv;
5303 
5304 		for (cpu = 0; cpu < num_cpus; cpu++) {
5305 			v->ui32 = i + cpu;
5306 			v->si32 = -i;
5307 			v->unused_bits2a = 3;
5308 			v->bits28 = i;
5309 			v->unused_bits2b = 3;
5310 			v->ui64 = i;
5311 			v->aenum = i & 0x03;
5312 			v->ui32b = 4;
5313 			v->bits2c = 1;
5314 			v->si8_4[0][0] = (cpu + i) & 0xff;
5315 			v->si8_4[0][1] = (cpu + i + 1) & 0xff;
5316 			v->si8_4[1][0] = (cpu + i + 2) & 0xff;
5317 			v->si8_4[1][1] = (cpu + i + 3) & 0xff;
5318 			v = (void *)v + rounded_value_size;
5319 		}
5320 	}
5321 
5322 #ifdef __SIZEOF_INT128__
5323 	if (mapv_kind == PPRINT_MAPV_KIND_INT128) {
5324 		struct pprint_mapv_int128 *v = mapv;
5325 
5326 		for (cpu = 0; cpu < num_cpus; cpu++) {
5327 			v->si128a = i;
5328 			v->si128b = -i;
5329 			v->bits3 = i & 0x07;
5330 			v->bits80 = (((unsigned __int128)1) << 64) + i;
5331 			v->ui128 = (((unsigned __int128)2) << 64) + i;
5332 			v = (void *)v + rounded_value_size;
5333 		}
5334 	}
5335 #endif
5336 }
5337 
5338 ssize_t get_pprint_expected_line(enum pprint_mapv_kind_t mapv_kind,
5339 				 char *expected_line, ssize_t line_size,
5340 				 bool percpu_map, unsigned int next_key,
5341 				 int cpu, void *mapv)
5342 {
5343 	ssize_t nexpected_line = -1;
5344 
5345 	if (mapv_kind == PPRINT_MAPV_KIND_BASIC) {
5346 		struct pprint_mapv *v = mapv;
5347 
5348 		nexpected_line = snprintf(expected_line, line_size,
5349 					  "%s%u: {%u,0,%d,0x%x,0x%x,0x%x,"
5350 					  "{%llu|[%u,%u,%u,%u,%u,%u,%u,%u]},%s,"
5351 					  "%u,0x%x,[[%d,%d],[%d,%d]]}\n",
5352 					  percpu_map ? "\tcpu" : "",
5353 					  percpu_map ? cpu : next_key,
5354 					  v->ui32, v->si32,
5355 					  v->unused_bits2a,
5356 					  v->bits28,
5357 					  v->unused_bits2b,
5358 					  (__u64)v->ui64,
5359 					  v->ui8a[0], v->ui8a[1],
5360 					  v->ui8a[2], v->ui8a[3],
5361 					  v->ui8a[4], v->ui8a[5],
5362 					  v->ui8a[6], v->ui8a[7],
5363 					  pprint_enum_str[v->aenum],
5364 					  v->ui32b,
5365 					  v->bits2c,
5366 					  v->si8_4[0][0], v->si8_4[0][1],
5367 					  v->si8_4[1][0], v->si8_4[1][1]);
5368 	}
5369 
5370 #ifdef __SIZEOF_INT128__
5371 	if (mapv_kind == PPRINT_MAPV_KIND_INT128) {
5372 		struct pprint_mapv_int128 *v = mapv;
5373 
5374 		nexpected_line = snprintf(expected_line, line_size,
5375 					  "%s%u: {0x%lx,0x%lx,0x%lx,"
5376 					  "0x%lx%016lx,0x%lx%016lx}\n",
5377 					  percpu_map ? "\tcpu" : "",
5378 					  percpu_map ? cpu : next_key,
5379 					  (uint64_t)v->si128a,
5380 					  (uint64_t)v->si128b,
5381 					  (uint64_t)v->bits3,
5382 					  (uint64_t)(v->bits80 >> 64),
5383 					  (uint64_t)v->bits80,
5384 					  (uint64_t)(v->ui128 >> 64),
5385 					  (uint64_t)v->ui128);
5386 	}
5387 #endif
5388 
5389 	return nexpected_line;
5390 }
5391 
5392 static int check_line(const char *expected_line, int nexpected_line,
5393 		      int expected_line_len, const char *line)
5394 {
5395 	if (CHECK(nexpected_line == expected_line_len,
5396 		  "expected_line is too long"))
5397 		return -1;
5398 
5399 	if (strcmp(expected_line, line)) {
5400 		fprintf(stderr, "unexpected pprint output\n");
5401 		fprintf(stderr, "expected: %s", expected_line);
5402 		fprintf(stderr, "    read: %s", line);
5403 		return -1;
5404 	}
5405 
5406 	return 0;
5407 }
5408 
5409 
5410 static void do_test_pprint(int test_num)
5411 {
5412 	const struct btf_raw_test *test = &pprint_test_template[test_num];
5413 	enum pprint_mapv_kind_t mapv_kind = test->mapv_kind;
5414 	LIBBPF_OPTS(bpf_map_create_opts, opts);
5415 	bool ordered_map, lossless_map, percpu_map;
5416 	int err, ret, num_cpus, rounded_value_size;
5417 	unsigned int key, nr_read_elems;
5418 	int map_fd = -1, btf_fd = -1;
5419 	unsigned int raw_btf_size;
5420 	char expected_line[255];
5421 	FILE *pin_file = NULL;
5422 	char pin_path[255];
5423 	size_t line_len = 0;
5424 	char *line = NULL;
5425 	void *mapv = NULL;
5426 	uint8_t *raw_btf;
5427 	ssize_t nread;
5428 
5429 	if (!test__start_subtest(test->descr))
5430 		return;
5431 
5432 	raw_btf = btf_raw_create(&hdr_tmpl, test->raw_types,
5433 				 test->str_sec, test->str_sec_size,
5434 				 &raw_btf_size, NULL);
5435 
5436 	if (!raw_btf)
5437 		return;
5438 
5439 	*btf_log_buf = '\0';
5440 	btf_fd = load_raw_btf(raw_btf, raw_btf_size);
5441 	free(raw_btf);
5442 
5443 	if (CHECK(btf_fd < 0, "errno:%d\n", errno)) {
5444 		err = -1;
5445 		goto done;
5446 	}
5447 
5448 	opts.btf_fd = btf_fd;
5449 	opts.btf_key_type_id = test->key_type_id;
5450 	opts.btf_value_type_id = test->value_type_id;
5451 	map_fd = bpf_map_create(test->map_type, test->map_name,
5452 				test->key_size, test->value_size, test->max_entries, &opts);
5453 	if (CHECK(map_fd < 0, "errno:%d", errno)) {
5454 		err = -1;
5455 		goto done;
5456 	}
5457 
5458 	ret = snprintf(pin_path, sizeof(pin_path), "%s/%s",
5459 		       "/sys/fs/bpf", test->map_name);
5460 
5461 	if (CHECK(ret >= sizeof(pin_path), "pin_path %s/%s is too long",
5462 		  "/sys/fs/bpf", test->map_name)) {
5463 		err = -1;
5464 		goto done;
5465 	}
5466 
5467 	err = bpf_obj_pin(map_fd, pin_path);
5468 	if (CHECK(err, "bpf_obj_pin(%s): errno:%d.", pin_path, errno))
5469 		goto done;
5470 
5471 	percpu_map = test->percpu_map;
5472 	num_cpus = percpu_map ? bpf_num_possible_cpus() : 1;
5473 	rounded_value_size = round_up(get_pprint_mapv_size(mapv_kind), 8);
5474 	mapv = calloc(num_cpus, rounded_value_size);
5475 	if (CHECK(!mapv, "mapv allocation failure")) {
5476 		err = -1;
5477 		goto done;
5478 	}
5479 
5480 	for (key = 0; key < test->max_entries; key++) {
5481 		set_pprint_mapv(mapv_kind, mapv, key, num_cpus, rounded_value_size);
5482 		bpf_map_update_elem(map_fd, &key, mapv, 0);
5483 	}
5484 
5485 	pin_file = fopen(pin_path, "r");
5486 	if (CHECK(!pin_file, "fopen(%s): errno:%d", pin_path, errno)) {
5487 		err = -1;
5488 		goto done;
5489 	}
5490 
5491 	/* Skip lines start with '#' */
5492 	while ((nread = getline(&line, &line_len, pin_file)) > 0 &&
5493 	       *line == '#')
5494 		;
5495 
5496 	if (CHECK(nread <= 0, "Unexpected EOF")) {
5497 		err = -1;
5498 		goto done;
5499 	}
5500 
5501 	nr_read_elems = 0;
5502 	ordered_map = test->ordered_map;
5503 	lossless_map = test->lossless_map;
5504 	do {
5505 		ssize_t nexpected_line;
5506 		unsigned int next_key;
5507 		void *cmapv;
5508 		int cpu;
5509 
5510 		next_key = ordered_map ? nr_read_elems : atoi(line);
5511 		set_pprint_mapv(mapv_kind, mapv, next_key, num_cpus, rounded_value_size);
5512 		cmapv = mapv;
5513 
5514 		for (cpu = 0; cpu < num_cpus; cpu++) {
5515 			if (percpu_map) {
5516 				/* for percpu map, the format looks like:
5517 				 * <key>: {
5518 				 *	cpu0: <value_on_cpu0>
5519 				 *	cpu1: <value_on_cpu1>
5520 				 *	...
5521 				 *	cpun: <value_on_cpun>
5522 				 * }
5523 				 *
5524 				 * let us verify the line containing the key here.
5525 				 */
5526 				if (cpu == 0) {
5527 					nexpected_line = snprintf(expected_line,
5528 								  sizeof(expected_line),
5529 								  "%u: {\n",
5530 								  next_key);
5531 
5532 					err = check_line(expected_line, nexpected_line,
5533 							 sizeof(expected_line), line);
5534 					if (err < 0)
5535 						goto done;
5536 				}
5537 
5538 				/* read value@cpu */
5539 				nread = getline(&line, &line_len, pin_file);
5540 				if (nread < 0)
5541 					break;
5542 			}
5543 
5544 			nexpected_line = get_pprint_expected_line(mapv_kind, expected_line,
5545 								  sizeof(expected_line),
5546 								  percpu_map, next_key,
5547 								  cpu, cmapv);
5548 			err = check_line(expected_line, nexpected_line,
5549 					 sizeof(expected_line), line);
5550 			if (err < 0)
5551 				goto done;
5552 
5553 			cmapv = cmapv + rounded_value_size;
5554 		}
5555 
5556 		if (percpu_map) {
5557 			/* skip the last bracket for the percpu map */
5558 			nread = getline(&line, &line_len, pin_file);
5559 			if (nread < 0)
5560 				break;
5561 		}
5562 
5563 		nread = getline(&line, &line_len, pin_file);
5564 	} while (++nr_read_elems < test->max_entries && nread > 0);
5565 
5566 	if (lossless_map &&
5567 	    CHECK(nr_read_elems < test->max_entries,
5568 		  "Unexpected EOF. nr_read_elems:%u test->max_entries:%u",
5569 		  nr_read_elems, test->max_entries)) {
5570 		err = -1;
5571 		goto done;
5572 	}
5573 
5574 	if (CHECK(nread > 0, "Unexpected extra pprint output: %s", line)) {
5575 		err = -1;
5576 		goto done;
5577 	}
5578 
5579 	err = 0;
5580 
5581 done:
5582 	if (mapv)
5583 		free(mapv);
5584 	if (!err)
5585 		fprintf(stderr, "OK");
5586 	if (*btf_log_buf && (err || always_log))
5587 		fprintf(stderr, "\n%s", btf_log_buf);
5588 	if (btf_fd >= 0)
5589 		close(btf_fd);
5590 	if (map_fd >= 0)
5591 		close(map_fd);
5592 	if (pin_file)
5593 		fclose(pin_file);
5594 	unlink(pin_path);
5595 	free(line);
5596 }
5597 
5598 static void test_pprint(void)
5599 {
5600 	unsigned int i;
5601 
5602 	/* test various maps with the first test template */
5603 	for (i = 0; i < ARRAY_SIZE(pprint_tests_meta); i++) {
5604 		pprint_test_template[0].descr = pprint_tests_meta[i].descr;
5605 		pprint_test_template[0].map_type = pprint_tests_meta[i].map_type;
5606 		pprint_test_template[0].map_name = pprint_tests_meta[i].map_name;
5607 		pprint_test_template[0].ordered_map = pprint_tests_meta[i].ordered_map;
5608 		pprint_test_template[0].lossless_map = pprint_tests_meta[i].lossless_map;
5609 		pprint_test_template[0].percpu_map = pprint_tests_meta[i].percpu_map;
5610 
5611 		do_test_pprint(0);
5612 	}
5613 
5614 	/* test rest test templates with the first map */
5615 	for (i = 1; i < ARRAY_SIZE(pprint_test_template); i++) {
5616 		pprint_test_template[i].descr = pprint_tests_meta[0].descr;
5617 		pprint_test_template[i].map_type = pprint_tests_meta[0].map_type;
5618 		pprint_test_template[i].map_name = pprint_tests_meta[0].map_name;
5619 		pprint_test_template[i].ordered_map = pprint_tests_meta[0].ordered_map;
5620 		pprint_test_template[i].lossless_map = pprint_tests_meta[0].lossless_map;
5621 		pprint_test_template[i].percpu_map = pprint_tests_meta[0].percpu_map;
5622 		do_test_pprint(i);
5623 	}
5624 }
5625 
5626 #define BPF_LINE_INFO_ENC(insn_off, file_off, line_off, line_num, line_col) \
5627 	(insn_off), (file_off), (line_off), ((line_num) << 10 | ((line_col) & 0x3ff))
5628 
5629 static struct prog_info_raw_test {
5630 	const char *descr;
5631 	const char *str_sec;
5632 	const char *err_str;
5633 	__u32 raw_types[MAX_NR_RAW_U32];
5634 	__u32 str_sec_size;
5635 	struct bpf_insn insns[MAX_INSNS];
5636 	__u32 prog_type;
5637 	__u32 func_info[MAX_SUBPROGS][2];
5638 	__u32 func_info_rec_size;
5639 	__u32 func_info_cnt;
5640 	__u32 line_info[MAX_NR_RAW_U32];
5641 	__u32 line_info_rec_size;
5642 	__u32 nr_jited_ksyms;
5643 	bool expected_prog_load_failure;
5644 	__u32 dead_code_cnt;
5645 	__u32 dead_code_mask;
5646 	__u32 dead_func_cnt;
5647 	__u32 dead_func_mask;
5648 } info_raw_tests[] = {
5649 {
5650 	.descr = "func_type (main func + one sub)",
5651 	.raw_types = {
5652 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5653 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),	/* [2] */
5654 		BTF_FUNC_PROTO_ENC(1, 2),			/* [3] */
5655 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5656 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5657 		BTF_FUNC_PROTO_ENC(1, 2),			/* [4] */
5658 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5659 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5660 		BTF_FUNC_ENC(NAME_TBD, 3),			/* [5] */
5661 		BTF_FUNC_ENC(NAME_TBD, 4),			/* [6] */
5662 		BTF_END_RAW,
5663 	},
5664 	.str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5665 	.str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5666 	.insns = {
5667 		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5668 		BPF_MOV64_IMM(BPF_REG_0, 1),
5669 		BPF_EXIT_INSN(),
5670 		BPF_MOV64_IMM(BPF_REG_0, 2),
5671 		BPF_EXIT_INSN(),
5672 	},
5673 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5674 	.func_info = { {0, 5}, {3, 6} },
5675 	.func_info_rec_size = 8,
5676 	.func_info_cnt = 2,
5677 	.line_info = { BTF_END_RAW },
5678 },
5679 
5680 {
5681 	.descr = "func_type (Incorrect func_info_rec_size)",
5682 	.raw_types = {
5683 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5684 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),	/* [2] */
5685 		BTF_FUNC_PROTO_ENC(1, 2),			/* [3] */
5686 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5687 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5688 		BTF_FUNC_PROTO_ENC(1, 2),			/* [4] */
5689 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5690 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5691 		BTF_FUNC_ENC(NAME_TBD, 3),			/* [5] */
5692 		BTF_FUNC_ENC(NAME_TBD, 4),			/* [6] */
5693 		BTF_END_RAW,
5694 	},
5695 	.str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5696 	.str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5697 	.insns = {
5698 		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5699 		BPF_MOV64_IMM(BPF_REG_0, 1),
5700 		BPF_EXIT_INSN(),
5701 		BPF_MOV64_IMM(BPF_REG_0, 2),
5702 		BPF_EXIT_INSN(),
5703 	},
5704 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5705 	.func_info = { {0, 5}, {3, 6} },
5706 	.func_info_rec_size = 4,
5707 	.func_info_cnt = 2,
5708 	.line_info = { BTF_END_RAW },
5709 	.expected_prog_load_failure = true,
5710 },
5711 
5712 {
5713 	.descr = "func_type (Incorrect func_info_cnt)",
5714 	.raw_types = {
5715 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5716 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),	/* [2] */
5717 		BTF_FUNC_PROTO_ENC(1, 2),			/* [3] */
5718 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5719 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5720 		BTF_FUNC_PROTO_ENC(1, 2),			/* [4] */
5721 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5722 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5723 		BTF_FUNC_ENC(NAME_TBD, 3),			/* [5] */
5724 		BTF_FUNC_ENC(NAME_TBD, 4),			/* [6] */
5725 		BTF_END_RAW,
5726 	},
5727 	.str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5728 	.str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5729 	.insns = {
5730 		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5731 		BPF_MOV64_IMM(BPF_REG_0, 1),
5732 		BPF_EXIT_INSN(),
5733 		BPF_MOV64_IMM(BPF_REG_0, 2),
5734 		BPF_EXIT_INSN(),
5735 	},
5736 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5737 	.func_info = { {0, 5}, {3, 6} },
5738 	.func_info_rec_size = 8,
5739 	.func_info_cnt = 1,
5740 	.line_info = { BTF_END_RAW },
5741 	.expected_prog_load_failure = true,
5742 },
5743 
5744 {
5745 	.descr = "func_type (Incorrect bpf_func_info.insn_off)",
5746 	.raw_types = {
5747 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5748 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),	/* [2] */
5749 		BTF_FUNC_PROTO_ENC(1, 2),			/* [3] */
5750 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5751 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5752 		BTF_FUNC_PROTO_ENC(1, 2),			/* [4] */
5753 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5754 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5755 		BTF_FUNC_ENC(NAME_TBD, 3),			/* [5] */
5756 		BTF_FUNC_ENC(NAME_TBD, 4),			/* [6] */
5757 		BTF_END_RAW,
5758 	},
5759 	.str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5760 	.str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5761 	.insns = {
5762 		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5763 		BPF_MOV64_IMM(BPF_REG_0, 1),
5764 		BPF_EXIT_INSN(),
5765 		BPF_MOV64_IMM(BPF_REG_0, 2),
5766 		BPF_EXIT_INSN(),
5767 	},
5768 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5769 	.func_info = { {0, 5}, {2, 6} },
5770 	.func_info_rec_size = 8,
5771 	.func_info_cnt = 2,
5772 	.line_info = { BTF_END_RAW },
5773 	.expected_prog_load_failure = true,
5774 },
5775 
5776 {
5777 	.descr = "line_info (No subprog)",
5778 	.raw_types = {
5779 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5780 		BTF_END_RAW,
5781 	},
5782 	BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5783 	.insns = {
5784 		BPF_MOV64_IMM(BPF_REG_0, 1),
5785 		BPF_MOV64_IMM(BPF_REG_1, 2),
5786 		BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5787 		BPF_EXIT_INSN(),
5788 	},
5789 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5790 	.func_info_cnt = 0,
5791 	.line_info = {
5792 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5793 		BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9),
5794 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5795 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7),
5796 		BTF_END_RAW,
5797 	},
5798 	.line_info_rec_size = sizeof(struct bpf_line_info),
5799 	.nr_jited_ksyms = 1,
5800 },
5801 
5802 {
5803 	.descr = "line_info (No subprog. insn_off >= prog->len)",
5804 	.raw_types = {
5805 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5806 		BTF_END_RAW,
5807 	},
5808 	BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5809 	.insns = {
5810 		BPF_MOV64_IMM(BPF_REG_0, 1),
5811 		BPF_MOV64_IMM(BPF_REG_1, 2),
5812 		BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5813 		BPF_EXIT_INSN(),
5814 	},
5815 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5816 	.func_info_cnt = 0,
5817 	.line_info = {
5818 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5819 		BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9),
5820 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5821 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7),
5822 		BPF_LINE_INFO_ENC(4, 0, 0, 5, 6),
5823 		BTF_END_RAW,
5824 	},
5825 	.line_info_rec_size = sizeof(struct bpf_line_info),
5826 	.nr_jited_ksyms = 1,
5827 	.err_str = "line_info[4].insn_off",
5828 	.expected_prog_load_failure = true,
5829 },
5830 
5831 {
5832 	.descr = "line_info (Zero bpf insn code)",
5833 	.raw_types = {
5834 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5835 		BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),	/* [2] */
5836 		BTF_TYPEDEF_ENC(NAME_TBD, 2),			/* [3] */
5837 		BTF_END_RAW,
5838 	},
5839 	BTF_STR_SEC("\0int\0unsigned long\0u64\0u64 a=1;\0return a;"),
5840 	.insns = {
5841 		BPF_LD_IMM64(BPF_REG_0, 1),
5842 		BPF_EXIT_INSN(),
5843 	},
5844 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5845 	.func_info_cnt = 0,
5846 	.line_info = {
5847 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5848 		BPF_LINE_INFO_ENC(1, 0, 0, 2, 9),
5849 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5850 		BTF_END_RAW,
5851 	},
5852 	.line_info_rec_size = sizeof(struct bpf_line_info),
5853 	.nr_jited_ksyms = 1,
5854 	.err_str = "Invalid insn code at line_info[1]",
5855 	.expected_prog_load_failure = true,
5856 },
5857 
5858 {
5859 	.descr = "line_info (No subprog. zero tailing line_info",
5860 	.raw_types = {
5861 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5862 		BTF_END_RAW,
5863 	},
5864 	BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5865 	.insns = {
5866 		BPF_MOV64_IMM(BPF_REG_0, 1),
5867 		BPF_MOV64_IMM(BPF_REG_1, 2),
5868 		BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5869 		BPF_EXIT_INSN(),
5870 	},
5871 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5872 	.func_info_cnt = 0,
5873 	.line_info = {
5874 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10), 0,
5875 		BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9), 0,
5876 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8), 0,
5877 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7), 0,
5878 		BTF_END_RAW,
5879 	},
5880 	.line_info_rec_size = sizeof(struct bpf_line_info) + sizeof(__u32),
5881 	.nr_jited_ksyms = 1,
5882 },
5883 
5884 {
5885 	.descr = "line_info (No subprog. nonzero tailing line_info)",
5886 	.raw_types = {
5887 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5888 		BTF_END_RAW,
5889 	},
5890 	BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5891 	.insns = {
5892 		BPF_MOV64_IMM(BPF_REG_0, 1),
5893 		BPF_MOV64_IMM(BPF_REG_1, 2),
5894 		BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5895 		BPF_EXIT_INSN(),
5896 	},
5897 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5898 	.func_info_cnt = 0,
5899 	.line_info = {
5900 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10), 0,
5901 		BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9), 0,
5902 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8), 0,
5903 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7), 1,
5904 		BTF_END_RAW,
5905 	},
5906 	.line_info_rec_size = sizeof(struct bpf_line_info) + sizeof(__u32),
5907 	.nr_jited_ksyms = 1,
5908 	.err_str = "nonzero tailing record in line_info",
5909 	.expected_prog_load_failure = true,
5910 },
5911 
5912 {
5913 	.descr = "line_info (subprog)",
5914 	.raw_types = {
5915 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5916 		BTF_END_RAW,
5917 	},
5918 	BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5919 	.insns = {
5920 		BPF_MOV64_IMM(BPF_REG_2, 1),
5921 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5922 		BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5923 		BPF_CALL_REL(1),
5924 		BPF_EXIT_INSN(),
5925 		BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5926 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5927 		BPF_EXIT_INSN(),
5928 	},
5929 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5930 	.func_info_cnt = 0,
5931 	.line_info = {
5932 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5933 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
5934 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 3, 8),
5935 		BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
5936 		BTF_END_RAW,
5937 	},
5938 	.line_info_rec_size = sizeof(struct bpf_line_info),
5939 	.nr_jited_ksyms = 2,
5940 },
5941 
5942 {
5943 	.descr = "line_info (subprog + func_info)",
5944 	.raw_types = {
5945 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5946 		BTF_FUNC_PROTO_ENC(1, 1),			/* [2] */
5947 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5948 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
5949 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [4] */
5950 		BTF_END_RAW,
5951 	},
5952 	BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5953 	.insns = {
5954 		BPF_MOV64_IMM(BPF_REG_2, 1),
5955 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5956 		BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5957 		BPF_CALL_REL(1),
5958 		BPF_EXIT_INSN(),
5959 		BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5960 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5961 		BPF_EXIT_INSN(),
5962 	},
5963 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5964 	.func_info_cnt = 2,
5965 	.func_info_rec_size = 8,
5966 	.func_info = { {0, 4}, {5, 3} },
5967 	.line_info = {
5968 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5969 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
5970 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 3, 8),
5971 		BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
5972 		BTF_END_RAW,
5973 	},
5974 	.line_info_rec_size = sizeof(struct bpf_line_info),
5975 	.nr_jited_ksyms = 2,
5976 },
5977 
5978 {
5979 	.descr = "line_info (subprog. missing 1st func line info)",
5980 	.raw_types = {
5981 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
5982 		BTF_END_RAW,
5983 	},
5984 	BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5985 	.insns = {
5986 		BPF_MOV64_IMM(BPF_REG_2, 1),
5987 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5988 		BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5989 		BPF_CALL_REL(1),
5990 		BPF_EXIT_INSN(),
5991 		BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5992 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5993 		BPF_EXIT_INSN(),
5994 	},
5995 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
5996 	.func_info_cnt = 0,
5997 	.line_info = {
5998 		BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 1, 10),
5999 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
6000 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 3, 8),
6001 		BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
6002 		BTF_END_RAW,
6003 	},
6004 	.line_info_rec_size = sizeof(struct bpf_line_info),
6005 	.nr_jited_ksyms = 2,
6006 	.err_str = "missing bpf_line_info for func#0",
6007 	.expected_prog_load_failure = true,
6008 },
6009 
6010 {
6011 	.descr = "line_info (subprog. missing 2nd func line info)",
6012 	.raw_types = {
6013 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6014 		BTF_END_RAW,
6015 	},
6016 	BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
6017 	.insns = {
6018 		BPF_MOV64_IMM(BPF_REG_2, 1),
6019 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
6020 		BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
6021 		BPF_CALL_REL(1),
6022 		BPF_EXIT_INSN(),
6023 		BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
6024 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6025 		BPF_EXIT_INSN(),
6026 	},
6027 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6028 	.func_info_cnt = 0,
6029 	.line_info = {
6030 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6031 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
6032 		BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 3, 8),
6033 		BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
6034 		BTF_END_RAW,
6035 	},
6036 	.line_info_rec_size = sizeof(struct bpf_line_info),
6037 	.nr_jited_ksyms = 2,
6038 	.err_str = "missing bpf_line_info for func#1",
6039 	.expected_prog_load_failure = true,
6040 },
6041 
6042 {
6043 	.descr = "line_info (subprog. unordered insn offset)",
6044 	.raw_types = {
6045 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6046 		BTF_END_RAW,
6047 	},
6048 	BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
6049 	.insns = {
6050 		BPF_MOV64_IMM(BPF_REG_2, 1),
6051 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
6052 		BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
6053 		BPF_CALL_REL(1),
6054 		BPF_EXIT_INSN(),
6055 		BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
6056 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6057 		BPF_EXIT_INSN(),
6058 	},
6059 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6060 	.func_info_cnt = 0,
6061 	.line_info = {
6062 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6063 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 2, 9),
6064 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
6065 		BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
6066 		BTF_END_RAW,
6067 	},
6068 	.line_info_rec_size = sizeof(struct bpf_line_info),
6069 	.nr_jited_ksyms = 2,
6070 	.err_str = "Invalid line_info[2].insn_off",
6071 	.expected_prog_load_failure = true,
6072 },
6073 
6074 {
6075 	.descr = "line_info (dead start)",
6076 	.raw_types = {
6077 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6078 		BTF_END_RAW,
6079 	},
6080 	BTF_STR_SEC("\0int\0/* dead jmp */\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
6081 	.insns = {
6082 		BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6083 		BPF_MOV64_IMM(BPF_REG_0, 1),
6084 		BPF_MOV64_IMM(BPF_REG_1, 2),
6085 		BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
6086 		BPF_EXIT_INSN(),
6087 	},
6088 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6089 	.func_info_cnt = 0,
6090 	.line_info = {
6091 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6092 		BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9),
6093 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
6094 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7),
6095 		BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 5, 6),
6096 		BTF_END_RAW,
6097 	},
6098 	.line_info_rec_size = sizeof(struct bpf_line_info),
6099 	.nr_jited_ksyms = 1,
6100 	.dead_code_cnt = 1,
6101 	.dead_code_mask = 0x01,
6102 },
6103 
6104 {
6105 	.descr = "line_info (dead end)",
6106 	.raw_types = {
6107 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6108 		BTF_END_RAW,
6109 	},
6110 	BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0/* dead jmp */\0return a + b;\0/* dead exit */"),
6111 	.insns = {
6112 		BPF_MOV64_IMM(BPF_REG_0, 1),
6113 		BPF_MOV64_IMM(BPF_REG_1, 2),
6114 		BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
6115 		BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 10, 1),
6116 		BPF_EXIT_INSN(),
6117 		BPF_EXIT_INSN(),
6118 	},
6119 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6120 	.func_info_cnt = 0,
6121 	.line_info = {
6122 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 12),
6123 		BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 11),
6124 		BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 10),
6125 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 9),
6126 		BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 5, 8),
6127 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 6, 7),
6128 		BTF_END_RAW,
6129 	},
6130 	.line_info_rec_size = sizeof(struct bpf_line_info),
6131 	.nr_jited_ksyms = 1,
6132 	.dead_code_cnt = 2,
6133 	.dead_code_mask = 0x28,
6134 },
6135 
6136 {
6137 	.descr = "line_info (dead code + subprog + func_info)",
6138 	.raw_types = {
6139 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6140 		BTF_FUNC_PROTO_ENC(1, 1),			/* [2] */
6141 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6142 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
6143 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [4] */
6144 		BTF_END_RAW,
6145 	},
6146 	BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0/* dead jmp */"
6147 		    "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
6148 		    "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
6149 		    "\0return func(a);\0b+=1;\0return b;"),
6150 	.insns = {
6151 		BPF_MOV64_IMM(BPF_REG_2, 1),
6152 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
6153 		BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
6154 		BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 8),
6155 		BPF_MOV64_IMM(BPF_REG_2, 1),
6156 		BPF_MOV64_IMM(BPF_REG_2, 1),
6157 		BPF_MOV64_IMM(BPF_REG_2, 1),
6158 		BPF_MOV64_IMM(BPF_REG_2, 1),
6159 		BPF_MOV64_IMM(BPF_REG_2, 1),
6160 		BPF_MOV64_IMM(BPF_REG_2, 1),
6161 		BPF_MOV64_IMM(BPF_REG_2, 1),
6162 		BPF_MOV64_IMM(BPF_REG_2, 1),
6163 		BPF_CALL_REL(1),
6164 		BPF_EXIT_INSN(),
6165 		BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
6166 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6167 		BPF_EXIT_INSN(),
6168 	},
6169 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6170 	.func_info_cnt = 2,
6171 	.func_info_rec_size = 8,
6172 	.func_info = { {0, 4}, {14, 3} },
6173 	.line_info = {
6174 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6175 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6176 		BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6177 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6178 		BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6179 		BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6180 		BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6181 		BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6182 		BPF_LINE_INFO_ENC(10, 0, NAME_TBD, 1, 10),
6183 		BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 2, 9),
6184 		BPF_LINE_INFO_ENC(12, 0, NAME_TBD, 2, 9),
6185 		BPF_LINE_INFO_ENC(14, 0, NAME_TBD, 3, 8),
6186 		BPF_LINE_INFO_ENC(16, 0, NAME_TBD, 4, 7),
6187 		BTF_END_RAW,
6188 	},
6189 	.line_info_rec_size = sizeof(struct bpf_line_info),
6190 	.nr_jited_ksyms = 2,
6191 	.dead_code_cnt = 9,
6192 	.dead_code_mask = 0x3fe,
6193 },
6194 
6195 {
6196 	.descr = "line_info (dead subprog)",
6197 	.raw_types = {
6198 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6199 		BTF_FUNC_PROTO_ENC(1, 1),			/* [2] */
6200 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6201 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
6202 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [4] */
6203 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [5] */
6204 		BTF_END_RAW,
6205 	},
6206 	BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
6207 		    "\0return 0;\0return 0;\0/* dead */\0/* dead */"
6208 		    "\0/* dead */\0return bla + 1;\0return bla + 1;"
6209 		    "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
6210 	.insns = {
6211 		BPF_MOV64_IMM(BPF_REG_2, 1),
6212 		BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6213 		BPF_CALL_REL(3),
6214 		BPF_CALL_REL(5),
6215 		BPF_MOV64_IMM(BPF_REG_0, 0),
6216 		BPF_EXIT_INSN(),
6217 		BPF_MOV64_IMM(BPF_REG_0, 0),
6218 		BPF_CALL_REL(1),
6219 		BPF_EXIT_INSN(),
6220 		BPF_MOV64_REG(BPF_REG_0, 2),
6221 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6222 		BPF_EXIT_INSN(),
6223 	},
6224 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6225 	.func_info_cnt = 3,
6226 	.func_info_rec_size = 8,
6227 		.func_info = { {0, 4}, {6, 3}, {9, 5} },
6228 	.line_info = {
6229 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6230 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6231 		BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6232 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6233 		BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6234 		BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6235 		BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6236 		BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6237 		BPF_LINE_INFO_ENC(10, 0, NAME_TBD, 1, 10),
6238 		BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 2, 9),
6239 		BTF_END_RAW,
6240 	},
6241 	.line_info_rec_size = sizeof(struct bpf_line_info),
6242 	.nr_jited_ksyms = 2,
6243 	.dead_code_cnt = 3,
6244 	.dead_code_mask = 0x70,
6245 	.dead_func_cnt = 1,
6246 	.dead_func_mask = 0x2,
6247 },
6248 
6249 {
6250 	.descr = "line_info (dead last subprog)",
6251 	.raw_types = {
6252 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6253 		BTF_FUNC_PROTO_ENC(1, 1),			/* [2] */
6254 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6255 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
6256 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [5] */
6257 		BTF_END_RAW,
6258 	},
6259 	BTF_STR_SEC("\0int\0x\0dead\0main\0int a=1+1;\0/* live call */"
6260 		    "\0return 0;\0/* dead */\0/* dead */"),
6261 	.insns = {
6262 		BPF_MOV64_IMM(BPF_REG_2, 1),
6263 		BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6264 		BPF_CALL_REL(2),
6265 		BPF_MOV64_IMM(BPF_REG_0, 0),
6266 		BPF_EXIT_INSN(),
6267 		BPF_MOV64_IMM(BPF_REG_0, 0),
6268 		BPF_EXIT_INSN(),
6269 	},
6270 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6271 	.func_info_cnt = 2,
6272 	.func_info_rec_size = 8,
6273 		.func_info = { {0, 4}, {5, 3} },
6274 	.line_info = {
6275 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6276 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6277 		BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6278 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6279 		BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6280 		BTF_END_RAW,
6281 	},
6282 	.line_info_rec_size = sizeof(struct bpf_line_info),
6283 	.nr_jited_ksyms = 1,
6284 	.dead_code_cnt = 2,
6285 	.dead_code_mask = 0x18,
6286 	.dead_func_cnt = 1,
6287 	.dead_func_mask = 0x2,
6288 },
6289 
6290 {
6291 	.descr = "line_info (dead subprog + dead start)",
6292 	.raw_types = {
6293 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6294 		BTF_FUNC_PROTO_ENC(1, 1),			/* [2] */
6295 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6296 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
6297 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [4] */
6298 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [5] */
6299 		BTF_END_RAW,
6300 	},
6301 	BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* dead */"
6302 		    "\0return 0;\0return 0;\0return 0;"
6303 		    "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
6304 		    "\0return b + 1;\0return b + 1;\0return b + 1;"),
6305 	.insns = {
6306 		BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6307 		BPF_MOV64_IMM(BPF_REG_2, 1),
6308 		BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6309 		BPF_CALL_REL(3),
6310 		BPF_CALL_REL(5),
6311 		BPF_MOV64_IMM(BPF_REG_0, 0),
6312 		BPF_EXIT_INSN(),
6313 		BPF_MOV64_IMM(BPF_REG_0, 0),
6314 		BPF_CALL_REL(1),
6315 		BPF_EXIT_INSN(),
6316 		BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6317 		BPF_MOV64_REG(BPF_REG_0, 2),
6318 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6319 		BPF_EXIT_INSN(),
6320 	},
6321 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6322 	.func_info_cnt = 3,
6323 	.func_info_rec_size = 8,
6324 		.func_info = { {0, 4}, {7, 3}, {10, 5} },
6325 	.line_info = {
6326 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6327 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6328 		BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6329 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6330 		BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6331 		BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6332 		BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6333 		BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6334 		BPF_LINE_INFO_ENC(10, 0, NAME_TBD, 1, 10),
6335 		BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 2, 9),
6336 		BPF_LINE_INFO_ENC(12, 0, NAME_TBD, 2, 9),
6337 		BPF_LINE_INFO_ENC(13, 0, NAME_TBD, 2, 9),
6338 		BTF_END_RAW,
6339 	},
6340 	.line_info_rec_size = sizeof(struct bpf_line_info),
6341 	.nr_jited_ksyms = 2,
6342 	.dead_code_cnt = 5,
6343 	.dead_code_mask = 0x1e2,
6344 	.dead_func_cnt = 1,
6345 	.dead_func_mask = 0x2,
6346 },
6347 
6348 {
6349 	.descr = "line_info (dead subprog + dead start w/ move)",
6350 	.raw_types = {
6351 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6352 		BTF_FUNC_PROTO_ENC(1, 1),			/* [2] */
6353 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6354 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
6355 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [4] */
6356 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [5] */
6357 		BTF_END_RAW,
6358 	},
6359 	BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
6360 		    "\0return 0;\0return 0;\0/* dead */\0/* dead */"
6361 		    "\0/* dead */\0return bla + 1;\0return bla + 1;"
6362 		    "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
6363 	.insns = {
6364 		BPF_MOV64_IMM(BPF_REG_2, 1),
6365 		BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6366 		BPF_CALL_REL(3),
6367 		BPF_CALL_REL(5),
6368 		BPF_MOV64_IMM(BPF_REG_0, 0),
6369 		BPF_EXIT_INSN(),
6370 		BPF_MOV64_IMM(BPF_REG_0, 0),
6371 		BPF_CALL_REL(1),
6372 		BPF_EXIT_INSN(),
6373 		BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6374 		BPF_MOV64_REG(BPF_REG_0, 2),
6375 		BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6376 		BPF_EXIT_INSN(),
6377 	},
6378 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6379 	.func_info_cnt = 3,
6380 	.func_info_rec_size = 8,
6381 		.func_info = { {0, 4}, {6, 3}, {9, 5} },
6382 	.line_info = {
6383 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6384 		BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6385 		BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6386 		BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6387 		BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6388 		BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6389 		BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6390 		BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6391 		BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 1, 10),
6392 		BPF_LINE_INFO_ENC(12, 0, NAME_TBD, 2, 9),
6393 		BTF_END_RAW,
6394 	},
6395 	.line_info_rec_size = sizeof(struct bpf_line_info),
6396 	.nr_jited_ksyms = 2,
6397 	.dead_code_cnt = 3,
6398 	.dead_code_mask = 0x70,
6399 	.dead_func_cnt = 1,
6400 	.dead_func_mask = 0x2,
6401 },
6402 
6403 {
6404 	.descr = "line_info (dead end + subprog start w/ no linfo)",
6405 	.raw_types = {
6406 		BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6407 		BTF_FUNC_PROTO_ENC(1, 1),			/* [2] */
6408 			BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6409 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [3] */
6410 		BTF_FUNC_ENC(NAME_TBD, 2),			/* [4] */
6411 		BTF_END_RAW,
6412 	},
6413 	BTF_STR_SEC("\0int\0x\0main\0func\0/* main linfo */\0/* func linfo */"),
6414 	.insns = {
6415 		BPF_MOV64_IMM(BPF_REG_0, 0),
6416 		BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 1, 3),
6417 		BPF_CALL_REL(3),
6418 		BPF_MOV64_IMM(BPF_REG_0, 0),
6419 		BPF_EXIT_INSN(),
6420 		BPF_EXIT_INSN(),
6421 		BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6422 		BPF_EXIT_INSN(),
6423 	},
6424 	.prog_type = BPF_PROG_TYPE_TRACEPOINT,
6425 	.func_info_cnt = 2,
6426 	.func_info_rec_size = 8,
6427 	.func_info = { {0, 3}, {6, 4}, },
6428 	.line_info = {
6429 		BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6430 		BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6431 		BTF_END_RAW,
6432 	},
6433 	.line_info_rec_size = sizeof(struct bpf_line_info),
6434 	.nr_jited_ksyms = 2,
6435 },
6436 
6437 };
6438 
6439 static size_t probe_prog_length(const struct bpf_insn *fp)
6440 {
6441 	size_t len;
6442 
6443 	for (len = MAX_INSNS - 1; len > 0; --len)
6444 		if (fp[len].code != 0 || fp[len].imm != 0)
6445 			break;
6446 	return len + 1;
6447 }
6448 
6449 static __u32 *patch_name_tbd(const __u32 *raw_u32,
6450 			     const char *str, __u32 str_off,
6451 			     unsigned int str_sec_size,
6452 			     unsigned int *ret_size)
6453 {
6454 	int i, raw_u32_size = get_raw_sec_size(raw_u32);
6455 	const char *end_str = str + str_sec_size;
6456 	const char *next_str = str + str_off;
6457 	__u32 *new_u32 = NULL;
6458 
6459 	if (raw_u32_size == -1)
6460 		return ERR_PTR(-EINVAL);
6461 
6462 	if (!raw_u32_size) {
6463 		*ret_size = 0;
6464 		return NULL;
6465 	}
6466 
6467 	new_u32 = malloc(raw_u32_size);
6468 	if (!new_u32)
6469 		return ERR_PTR(-ENOMEM);
6470 
6471 	for (i = 0; i < raw_u32_size / sizeof(raw_u32[0]); i++) {
6472 		if (raw_u32[i] == NAME_TBD) {
6473 			next_str = get_next_str(next_str, end_str);
6474 			if (CHECK(!next_str, "Error in getting next_str\n")) {
6475 				free(new_u32);
6476 				return ERR_PTR(-EINVAL);
6477 			}
6478 			new_u32[i] = next_str - str;
6479 			next_str += strlen(next_str);
6480 		} else {
6481 			new_u32[i] = raw_u32[i];
6482 		}
6483 	}
6484 
6485 	*ret_size = raw_u32_size;
6486 	return new_u32;
6487 }
6488 
6489 static int test_get_finfo(const struct prog_info_raw_test *test,
6490 			  int prog_fd)
6491 {
6492 	struct bpf_prog_info info = {};
6493 	struct bpf_func_info *finfo;
6494 	__u32 info_len, rec_size, i;
6495 	void *func_info = NULL;
6496 	__u32 nr_func_info;
6497 	int err;
6498 
6499 	/* get necessary lens */
6500 	info_len = sizeof(struct bpf_prog_info);
6501 	err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6502 	if (CHECK(err < 0, "invalid get info (1st) errno:%d", errno)) {
6503 		fprintf(stderr, "%s\n", btf_log_buf);
6504 		return -1;
6505 	}
6506 	nr_func_info = test->func_info_cnt - test->dead_func_cnt;
6507 	if (CHECK(info.nr_func_info != nr_func_info,
6508 		  "incorrect info.nr_func_info (1st) %d",
6509 		  info.nr_func_info)) {
6510 		return -1;
6511 	}
6512 
6513 	rec_size = info.func_info_rec_size;
6514 	if (CHECK(rec_size != sizeof(struct bpf_func_info),
6515 		  "incorrect info.func_info_rec_size (1st) %d", rec_size)) {
6516 		return -1;
6517 	}
6518 
6519 	if (!info.nr_func_info)
6520 		return 0;
6521 
6522 	func_info = malloc(info.nr_func_info * rec_size);
6523 	if (CHECK(!func_info, "out of memory"))
6524 		return -1;
6525 
6526 	/* reset info to only retrieve func_info related data */
6527 	memset(&info, 0, sizeof(info));
6528 	info.nr_func_info = nr_func_info;
6529 	info.func_info_rec_size = rec_size;
6530 	info.func_info = ptr_to_u64(func_info);
6531 	err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6532 	if (CHECK(err < 0, "invalid get info (2nd) errno:%d", errno)) {
6533 		fprintf(stderr, "%s\n", btf_log_buf);
6534 		err = -1;
6535 		goto done;
6536 	}
6537 	if (CHECK(info.nr_func_info != nr_func_info,
6538 		  "incorrect info.nr_func_info (2nd) %d",
6539 		  info.nr_func_info)) {
6540 		err = -1;
6541 		goto done;
6542 	}
6543 	if (CHECK(info.func_info_rec_size != rec_size,
6544 		  "incorrect info.func_info_rec_size (2nd) %d",
6545 		  info.func_info_rec_size)) {
6546 		err = -1;
6547 		goto done;
6548 	}
6549 
6550 	finfo = func_info;
6551 	for (i = 0; i < nr_func_info; i++) {
6552 		if (test->dead_func_mask & (1 << i))
6553 			continue;
6554 		if (CHECK(finfo->type_id != test->func_info[i][1],
6555 			  "incorrect func_type %u expected %u",
6556 			  finfo->type_id, test->func_info[i][1])) {
6557 			err = -1;
6558 			goto done;
6559 		}
6560 		finfo = (void *)finfo + rec_size;
6561 	}
6562 
6563 	err = 0;
6564 
6565 done:
6566 	free(func_info);
6567 	return err;
6568 }
6569 
6570 static int test_get_linfo(const struct prog_info_raw_test *test,
6571 			  const void *patched_linfo,
6572 			  __u32 cnt, int prog_fd)
6573 {
6574 	__u32 i, info_len, nr_jited_ksyms, nr_jited_func_lens;
6575 	__u64 *jited_linfo = NULL, *jited_ksyms = NULL;
6576 	__u32 rec_size, jited_rec_size, jited_cnt;
6577 	struct bpf_line_info *linfo = NULL;
6578 	__u32 cur_func_len, ksyms_found;
6579 	struct bpf_prog_info info = {};
6580 	__u32 *jited_func_lens = NULL;
6581 	__u64 cur_func_ksyms;
6582 	__u32 dead_insns;
6583 	int err;
6584 
6585 	jited_cnt = cnt;
6586 	rec_size = sizeof(*linfo);
6587 	jited_rec_size = sizeof(*jited_linfo);
6588 	if (test->nr_jited_ksyms)
6589 		nr_jited_ksyms = test->nr_jited_ksyms;
6590 	else
6591 		nr_jited_ksyms = test->func_info_cnt - test->dead_func_cnt;
6592 	nr_jited_func_lens = nr_jited_ksyms;
6593 
6594 	info_len = sizeof(struct bpf_prog_info);
6595 	err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6596 	if (CHECK(err < 0, "err:%d errno:%d", err, errno)) {
6597 		err = -1;
6598 		goto done;
6599 	}
6600 
6601 	if (!info.jited_prog_len) {
6602 		/* prog is not jited */
6603 		jited_cnt = 0;
6604 		nr_jited_ksyms = 1;
6605 		nr_jited_func_lens = 1;
6606 	}
6607 
6608 	if (CHECK(info.nr_line_info != cnt ||
6609 		  info.nr_jited_line_info != jited_cnt ||
6610 		  info.nr_jited_ksyms != nr_jited_ksyms ||
6611 		  info.nr_jited_func_lens != nr_jited_func_lens ||
6612 		  (!info.nr_line_info && info.nr_jited_line_info),
6613 		  "info: nr_line_info:%u(expected:%u) nr_jited_line_info:%u(expected:%u) nr_jited_ksyms:%u(expected:%u) nr_jited_func_lens:%u(expected:%u)",
6614 		  info.nr_line_info, cnt,
6615 		  info.nr_jited_line_info, jited_cnt,
6616 		  info.nr_jited_ksyms, nr_jited_ksyms,
6617 		  info.nr_jited_func_lens, nr_jited_func_lens)) {
6618 		err = -1;
6619 		goto done;
6620 	}
6621 
6622 	if (CHECK(info.line_info_rec_size != sizeof(struct bpf_line_info) ||
6623 		  info.jited_line_info_rec_size != sizeof(__u64),
6624 		  "info: line_info_rec_size:%u(userspace expected:%u) jited_line_info_rec_size:%u(userspace expected:%u)",
6625 		  info.line_info_rec_size, rec_size,
6626 		  info.jited_line_info_rec_size, jited_rec_size)) {
6627 		err = -1;
6628 		goto done;
6629 	}
6630 
6631 	if (!cnt)
6632 		return 0;
6633 
6634 	rec_size = info.line_info_rec_size;
6635 	jited_rec_size = info.jited_line_info_rec_size;
6636 
6637 	memset(&info, 0, sizeof(info));
6638 
6639 	linfo = calloc(cnt, rec_size);
6640 	if (CHECK(!linfo, "!linfo")) {
6641 		err = -1;
6642 		goto done;
6643 	}
6644 	info.nr_line_info = cnt;
6645 	info.line_info_rec_size = rec_size;
6646 	info.line_info = ptr_to_u64(linfo);
6647 
6648 	if (jited_cnt) {
6649 		jited_linfo = calloc(jited_cnt, jited_rec_size);
6650 		jited_ksyms = calloc(nr_jited_ksyms, sizeof(*jited_ksyms));
6651 		jited_func_lens = calloc(nr_jited_func_lens,
6652 					 sizeof(*jited_func_lens));
6653 		if (CHECK(!jited_linfo || !jited_ksyms || !jited_func_lens,
6654 			  "jited_linfo:%p jited_ksyms:%p jited_func_lens:%p",
6655 			  jited_linfo, jited_ksyms, jited_func_lens)) {
6656 			err = -1;
6657 			goto done;
6658 		}
6659 
6660 		info.nr_jited_line_info = jited_cnt;
6661 		info.jited_line_info_rec_size = jited_rec_size;
6662 		info.jited_line_info = ptr_to_u64(jited_linfo);
6663 		info.nr_jited_ksyms = nr_jited_ksyms;
6664 		info.jited_ksyms = ptr_to_u64(jited_ksyms);
6665 		info.nr_jited_func_lens = nr_jited_func_lens;
6666 		info.jited_func_lens = ptr_to_u64(jited_func_lens);
6667 	}
6668 
6669 	err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6670 
6671 	/*
6672 	 * Only recheck the info.*line_info* fields.
6673 	 * Other fields are not the concern of this test.
6674 	 */
6675 	if (CHECK(err < 0 ||
6676 		  info.nr_line_info != cnt ||
6677 		  (jited_cnt && !info.jited_line_info) ||
6678 		  info.nr_jited_line_info != jited_cnt ||
6679 		  info.line_info_rec_size != rec_size ||
6680 		  info.jited_line_info_rec_size != jited_rec_size,
6681 		  "err:%d errno:%d info: nr_line_info:%u(expected:%u) nr_jited_line_info:%u(expected:%u) line_info_rec_size:%u(expected:%u) jited_linfo_rec_size:%u(expected:%u) line_info:%p jited_line_info:%p",
6682 		  err, errno,
6683 		  info.nr_line_info, cnt,
6684 		  info.nr_jited_line_info, jited_cnt,
6685 		  info.line_info_rec_size, rec_size,
6686 		  info.jited_line_info_rec_size, jited_rec_size,
6687 		  (void *)(long)info.line_info,
6688 		  (void *)(long)info.jited_line_info)) {
6689 		err = -1;
6690 		goto done;
6691 	}
6692 
6693 	dead_insns = 0;
6694 	while (test->dead_code_mask & (1 << dead_insns))
6695 		dead_insns++;
6696 
6697 	CHECK(linfo[0].insn_off, "linfo[0].insn_off:%u",
6698 	      linfo[0].insn_off);
6699 	for (i = 1; i < cnt; i++) {
6700 		const struct bpf_line_info *expected_linfo;
6701 
6702 		while (test->dead_code_mask & (1 << (i + dead_insns)))
6703 			dead_insns++;
6704 
6705 		expected_linfo = patched_linfo +
6706 			((i + dead_insns) * test->line_info_rec_size);
6707 		if (CHECK(linfo[i].insn_off <= linfo[i - 1].insn_off,
6708 			  "linfo[%u].insn_off:%u <= linfo[%u].insn_off:%u",
6709 			  i, linfo[i].insn_off,
6710 			  i - 1, linfo[i - 1].insn_off)) {
6711 			err = -1;
6712 			goto done;
6713 		}
6714 		if (CHECK(linfo[i].file_name_off != expected_linfo->file_name_off ||
6715 			  linfo[i].line_off != expected_linfo->line_off ||
6716 			  linfo[i].line_col != expected_linfo->line_col,
6717 			  "linfo[%u] (%u, %u, %u) != (%u, %u, %u)", i,
6718 			  linfo[i].file_name_off,
6719 			  linfo[i].line_off,
6720 			  linfo[i].line_col,
6721 			  expected_linfo->file_name_off,
6722 			  expected_linfo->line_off,
6723 			  expected_linfo->line_col)) {
6724 			err = -1;
6725 			goto done;
6726 		}
6727 	}
6728 
6729 	if (!jited_cnt) {
6730 		fprintf(stderr, "not jited. skipping jited_line_info check. ");
6731 		err = 0;
6732 		goto done;
6733 	}
6734 
6735 	if (CHECK(jited_linfo[0] != jited_ksyms[0],
6736 		  "jited_linfo[0]:%lx != jited_ksyms[0]:%lx",
6737 		  (long)(jited_linfo[0]), (long)(jited_ksyms[0]))) {
6738 		err = -1;
6739 		goto done;
6740 	}
6741 
6742 	ksyms_found = 1;
6743 	cur_func_len = jited_func_lens[0];
6744 	cur_func_ksyms = jited_ksyms[0];
6745 	for (i = 1; i < jited_cnt; i++) {
6746 		if (ksyms_found < nr_jited_ksyms &&
6747 		    jited_linfo[i] == jited_ksyms[ksyms_found]) {
6748 			cur_func_ksyms = jited_ksyms[ksyms_found];
6749 			cur_func_len = jited_ksyms[ksyms_found];
6750 			ksyms_found++;
6751 			continue;
6752 		}
6753 
6754 		if (CHECK(jited_linfo[i] <= jited_linfo[i - 1],
6755 			  "jited_linfo[%u]:%lx <= jited_linfo[%u]:%lx",
6756 			  i, (long)jited_linfo[i],
6757 			  i - 1, (long)(jited_linfo[i - 1]))) {
6758 			err = -1;
6759 			goto done;
6760 		}
6761 
6762 		if (CHECK(jited_linfo[i] - cur_func_ksyms > cur_func_len,
6763 			  "jited_linfo[%u]:%lx - %lx > %u",
6764 			  i, (long)jited_linfo[i], (long)cur_func_ksyms,
6765 			  cur_func_len)) {
6766 			err = -1;
6767 			goto done;
6768 		}
6769 	}
6770 
6771 	if (CHECK(ksyms_found != nr_jited_ksyms,
6772 		  "ksyms_found:%u != nr_jited_ksyms:%u",
6773 		  ksyms_found, nr_jited_ksyms)) {
6774 		err = -1;
6775 		goto done;
6776 	}
6777 
6778 	err = 0;
6779 
6780 done:
6781 	free(linfo);
6782 	free(jited_linfo);
6783 	free(jited_ksyms);
6784 	free(jited_func_lens);
6785 	return err;
6786 }
6787 
6788 static void do_test_info_raw(unsigned int test_num)
6789 {
6790 	const struct prog_info_raw_test *test = &info_raw_tests[test_num - 1];
6791 	unsigned int raw_btf_size, linfo_str_off, linfo_size = 0;
6792 	int btf_fd = -1, prog_fd = -1, err = 0;
6793 	void *raw_btf, *patched_linfo = NULL;
6794 	const char *ret_next_str;
6795 	union bpf_attr attr = {};
6796 
6797 	if (!test__start_subtest(test->descr))
6798 		return;
6799 
6800 	raw_btf = btf_raw_create(&hdr_tmpl, test->raw_types,
6801 				 test->str_sec, test->str_sec_size,
6802 				 &raw_btf_size, &ret_next_str);
6803 	if (!raw_btf)
6804 		return;
6805 
6806 	*btf_log_buf = '\0';
6807 	btf_fd = load_raw_btf(raw_btf, raw_btf_size);
6808 	free(raw_btf);
6809 
6810 	if (CHECK(btf_fd < 0, "invalid btf_fd errno:%d", errno)) {
6811 		err = -1;
6812 		goto done;
6813 	}
6814 
6815 	if (*btf_log_buf && always_log)
6816 		fprintf(stderr, "\n%s", btf_log_buf);
6817 	*btf_log_buf = '\0';
6818 
6819 	linfo_str_off = ret_next_str - test->str_sec;
6820 	patched_linfo = patch_name_tbd(test->line_info,
6821 				       test->str_sec, linfo_str_off,
6822 				       test->str_sec_size, &linfo_size);
6823 	err = libbpf_get_error(patched_linfo);
6824 	if (err) {
6825 		fprintf(stderr, "error in creating raw bpf_line_info");
6826 		err = -1;
6827 		goto done;
6828 	}
6829 
6830 	attr.prog_type = test->prog_type;
6831 	attr.insns = ptr_to_u64(test->insns);
6832 	attr.insn_cnt = probe_prog_length(test->insns);
6833 	attr.license = ptr_to_u64("GPL");
6834 	attr.prog_btf_fd = btf_fd;
6835 	attr.func_info_rec_size = test->func_info_rec_size;
6836 	attr.func_info_cnt = test->func_info_cnt;
6837 	attr.func_info = ptr_to_u64(test->func_info);
6838 	attr.log_buf = ptr_to_u64(btf_log_buf);
6839 	attr.log_size = BTF_LOG_BUF_SIZE;
6840 	attr.log_level = 1;
6841 	if (linfo_size) {
6842 		attr.line_info_rec_size = test->line_info_rec_size;
6843 		attr.line_info = ptr_to_u64(patched_linfo);
6844 		attr.line_info_cnt = linfo_size / attr.line_info_rec_size;
6845 	}
6846 
6847 	prog_fd = syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
6848 	err = ((prog_fd < 0) != test->expected_prog_load_failure);
6849 	if (CHECK(err, "prog_fd:%d expected_prog_load_failure:%u errno:%d",
6850 		  prog_fd, test->expected_prog_load_failure, errno) ||
6851 	    CHECK(test->err_str && !strstr(btf_log_buf, test->err_str),
6852 		  "expected err_str:%s", test->err_str)) {
6853 		err = -1;
6854 		goto done;
6855 	}
6856 
6857 	if (prog_fd < 0)
6858 		goto done;
6859 
6860 	err = test_get_finfo(test, prog_fd);
6861 	if (err)
6862 		goto done;
6863 
6864 	err = test_get_linfo(test, patched_linfo,
6865 			     attr.line_info_cnt - test->dead_code_cnt,
6866 			     prog_fd);
6867 	if (err)
6868 		goto done;
6869 
6870 done:
6871 	if (*btf_log_buf && (err || always_log))
6872 		fprintf(stderr, "\n%s", btf_log_buf);
6873 
6874 	if (btf_fd >= 0)
6875 		close(btf_fd);
6876 	if (prog_fd >= 0)
6877 		close(prog_fd);
6878 
6879 	if (!libbpf_get_error(patched_linfo))
6880 		free(patched_linfo);
6881 }
6882 
6883 struct btf_raw_data {
6884 	__u32 raw_types[MAX_NR_RAW_U32];
6885 	const char *str_sec;
6886 	__u32 str_sec_size;
6887 };
6888 
6889 struct btf_dedup_test {
6890 	const char *descr;
6891 	struct btf_raw_data input;
6892 	struct btf_raw_data expect;
6893 	struct btf_dedup_opts opts;
6894 };
6895 
6896 static struct btf_dedup_test dedup_tests[] = {
6897 
6898 {
6899 	.descr = "dedup: unused strings filtering",
6900 	.input = {
6901 		.raw_types = {
6902 			BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 32, 4),
6903 			BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED, 0, 64, 8),
6904 			BTF_END_RAW,
6905 		},
6906 		BTF_STR_SEC("\0unused\0int\0foo\0bar\0long"),
6907 	},
6908 	.expect = {
6909 		.raw_types = {
6910 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
6911 			BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 64, 8),
6912 			BTF_END_RAW,
6913 		},
6914 		BTF_STR_SEC("\0int\0long"),
6915 	},
6916 },
6917 {
6918 	.descr = "dedup: strings deduplication",
6919 	.input = {
6920 		.raw_types = {
6921 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
6922 			BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 64, 8),
6923 			BTF_TYPE_INT_ENC(NAME_NTH(3), BTF_INT_SIGNED, 0, 32, 4),
6924 			BTF_TYPE_INT_ENC(NAME_NTH(4), BTF_INT_SIGNED, 0, 64, 8),
6925 			BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED, 0, 32, 4),
6926 			BTF_END_RAW,
6927 		},
6928 		BTF_STR_SEC("\0int\0long int\0int\0long int\0int"),
6929 	},
6930 	.expect = {
6931 		.raw_types = {
6932 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
6933 			BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 64, 8),
6934 			BTF_END_RAW,
6935 		},
6936 		BTF_STR_SEC("\0int\0long int"),
6937 	},
6938 },
6939 {
6940 	.descr = "dedup: struct example #1",
6941 	/*
6942 	 * struct s {
6943 	 *	struct s *next;
6944 	 *	const int *a;
6945 	 *	int b[16];
6946 	 *	int c;
6947 	 * }
6948 	 */
6949 	.input = {
6950 		.raw_types = {
6951 			/* int */
6952 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6953 			/* int[16] */
6954 			BTF_TYPE_ARRAY_ENC(1, 1, 16),					/* [2] */
6955 			/* struct s { */
6956 			BTF_STRUCT_ENC(NAME_NTH(2), 5, 88),				/* [3] */
6957 				BTF_MEMBER_ENC(NAME_NTH(3), 4, 0),	/* struct s *next;	*/
6958 				BTF_MEMBER_ENC(NAME_NTH(4), 5, 64),	/* const int *a;	*/
6959 				BTF_MEMBER_ENC(NAME_NTH(5), 2, 128),	/* int b[16];		*/
6960 				BTF_MEMBER_ENC(NAME_NTH(6), 1, 640),	/* int c;		*/
6961 				BTF_MEMBER_ENC(NAME_NTH(8), 15, 672),	/* float d;		*/
6962 			/* ptr -> [3] struct s */
6963 			BTF_PTR_ENC(3),							/* [4] */
6964 			/* ptr -> [6] const int */
6965 			BTF_PTR_ENC(6),							/* [5] */
6966 			/* const -> [1] int */
6967 			BTF_CONST_ENC(1),						/* [6] */
6968 			/* tag -> [3] struct s */
6969 			BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1),				/* [7] */
6970 			/* tag -> [3] struct s, member 1 */
6971 			BTF_DECL_TAG_ENC(NAME_NTH(2), 3, 1),				/* [8] */
6972 
6973 			/* full copy of the above */
6974 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),	/* [9] */
6975 			BTF_TYPE_ARRAY_ENC(9, 9, 16),					/* [10] */
6976 			BTF_STRUCT_ENC(NAME_NTH(2), 5, 88),				/* [11] */
6977 				BTF_MEMBER_ENC(NAME_NTH(3), 12, 0),
6978 				BTF_MEMBER_ENC(NAME_NTH(4), 13, 64),
6979 				BTF_MEMBER_ENC(NAME_NTH(5), 10, 128),
6980 				BTF_MEMBER_ENC(NAME_NTH(6), 9, 640),
6981 				BTF_MEMBER_ENC(NAME_NTH(8), 15, 672),
6982 			BTF_PTR_ENC(11),						/* [12] */
6983 			BTF_PTR_ENC(14),						/* [13] */
6984 			BTF_CONST_ENC(9),						/* [14] */
6985 			BTF_TYPE_FLOAT_ENC(NAME_NTH(7), 4),				/* [15] */
6986 			BTF_DECL_TAG_ENC(NAME_NTH(2), 11, -1),				/* [16] */
6987 			BTF_DECL_TAG_ENC(NAME_NTH(2), 11, 1),				/* [17] */
6988 			BTF_END_RAW,
6989 		},
6990 		BTF_STR_SEC("\0int\0s\0next\0a\0b\0c\0float\0d"),
6991 	},
6992 	.expect = {
6993 		.raw_types = {
6994 			/* int */
6995 			BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
6996 			/* int[16] */
6997 			BTF_TYPE_ARRAY_ENC(1, 1, 16),					/* [2] */
6998 			/* struct s { */
6999 			BTF_STRUCT_ENC(NAME_NTH(8), 5, 88),				/* [3] */
7000 				BTF_MEMBER_ENC(NAME_NTH(7), 4, 0),	/* struct s *next;	*/
7001 				BTF_MEMBER_ENC(NAME_NTH(1), 5, 64),	/* const int *a;	*/
7002 				BTF_MEMBER_ENC(NAME_NTH(2), 2, 128),	/* int b[16];		*/
7003 				BTF_MEMBER_ENC(NAME_NTH(3), 1, 640),	/* int c;		*/
7004 				BTF_MEMBER_ENC(NAME_NTH(4), 9, 672),	/* float d;		*/
7005 			/* ptr -> [3] struct s */
7006 			BTF_PTR_ENC(3),							/* [4] */
7007 			/* ptr -> [6] const int */
7008 			BTF_PTR_ENC(6),							/* [5] */
7009 			/* const -> [1] int */
7010 			BTF_CONST_ENC(1),						/* [6] */
7011 			BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1),				/* [7] */
7012 			BTF_DECL_TAG_ENC(NAME_NTH(2), 3, 1),				/* [8] */
7013 			BTF_TYPE_FLOAT_ENC(NAME_NTH(7), 4),				/* [9] */
7014 			BTF_END_RAW,
7015 		},
7016 		BTF_STR_SEC("\0a\0b\0c\0d\0int\0float\0next\0s"),
7017 	},
7018 },
7019 {
7020 	.descr = "dedup: struct <-> fwd resolution w/ hash collision",
7021 	/*
7022 	 * // CU 1:
7023 	 * struct x;
7024 	 * struct s {
7025 	 *	struct x *x;
7026 	 * };
7027 	 * // CU 2:
7028 	 * struct x {};
7029 	 * struct s {
7030 	 *	struct x *x;
7031 	 * };
7032 	 */
7033 	.input = {
7034 		.raw_types = {
7035 			/* CU 1 */
7036 			BTF_FWD_ENC(NAME_TBD, 0 /* struct fwd */),	/* [1] fwd x      */
7037 			BTF_PTR_ENC(1),					/* [2] ptr -> [1] */
7038 			BTF_STRUCT_ENC(NAME_TBD, 1, 8),			/* [3] struct s   */
7039 				BTF_MEMBER_ENC(NAME_TBD, 2, 0),
7040 			/* CU 2 */
7041 			BTF_STRUCT_ENC(NAME_TBD, 0, 0),			/* [4] struct x   */
7042 			BTF_PTR_ENC(4),					/* [5] ptr -> [4] */
7043 			BTF_STRUCT_ENC(NAME_TBD, 1, 8),			/* [6] struct s   */
7044 				BTF_MEMBER_ENC(NAME_TBD, 5, 0),
7045 			BTF_END_RAW,
7046 		},
7047 		BTF_STR_SEC("\0x\0s\0x\0x\0s\0x\0"),
7048 	},
7049 	.expect = {
7050 		.raw_types = {
7051 			BTF_PTR_ENC(3),					/* [1] ptr -> [3] */
7052 			BTF_STRUCT_ENC(NAME_TBD, 1, 8),			/* [2] struct s   */
7053 				BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7054 			BTF_STRUCT_ENC(NAME_NTH(2), 0, 0),		/* [3] struct x   */
7055 			BTF_END_RAW,
7056 		},
7057 		BTF_STR_SEC("\0s\0x"),
7058 	},
7059 	.opts = {
7060 		.force_collisions = true, /* force hash collisions */
7061 	},
7062 },
7063 {
7064 	.descr = "dedup: void equiv check",
7065 	/*
7066 	 * // CU 1:
7067 	 * struct s {
7068 	 *	struct {} *x;
7069 	 * };
7070 	 * // CU 2:
7071 	 * struct s {
7072 	 *	int *x;
7073 	 * };
7074 	 */
7075 	.input = {
7076 		.raw_types = {
7077 			/* CU 1 */
7078 			BTF_STRUCT_ENC(0, 0, 1),				/* [1] struct {}  */
7079 			BTF_PTR_ENC(1),						/* [2] ptr -> [1] */
7080 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 8),			/* [3] struct s   */
7081 				BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7082 			/* CU 2 */
7083 			BTF_PTR_ENC(0),						/* [4] ptr -> void */
7084 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 8),			/* [5] struct s   */
7085 				BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
7086 			BTF_END_RAW,
7087 		},
7088 		BTF_STR_SEC("\0s\0x"),
7089 	},
7090 	.expect = {
7091 		.raw_types = {
7092 			/* CU 1 */
7093 			BTF_STRUCT_ENC(0, 0, 1),				/* [1] struct {}  */
7094 			BTF_PTR_ENC(1),						/* [2] ptr -> [1] */
7095 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 8),			/* [3] struct s   */
7096 				BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7097 			/* CU 2 */
7098 			BTF_PTR_ENC(0),						/* [4] ptr -> void */
7099 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 8),			/* [5] struct s   */
7100 				BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
7101 			BTF_END_RAW,
7102 		},
7103 		BTF_STR_SEC("\0s\0x"),
7104 	},
7105 	.opts = {
7106 		.force_collisions = true, /* force hash collisions */
7107 	},
7108 },
7109 {
7110 	.descr = "dedup: all possible kinds (no duplicates)",
7111 	.input = {
7112 		.raw_types = {
7113 			BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 8),		/* [1] int */
7114 			BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 4),	/* [2] enum */
7115 				BTF_ENUM_ENC(NAME_TBD, 0),
7116 				BTF_ENUM_ENC(NAME_TBD, 1),
7117 			BTF_FWD_ENC(NAME_TBD, 1 /* union kind_flag */),			/* [3] fwd */
7118 			BTF_TYPE_ARRAY_ENC(2, 1, 7),					/* [4] array */
7119 			BTF_STRUCT_ENC(NAME_TBD, 1, 4),					/* [5] struct */
7120 				BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7121 			BTF_UNION_ENC(NAME_TBD, 1, 4),					/* [6] union */
7122 				BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7123 			BTF_TYPEDEF_ENC(NAME_TBD, 1),					/* [7] typedef */
7124 			BTF_PTR_ENC(0),							/* [8] ptr */
7125 			BTF_CONST_ENC(8),						/* [9] const */
7126 			BTF_VOLATILE_ENC(8),						/* [10] volatile */
7127 			BTF_RESTRICT_ENC(8),						/* [11] restrict */
7128 			BTF_FUNC_PROTO_ENC(1, 2),					/* [12] func_proto */
7129 				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
7130 				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
7131 			BTF_FUNC_ENC(NAME_TBD, 12),					/* [13] func */
7132 			BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),				/* [14] float */
7133 			BTF_DECL_TAG_ENC(NAME_TBD, 13, -1),				/* [15] decl_tag */
7134 			BTF_DECL_TAG_ENC(NAME_TBD, 13, 1),				/* [16] decl_tag */
7135 			BTF_DECL_TAG_ENC(NAME_TBD, 7, -1),				/* [17] decl_tag */
7136 			BTF_TYPE_TAG_ENC(NAME_TBD, 8),					/* [18] type_tag */
7137 			BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 2), 8),	/* [19] enum64 */
7138 				BTF_ENUM64_ENC(NAME_TBD, 0, 0),
7139 				BTF_ENUM64_ENC(NAME_TBD, 1, 1),
7140 			BTF_END_RAW,
7141 		},
7142 		BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R\0S\0T\0U"),
7143 	},
7144 	.expect = {
7145 		.raw_types = {
7146 			BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 8),		/* [1] int */
7147 			BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 4),	/* [2] enum */
7148 				BTF_ENUM_ENC(NAME_TBD, 0),
7149 				BTF_ENUM_ENC(NAME_TBD, 1),
7150 			BTF_FWD_ENC(NAME_TBD, 1 /* union kind_flag */),			/* [3] fwd */
7151 			BTF_TYPE_ARRAY_ENC(2, 1, 7),					/* [4] array */
7152 			BTF_STRUCT_ENC(NAME_TBD, 1, 4),					/* [5] struct */
7153 				BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7154 			BTF_UNION_ENC(NAME_TBD, 1, 4),					/* [6] union */
7155 				BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7156 			BTF_TYPEDEF_ENC(NAME_TBD, 1),					/* [7] typedef */
7157 			BTF_PTR_ENC(0),							/* [8] ptr */
7158 			BTF_CONST_ENC(8),						/* [9] const */
7159 			BTF_VOLATILE_ENC(8),						/* [10] volatile */
7160 			BTF_RESTRICT_ENC(8),						/* [11] restrict */
7161 			BTF_FUNC_PROTO_ENC(1, 2),					/* [12] func_proto */
7162 				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
7163 				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
7164 			BTF_FUNC_ENC(NAME_TBD, 12),					/* [13] func */
7165 			BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),				/* [14] float */
7166 			BTF_DECL_TAG_ENC(NAME_TBD, 13, -1),				/* [15] decl_tag */
7167 			BTF_DECL_TAG_ENC(NAME_TBD, 13, 1),				/* [16] decl_tag */
7168 			BTF_DECL_TAG_ENC(NAME_TBD, 7, -1),				/* [17] decl_tag */
7169 			BTF_TYPE_TAG_ENC(NAME_TBD, 8),					/* [18] type_tag */
7170 			BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 2), 8),	/* [19] enum64 */
7171 				BTF_ENUM64_ENC(NAME_TBD, 0, 0),
7172 				BTF_ENUM64_ENC(NAME_TBD, 1, 1),
7173 			BTF_END_RAW,
7174 		},
7175 		BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R\0S\0T\0U"),
7176 	},
7177 },
7178 {
7179 	.descr = "dedup: no int/float duplicates",
7180 	.input = {
7181 		.raw_types = {
7182 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 8),
7183 			/* different name */
7184 			BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 32, 8),
7185 			/* different encoding */
7186 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR, 0, 32, 8),
7187 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL, 0, 32, 8),
7188 			/* different bit offset */
7189 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 8, 32, 8),
7190 			/* different bit size */
7191 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 27, 8),
7192 			/* different byte size */
7193 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
7194 			/* all allowed sizes */
7195 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 2),
7196 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 4),
7197 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 8),
7198 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 12),
7199 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 16),
7200 			BTF_END_RAW,
7201 		},
7202 		BTF_STR_SEC("\0int\0some other int\0float"),
7203 	},
7204 	.expect = {
7205 		.raw_types = {
7206 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 8),
7207 			/* different name */
7208 			BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 32, 8),
7209 			/* different encoding */
7210 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR, 0, 32, 8),
7211 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL, 0, 32, 8),
7212 			/* different bit offset */
7213 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 8, 32, 8),
7214 			/* different bit size */
7215 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 27, 8),
7216 			/* different byte size */
7217 			BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
7218 			/* all allowed sizes */
7219 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 2),
7220 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 4),
7221 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 8),
7222 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 12),
7223 			BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 16),
7224 			BTF_END_RAW,
7225 		},
7226 		BTF_STR_SEC("\0int\0some other int\0float"),
7227 	},
7228 },
7229 {
7230 	.descr = "dedup: enum fwd resolution",
7231 	.input = {
7232 		.raw_types = {
7233 			/* [1] fwd enum 'e1' before full enum */
7234 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 4),
7235 			/* [2] full enum 'e1' after fwd */
7236 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7237 				BTF_ENUM_ENC(NAME_NTH(2), 123),
7238 			/* [3] full enum 'e2' before fwd */
7239 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7240 				BTF_ENUM_ENC(NAME_NTH(4), 456),
7241 			/* [4] fwd enum 'e2' after full enum */
7242 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 4),
7243 			/* [5] fwd enum with different size, size does not matter for fwd */
7244 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 1),
7245 			/* [6] incompatible full enum with different value */
7246 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7247 				BTF_ENUM_ENC(NAME_NTH(2), 321),
7248 			BTF_END_RAW,
7249 		},
7250 		BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7251 	},
7252 	.expect = {
7253 		.raw_types = {
7254 			/* [1] full enum 'e1' */
7255 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7256 				BTF_ENUM_ENC(NAME_NTH(2), 123),
7257 			/* [2] full enum 'e2' */
7258 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7259 				BTF_ENUM_ENC(NAME_NTH(4), 456),
7260 			/* [3] incompatible full enum with different value */
7261 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7262 				BTF_ENUM_ENC(NAME_NTH(2), 321),
7263 			BTF_END_RAW,
7264 		},
7265 		BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7266 	},
7267 },
7268 {
7269 	.descr = "dedup: datasec and vars pass-through",
7270 	.input = {
7271 		.raw_types = {
7272 			/* int */
7273 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7274 			/* static int t */
7275 			BTF_VAR_ENC(NAME_NTH(2), 1, 0),			/* [2] */
7276 			/* .bss section */				/* [3] */
7277 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7278 			BTF_VAR_SECINFO_ENC(2, 0, 4),
7279 			/* int, referenced from [5] */
7280 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [4] */
7281 			/* another static int t */
7282 			BTF_VAR_ENC(NAME_NTH(2), 4, 0),			/* [5] */
7283 			/* another .bss section */			/* [6] */
7284 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7285 			BTF_VAR_SECINFO_ENC(5, 0, 4),
7286 			BTF_END_RAW,
7287 		},
7288 		BTF_STR_SEC("\0.bss\0t"),
7289 	},
7290 	.expect = {
7291 		.raw_types = {
7292 			/* int */
7293 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7294 			/* static int t */
7295 			BTF_VAR_ENC(NAME_NTH(2), 1, 0),			/* [2] */
7296 			/* .bss section */				/* [3] */
7297 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7298 			BTF_VAR_SECINFO_ENC(2, 0, 4),
7299 			/* another static int t */
7300 			BTF_VAR_ENC(NAME_NTH(2), 1, 0),			/* [4] */
7301 			/* another .bss section */			/* [5] */
7302 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7303 			BTF_VAR_SECINFO_ENC(4, 0, 4),
7304 			BTF_END_RAW,
7305 		},
7306 		BTF_STR_SEC("\0.bss\0t"),
7307 	},
7308 	.opts = {
7309 		.force_collisions = true
7310 	},
7311 },
7312 {
7313 	.descr = "dedup: func/func_arg/var tags",
7314 	.input = {
7315 		.raw_types = {
7316 			/* int */
7317 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7318 			/* static int t */
7319 			BTF_VAR_ENC(NAME_NTH(1), 1, 0),			/* [2] */
7320 			/* void f(int a1, int a2) */
7321 			BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
7322 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7323 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(3), 1),
7324 			BTF_FUNC_ENC(NAME_NTH(4), 3),			/* [4] */
7325 			/* tag -> t */
7326 			BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1),		/* [5] */
7327 			BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1),		/* [6] */
7328 			/* tag -> func */
7329 			BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1),		/* [7] */
7330 			BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1),		/* [8] */
7331 			/* tag -> func arg a1 */
7332 			BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1),		/* [9] */
7333 			BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1),		/* [10] */
7334 			BTF_END_RAW,
7335 		},
7336 		BTF_STR_SEC("\0t\0a1\0a2\0f\0tag"),
7337 	},
7338 	.expect = {
7339 		.raw_types = {
7340 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7341 			BTF_VAR_ENC(NAME_NTH(1), 1, 0),			/* [2] */
7342 			BTF_FUNC_PROTO_ENC(0, 2),			/* [3] */
7343 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7344 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(3), 1),
7345 			BTF_FUNC_ENC(NAME_NTH(4), 3),			/* [4] */
7346 			BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1),		/* [5] */
7347 			BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1),		/* [6] */
7348 			BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1),		/* [7] */
7349 			BTF_END_RAW,
7350 		},
7351 		BTF_STR_SEC("\0t\0a1\0a2\0f\0tag"),
7352 	},
7353 },
7354 {
7355 	.descr = "dedup: func/func_param tags",
7356 	.input = {
7357 		.raw_types = {
7358 			/* int */
7359 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7360 			/* void f(int a1, int a2) */
7361 			BTF_FUNC_PROTO_ENC(0, 2),			/* [2] */
7362 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
7363 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7364 			BTF_FUNC_ENC(NAME_NTH(3), 2),			/* [3] */
7365 			/* void f(int a1, int a2) */
7366 			BTF_FUNC_PROTO_ENC(0, 2),			/* [4] */
7367 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
7368 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7369 			BTF_FUNC_ENC(NAME_NTH(3), 4),			/* [5] */
7370 			/* tag -> f: tag1, tag2 */
7371 			BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1),		/* [6] */
7372 			BTF_DECL_TAG_ENC(NAME_NTH(5), 3, -1),		/* [7] */
7373 			/* tag -> f/a2: tag1, tag2 */
7374 			BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1),		/* [8] */
7375 			BTF_DECL_TAG_ENC(NAME_NTH(5), 3, 1),		/* [9] */
7376 			/* tag -> f: tag1, tag3 */
7377 			BTF_DECL_TAG_ENC(NAME_NTH(4), 5, -1),		/* [10] */
7378 			BTF_DECL_TAG_ENC(NAME_NTH(6), 5, -1),		/* [11] */
7379 			/* tag -> f/a2: tag1, tag3 */
7380 			BTF_DECL_TAG_ENC(NAME_NTH(4), 5, 1),		/* [12] */
7381 			BTF_DECL_TAG_ENC(NAME_NTH(6), 5, 1),		/* [13] */
7382 			BTF_END_RAW,
7383 		},
7384 		BTF_STR_SEC("\0a1\0a2\0f\0tag1\0tag2\0tag3"),
7385 	},
7386 	.expect = {
7387 		.raw_types = {
7388 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7389 			BTF_FUNC_PROTO_ENC(0, 2),			/* [2] */
7390 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
7391 				BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7392 			BTF_FUNC_ENC(NAME_NTH(3), 2),			/* [3] */
7393 			BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1),		/* [4] */
7394 			BTF_DECL_TAG_ENC(NAME_NTH(5), 3, -1),		/* [5] */
7395 			BTF_DECL_TAG_ENC(NAME_NTH(6), 3, -1),		/* [6] */
7396 			BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1),		/* [7] */
7397 			BTF_DECL_TAG_ENC(NAME_NTH(5), 3, 1),		/* [8] */
7398 			BTF_DECL_TAG_ENC(NAME_NTH(6), 3, 1),		/* [9] */
7399 			BTF_END_RAW,
7400 		},
7401 		BTF_STR_SEC("\0a1\0a2\0f\0tag1\0tag2\0tag3"),
7402 	},
7403 },
7404 {
7405 	.descr = "dedup: struct/struct_member tags",
7406 	.input = {
7407 		.raw_types = {
7408 			/* int */
7409 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7410 			BTF_STRUCT_ENC(NAME_NTH(1), 2, 8),		/* [2] */
7411 				BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
7412 				BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
7413 			BTF_STRUCT_ENC(NAME_NTH(1), 2, 8),		/* [3] */
7414 				BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
7415 				BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
7416 			/* tag -> t: tag1, tag2 */
7417 			BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1),		/* [4] */
7418 			BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1),		/* [5] */
7419 			/* tag -> t/m2: tag1, tag2 */
7420 			BTF_DECL_TAG_ENC(NAME_NTH(4), 2, 1),		/* [6] */
7421 			BTF_DECL_TAG_ENC(NAME_NTH(5), 2, 1),		/* [7] */
7422 			/* tag -> t: tag1, tag3 */
7423 			BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1),		/* [8] */
7424 			BTF_DECL_TAG_ENC(NAME_NTH(6), 3, -1),		/* [9] */
7425 			/* tag -> t/m2: tag1, tag3 */
7426 			BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1),		/* [10] */
7427 			BTF_DECL_TAG_ENC(NAME_NTH(6), 3, 1),		/* [11] */
7428 			BTF_END_RAW,
7429 		},
7430 		BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
7431 	},
7432 	.expect = {
7433 		.raw_types = {
7434 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7435 			BTF_STRUCT_ENC(NAME_NTH(1), 2, 8),		/* [2] */
7436 				BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
7437 				BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
7438 			BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1),		/* [3] */
7439 			BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1),		/* [4] */
7440 			BTF_DECL_TAG_ENC(NAME_NTH(6), 2, -1),		/* [5] */
7441 			BTF_DECL_TAG_ENC(NAME_NTH(4), 2, 1),		/* [6] */
7442 			BTF_DECL_TAG_ENC(NAME_NTH(5), 2, 1),		/* [7] */
7443 			BTF_DECL_TAG_ENC(NAME_NTH(6), 2, 1),		/* [8] */
7444 			BTF_END_RAW,
7445 		},
7446 		BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
7447 	},
7448 },
7449 {
7450 	.descr = "dedup: typedef tags",
7451 	.input = {
7452 		.raw_types = {
7453 			/* int */
7454 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7455 			BTF_TYPEDEF_ENC(NAME_NTH(1), 1),		/* [2] */
7456 			BTF_TYPEDEF_ENC(NAME_NTH(1), 1),		/* [3] */
7457 			/* tag -> t: tag1, tag2 */
7458 			BTF_DECL_TAG_ENC(NAME_NTH(2), 2, -1),		/* [4] */
7459 			BTF_DECL_TAG_ENC(NAME_NTH(3), 2, -1),		/* [5] */
7460 			/* tag -> t: tag1, tag3 */
7461 			BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1),		/* [6] */
7462 			BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1),		/* [7] */
7463 			BTF_END_RAW,
7464 		},
7465 		BTF_STR_SEC("\0t\0tag1\0tag2\0tag3"),
7466 	},
7467 	.expect = {
7468 		.raw_types = {
7469 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7470 			BTF_TYPEDEF_ENC(NAME_NTH(1), 1),		/* [2] */
7471 			BTF_DECL_TAG_ENC(NAME_NTH(2), 2, -1),		/* [3] */
7472 			BTF_DECL_TAG_ENC(NAME_NTH(3), 2, -1),		/* [4] */
7473 			BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1),		/* [5] */
7474 			BTF_END_RAW,
7475 		},
7476 		BTF_STR_SEC("\0t\0tag1\0tag2\0tag3"),
7477 	},
7478 },
7479 {
7480 	.descr = "dedup: btf_type_tag #1",
7481 	.input = {
7482 		.raw_types = {
7483 			/* ptr -> tag2 -> tag1 -> int */
7484 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7485 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
7486 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),		/* [3] */
7487 			BTF_PTR_ENC(3),					/* [4] */
7488 			/* ptr -> tag2 -> tag1 -> int */
7489 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [5] */
7490 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 5),		/* [6] */
7491 			BTF_PTR_ENC(6),					/* [7] */
7492 			/* ptr -> tag1 -> int */
7493 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [8] */
7494 			BTF_PTR_ENC(8),					/* [9] */
7495 			BTF_END_RAW,
7496 		},
7497 		BTF_STR_SEC("\0tag1\0tag2"),
7498 	},
7499 	.expect = {
7500 		.raw_types = {
7501 			/* ptr -> tag2 -> tag1 -> int */
7502 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7503 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
7504 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),		/* [3] */
7505 			BTF_PTR_ENC(3),					/* [4] */
7506 			/* ptr -> tag1 -> int */
7507 			BTF_PTR_ENC(2),					/* [5] */
7508 			BTF_END_RAW,
7509 		},
7510 		BTF_STR_SEC("\0tag1\0tag2"),
7511 	},
7512 },
7513 {
7514 	.descr = "dedup: btf_type_tag #2",
7515 	.input = {
7516 		.raw_types = {
7517 			/* ptr -> tag2 -> tag1 -> int */
7518 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7519 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
7520 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),		/* [3] */
7521 			BTF_PTR_ENC(3),					/* [4] */
7522 			/* ptr -> tag2 -> int */
7523 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 1),		/* [5] */
7524 			BTF_PTR_ENC(5),					/* [6] */
7525 			BTF_END_RAW,
7526 		},
7527 		BTF_STR_SEC("\0tag1\0tag2"),
7528 	},
7529 	.expect = {
7530 		.raw_types = {
7531 			/* ptr -> tag2 -> tag1 -> int */
7532 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7533 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
7534 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),		/* [3] */
7535 			BTF_PTR_ENC(3),					/* [4] */
7536 			/* ptr -> tag2 -> int */
7537 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 1),		/* [5] */
7538 			BTF_PTR_ENC(5),					/* [6] */
7539 			BTF_END_RAW,
7540 		},
7541 		BTF_STR_SEC("\0tag1\0tag2"),
7542 	},
7543 },
7544 {
7545 	.descr = "dedup: btf_type_tag #3",
7546 	.input = {
7547 		.raw_types = {
7548 			/* ptr -> tag2 -> tag1 -> int */
7549 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7550 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
7551 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),		/* [3] */
7552 			BTF_PTR_ENC(3),					/* [4] */
7553 			/* ptr -> tag1 -> tag2 -> int */
7554 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 1),		/* [5] */
7555 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 5),		/* [6] */
7556 			BTF_PTR_ENC(6),					/* [7] */
7557 			BTF_END_RAW,
7558 		},
7559 		BTF_STR_SEC("\0tag1\0tag2"),
7560 	},
7561 	.expect = {
7562 		.raw_types = {
7563 			/* ptr -> tag2 -> tag1 -> int */
7564 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7565 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
7566 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),		/* [3] */
7567 			BTF_PTR_ENC(3),					/* [4] */
7568 			/* ptr -> tag1 -> tag2 -> int */
7569 			BTF_TYPE_TAG_ENC(NAME_NTH(2), 1),		/* [5] */
7570 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 5),		/* [6] */
7571 			BTF_PTR_ENC(6),					/* [7] */
7572 			BTF_END_RAW,
7573 		},
7574 		BTF_STR_SEC("\0tag1\0tag2"),
7575 	},
7576 },
7577 {
7578 	.descr = "dedup: btf_type_tag #4",
7579 	.input = {
7580 		.raw_types = {
7581 			/* ptr -> tag1 -> int */
7582 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7583 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
7584 			BTF_PTR_ENC(2),					/* [3] */
7585 			/* ptr -> tag1 -> long */
7586 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 64, 8),	/* [4] */
7587 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 4),		/* [5] */
7588 			BTF_PTR_ENC(5),					/* [6] */
7589 			BTF_END_RAW,
7590 		},
7591 		BTF_STR_SEC("\0tag1"),
7592 	},
7593 	.expect = {
7594 		.raw_types = {
7595 			/* ptr -> tag1 -> int */
7596 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
7597 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
7598 			BTF_PTR_ENC(2),					/* [3] */
7599 			/* ptr -> tag1 -> long */
7600 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 64, 8),	/* [4] */
7601 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 4),		/* [5] */
7602 			BTF_PTR_ENC(5),					/* [6] */
7603 			BTF_END_RAW,
7604 		},
7605 		BTF_STR_SEC("\0tag1"),
7606 	},
7607 },
7608 {
7609 	.descr = "dedup: btf_type_tag #5, struct",
7610 	.input = {
7611 		.raw_types = {
7612 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),				/* [1] */
7613 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),					/* [2] */
7614 			BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4),	/* [3] */
7615 			BTF_MEMBER_ENC(NAME_NTH(3), 2, BTF_MEMBER_OFFSET(0, 0)),
7616 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),					/* [4] */
7617 			BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4),	/* [5] */
7618 			BTF_MEMBER_ENC(NAME_NTH(3), 4, BTF_MEMBER_OFFSET(0, 0)),
7619 			BTF_END_RAW,
7620 		},
7621 		BTF_STR_SEC("\0tag1\0t\0m"),
7622 	},
7623 	.expect = {
7624 		.raw_types = {
7625 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),				/* [1] */
7626 			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),					/* [2] */
7627 			BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4),	/* [3] */
7628 			BTF_MEMBER_ENC(NAME_NTH(3), 2, BTF_MEMBER_OFFSET(0, 0)),
7629 			BTF_END_RAW,
7630 		},
7631 		BTF_STR_SEC("\0tag1\0t\0m"),
7632 	},
7633 },
7634 {
7635 	.descr = "dedup: enum64, standalone",
7636 	.input = {
7637 		.raw_types = {
7638 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7639 				BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7640 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7641 				BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7642 			BTF_END_RAW,
7643 		},
7644 		BTF_STR_SEC("\0e1\0e1_val"),
7645 	},
7646 	.expect = {
7647 		.raw_types = {
7648 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7649 				BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7650 			BTF_END_RAW,
7651 		},
7652 		BTF_STR_SEC("\0e1\0e1_val"),
7653 	},
7654 },
7655 {
7656 	.descr = "dedup: enum64, fwd resolution",
7657 	.input = {
7658 		.raw_types = {
7659 			/* [1] fwd enum64 'e1' before full enum */
7660 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8),
7661 			/* [2] full enum64 'e1' after fwd */
7662 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7663 				BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7664 			/* [3] full enum64 'e2' before fwd */
7665 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7666 				BTF_ENUM64_ENC(NAME_NTH(4), 0, 456),
7667 			/* [4] fwd enum64 'e2' after full enum */
7668 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8),
7669 			/* [5] incompatible full enum64 with different value */
7670 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7671 				BTF_ENUM64_ENC(NAME_NTH(2), 0, 321),
7672 			BTF_END_RAW,
7673 		},
7674 		BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7675 	},
7676 	.expect = {
7677 		.raw_types = {
7678 			/* [1] full enum64 'e1' */
7679 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7680 				BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7681 			/* [2] full enum64 'e2' */
7682 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7683 				BTF_ENUM64_ENC(NAME_NTH(4), 0, 456),
7684 			/* [3] incompatible full enum64 with different value */
7685 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7686 				BTF_ENUM64_ENC(NAME_NTH(2), 0, 321),
7687 			BTF_END_RAW,
7688 		},
7689 		BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7690 	},
7691 },
7692 {
7693 	.descr = "dedup: enum and enum64, no dedup",
7694 	.input = {
7695 		.raw_types = {
7696 			/* [1] enum 'e1' */
7697 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7698 				BTF_ENUM_ENC(NAME_NTH(2), 1),
7699 			/* [2] enum64 'e1' */
7700 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 4),
7701 				BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7702 			BTF_END_RAW,
7703 		},
7704 		BTF_STR_SEC("\0e1\0e1_val"),
7705 	},
7706 	.expect = {
7707 		.raw_types = {
7708 			/* [1] enum 'e1' */
7709 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7710 				BTF_ENUM_ENC(NAME_NTH(2), 1),
7711 			/* [2] enum64 'e1' */
7712 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 4),
7713 				BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7714 			BTF_END_RAW,
7715 		},
7716 		BTF_STR_SEC("\0e1\0e1_val"),
7717 	},
7718 },
7719 {
7720 	.descr = "dedup: enum of different size: no dedup",
7721 	.input = {
7722 		.raw_types = {
7723 			/* [1] enum 'e1' */
7724 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7725 				BTF_ENUM_ENC(NAME_NTH(2), 1),
7726 			/* [2] enum 'e1' */
7727 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 2),
7728 				BTF_ENUM_ENC(NAME_NTH(2), 1),
7729 			BTF_END_RAW,
7730 		},
7731 		BTF_STR_SEC("\0e1\0e1_val"),
7732 	},
7733 	.expect = {
7734 		.raw_types = {
7735 			/* [1] enum 'e1' */
7736 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7737 				BTF_ENUM_ENC(NAME_NTH(2), 1),
7738 			/* [2] enum 'e1' */
7739 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 2),
7740 				BTF_ENUM_ENC(NAME_NTH(2), 1),
7741 			BTF_END_RAW,
7742 		},
7743 		BTF_STR_SEC("\0e1\0e1_val"),
7744 	},
7745 },
7746 {
7747 	.descr = "dedup: enum fwd to enum64",
7748 	.input = {
7749 		.raw_types = {
7750 			/* [1] enum64 'e1' */
7751 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7752 				BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7753 			/* [2] enum 'e1' fwd */
7754 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 4),
7755 			/* [3] typedef enum 'e1' td */
7756 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 2),
7757 			BTF_END_RAW,
7758 		},
7759 		BTF_STR_SEC("\0e1\0e1_val\0td"),
7760 	},
7761 	.expect = {
7762 		.raw_types = {
7763 			/* [1] enum64 'e1' */
7764 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7765 				BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7766 			/* [2] typedef enum 'e1' td */
7767 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 1),
7768 			BTF_END_RAW,
7769 		},
7770 		BTF_STR_SEC("\0e1\0e1_val\0td"),
7771 	},
7772 },
7773 {
7774 	.descr = "dedup: enum64 fwd to enum",
7775 	.input = {
7776 		.raw_types = {
7777 			/* [1] enum 'e1' */
7778 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7779 				BTF_ENUM_ENC(NAME_NTH(2), 1),
7780 			/* [2] enum64 'e1' fwd */
7781 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8),
7782 			/* [3] typedef enum 'e1' td */
7783 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 2),
7784 			BTF_END_RAW,
7785 		},
7786 		BTF_STR_SEC("\0e1\0e1_val\0td"),
7787 	},
7788 	.expect = {
7789 		.raw_types = {
7790 			/* [1] enum 'e1' */
7791 			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7792 				BTF_ENUM_ENC(NAME_NTH(2), 1),
7793 			/* [2] typedef enum 'e1' td */
7794 			BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 1),
7795 			BTF_END_RAW,
7796 		},
7797 		BTF_STR_SEC("\0e1\0e1_val\0td"),
7798 	},
7799 },
7800 {
7801 	.descr = "dedup: standalone fwd declaration struct",
7802 	/*
7803 	 * Verify that CU1:foo and CU2:foo would be unified and that
7804 	 * typedef/ptr would be updated to point to CU1:foo.
7805 	 *
7806 	 * // CU 1:
7807 	 * struct foo { int x; };
7808 	 *
7809 	 * // CU 2:
7810 	 * struct foo;
7811 	 * typedef struct foo *foo_ptr;
7812 	 */
7813 	.input = {
7814 		.raw_types = {
7815 			/* CU 1 */
7816 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 4),             /* [1] */
7817 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7818 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7819 			/* CU 2 */
7820 			BTF_FWD_ENC(NAME_NTH(1), 0),                   /* [3] */
7821 			BTF_PTR_ENC(3),                                /* [4] */
7822 			BTF_TYPEDEF_ENC(NAME_NTH(3), 4),               /* [5] */
7823 			BTF_END_RAW,
7824 		},
7825 		BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7826 	},
7827 	.expect = {
7828 		.raw_types = {
7829 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 4),             /* [1] */
7830 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7831 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7832 			BTF_PTR_ENC(1),                                /* [3] */
7833 			BTF_TYPEDEF_ENC(NAME_NTH(3), 3),               /* [4] */
7834 			BTF_END_RAW,
7835 		},
7836 		BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7837 	},
7838 },
7839 {
7840 	.descr = "dedup: standalone fwd declaration union",
7841 	/*
7842 	 * Verify that CU1:foo and CU2:foo would be unified and that
7843 	 * typedef/ptr would be updated to point to CU1:foo.
7844 	 * Same as "dedup: standalone fwd declaration struct" but for unions.
7845 	 *
7846 	 * // CU 1:
7847 	 * union foo { int x; };
7848 	 *
7849 	 * // CU 2:
7850 	 * union foo;
7851 	 * typedef union foo *foo_ptr;
7852 	 */
7853 	.input = {
7854 		.raw_types = {
7855 			/* CU 1 */
7856 			BTF_UNION_ENC(NAME_NTH(1), 1, 4),              /* [1] */
7857 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7858 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7859 			/* CU 2 */
7860 			BTF_FWD_ENC(NAME_TBD, 1),                      /* [3] */
7861 			BTF_PTR_ENC(3),                                /* [4] */
7862 			BTF_TYPEDEF_ENC(NAME_NTH(3), 4),               /* [5] */
7863 			BTF_END_RAW,
7864 		},
7865 		BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7866 	},
7867 	.expect = {
7868 		.raw_types = {
7869 			BTF_UNION_ENC(NAME_NTH(1), 1, 4),              /* [1] */
7870 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7871 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7872 			BTF_PTR_ENC(1),                                /* [3] */
7873 			BTF_TYPEDEF_ENC(NAME_NTH(3), 3),               /* [4] */
7874 			BTF_END_RAW,
7875 		},
7876 		BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7877 	},
7878 },
7879 {
7880 	.descr = "dedup: standalone fwd declaration wrong kind",
7881 	/*
7882 	 * Negative test for btf_dedup_resolve_fwds:
7883 	 * - CU1:foo is a struct, C2:foo is a union, thus CU2:foo is not deduped;
7884 	 * - typedef/ptr should remain unchanged as well.
7885 	 *
7886 	 * // CU 1:
7887 	 * struct foo { int x; };
7888 	 *
7889 	 * // CU 2:
7890 	 * union foo;
7891 	 * typedef union foo *foo_ptr;
7892 	 */
7893 	.input = {
7894 		.raw_types = {
7895 			/* CU 1 */
7896 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 4),             /* [1] */
7897 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7898 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7899 			/* CU 2 */
7900 			BTF_FWD_ENC(NAME_NTH(3), 1),                   /* [3] */
7901 			BTF_PTR_ENC(3),                                /* [4] */
7902 			BTF_TYPEDEF_ENC(NAME_NTH(3), 4),               /* [5] */
7903 			BTF_END_RAW,
7904 		},
7905 		BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7906 	},
7907 	.expect = {
7908 		.raw_types = {
7909 			/* CU 1 */
7910 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 4),             /* [1] */
7911 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7912 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7913 			/* CU 2 */
7914 			BTF_FWD_ENC(NAME_NTH(3), 1),                   /* [3] */
7915 			BTF_PTR_ENC(3),                                /* [4] */
7916 			BTF_TYPEDEF_ENC(NAME_NTH(3), 4),               /* [5] */
7917 			BTF_END_RAW,
7918 		},
7919 		BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7920 	},
7921 },
7922 {
7923 	.descr = "dedup: standalone fwd declaration name conflict",
7924 	/*
7925 	 * Negative test for btf_dedup_resolve_fwds:
7926 	 * - two candidates for CU2:foo dedup, thus it is unchanged;
7927 	 * - typedef/ptr should remain unchanged as well.
7928 	 *
7929 	 * // CU 1:
7930 	 * struct foo { int x; };
7931 	 *
7932 	 * // CU 2:
7933 	 * struct foo;
7934 	 * typedef struct foo *foo_ptr;
7935 	 *
7936 	 * // CU 3:
7937 	 * struct foo { int x; int y; };
7938 	 */
7939 	.input = {
7940 		.raw_types = {
7941 			/* CU 1 */
7942 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 4),             /* [1] */
7943 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7944 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7945 			/* CU 2 */
7946 			BTF_FWD_ENC(NAME_NTH(1), 0),                   /* [3] */
7947 			BTF_PTR_ENC(3),                                /* [4] */
7948 			BTF_TYPEDEF_ENC(NAME_NTH(4), 4),               /* [5] */
7949 			/* CU 3 */
7950 			BTF_STRUCT_ENC(NAME_NTH(1), 2, 8),             /* [6] */
7951 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7952 			BTF_MEMBER_ENC(NAME_NTH(3), 2, 0),
7953 			BTF_END_RAW,
7954 		},
7955 		BTF_STR_SEC("\0foo\0x\0y\0foo_ptr"),
7956 	},
7957 	.expect = {
7958 		.raw_types = {
7959 			/* CU 1 */
7960 			BTF_STRUCT_ENC(NAME_NTH(1), 1, 4),             /* [1] */
7961 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7962 			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7963 			/* CU 2 */
7964 			BTF_FWD_ENC(NAME_NTH(1), 0),                   /* [3] */
7965 			BTF_PTR_ENC(3),                                /* [4] */
7966 			BTF_TYPEDEF_ENC(NAME_NTH(4), 4),               /* [5] */
7967 			/* CU 3 */
7968 			BTF_STRUCT_ENC(NAME_NTH(1), 2, 8),             /* [6] */
7969 			BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7970 			BTF_MEMBER_ENC(NAME_NTH(3), 2, 0),
7971 			BTF_END_RAW,
7972 		},
7973 		BTF_STR_SEC("\0foo\0x\0y\0foo_ptr"),
7974 	},
7975 },
7976 };
7977 
7978 static int btf_type_size(const struct btf_type *t)
7979 {
7980 	int base_size = sizeof(struct btf_type);
7981 	__u16 vlen = BTF_INFO_VLEN(t->info);
7982 	__u16 kind = BTF_INFO_KIND(t->info);
7983 
7984 	switch (kind) {
7985 	case BTF_KIND_FWD:
7986 	case BTF_KIND_CONST:
7987 	case BTF_KIND_VOLATILE:
7988 	case BTF_KIND_RESTRICT:
7989 	case BTF_KIND_PTR:
7990 	case BTF_KIND_TYPEDEF:
7991 	case BTF_KIND_FUNC:
7992 	case BTF_KIND_FLOAT:
7993 	case BTF_KIND_TYPE_TAG:
7994 		return base_size;
7995 	case BTF_KIND_INT:
7996 		return base_size + sizeof(__u32);
7997 	case BTF_KIND_ENUM:
7998 		return base_size + vlen * sizeof(struct btf_enum);
7999 	case BTF_KIND_ENUM64:
8000 		return base_size + vlen * sizeof(struct btf_enum64);
8001 	case BTF_KIND_ARRAY:
8002 		return base_size + sizeof(struct btf_array);
8003 	case BTF_KIND_STRUCT:
8004 	case BTF_KIND_UNION:
8005 		return base_size + vlen * sizeof(struct btf_member);
8006 	case BTF_KIND_FUNC_PROTO:
8007 		return base_size + vlen * sizeof(struct btf_param);
8008 	case BTF_KIND_VAR:
8009 		return base_size + sizeof(struct btf_var);
8010 	case BTF_KIND_DATASEC:
8011 		return base_size + vlen * sizeof(struct btf_var_secinfo);
8012 	case BTF_KIND_DECL_TAG:
8013 		return base_size + sizeof(struct btf_decl_tag);
8014 	default:
8015 		fprintf(stderr, "Unsupported BTF_KIND:%u\n", kind);
8016 		return -EINVAL;
8017 	}
8018 }
8019 
8020 static void dump_btf_strings(const char *strs, __u32 len)
8021 {
8022 	const char *cur = strs;
8023 	int i = 0;
8024 
8025 	while (cur < strs + len) {
8026 		fprintf(stderr, "string #%d: '%s'\n", i, cur);
8027 		cur += strlen(cur) + 1;
8028 		i++;
8029 	}
8030 }
8031 
8032 static void do_test_dedup(unsigned int test_num)
8033 {
8034 	struct btf_dedup_test *test = &dedup_tests[test_num - 1];
8035 	__u32 test_nr_types, expect_nr_types, test_btf_size, expect_btf_size;
8036 	const struct btf_header *test_hdr, *expect_hdr;
8037 	struct btf *test_btf = NULL, *expect_btf = NULL;
8038 	const void *test_btf_data, *expect_btf_data;
8039 	const char *ret_test_next_str, *ret_expect_next_str;
8040 	const char *test_strs, *expect_strs;
8041 	const char *test_str_cur;
8042 	const char *expect_str_cur, *expect_str_end;
8043 	unsigned int raw_btf_size;
8044 	void *raw_btf;
8045 	int err = 0, i;
8046 
8047 	if (!test__start_subtest(test->descr))
8048 		return;
8049 
8050 	raw_btf = btf_raw_create(&hdr_tmpl, test->input.raw_types,
8051 				 test->input.str_sec, test->input.str_sec_size,
8052 				 &raw_btf_size, &ret_test_next_str);
8053 	if (!raw_btf)
8054 		return;
8055 
8056 	test_btf = btf__new((__u8 *)raw_btf, raw_btf_size);
8057 	err = libbpf_get_error(test_btf);
8058 	free(raw_btf);
8059 	if (CHECK(err, "invalid test_btf errno:%d", err)) {
8060 		err = -1;
8061 		goto done;
8062 	}
8063 
8064 	raw_btf = btf_raw_create(&hdr_tmpl, test->expect.raw_types,
8065 				 test->expect.str_sec,
8066 				 test->expect.str_sec_size,
8067 				 &raw_btf_size, &ret_expect_next_str);
8068 	if (!raw_btf)
8069 		return;
8070 	expect_btf = btf__new((__u8 *)raw_btf, raw_btf_size);
8071 	err = libbpf_get_error(expect_btf);
8072 	free(raw_btf);
8073 	if (CHECK(err, "invalid expect_btf errno:%d", err)) {
8074 		err = -1;
8075 		goto done;
8076 	}
8077 
8078 	test->opts.sz = sizeof(test->opts);
8079 	err = btf__dedup(test_btf, &test->opts);
8080 	if (CHECK(err, "btf_dedup failed errno:%d", err)) {
8081 		err = -1;
8082 		goto done;
8083 	}
8084 
8085 	test_btf_data = btf__raw_data(test_btf, &test_btf_size);
8086 	expect_btf_data = btf__raw_data(expect_btf, &expect_btf_size);
8087 	if (CHECK(test_btf_size != expect_btf_size,
8088 		  "test_btf_size:%u != expect_btf_size:%u",
8089 		  test_btf_size, expect_btf_size)) {
8090 		err = -1;
8091 		goto done;
8092 	}
8093 
8094 	test_hdr = test_btf_data;
8095 	test_strs = test_btf_data + sizeof(*test_hdr) + test_hdr->str_off;
8096 	expect_hdr = expect_btf_data;
8097 	expect_strs = expect_btf_data + sizeof(*test_hdr) + expect_hdr->str_off;
8098 	if (CHECK(test_hdr->str_len != expect_hdr->str_len,
8099 		  "test_hdr->str_len:%u != expect_hdr->str_len:%u",
8100 		  test_hdr->str_len, expect_hdr->str_len)) {
8101 		fprintf(stderr, "\ntest strings:\n");
8102 		dump_btf_strings(test_strs, test_hdr->str_len);
8103 		fprintf(stderr, "\nexpected strings:\n");
8104 		dump_btf_strings(expect_strs, expect_hdr->str_len);
8105 		err = -1;
8106 		goto done;
8107 	}
8108 
8109 	expect_str_cur = expect_strs;
8110 	expect_str_end = expect_strs + expect_hdr->str_len;
8111 	while (expect_str_cur < expect_str_end) {
8112 		size_t test_len, expect_len;
8113 		int off;
8114 
8115 		off = btf__find_str(test_btf, expect_str_cur);
8116 		if (CHECK(off < 0, "exp str '%s' not found: %d\n", expect_str_cur, off)) {
8117 			err = -1;
8118 			goto done;
8119 		}
8120 		test_str_cur = btf__str_by_offset(test_btf, off);
8121 
8122 		test_len = strlen(test_str_cur);
8123 		expect_len = strlen(expect_str_cur);
8124 		if (CHECK(test_len != expect_len,
8125 			  "test_len:%zu != expect_len:%zu "
8126 			  "(test_str:%s, expect_str:%s)",
8127 			  test_len, expect_len, test_str_cur, expect_str_cur)) {
8128 			err = -1;
8129 			goto done;
8130 		}
8131 		if (CHECK(strcmp(test_str_cur, expect_str_cur),
8132 			  "test_str:%s != expect_str:%s",
8133 			  test_str_cur, expect_str_cur)) {
8134 			err = -1;
8135 			goto done;
8136 		}
8137 		expect_str_cur += expect_len + 1;
8138 	}
8139 
8140 	test_nr_types = btf__type_cnt(test_btf);
8141 	expect_nr_types = btf__type_cnt(expect_btf);
8142 	if (CHECK(test_nr_types != expect_nr_types,
8143 		  "test_nr_types:%u != expect_nr_types:%u",
8144 		  test_nr_types, expect_nr_types)) {
8145 		err = -1;
8146 		goto done;
8147 	}
8148 
8149 	for (i = 1; i < test_nr_types; i++) {
8150 		const struct btf_type *test_type, *expect_type;
8151 		int test_size, expect_size;
8152 
8153 		test_type = btf__type_by_id(test_btf, i);
8154 		expect_type = btf__type_by_id(expect_btf, i);
8155 		test_size = btf_type_size(test_type);
8156 		expect_size = btf_type_size(expect_type);
8157 
8158 		if (CHECK(test_size != expect_size,
8159 			  "type #%d: test_size:%d != expect_size:%u",
8160 			  i, test_size, expect_size)) {
8161 			err = -1;
8162 			goto done;
8163 		}
8164 		if (CHECK(btf_kind(test_type) != btf_kind(expect_type),
8165 			  "type %d kind: exp %d != got %u\n",
8166 			  i, btf_kind(expect_type), btf_kind(test_type))) {
8167 			err = -1;
8168 			goto done;
8169 		}
8170 		if (CHECK(test_type->info != expect_type->info,
8171 			  "type %d info: exp %d != got %u\n",
8172 			  i, expect_type->info, test_type->info)) {
8173 			err = -1;
8174 			goto done;
8175 		}
8176 		if (CHECK(test_type->size != expect_type->size,
8177 			  "type %d size/type: exp %d != got %u\n",
8178 			  i, expect_type->size, test_type->size)) {
8179 			err = -1;
8180 			goto done;
8181 		}
8182 	}
8183 
8184 done:
8185 	btf__free(test_btf);
8186 	btf__free(expect_btf);
8187 }
8188 
8189 void test_btf(void)
8190 {
8191 	int i;
8192 
8193 	always_log = env.verbosity > VERBOSE_NONE;
8194 
8195 	for (i = 1; i <= ARRAY_SIZE(raw_tests); i++)
8196 		do_test_raw(i);
8197 	for (i = 1; i <= ARRAY_SIZE(get_info_tests); i++)
8198 		do_test_get_info(i);
8199 	for (i = 1; i <= ARRAY_SIZE(file_tests); i++)
8200 		do_test_file(i);
8201 	for (i = 1; i <= ARRAY_SIZE(info_raw_tests); i++)
8202 		do_test_info_raw(i);
8203 	for (i = 1; i <= ARRAY_SIZE(dedup_tests); i++)
8204 		do_test_dedup(i);
8205 	test_pprint();
8206 }
8207