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