1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018 Facebook */
7 #include <linux/kernel.h>
8 #include <linux/filter.h>
9 #include <linux/unistd.h>
21 #include <bpf/libbpf.h>
25 #include "../test_btf.h"
26 #include "test_progs.h"
29 #define MAX_SUBPROGS 16
31 static int duration = 0;
32 static bool always_log;
35 #define CHECK(condition, format...) _CHECK(condition, "check", duration, format)
37 #define NAME_TBD 0xdeadb33f
39 #define NAME_NTH(N) (0xfffe0000 | N)
40 #define IS_NAME_NTH(X) ((X & 0xffff0000) == 0xfffe0000)
41 #define GET_NAME_NTH_IDX(X) (X & 0x0000ffff)
43 #define MAX_NR_RAW_U32 1024
44 #define BTF_LOG_BUF_SIZE 65535
46 static char btf_log_buf[BTF_LOG_BUF_SIZE];
48 static struct btf_header hdr_tmpl = {
50 .version = BTF_VERSION,
51 .hdr_len = sizeof(struct btf_header),
54 /* several different mapv kinds(types) supported by pprint */
55 enum pprint_mapv_kind_t {
56 PPRINT_MAPV_KIND_BASIC = 0,
57 PPRINT_MAPV_KIND_INT128,
65 __u32 raw_types[MAX_NR_RAW_U32];
67 enum bpf_map_type map_type;
82 enum pprint_mapv_kind_t mapv_kind;
85 #define BTF_STR_SEC(str) \
86 .str_sec = str, .str_sec_size = sizeof(str)
88 static struct btf_raw_test raw_tests[] = {
95 * unsigned long long m;
105 .descr = "struct test #1",
108 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
109 /* unsigned long long */
110 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
112 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
114 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
115 /* struct A { */ /* [5] */
116 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 6), 180),
117 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
118 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
119 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
120 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
121 BTF_MEMBER_ENC(NAME_TBD, 6, 384),/* int q[4][8] */
122 BTF_MEMBER_ENC(NAME_TBD, 7, 1408), /* enum E r */
125 BTF_TYPE_ARRAY_ENC(4, 1, 4), /* [6] */
126 /* enum E */ /* [7] */
127 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), sizeof(int)),
128 BTF_ENUM_ENC(NAME_TBD, 0),
129 BTF_ENUM_ENC(NAME_TBD, 1),
132 .str_sec = "\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1",
133 .str_sec_size = sizeof("\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1"),
134 .map_type = BPF_MAP_TYPE_ARRAY,
135 .map_name = "struct_test1_map",
136 .key_size = sizeof(int),
143 /* typedef struct b Struct_B;
148 * const Struct_B o[4];
157 .descr = "struct test #2",
160 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
161 /* struct b [4] */ /* [2] */
162 BTF_TYPE_ARRAY_ENC(4, 1, 4),
164 /* struct A { */ /* [3] */
165 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 3), 68),
166 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
167 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* struct B n[4] */
168 BTF_MEMBER_ENC(NAME_TBD, 8, 288),/* const Struct_B o[4];*/
171 /* struct B { */ /* [4] */
172 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
173 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
174 BTF_MEMBER_ENC(NAME_TBD, 1, 32),/* int n; */
177 /* const int */ /* [5] */
178 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 1),
179 /* typedef struct b Struct_B */ /* [6] */
180 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 4),
181 /* const Struct_B */ /* [7] */
182 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 6),
183 /* const Struct_B [4] */ /* [8] */
184 BTF_TYPE_ARRAY_ENC(7, 1, 4),
187 .str_sec = "\0A\0m\0n\0o\0B\0m\0n\0Struct_B",
188 .str_sec_size = sizeof("\0A\0m\0n\0o\0B\0m\0n\0Struct_B"),
189 .map_type = BPF_MAP_TYPE_ARRAY,
190 .map_name = "struct_test2_map",
191 .key_size = sizeof(int),
198 .descr = "struct test #3 Invalid member offset",
201 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
202 /* int64 */ /* [2] */
203 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 64, 8),
205 /* struct A { */ /* [3] */
206 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 16),
207 BTF_MEMBER_ENC(NAME_TBD, 1, 64), /* int m; */
208 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* int64 n; */
212 .str_sec = "\0A\0m\0n\0",
213 .str_sec_size = sizeof("\0A\0m\0n\0"),
214 .map_type = BPF_MAP_TYPE_ARRAY,
215 .map_name = "struct_test3_map",
216 .key_size = sizeof(int),
221 .btf_load_err = true,
222 .err_str = "Invalid member bits_offset",
226 * unsigned long long m;
234 .descr = "global data test #1",
237 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
238 /* unsigned long long */
239 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
241 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
243 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
244 /* struct A { */ /* [5] */
245 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
246 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
247 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
248 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
249 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
253 .str_sec = "\0A\0m\0n\0o\0p",
254 .str_sec_size = sizeof("\0A\0m\0n\0o\0p"),
255 .map_type = BPF_MAP_TYPE_ARRAY,
256 .map_name = "struct_test1_map",
257 .key_size = sizeof(int),
265 * unsigned long long m;
271 * static struct A t; <- in .bss
274 .descr = "global data test #2",
277 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
278 /* unsigned long long */
279 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
281 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
283 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
284 /* struct A { */ /* [5] */
285 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
286 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
287 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
288 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
289 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
291 /* static struct A t */
292 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
293 /* .bss section */ /* [7] */
294 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 48),
295 BTF_VAR_SECINFO_ENC(6, 0, 48),
298 .str_sec = "\0A\0m\0n\0o\0p\0t\0.bss",
299 .str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
300 .map_type = BPF_MAP_TYPE_ARRAY,
302 .key_size = sizeof(int),
309 .descr = "global data test #3",
312 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
314 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
315 /* .bss section */ /* [3] */
316 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
317 BTF_VAR_SECINFO_ENC(2, 0, 4),
320 .str_sec = "\0t\0.bss",
321 .str_sec_size = sizeof("\0t\0.bss"),
322 .map_type = BPF_MAP_TYPE_ARRAY,
324 .key_size = sizeof(int),
331 .descr = "global data test #4, unsupported linkage",
334 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
336 BTF_VAR_ENC(NAME_TBD, 1, 2), /* [2] */
337 /* .bss section */ /* [3] */
338 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
339 BTF_VAR_SECINFO_ENC(2, 0, 4),
342 .str_sec = "\0t\0.bss",
343 .str_sec_size = sizeof("\0t\0.bss"),
344 .map_type = BPF_MAP_TYPE_ARRAY,
346 .key_size = sizeof(int),
351 .btf_load_err = true,
352 .err_str = "Linkage not supported",
355 .descr = "global data test #5, invalid var type",
358 BTF_VAR_ENC(NAME_TBD, 0, 0), /* [1] */
359 /* .bss section */ /* [2] */
360 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
361 BTF_VAR_SECINFO_ENC(1, 0, 4),
364 .str_sec = "\0t\0.bss",
365 .str_sec_size = sizeof("\0t\0.bss"),
366 .map_type = BPF_MAP_TYPE_ARRAY,
368 .key_size = sizeof(int),
373 .btf_load_err = true,
374 .err_str = "Invalid type_id",
377 .descr = "global data test #6, invalid var type (fwd type)",
380 BTF_TYPE_ENC(NAME_TBD,
381 BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [1] */
382 /* static union A t */
383 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
384 /* .bss section */ /* [3] */
385 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
386 BTF_VAR_SECINFO_ENC(2, 0, 4),
389 .str_sec = "\0A\0t\0.bss",
390 .str_sec_size = sizeof("\0A\0t\0.bss"),
391 .map_type = BPF_MAP_TYPE_ARRAY,
393 .key_size = sizeof(int),
398 .btf_load_err = true,
399 .err_str = "Invalid type",
402 .descr = "global data test #7, invalid var type (fwd type)",
405 BTF_TYPE_ENC(NAME_TBD,
406 BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [1] */
407 /* static union A t */
408 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
409 /* .bss section */ /* [3] */
410 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
411 BTF_VAR_SECINFO_ENC(1, 0, 4),
414 .str_sec = "\0A\0t\0.bss",
415 .str_sec_size = sizeof("\0A\0t\0.bss"),
416 .map_type = BPF_MAP_TYPE_ARRAY,
418 .key_size = sizeof(int),
423 .btf_load_err = true,
424 .err_str = "Invalid type",
427 .descr = "global data test #8, invalid var size",
430 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
431 /* unsigned long long */
432 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
434 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
436 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
437 /* struct A { */ /* [5] */
438 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
439 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
440 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
441 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
442 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
444 /* static struct A t */
445 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
446 /* .bss section */ /* [7] */
447 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 48),
448 BTF_VAR_SECINFO_ENC(6, 0, 47),
451 .str_sec = "\0A\0m\0n\0o\0p\0t\0.bss",
452 .str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
453 .map_type = BPF_MAP_TYPE_ARRAY,
455 .key_size = sizeof(int),
460 .btf_load_err = true,
461 .err_str = "Invalid size",
464 .descr = "global data test #9, invalid var size",
467 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
468 /* unsigned long long */
469 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
471 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
473 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
474 /* struct A { */ /* [5] */
475 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
476 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
477 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
478 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
479 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
481 /* static struct A t */
482 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
483 /* .bss section */ /* [7] */
484 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 46),
485 BTF_VAR_SECINFO_ENC(6, 0, 48),
488 .str_sec = "\0A\0m\0n\0o\0p\0t\0.bss",
489 .str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
490 .map_type = BPF_MAP_TYPE_ARRAY,
492 .key_size = sizeof(int),
497 .btf_load_err = true,
498 .err_str = "Invalid size",
501 .descr = "global data test #10, invalid var size",
504 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
505 /* unsigned long long */
506 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
508 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
510 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
511 /* struct A { */ /* [5] */
512 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
513 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
514 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
515 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
516 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
518 /* static struct A t */
519 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
520 /* .bss section */ /* [7] */
521 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 46),
522 BTF_VAR_SECINFO_ENC(6, 0, 46),
525 .str_sec = "\0A\0m\0n\0o\0p\0t\0.bss",
526 .str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
527 .map_type = BPF_MAP_TYPE_ARRAY,
529 .key_size = sizeof(int),
534 .btf_load_err = true,
535 .err_str = "Invalid size",
538 .descr = "global data test #11, multiple section members",
541 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
542 /* unsigned long long */
543 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
545 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
547 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
548 /* struct A { */ /* [5] */
549 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
550 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
551 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
552 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
553 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
555 /* static struct A t */
556 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
558 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [7] */
559 /* .bss section */ /* [8] */
560 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2), 62),
561 BTF_VAR_SECINFO_ENC(6, 10, 48),
562 BTF_VAR_SECINFO_ENC(7, 58, 4),
565 .str_sec = "\0A\0m\0n\0o\0p\0t\0u\0.bss",
566 .str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
567 .map_type = BPF_MAP_TYPE_ARRAY,
569 .key_size = sizeof(int),
576 .descr = "global data test #12, invalid offset",
579 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
580 /* unsigned long long */
581 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
583 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
585 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
586 /* struct A { */ /* [5] */
587 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
588 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
589 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
590 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
591 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
593 /* static struct A t */
594 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
596 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [7] */
597 /* .bss section */ /* [8] */
598 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2), 62),
599 BTF_VAR_SECINFO_ENC(6, 10, 48),
600 BTF_VAR_SECINFO_ENC(7, 60, 4),
603 .str_sec = "\0A\0m\0n\0o\0p\0t\0u\0.bss",
604 .str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
605 .map_type = BPF_MAP_TYPE_ARRAY,
607 .key_size = sizeof(int),
612 .btf_load_err = true,
613 .err_str = "Invalid offset+size",
616 .descr = "global data test #13, invalid offset",
619 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
620 /* unsigned long long */
621 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
623 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
625 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
626 /* struct A { */ /* [5] */
627 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
628 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
629 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
630 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
631 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
633 /* static struct A t */
634 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
636 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [7] */
637 /* .bss section */ /* [8] */
638 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2), 62),
639 BTF_VAR_SECINFO_ENC(6, 10, 48),
640 BTF_VAR_SECINFO_ENC(7, 12, 4),
643 .str_sec = "\0A\0m\0n\0o\0p\0t\0u\0.bss",
644 .str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
645 .map_type = BPF_MAP_TYPE_ARRAY,
647 .key_size = sizeof(int),
652 .btf_load_err = true,
653 .err_str = "Invalid offset",
656 .descr = "global data test #14, invalid offset",
659 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
660 /* unsigned long long */
661 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
663 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1), /* [3] */
665 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
666 /* struct A { */ /* [5] */
667 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 4), 48),
668 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* unsigned long long m;*/
669 BTF_MEMBER_ENC(NAME_TBD, 1, 64),/* int n; */
670 BTF_MEMBER_ENC(NAME_TBD, 3, 96),/* char o; */
671 BTF_MEMBER_ENC(NAME_TBD, 4, 128),/* int p[8] */
673 /* static struct A t */
674 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
676 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [7] */
677 /* .bss section */ /* [8] */
678 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2), 62),
679 BTF_VAR_SECINFO_ENC(7, 58, 4),
680 BTF_VAR_SECINFO_ENC(6, 10, 48),
683 .str_sec = "\0A\0m\0n\0o\0p\0t\0u\0.bss",
684 .str_sec_size = sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
685 .map_type = BPF_MAP_TYPE_ARRAY,
687 .key_size = sizeof(int),
692 .btf_load_err = true,
693 .err_str = "Invalid offset",
696 .descr = "global data test #15, not var kind",
699 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
700 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
701 /* .bss section */ /* [3] */
702 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
703 BTF_VAR_SECINFO_ENC(1, 0, 4),
706 .str_sec = "\0A\0t\0.bss",
707 .str_sec_size = sizeof("\0A\0t\0.bss"),
708 .map_type = BPF_MAP_TYPE_ARRAY,
710 .key_size = sizeof(int),
715 .btf_load_err = true,
716 .err_str = "Not a VAR kind member",
719 .descr = "global data test #16, invalid var referencing sec",
722 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
723 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [2] */
724 BTF_VAR_ENC(NAME_TBD, 2, 0), /* [3] */
725 /* a section */ /* [4] */
726 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
727 BTF_VAR_SECINFO_ENC(3, 0, 4),
728 /* a section */ /* [5] */
729 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
730 BTF_VAR_SECINFO_ENC(6, 0, 4),
731 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [6] */
734 .str_sec = "\0A\0t\0s\0a\0a",
735 .str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
736 .map_type = BPF_MAP_TYPE_ARRAY,
738 .key_size = sizeof(int),
743 .btf_load_err = true,
744 .err_str = "Invalid type_id",
747 .descr = "global data test #17, invalid var referencing var",
750 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
751 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
752 BTF_VAR_ENC(NAME_TBD, 2, 0), /* [3] */
753 /* a section */ /* [4] */
754 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
755 BTF_VAR_SECINFO_ENC(3, 0, 4),
758 .str_sec = "\0A\0t\0s\0a\0a",
759 .str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
760 .map_type = BPF_MAP_TYPE_ARRAY,
762 .key_size = sizeof(int),
767 .btf_load_err = true,
768 .err_str = "Invalid type_id",
771 .descr = "global data test #18, invalid var loop",
774 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
775 BTF_VAR_ENC(NAME_TBD, 2, 0), /* [2] */
776 /* .bss section */ /* [3] */
777 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
778 BTF_VAR_SECINFO_ENC(2, 0, 4),
781 .str_sec = "\0A\0t\0aaa",
782 .str_sec_size = sizeof("\0A\0t\0aaa"),
783 .map_type = BPF_MAP_TYPE_ARRAY,
785 .key_size = sizeof(int),
790 .btf_load_err = true,
791 .err_str = "Invalid type_id",
794 .descr = "global data test #19, invalid var referencing var",
797 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
798 BTF_VAR_ENC(NAME_TBD, 3, 0), /* [2] */
799 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [3] */
802 .str_sec = "\0A\0t\0s\0a\0a",
803 .str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
804 .map_type = BPF_MAP_TYPE_ARRAY,
806 .key_size = sizeof(int),
811 .btf_load_err = true,
812 .err_str = "Invalid type_id",
815 .descr = "global data test #20, invalid ptr referencing var",
818 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
819 /* PTR type_id=3 */ /* [2] */
820 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 3),
821 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [3] */
824 .str_sec = "\0A\0t\0s\0a\0a",
825 .str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
826 .map_type = BPF_MAP_TYPE_ARRAY,
828 .key_size = sizeof(int),
833 .btf_load_err = true,
834 .err_str = "Invalid type_id",
837 .descr = "global data test #21, var included in struct",
840 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
841 /* struct A { */ /* [2] */
842 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 2),
843 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
844 BTF_MEMBER_ENC(NAME_TBD, 3, 32),/* VAR type_id=3; */
846 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [3] */
849 .str_sec = "\0A\0t\0s\0a\0a",
850 .str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
851 .map_type = BPF_MAP_TYPE_ARRAY,
853 .key_size = sizeof(int),
858 .btf_load_err = true,
859 .err_str = "Invalid member",
862 .descr = "global data test #22, array of var",
865 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
866 BTF_TYPE_ARRAY_ENC(3, 1, 4), /* [2] */
867 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [3] */
870 .str_sec = "\0A\0t\0s\0a\0a",
871 .str_sec_size = sizeof("\0A\0t\0s\0a\0a"),
872 .map_type = BPF_MAP_TYPE_ARRAY,
874 .key_size = sizeof(int),
879 .btf_load_err = true,
880 .err_str = "Invalid elem",
883 .descr = "var after datasec, ptr followed by modifier",
885 /* .bss section */ /* [1] */
886 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 2),
888 BTF_VAR_SECINFO_ENC(4, 0, sizeof(void*)),
889 BTF_VAR_SECINFO_ENC(6, sizeof(void*), 4),
891 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
893 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
894 BTF_VAR_ENC(NAME_TBD, 3, 0), /* [4] */
895 /* const int */ /* [5] */
896 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
897 BTF_VAR_ENC(NAME_TBD, 5, 0), /* [6] */
900 .str_sec = "\0a\0b\0c\0",
901 .str_sec_size = sizeof("\0a\0b\0c\0"),
902 .map_type = BPF_MAP_TYPE_ARRAY,
904 .key_size = sizeof(int),
905 .value_size = sizeof(void*)+4,
910 /* Test member exceeds the size of struct.
918 .descr = "size check test #1",
921 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
922 /* struct A { */ /* [2] */
923 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 2 - 1),
924 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
925 BTF_MEMBER_ENC(NAME_TBD, 1, 32),/* int n; */
929 .str_sec = "\0A\0m\0n",
930 .str_sec_size = sizeof("\0A\0m\0n"),
931 .map_type = BPF_MAP_TYPE_ARRAY,
932 .map_name = "size_check1_map",
933 .key_size = sizeof(int),
938 .btf_load_err = true,
939 .err_str = "Member exceeds struct_size",
942 /* Test member exceeds the size of struct
950 .descr = "size check test #2",
953 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
954 /* int[2] */ /* [2] */
955 BTF_TYPE_ARRAY_ENC(1, 1, 2),
956 /* struct A { */ /* [3] */
957 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 3 - 1),
958 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
959 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* int n[2]; */
963 .str_sec = "\0A\0m\0n",
964 .str_sec_size = sizeof("\0A\0m\0n"),
965 .map_type = BPF_MAP_TYPE_ARRAY,
966 .map_name = "size_check2_map",
967 .key_size = sizeof(int),
972 .btf_load_err = true,
973 .err_str = "Member exceeds struct_size",
976 /* Test member exceeds the size of struct
984 .descr = "size check test #3",
987 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
988 /* void* */ /* [2] */
989 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0),
990 /* struct A { */ /* [3] */
991 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) + sizeof(void *) - 1),
992 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
993 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* void *n; */
997 .str_sec = "\0A\0m\0n",
998 .str_sec_size = sizeof("\0A\0m\0n"),
999 .map_type = BPF_MAP_TYPE_ARRAY,
1000 .map_name = "size_check3_map",
1001 .key_size = sizeof(int),
1006 .btf_load_err = true,
1007 .err_str = "Member exceeds struct_size",
1010 /* Test member exceeds the size of struct
1023 .descr = "size check test #4",
1026 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
1027 /* enum E { */ /* [2] */
1028 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), sizeof(int)),
1029 BTF_ENUM_ENC(NAME_TBD, 0),
1030 BTF_ENUM_ENC(NAME_TBD, 1),
1032 /* struct A { */ /* [3] */
1033 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 2 - 1),
1034 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
1035 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* enum E n; */
1039 .str_sec = "\0E\0E0\0E1\0A\0m\0n",
1040 .str_sec_size = sizeof("\0E\0E0\0E1\0A\0m\0n"),
1041 .map_type = BPF_MAP_TYPE_ARRAY,
1042 .map_name = "size_check4_map",
1043 .key_size = sizeof(int),
1048 .btf_load_err = true,
1049 .err_str = "Member exceeds struct_size",
1052 /* Test member unexceeds the size of struct
1061 * enum E __attribute__((packed)) n;
1065 .descr = "size check test #5",
1068 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
1069 /* char */ /* [2] */
1070 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),
1071 /* enum E { */ /* [3] */
1072 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 1),
1073 BTF_ENUM_ENC(NAME_TBD, 0),
1074 BTF_ENUM_ENC(NAME_TBD, 1),
1076 /* struct A { */ /* [4] */
1077 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 2),
1078 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* char m; */
1079 BTF_MEMBER_ENC(NAME_TBD, 3, 8),/* enum E __attribute__((packed)) n; */
1083 .str_sec = "\0E\0E0\0E1\0A\0m\0n",
1084 .str_sec_size = sizeof("\0E\0E0\0E1\0A\0m\0n"),
1085 .map_type = BPF_MAP_TYPE_ARRAY,
1086 .map_name = "size_check5_map",
1087 .key_size = sizeof(int),
1094 /* typedef const void * const_void_ptr;
1100 .descr = "void test #1",
1103 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1104 /* const void */ /* [2] */
1105 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1106 /* const void* */ /* [3] */
1107 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
1108 /* typedef const void * const_void_ptr */
1109 BTF_TYPEDEF_ENC(NAME_TBD, 3), /* [4] */
1110 /* struct A { */ /* [5] */
1111 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1112 /* const_void_ptr m; */
1113 BTF_MEMBER_ENC(NAME_TBD, 4, 0),
1117 .str_sec = "\0const_void_ptr\0A\0m",
1118 .str_sec_size = sizeof("\0const_void_ptr\0A\0m"),
1119 .map_type = BPF_MAP_TYPE_ARRAY,
1120 .map_name = "void_test1_map",
1121 .key_size = sizeof(int),
1122 .value_size = sizeof(void *),
1133 .descr = "void test #2",
1136 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1137 /* const void */ /* [2] */
1138 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1139 /* struct A { */ /* [3] */
1140 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 8),
1142 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
1146 .str_sec = "\0A\0m",
1147 .str_sec_size = sizeof("\0A\0m"),
1148 .map_type = BPF_MAP_TYPE_ARRAY,
1149 .map_name = "void_test2_map",
1150 .key_size = sizeof(int),
1151 .value_size = sizeof(void *),
1155 .btf_load_err = true,
1156 .err_str = "Invalid member",
1159 /* typedef const void * const_void_ptr;
1163 .descr = "void test #3",
1166 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1167 /* const void */ /* [2] */
1168 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1169 /* const void* */ /* [3] */
1170 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
1171 /* typedef const void * const_void_ptr */
1172 BTF_TYPEDEF_ENC(NAME_TBD, 3), /* [4] */
1173 /* const_void_ptr[4] */
1174 BTF_TYPE_ARRAY_ENC(4, 1, 4), /* [5] */
1177 .str_sec = "\0const_void_ptr",
1178 .str_sec_size = sizeof("\0const_void_ptr"),
1179 .map_type = BPF_MAP_TYPE_ARRAY,
1180 .map_name = "void_test3_map",
1181 .key_size = sizeof(int),
1182 .value_size = sizeof(void *) * 4,
1190 .descr = "void test #4",
1193 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1194 /* const void */ /* [2] */
1195 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1196 /* const void[4] */ /* [3] */
1197 BTF_TYPE_ARRAY_ENC(2, 1, 4),
1200 .str_sec = "\0A\0m",
1201 .str_sec_size = sizeof("\0A\0m"),
1202 .map_type = BPF_MAP_TYPE_ARRAY,
1203 .map_name = "void_test4_map",
1204 .key_size = sizeof(int),
1205 .value_size = sizeof(void *) * 4,
1209 .btf_load_err = true,
1210 .err_str = "Invalid elem",
1213 /* Array_A <------------------+
1214 * elem_type == Array_B |
1217 * Array_B <-------- + |
1218 * elem_type == Array A --+
1221 .descr = "loop test #1",
1224 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1225 /* Array_A */ /* [2] */
1226 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1227 /* Array_B */ /* [3] */
1228 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1232 .str_sec_size = sizeof(""),
1233 .map_type = BPF_MAP_TYPE_ARRAY,
1234 .map_name = "loop_test1_map",
1235 .key_size = sizeof(int),
1236 .value_size = sizeof(sizeof(int) * 8),
1240 .btf_load_err = true,
1241 .err_str = "Loop detected",
1244 /* typedef is _before_ the BTF type of Array_A and Array_B
1246 * typedef Array_B int_array;
1248 * Array_A <------------------+
1249 * elem_type == int_array |
1252 * Array_B <-------- + |
1253 * elem_type == Array_A --+
1256 .descr = "loop test #2",
1259 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1260 /* typedef Array_B int_array */
1261 BTF_TYPEDEF_ENC(1, 4), /* [2] */
1263 BTF_TYPE_ARRAY_ENC(2, 1, 8), /* [3] */
1265 BTF_TYPE_ARRAY_ENC(3, 1, 8), /* [4] */
1268 .str_sec = "\0int_array\0",
1269 .str_sec_size = sizeof("\0int_array"),
1270 .map_type = BPF_MAP_TYPE_ARRAY,
1271 .map_name = "loop_test2_map",
1272 .key_size = sizeof(int),
1273 .value_size = sizeof(sizeof(int) * 8),
1277 .btf_load_err = true,
1278 .err_str = "Loop detected",
1281 /* Array_A <------------------+
1282 * elem_type == Array_B |
1285 * Array_B <-------- + |
1286 * elem_type == Array_A --+
1289 .descr = "loop test #3",
1292 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1293 /* Array_A */ /* [2] */
1294 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1295 /* Array_B */ /* [3] */
1296 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1300 .str_sec_size = sizeof(""),
1301 .map_type = BPF_MAP_TYPE_ARRAY,
1302 .map_name = "loop_test3_map",
1303 .key_size = sizeof(int),
1304 .value_size = sizeof(sizeof(int) * 8),
1308 .btf_load_err = true,
1309 .err_str = "Loop detected",
1312 /* typedef is _between_ the BTF type of Array_A and Array_B
1314 * typedef Array_B int_array;
1316 * Array_A <------------------+
1317 * elem_type == int_array |
1320 * Array_B <-------- + |
1321 * elem_type == Array_A --+
1324 .descr = "loop test #4",
1327 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1328 /* Array_A */ /* [2] */
1329 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1330 /* typedef Array_B int_array */ /* [3] */
1331 BTF_TYPEDEF_ENC(NAME_TBD, 4),
1332 /* Array_B */ /* [4] */
1333 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1336 .str_sec = "\0int_array\0",
1337 .str_sec_size = sizeof("\0int_array"),
1338 .map_type = BPF_MAP_TYPE_ARRAY,
1339 .map_name = "loop_test4_map",
1340 .key_size = sizeof(int),
1341 .value_size = sizeof(sizeof(int) * 8),
1345 .btf_load_err = true,
1346 .err_str = "Loop detected",
1349 /* typedef struct B Struct_B
1362 .descr = "loop test #5",
1365 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1366 /* struct A */ /* [2] */
1367 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
1368 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int x; */
1369 BTF_MEMBER_ENC(NAME_TBD, 3, 32),/* Struct_B y; */
1370 /* typedef struct B Struct_B */
1371 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
1372 /* struct B */ /* [4] */
1373 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
1374 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int x; */
1375 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* struct A y; */
1378 .str_sec = "\0A\0x\0y\0Struct_B\0B\0x\0y",
1379 .str_sec_size = sizeof("\0A\0x\0y\0Struct_B\0B\0x\0y"),
1380 .map_type = BPF_MAP_TYPE_ARRAY,
1381 .map_name = "loop_test5_map",
1382 .key_size = sizeof(int),
1387 .btf_load_err = true,
1388 .err_str = "Loop detected",
1393 * struct A array_a[4];
1397 .descr = "loop test #6",
1400 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1401 BTF_TYPE_ARRAY_ENC(3, 1, 4), /* [2] */
1402 /* struct A */ /* [3] */
1403 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
1404 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int x; */
1405 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* struct A array_a[4]; */
1408 .str_sec = "\0A\0x\0y",
1409 .str_sec_size = sizeof("\0A\0x\0y"),
1410 .map_type = BPF_MAP_TYPE_ARRAY,
1411 .map_name = "loop_test6_map",
1412 .key_size = sizeof(int),
1417 .btf_load_err = true,
1418 .err_str = "Loop detected",
1422 .descr = "loop test #7",
1425 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1426 /* struct A { */ /* [2] */
1427 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1428 /* const void *m; */
1429 BTF_MEMBER_ENC(NAME_TBD, 3, 0),
1430 /* CONST type_id=3 */ /* [3] */
1431 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 4),
1432 /* PTR type_id=2 */ /* [4] */
1433 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 3),
1436 .str_sec = "\0A\0m",
1437 .str_sec_size = sizeof("\0A\0m"),
1438 .map_type = BPF_MAP_TYPE_ARRAY,
1439 .map_name = "loop_test7_map",
1440 .key_size = sizeof(int),
1441 .value_size = sizeof(void *),
1445 .btf_load_err = true,
1446 .err_str = "Loop detected",
1450 .descr = "loop test #8",
1453 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1454 /* struct A { */ /* [2] */
1455 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1456 /* const void *m; */
1457 BTF_MEMBER_ENC(NAME_TBD, 4, 0),
1458 /* struct B { */ /* [3] */
1459 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1460 /* const void *n; */
1461 BTF_MEMBER_ENC(NAME_TBD, 6, 0),
1462 /* CONST type_id=5 */ /* [4] */
1463 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 5),
1464 /* PTR type_id=6 */ /* [5] */
1465 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 6),
1466 /* CONST type_id=7 */ /* [6] */
1467 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 7),
1468 /* PTR type_id=4 */ /* [7] */
1469 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 4),
1472 .str_sec = "\0A\0m\0B\0n",
1473 .str_sec_size = sizeof("\0A\0m\0B\0n"),
1474 .map_type = BPF_MAP_TYPE_ARRAY,
1475 .map_name = "loop_test8_map",
1476 .key_size = sizeof(int),
1477 .value_size = sizeof(void *),
1481 .btf_load_err = true,
1482 .err_str = "Loop detected",
1486 .descr = "string section does not end with null",
1489 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1493 .str_sec_size = sizeof("\0int") - 1,
1494 .map_type = BPF_MAP_TYPE_ARRAY,
1495 .map_name = "hdr_test_map",
1496 .key_size = sizeof(int),
1497 .value_size = sizeof(int),
1501 .btf_load_err = true,
1502 .err_str = "Invalid string section",
1506 .descr = "empty string section",
1509 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1514 .map_type = BPF_MAP_TYPE_ARRAY,
1515 .map_name = "hdr_test_map",
1516 .key_size = sizeof(int),
1517 .value_size = sizeof(int),
1521 .btf_load_err = true,
1522 .err_str = "Invalid string section",
1526 .descr = "empty type section",
1531 .str_sec_size = sizeof("\0int"),
1532 .map_type = BPF_MAP_TYPE_ARRAY,
1533 .map_name = "hdr_test_map",
1534 .key_size = sizeof(int),
1535 .value_size = sizeof(int),
1539 .btf_load_err = true,
1540 .err_str = "No type found",
1544 .descr = "btf_header test. Longer hdr_len",
1547 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1551 .str_sec_size = sizeof("\0int"),
1552 .map_type = BPF_MAP_TYPE_ARRAY,
1553 .map_name = "hdr_test_map",
1554 .key_size = sizeof(int),
1555 .value_size = sizeof(int),
1559 .btf_load_err = true,
1561 .err_str = "Unsupported btf_header",
1565 .descr = "btf_header test. Gap between hdr and type",
1568 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1572 .str_sec_size = sizeof("\0int"),
1573 .map_type = BPF_MAP_TYPE_ARRAY,
1574 .map_name = "hdr_test_map",
1575 .key_size = sizeof(int),
1576 .value_size = sizeof(int),
1580 .btf_load_err = true,
1581 .type_off_delta = 4,
1582 .err_str = "Unsupported section found",
1586 .descr = "btf_header test. Gap between type and str",
1589 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1593 .str_sec_size = sizeof("\0int"),
1594 .map_type = BPF_MAP_TYPE_ARRAY,
1595 .map_name = "hdr_test_map",
1596 .key_size = sizeof(int),
1597 .value_size = sizeof(int),
1601 .btf_load_err = true,
1603 .err_str = "Unsupported section found",
1607 .descr = "btf_header test. Overlap between type and str",
1610 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1614 .str_sec_size = sizeof("\0int"),
1615 .map_type = BPF_MAP_TYPE_ARRAY,
1616 .map_name = "hdr_test_map",
1617 .key_size = sizeof(int),
1618 .value_size = sizeof(int),
1622 .btf_load_err = true,
1623 .str_off_delta = -4,
1624 .err_str = "Section overlap found",
1628 .descr = "btf_header test. Larger BTF size",
1631 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1635 .str_sec_size = sizeof("\0int"),
1636 .map_type = BPF_MAP_TYPE_ARRAY,
1637 .map_name = "hdr_test_map",
1638 .key_size = sizeof(int),
1639 .value_size = sizeof(int),
1643 .btf_load_err = true,
1644 .str_len_delta = -4,
1645 .err_str = "Unsupported section found",
1649 .descr = "btf_header test. Smaller BTF size",
1652 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1656 .str_sec_size = sizeof("\0int"),
1657 .map_type = BPF_MAP_TYPE_ARRAY,
1658 .map_name = "hdr_test_map",
1659 .key_size = sizeof(int),
1660 .value_size = sizeof(int),
1664 .btf_load_err = true,
1666 .err_str = "Total section length too long",
1670 .descr = "array test. index_type/elem_type \"int\"",
1673 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1674 /* int[16] */ /* [2] */
1675 BTF_TYPE_ARRAY_ENC(1, 1, 16),
1679 .str_sec_size = sizeof(""),
1680 .map_type = BPF_MAP_TYPE_ARRAY,
1681 .map_name = "array_test_map",
1682 .key_size = sizeof(int),
1683 .value_size = sizeof(int),
1690 .descr = "array test. index_type/elem_type \"const int\"",
1693 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1694 /* int[16] */ /* [2] */
1695 BTF_TYPE_ARRAY_ENC(3, 3, 16),
1696 /* CONST type_id=1 */ /* [3] */
1697 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 1),
1701 .str_sec_size = sizeof(""),
1702 .map_type = BPF_MAP_TYPE_ARRAY,
1703 .map_name = "array_test_map",
1704 .key_size = sizeof(int),
1705 .value_size = sizeof(int),
1712 .descr = "array test. index_type \"const int:31\"",
1715 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1716 /* int:31 */ /* [2] */
1717 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 31, 4),
1718 /* int[16] */ /* [3] */
1719 BTF_TYPE_ARRAY_ENC(1, 4, 16),
1720 /* CONST type_id=2 */ /* [4] */
1721 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
1725 .str_sec_size = sizeof(""),
1726 .map_type = BPF_MAP_TYPE_ARRAY,
1727 .map_name = "array_test_map",
1728 .key_size = sizeof(int),
1729 .value_size = sizeof(int),
1733 .btf_load_err = true,
1734 .err_str = "Invalid index",
1738 .descr = "array test. elem_type \"const int:31\"",
1741 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1742 /* int:31 */ /* [2] */
1743 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 31, 4),
1744 /* int[16] */ /* [3] */
1745 BTF_TYPE_ARRAY_ENC(4, 1, 16),
1746 /* CONST type_id=2 */ /* [4] */
1747 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
1751 .str_sec_size = sizeof(""),
1752 .map_type = BPF_MAP_TYPE_ARRAY,
1753 .map_name = "array_test_map",
1754 .key_size = sizeof(int),
1755 .value_size = sizeof(int),
1759 .btf_load_err = true,
1760 .err_str = "Invalid array of int",
1764 .descr = "array test. index_type \"void\"",
1767 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1768 /* int[16] */ /* [2] */
1769 BTF_TYPE_ARRAY_ENC(1, 0, 16),
1773 .str_sec_size = sizeof(""),
1774 .map_type = BPF_MAP_TYPE_ARRAY,
1775 .map_name = "array_test_map",
1776 .key_size = sizeof(int),
1777 .value_size = sizeof(int),
1781 .btf_load_err = true,
1782 .err_str = "Invalid index",
1786 .descr = "array test. index_type \"const void\"",
1789 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1790 /* int[16] */ /* [2] */
1791 BTF_TYPE_ARRAY_ENC(1, 3, 16),
1792 /* CONST type_id=0 (void) */ /* [3] */
1793 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1797 .str_sec_size = sizeof(""),
1798 .map_type = BPF_MAP_TYPE_ARRAY,
1799 .map_name = "array_test_map",
1800 .key_size = sizeof(int),
1801 .value_size = sizeof(int),
1805 .btf_load_err = true,
1806 .err_str = "Invalid index",
1810 .descr = "array test. elem_type \"const void\"",
1813 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1814 /* int[16] */ /* [2] */
1815 BTF_TYPE_ARRAY_ENC(3, 1, 16),
1816 /* CONST type_id=0 (void) */ /* [3] */
1817 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1821 .str_sec_size = sizeof(""),
1822 .map_type = BPF_MAP_TYPE_ARRAY,
1823 .map_name = "array_test_map",
1824 .key_size = sizeof(int),
1825 .value_size = sizeof(int),
1829 .btf_load_err = true,
1830 .err_str = "Invalid elem",
1834 .descr = "array test. elem_type \"const void *\"",
1837 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1838 /* const void *[16] */ /* [2] */
1839 BTF_TYPE_ARRAY_ENC(3, 1, 16),
1840 /* CONST type_id=4 */ /* [3] */
1841 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 4),
1842 /* void* */ /* [4] */
1843 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0),
1847 .str_sec_size = sizeof(""),
1848 .map_type = BPF_MAP_TYPE_ARRAY,
1849 .map_name = "array_test_map",
1850 .key_size = sizeof(int),
1851 .value_size = sizeof(int),
1858 .descr = "array test. index_type \"const void *\"",
1861 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1862 /* const void *[16] */ /* [2] */
1863 BTF_TYPE_ARRAY_ENC(3, 3, 16),
1864 /* CONST type_id=4 */ /* [3] */
1865 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 4),
1866 /* void* */ /* [4] */
1867 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0),
1871 .str_sec_size = sizeof(""),
1872 .map_type = BPF_MAP_TYPE_ARRAY,
1873 .map_name = "array_test_map",
1874 .key_size = sizeof(int),
1875 .value_size = sizeof(int),
1879 .btf_load_err = true,
1880 .err_str = "Invalid index",
1884 .descr = "array test. t->size != 0\"",
1887 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1888 /* int[16] */ /* [2] */
1889 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY, 0, 0), 1),
1890 BTF_ARRAY_ENC(1, 1, 16),
1894 .str_sec_size = sizeof(""),
1895 .map_type = BPF_MAP_TYPE_ARRAY,
1896 .map_name = "array_test_map",
1897 .key_size = sizeof(int),
1898 .value_size = sizeof(int),
1902 .btf_load_err = true,
1903 .err_str = "size != 0",
1907 .descr = "int test. invalid int_data",
1909 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), 4),
1914 .str_sec_size = sizeof(""),
1915 .map_type = BPF_MAP_TYPE_ARRAY,
1916 .map_name = "array_test_map",
1917 .key_size = sizeof(int),
1918 .value_size = sizeof(int),
1922 .btf_load_err = true,
1923 .err_str = "Invalid int_data",
1927 .descr = "invalid BTF_INFO",
1930 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1931 BTF_TYPE_ENC(0, 0x20000000, 4),
1935 .str_sec_size = sizeof(""),
1936 .map_type = BPF_MAP_TYPE_ARRAY,
1937 .map_name = "array_test_map",
1938 .key_size = sizeof(int),
1939 .value_size = sizeof(int),
1943 .btf_load_err = true,
1944 .err_str = "Invalid btf_info",
1948 .descr = "fwd test. t->type != 0\"",
1951 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1952 /* fwd type */ /* [2] */
1953 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD, 0, 0), 1),
1957 .str_sec_size = sizeof(""),
1958 .map_type = BPF_MAP_TYPE_ARRAY,
1959 .map_name = "fwd_test_map",
1960 .key_size = sizeof(int),
1961 .value_size = sizeof(int),
1965 .btf_load_err = true,
1966 .err_str = "type != 0",
1970 .descr = "typedef (invalid name, name_off = 0)",
1972 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1973 BTF_TYPEDEF_ENC(0, 1), /* [2] */
1976 .str_sec = "\0__int",
1977 .str_sec_size = sizeof("\0__int"),
1978 .map_type = BPF_MAP_TYPE_ARRAY,
1979 .map_name = "typedef_check_btf",
1980 .key_size = sizeof(int),
1981 .value_size = sizeof(int),
1985 .btf_load_err = true,
1986 .err_str = "Invalid name",
1990 .descr = "typedef (invalid name, invalid identifier)",
1992 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1993 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [2] */
1996 .str_sec = "\0__!int",
1997 .str_sec_size = sizeof("\0__!int"),
1998 .map_type = BPF_MAP_TYPE_ARRAY,
1999 .map_name = "typedef_check_btf",
2000 .key_size = sizeof(int),
2001 .value_size = sizeof(int),
2005 .btf_load_err = true,
2006 .err_str = "Invalid name",
2010 .descr = "ptr type (invalid name, name_off <> 0)",
2012 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2013 BTF_TYPE_ENC(NAME_TBD,
2014 BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 1), /* [2] */
2017 .str_sec = "\0__int",
2018 .str_sec_size = sizeof("\0__int"),
2019 .map_type = BPF_MAP_TYPE_ARRAY,
2020 .map_name = "ptr_type_check_btf",
2021 .key_size = sizeof(int),
2022 .value_size = sizeof(int),
2026 .btf_load_err = true,
2027 .err_str = "Invalid name",
2031 .descr = "volatile type (invalid name, name_off <> 0)",
2033 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2034 BTF_TYPE_ENC(NAME_TBD,
2035 BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), 1), /* [2] */
2038 .str_sec = "\0__int",
2039 .str_sec_size = sizeof("\0__int"),
2040 .map_type = BPF_MAP_TYPE_ARRAY,
2041 .map_name = "volatile_type_check_btf",
2042 .key_size = sizeof(int),
2043 .value_size = sizeof(int),
2047 .btf_load_err = true,
2048 .err_str = "Invalid name",
2052 .descr = "const type (invalid name, name_off <> 0)",
2054 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2055 BTF_TYPE_ENC(NAME_TBD,
2056 BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 1), /* [2] */
2059 .str_sec = "\0__int",
2060 .str_sec_size = sizeof("\0__int"),
2061 .map_type = BPF_MAP_TYPE_ARRAY,
2062 .map_name = "const_type_check_btf",
2063 .key_size = sizeof(int),
2064 .value_size = sizeof(int),
2068 .btf_load_err = true,
2069 .err_str = "Invalid name",
2073 .descr = "restrict type (invalid name, name_off <> 0)",
2075 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2076 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 1), /* [2] */
2077 BTF_TYPE_ENC(NAME_TBD,
2078 BTF_INFO_ENC(BTF_KIND_RESTRICT, 0, 0), 2), /* [3] */
2081 .str_sec = "\0__int",
2082 .str_sec_size = sizeof("\0__int"),
2083 .map_type = BPF_MAP_TYPE_ARRAY,
2084 .map_name = "restrict_type_check_btf",
2085 .key_size = sizeof(int),
2086 .value_size = sizeof(int),
2090 .btf_load_err = true,
2091 .err_str = "Invalid name",
2095 .descr = "fwd type (invalid name, name_off = 0)",
2097 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2098 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD, 0, 0), 0), /* [2] */
2101 .str_sec = "\0__skb",
2102 .str_sec_size = sizeof("\0__skb"),
2103 .map_type = BPF_MAP_TYPE_ARRAY,
2104 .map_name = "fwd_type_check_btf",
2105 .key_size = sizeof(int),
2106 .value_size = sizeof(int),
2110 .btf_load_err = true,
2111 .err_str = "Invalid name",
2115 .descr = "fwd type (invalid name, invalid identifier)",
2117 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2118 BTF_TYPE_ENC(NAME_TBD,
2119 BTF_INFO_ENC(BTF_KIND_FWD, 0, 0), 0), /* [2] */
2122 .str_sec = "\0__!skb",
2123 .str_sec_size = sizeof("\0__!skb"),
2124 .map_type = BPF_MAP_TYPE_ARRAY,
2125 .map_name = "fwd_type_check_btf",
2126 .key_size = sizeof(int),
2127 .value_size = sizeof(int),
2131 .btf_load_err = true,
2132 .err_str = "Invalid name",
2136 .descr = "array type (invalid name, name_off <> 0)",
2138 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2139 BTF_TYPE_ENC(NAME_TBD,
2140 BTF_INFO_ENC(BTF_KIND_ARRAY, 0, 0), 0), /* [2] */
2141 BTF_ARRAY_ENC(1, 1, 4),
2144 .str_sec = "\0__skb",
2145 .str_sec_size = sizeof("\0__skb"),
2146 .map_type = BPF_MAP_TYPE_ARRAY,
2147 .map_name = "array_type_check_btf",
2148 .key_size = sizeof(int),
2149 .value_size = sizeof(int),
2153 .btf_load_err = true,
2154 .err_str = "Invalid name",
2158 .descr = "struct type (name_off = 0)",
2160 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2162 BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4), /* [2] */
2163 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2167 .str_sec_size = sizeof("\0A"),
2168 .map_type = BPF_MAP_TYPE_ARRAY,
2169 .map_name = "struct_type_check_btf",
2170 .key_size = sizeof(int),
2171 .value_size = sizeof(int),
2178 .descr = "struct type (invalid name, invalid identifier)",
2180 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2181 BTF_TYPE_ENC(NAME_TBD,
2182 BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4), /* [2] */
2183 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2186 .str_sec = "\0A!\0B",
2187 .str_sec_size = sizeof("\0A!\0B"),
2188 .map_type = BPF_MAP_TYPE_ARRAY,
2189 .map_name = "struct_type_check_btf",
2190 .key_size = sizeof(int),
2191 .value_size = sizeof(int),
2195 .btf_load_err = true,
2196 .err_str = "Invalid name",
2200 .descr = "struct member (name_off = 0)",
2202 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2204 BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4), /* [2] */
2205 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2209 .str_sec_size = sizeof("\0A"),
2210 .map_type = BPF_MAP_TYPE_ARRAY,
2211 .map_name = "struct_type_check_btf",
2212 .key_size = sizeof(int),
2213 .value_size = sizeof(int),
2220 .descr = "struct member (invalid name, invalid identifier)",
2222 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2223 BTF_TYPE_ENC(NAME_TBD,
2224 BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4), /* [2] */
2225 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2228 .str_sec = "\0A\0B*",
2229 .str_sec_size = sizeof("\0A\0B*"),
2230 .map_type = BPF_MAP_TYPE_ARRAY,
2231 .map_name = "struct_type_check_btf",
2232 .key_size = sizeof(int),
2233 .value_size = sizeof(int),
2237 .btf_load_err = true,
2238 .err_str = "Invalid name",
2242 .descr = "enum type (name_off = 0)",
2244 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2246 BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2247 sizeof(int)), /* [2] */
2248 BTF_ENUM_ENC(NAME_TBD, 0),
2251 .str_sec = "\0A\0B",
2252 .str_sec_size = sizeof("\0A\0B"),
2253 .map_type = BPF_MAP_TYPE_ARRAY,
2254 .map_name = "enum_type_check_btf",
2255 .key_size = sizeof(int),
2256 .value_size = sizeof(int),
2263 .descr = "enum type (invalid name, invalid identifier)",
2265 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2266 BTF_TYPE_ENC(NAME_TBD,
2267 BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2268 sizeof(int)), /* [2] */
2269 BTF_ENUM_ENC(NAME_TBD, 0),
2272 .str_sec = "\0A!\0B",
2273 .str_sec_size = sizeof("\0A!\0B"),
2274 .map_type = BPF_MAP_TYPE_ARRAY,
2275 .map_name = "enum_type_check_btf",
2276 .key_size = sizeof(int),
2277 .value_size = sizeof(int),
2281 .btf_load_err = true,
2282 .err_str = "Invalid name",
2286 .descr = "enum member (invalid name, name_off = 0)",
2288 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2290 BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2291 sizeof(int)), /* [2] */
2296 .str_sec_size = sizeof(""),
2297 .map_type = BPF_MAP_TYPE_ARRAY,
2298 .map_name = "enum_type_check_btf",
2299 .key_size = sizeof(int),
2300 .value_size = sizeof(int),
2304 .btf_load_err = true,
2305 .err_str = "Invalid name",
2309 .descr = "enum member (invalid name, invalid identifier)",
2311 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2313 BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2314 sizeof(int)), /* [2] */
2315 BTF_ENUM_ENC(NAME_TBD, 0),
2319 .str_sec_size = sizeof("\0A!"),
2320 .map_type = BPF_MAP_TYPE_ARRAY,
2321 .map_name = "enum_type_check_btf",
2322 .key_size = sizeof(int),
2323 .value_size = sizeof(int),
2327 .btf_load_err = true,
2328 .err_str = "Invalid name",
2331 .descr = "arraymap invalid btf key (a bit field)",
2334 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2335 /* 32 bit int with 32 bit offset */ /* [2] */
2336 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 32, 32, 8),
2340 .str_sec_size = sizeof(""),
2341 .map_type = BPF_MAP_TYPE_ARRAY,
2342 .map_name = "array_map_check_btf",
2343 .key_size = sizeof(int),
2344 .value_size = sizeof(int),
2348 .map_create_err = true,
2352 .descr = "arraymap invalid btf key (!= 32 bits)",
2355 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2356 /* 16 bit int with 0 bit offset */ /* [2] */
2357 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 16, 2),
2361 .str_sec_size = sizeof(""),
2362 .map_type = BPF_MAP_TYPE_ARRAY,
2363 .map_name = "array_map_check_btf",
2364 .key_size = sizeof(int),
2365 .value_size = sizeof(int),
2369 .map_create_err = true,
2373 .descr = "arraymap invalid btf value (too small)",
2376 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2380 .str_sec_size = sizeof(""),
2381 .map_type = BPF_MAP_TYPE_ARRAY,
2382 .map_name = "array_map_check_btf",
2383 .key_size = sizeof(int),
2384 /* btf_value_size < map->value_size */
2385 .value_size = sizeof(__u64),
2389 .map_create_err = true,
2393 .descr = "arraymap invalid btf value (too big)",
2396 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2400 .str_sec_size = sizeof(""),
2401 .map_type = BPF_MAP_TYPE_ARRAY,
2402 .map_name = "array_map_check_btf",
2403 .key_size = sizeof(int),
2404 /* btf_value_size > map->value_size */
2405 .value_size = sizeof(__u16),
2409 .map_create_err = true,
2413 .descr = "func proto (int (*)(int, unsigned int))",
2415 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2416 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2417 /* int (*)(int, unsigned int) */
2418 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
2419 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2420 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2424 .str_sec_size = sizeof(""),
2425 .map_type = BPF_MAP_TYPE_ARRAY,
2426 .map_name = "func_proto_type_check_btf",
2427 .key_size = sizeof(int),
2428 .value_size = sizeof(int),
2435 .descr = "func proto (vararg)",
2437 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2438 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2439 /* void (*)(int, unsigned int, ...) */
2440 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2441 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2442 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2443 BTF_FUNC_PROTO_ARG_ENC(0, 0),
2447 .str_sec_size = sizeof(""),
2448 .map_type = BPF_MAP_TYPE_ARRAY,
2449 .map_name = "func_proto_type_check_btf",
2450 .key_size = sizeof(int),
2451 .value_size = sizeof(int),
2458 .descr = "func proto (vararg with name)",
2460 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2461 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2462 /* void (*)(int a, unsigned int b, ... c) */
2463 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2464 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2465 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2466 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 0),
2469 .str_sec = "\0a\0b\0c",
2470 .str_sec_size = sizeof("\0a\0b\0c"),
2471 .map_type = BPF_MAP_TYPE_ARRAY,
2472 .map_name = "func_proto_type_check_btf",
2473 .key_size = sizeof(int),
2474 .value_size = sizeof(int),
2478 .btf_load_err = true,
2479 .err_str = "Invalid arg#3",
2483 .descr = "func proto (arg after vararg)",
2485 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2486 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2487 /* void (*)(int a, ..., unsigned int b) */
2488 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2489 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2490 BTF_FUNC_PROTO_ARG_ENC(0, 0),
2491 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2494 .str_sec = "\0a\0b",
2495 .str_sec_size = sizeof("\0a\0b"),
2496 .map_type = BPF_MAP_TYPE_ARRAY,
2497 .map_name = "func_proto_type_check_btf",
2498 .key_size = sizeof(int),
2499 .value_size = sizeof(int),
2503 .btf_load_err = true,
2504 .err_str = "Invalid arg#2",
2508 .descr = "func proto (CONST=>TYPEDEF=>PTR=>FUNC_PROTO)",
2510 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2511 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2512 /* typedef void (*func_ptr)(int, unsigned int) */
2513 BTF_TYPEDEF_ENC(NAME_TBD, 5), /* [3] */
2514 /* const func_ptr */
2515 BTF_CONST_ENC(3), /* [4] */
2516 BTF_PTR_ENC(6), /* [5] */
2517 BTF_FUNC_PROTO_ENC(0, 2), /* [6] */
2518 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2519 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2522 .str_sec = "\0func_ptr",
2523 .str_sec_size = sizeof("\0func_ptr"),
2524 .map_type = BPF_MAP_TYPE_ARRAY,
2525 .map_name = "func_proto_type_check_btf",
2526 .key_size = sizeof(int),
2527 .value_size = sizeof(int),
2534 .descr = "func proto (TYPEDEF=>FUNC_PROTO)",
2536 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2537 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2538 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
2539 BTF_FUNC_PROTO_ENC(0, 2), /* [4] */
2540 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2541 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2544 .str_sec = "\0func_typedef",
2545 .str_sec_size = sizeof("\0func_typedef"),
2546 .map_type = BPF_MAP_TYPE_ARRAY,
2547 .map_name = "func_proto_type_check_btf",
2548 .key_size = sizeof(int),
2549 .value_size = sizeof(int),
2556 .descr = "func proto (btf_resolve(arg))",
2558 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2559 /* void (*)(const void *) */
2560 BTF_FUNC_PROTO_ENC(0, 1), /* [2] */
2561 BTF_FUNC_PROTO_ARG_ENC(0, 3),
2562 BTF_CONST_ENC(4), /* [3] */
2563 BTF_PTR_ENC(0), /* [4] */
2567 .str_sec_size = sizeof(""),
2568 .map_type = BPF_MAP_TYPE_ARRAY,
2569 .map_name = "func_proto_type_check_btf",
2570 .key_size = sizeof(int),
2571 .value_size = sizeof(int),
2578 .descr = "func proto (Not all arg has name)",
2580 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2581 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2582 /* void (*)(int, unsigned int b) */
2583 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2584 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2585 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2589 .str_sec_size = sizeof("\0b"),
2590 .map_type = BPF_MAP_TYPE_ARRAY,
2591 .map_name = "func_proto_type_check_btf",
2592 .key_size = sizeof(int),
2593 .value_size = sizeof(int),
2600 .descr = "func proto (Bad arg name_off)",
2602 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2603 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2604 /* void (*)(int a, unsigned int <bad_name_off>) */
2605 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2606 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2607 BTF_FUNC_PROTO_ARG_ENC(0x0fffffff, 2),
2611 .str_sec_size = sizeof("\0a"),
2612 .map_type = BPF_MAP_TYPE_ARRAY,
2613 .map_name = "func_proto_type_check_btf",
2614 .key_size = sizeof(int),
2615 .value_size = sizeof(int),
2619 .btf_load_err = true,
2620 .err_str = "Invalid arg#2",
2624 .descr = "func proto (Bad arg name)",
2626 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2627 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2628 /* void (*)(int a, unsigned int !!!) */
2629 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2630 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2631 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2634 .str_sec = "\0a\0!!!",
2635 .str_sec_size = sizeof("\0a\0!!!"),
2636 .map_type = BPF_MAP_TYPE_ARRAY,
2637 .map_name = "func_proto_type_check_btf",
2638 .key_size = sizeof(int),
2639 .value_size = sizeof(int),
2643 .btf_load_err = true,
2644 .err_str = "Invalid arg#2",
2648 .descr = "func proto (Invalid return type)",
2650 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2651 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2652 /* <bad_ret_type> (*)(int, unsigned int) */
2653 BTF_FUNC_PROTO_ENC(100, 2), /* [3] */
2654 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2655 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2659 .str_sec_size = sizeof(""),
2660 .map_type = BPF_MAP_TYPE_ARRAY,
2661 .map_name = "func_proto_type_check_btf",
2662 .key_size = sizeof(int),
2663 .value_size = sizeof(int),
2667 .btf_load_err = true,
2668 .err_str = "Invalid return type",
2672 .descr = "func proto (with func name)",
2674 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2675 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2676 /* void func_proto(int, unsigned int) */
2677 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 0, 2), 0), /* [3] */
2678 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2679 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2682 .str_sec = "\0func_proto",
2683 .str_sec_size = sizeof("\0func_proto"),
2684 .map_type = BPF_MAP_TYPE_ARRAY,
2685 .map_name = "func_proto_type_check_btf",
2686 .key_size = sizeof(int),
2687 .value_size = sizeof(int),
2691 .btf_load_err = true,
2692 .err_str = "Invalid name",
2696 .descr = "func proto (const void arg)",
2698 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2699 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2700 /* void (*)(const void) */
2701 BTF_FUNC_PROTO_ENC(0, 1), /* [3] */
2702 BTF_FUNC_PROTO_ARG_ENC(0, 4),
2703 BTF_CONST_ENC(0), /* [4] */
2707 .str_sec_size = sizeof(""),
2708 .map_type = BPF_MAP_TYPE_ARRAY,
2709 .map_name = "func_proto_type_check_btf",
2710 .key_size = sizeof(int),
2711 .value_size = sizeof(int),
2715 .btf_load_err = true,
2716 .err_str = "Invalid arg#1",
2720 .descr = "func (void func(int a, unsigned int b))",
2722 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2723 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2724 /* void (*)(int a, unsigned int b) */
2725 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2726 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2727 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2728 /* void func(int a, unsigned int b) */
2729 BTF_FUNC_ENC(NAME_TBD, 3), /* [4] */
2732 .str_sec = "\0a\0b\0func",
2733 .str_sec_size = sizeof("\0a\0b\0func"),
2734 .map_type = BPF_MAP_TYPE_ARRAY,
2735 .map_name = "func_type_check_btf",
2736 .key_size = sizeof(int),
2737 .value_size = sizeof(int),
2744 .descr = "func (No func name)",
2746 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2747 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2748 /* void (*)(int a, unsigned int b) */
2749 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2750 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2751 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2752 /* void <no_name>(int a, unsigned int b) */
2753 BTF_FUNC_ENC(0, 3), /* [4] */
2756 .str_sec = "\0a\0b",
2757 .str_sec_size = sizeof("\0a\0b"),
2758 .map_type = BPF_MAP_TYPE_ARRAY,
2759 .map_name = "func_type_check_btf",
2760 .key_size = sizeof(int),
2761 .value_size = sizeof(int),
2765 .btf_load_err = true,
2766 .err_str = "Invalid name",
2770 .descr = "func (Invalid func name)",
2772 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2773 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2774 /* void (*)(int a, unsigned int b) */
2775 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2776 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2777 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2778 /* void !!!(int a, unsigned int b) */
2779 BTF_FUNC_ENC(NAME_TBD, 3), /* [4] */
2782 .str_sec = "\0a\0b\0!!!",
2783 .str_sec_size = sizeof("\0a\0b\0!!!"),
2784 .map_type = BPF_MAP_TYPE_ARRAY,
2785 .map_name = "func_type_check_btf",
2786 .key_size = sizeof(int),
2787 .value_size = sizeof(int),
2791 .btf_load_err = true,
2792 .err_str = "Invalid name",
2796 .descr = "func (Some arg has no name)",
2798 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2799 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2800 /* void (*)(int a, unsigned int) */
2801 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2802 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2803 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2804 /* void func(int a, unsigned int) */
2805 BTF_FUNC_ENC(NAME_TBD, 3), /* [4] */
2808 .str_sec = "\0a\0func",
2809 .str_sec_size = sizeof("\0a\0func"),
2810 .map_type = BPF_MAP_TYPE_ARRAY,
2811 .map_name = "func_type_check_btf",
2812 .key_size = sizeof(int),
2813 .value_size = sizeof(int),
2817 .btf_load_err = true,
2818 .err_str = "Invalid arg#2",
2822 .descr = "func (Non zero vlen)",
2824 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2825 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2826 /* void (*)(int a, unsigned int b) */
2827 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2828 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2829 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2830 /* void func(int a, unsigned int b) */
2831 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FUNC, 0, 2), 3), /* [4] */
2834 .str_sec = "\0a\0b\0func",
2835 .str_sec_size = sizeof("\0a\0b\0func"),
2836 .map_type = BPF_MAP_TYPE_ARRAY,
2837 .map_name = "func_type_check_btf",
2838 .key_size = sizeof(int),
2839 .value_size = sizeof(int),
2843 .btf_load_err = true,
2844 .err_str = "Invalid func linkage",
2848 .descr = "func (Not referring to FUNC_PROTO)",
2850 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2851 BTF_FUNC_ENC(NAME_TBD, 1), /* [2] */
2854 .str_sec = "\0func",
2855 .str_sec_size = sizeof("\0func"),
2856 .map_type = BPF_MAP_TYPE_ARRAY,
2857 .map_name = "func_type_check_btf",
2858 .key_size = sizeof(int),
2859 .value_size = sizeof(int),
2863 .btf_load_err = true,
2864 .err_str = "Invalid type_id",
2868 .descr = "invalid int kind_flag",
2870 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2871 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT, 1, 0), 4), /* [2] */
2872 BTF_INT_ENC(0, 0, 32),
2876 .map_type = BPF_MAP_TYPE_ARRAY,
2877 .map_name = "int_type_check_btf",
2878 .key_size = sizeof(int),
2879 .value_size = sizeof(int),
2883 .btf_load_err = true,
2884 .err_str = "Invalid btf_info kind_flag",
2888 .descr = "invalid ptr kind_flag",
2890 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2891 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 1, 0), 1), /* [2] */
2895 .map_type = BPF_MAP_TYPE_ARRAY,
2896 .map_name = "ptr_type_check_btf",
2897 .key_size = sizeof(int),
2898 .value_size = sizeof(int),
2902 .btf_load_err = true,
2903 .err_str = "Invalid btf_info kind_flag",
2907 .descr = "invalid array kind_flag",
2909 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2910 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY, 1, 0), 0), /* [2] */
2911 BTF_ARRAY_ENC(1, 1, 1),
2915 .map_type = BPF_MAP_TYPE_ARRAY,
2916 .map_name = "array_type_check_btf",
2917 .key_size = sizeof(int),
2918 .value_size = sizeof(int),
2922 .btf_load_err = true,
2923 .err_str = "Invalid btf_info kind_flag",
2927 .descr = "valid fwd kind_flag",
2929 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2930 BTF_TYPE_ENC(NAME_TBD,
2931 BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [2] */
2935 .map_type = BPF_MAP_TYPE_ARRAY,
2936 .map_name = "fwd_type_check_btf",
2937 .key_size = sizeof(int),
2938 .value_size = sizeof(int),
2945 .descr = "invalid typedef kind_flag",
2947 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2948 BTF_TYPE_ENC(NAME_TBD,
2949 BTF_INFO_ENC(BTF_KIND_TYPEDEF, 1, 0), 1), /* [2] */
2953 .map_type = BPF_MAP_TYPE_ARRAY,
2954 .map_name = "typedef_type_check_btf",
2955 .key_size = sizeof(int),
2956 .value_size = sizeof(int),
2960 .btf_load_err = true,
2961 .err_str = "Invalid btf_info kind_flag",
2965 .descr = "invalid volatile kind_flag",
2967 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2968 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 1, 0), 1), /* [2] */
2972 .map_type = BPF_MAP_TYPE_ARRAY,
2973 .map_name = "volatile_type_check_btf",
2974 .key_size = sizeof(int),
2975 .value_size = sizeof(int),
2979 .btf_load_err = true,
2980 .err_str = "Invalid btf_info kind_flag",
2984 .descr = "invalid const kind_flag",
2986 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2987 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 1, 0), 1), /* [2] */
2991 .map_type = BPF_MAP_TYPE_ARRAY,
2992 .map_name = "const_type_check_btf",
2993 .key_size = sizeof(int),
2994 .value_size = sizeof(int),
2998 .btf_load_err = true,
2999 .err_str = "Invalid btf_info kind_flag",
3003 .descr = "invalid restrict kind_flag",
3005 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3006 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_RESTRICT, 1, 0), 1), /* [2] */
3010 .map_type = BPF_MAP_TYPE_ARRAY,
3011 .map_name = "restrict_type_check_btf",
3012 .key_size = sizeof(int),
3013 .value_size = sizeof(int),
3017 .btf_load_err = true,
3018 .err_str = "Invalid btf_info kind_flag",
3022 .descr = "invalid func kind_flag",
3024 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3025 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 0, 0), 0), /* [2] */
3026 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FUNC, 1, 0), 2), /* [3] */
3030 .map_type = BPF_MAP_TYPE_ARRAY,
3031 .map_name = "func_type_check_btf",
3032 .key_size = sizeof(int),
3033 .value_size = sizeof(int),
3037 .btf_load_err = true,
3038 .err_str = "Invalid btf_info kind_flag",
3042 .descr = "invalid func_proto kind_flag",
3044 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3045 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 1, 0), 0), /* [2] */
3049 .map_type = BPF_MAP_TYPE_ARRAY,
3050 .map_name = "func_proto_type_check_btf",
3051 .key_size = sizeof(int),
3052 .value_size = sizeof(int),
3056 .btf_load_err = true,
3057 .err_str = "Invalid btf_info kind_flag",
3061 .descr = "valid struct, kind_flag, bitfield_size = 0",
3063 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3064 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 8), /* [2] */
3065 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(0, 0)),
3066 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(0, 32)),
3069 BTF_STR_SEC("\0A\0B"),
3070 .map_type = BPF_MAP_TYPE_ARRAY,
3071 .map_name = "struct_type_check_btf",
3072 .key_size = sizeof(int),
3073 .value_size = sizeof(int),
3080 .descr = "valid struct, kind_flag, int member, bitfield_size != 0",
3082 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3083 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4), /* [2] */
3084 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 0)),
3085 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 4)),
3088 BTF_STR_SEC("\0A\0B"),
3089 .map_type = BPF_MAP_TYPE_ARRAY,
3090 .map_name = "struct_type_check_btf",
3091 .key_size = sizeof(int),
3092 .value_size = sizeof(int),
3099 .descr = "valid union, kind_flag, int member, bitfield_size != 0",
3101 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3102 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 4), /* [2] */
3103 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 0)),
3104 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 0)),
3107 BTF_STR_SEC("\0A\0B"),
3108 .map_type = BPF_MAP_TYPE_ARRAY,
3109 .map_name = "union_type_check_btf",
3110 .key_size = sizeof(int),
3111 .value_size = sizeof(int),
3118 .descr = "valid struct, kind_flag, enum member, bitfield_size != 0",
3120 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3121 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3122 BTF_ENUM_ENC(NAME_TBD, 0),
3123 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),/* [3] */
3124 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 0)),
3125 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 4)),
3128 BTF_STR_SEC("\0A\0B\0C"),
3129 .map_type = BPF_MAP_TYPE_ARRAY,
3130 .map_name = "struct_type_check_btf",
3131 .key_size = sizeof(int),
3132 .value_size = sizeof(int),
3139 .descr = "valid union, kind_flag, enum member, bitfield_size != 0",
3141 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3142 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3143 BTF_ENUM_ENC(NAME_TBD, 0),
3144 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 4), /* [3] */
3145 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 0)),
3146 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 0)),
3149 BTF_STR_SEC("\0A\0B\0C"),
3150 .map_type = BPF_MAP_TYPE_ARRAY,
3151 .map_name = "union_type_check_btf",
3152 .key_size = sizeof(int),
3153 .value_size = sizeof(int),
3160 .descr = "valid struct, kind_flag, typedef member, bitfield_size != 0",
3162 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3163 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3164 BTF_ENUM_ENC(NAME_TBD, 0),
3165 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),/* [3] */
3166 BTF_MEMBER_ENC(NAME_TBD, 4, BTF_MEMBER_OFFSET(4, 0)),
3167 BTF_MEMBER_ENC(NAME_TBD, 5, BTF_MEMBER_OFFSET(4, 4)),
3168 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [4] */
3169 BTF_TYPEDEF_ENC(NAME_TBD, 2), /* [5] */
3172 BTF_STR_SEC("\0A\0B\0C\0D\0E"),
3173 .map_type = BPF_MAP_TYPE_ARRAY,
3174 .map_name = "struct_type_check_btf",
3175 .key_size = sizeof(int),
3176 .value_size = sizeof(int),
3183 .descr = "valid union, kind_flag, typedef member, bitfield_size != 0",
3185 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3186 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3187 BTF_ENUM_ENC(NAME_TBD, 0),
3188 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 4), /* [3] */
3189 BTF_MEMBER_ENC(NAME_TBD, 4, BTF_MEMBER_OFFSET(4, 0)),
3190 BTF_MEMBER_ENC(NAME_TBD, 5, BTF_MEMBER_OFFSET(4, 0)),
3191 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [4] */
3192 BTF_TYPEDEF_ENC(NAME_TBD, 2), /* [5] */
3195 BTF_STR_SEC("\0A\0B\0C\0D\0E"),
3196 .map_type = BPF_MAP_TYPE_ARRAY,
3197 .map_name = "union_type_check_btf",
3198 .key_size = sizeof(int),
3199 .value_size = sizeof(int),
3206 .descr = "invalid struct, kind_flag, bitfield_size greater than struct size",
3208 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3209 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4), /* [2] */
3210 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(20, 0)),
3211 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(20, 20)),
3214 BTF_STR_SEC("\0A\0B"),
3215 .map_type = BPF_MAP_TYPE_ARRAY,
3216 .map_name = "struct_type_check_btf",
3217 .key_size = sizeof(int),
3218 .value_size = sizeof(int),
3222 .btf_load_err = true,
3223 .err_str = "Member exceeds struct_size",
3227 .descr = "invalid struct, kind_flag, bitfield base_type int not regular",
3229 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3230 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 20, 4), /* [2] */
3231 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4), /* [3] */
3232 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(20, 0)),
3233 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(20, 20)),
3236 BTF_STR_SEC("\0A\0B"),
3237 .map_type = BPF_MAP_TYPE_ARRAY,
3238 .map_name = "struct_type_check_btf",
3239 .key_size = sizeof(int),
3240 .value_size = sizeof(int),
3244 .btf_load_err = true,
3245 .err_str = "Invalid member base type",
3249 .descr = "invalid struct, kind_flag, base_type int not regular",
3251 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3252 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 12, 4), /* [2] */
3253 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4), /* [3] */
3254 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(8, 0)),
3255 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(8, 8)),
3258 BTF_STR_SEC("\0A\0B"),
3259 .map_type = BPF_MAP_TYPE_ARRAY,
3260 .map_name = "struct_type_check_btf",
3261 .key_size = sizeof(int),
3262 .value_size = sizeof(int),
3266 .btf_load_err = true,
3267 .err_str = "Invalid member base type",
3271 .descr = "invalid union, kind_flag, bitfield_size greater than struct size",
3273 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3274 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 2), /* [2] */
3275 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(8, 0)),
3276 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(20, 0)),
3279 BTF_STR_SEC("\0A\0B"),
3280 .map_type = BPF_MAP_TYPE_ARRAY,
3281 .map_name = "union_type_check_btf",
3282 .key_size = sizeof(int),
3283 .value_size = sizeof(int),
3287 .btf_load_err = true,
3288 .err_str = "Member exceeds struct_size",
3292 .descr = "invalid struct, kind_flag, int member, bitfield_size = 0, wrong byte alignment",
3294 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3295 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
3296 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 12), /* [3] */
3297 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),
3298 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 36)),
3301 BTF_STR_SEC("\0A\0B"),
3302 .map_type = BPF_MAP_TYPE_ARRAY,
3303 .map_name = "struct_type_check_btf",
3304 .key_size = sizeof(int),
3305 .value_size = sizeof(int),
3309 .btf_load_err = true,
3310 .err_str = "Invalid member offset",
3314 .descr = "invalid struct, kind_flag, enum member, bitfield_size = 0, wrong byte alignment",
3316 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3317 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
3318 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3319 BTF_ENUM_ENC(NAME_TBD, 0),
3320 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 12), /* [3] */
3321 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),
3322 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 36)),
3325 BTF_STR_SEC("\0A\0B\0C"),
3326 .map_type = BPF_MAP_TYPE_ARRAY,
3327 .map_name = "struct_type_check_btf",
3328 .key_size = sizeof(int),
3329 .value_size = sizeof(int),
3333 .btf_load_err = true,
3334 .err_str = "Invalid member offset",
3338 .descr = "128-bit int",
3340 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3341 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16), /* [2] */
3345 .map_type = BPF_MAP_TYPE_ARRAY,
3346 .map_name = "int_type_check_btf",
3347 .key_size = sizeof(int),
3348 .value_size = sizeof(int),
3355 .descr = "struct, 128-bit int member",
3357 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3358 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16), /* [2] */
3359 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 16), /* [3] */
3360 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3364 .map_type = BPF_MAP_TYPE_ARRAY,
3365 .map_name = "struct_type_check_btf",
3366 .key_size = sizeof(int),
3367 .value_size = sizeof(int),
3374 .descr = "struct, 120-bit int member bitfield",
3376 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3377 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 120, 16), /* [2] */
3378 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 16), /* [3] */
3379 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3383 .map_type = BPF_MAP_TYPE_ARRAY,
3384 .map_name = "struct_type_check_btf",
3385 .key_size = sizeof(int),
3386 .value_size = sizeof(int),
3393 .descr = "struct, kind_flag, 128-bit int member",
3395 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3396 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16), /* [2] */
3397 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 16), /* [3] */
3398 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),
3402 .map_type = BPF_MAP_TYPE_ARRAY,
3403 .map_name = "struct_type_check_btf",
3404 .key_size = sizeof(int),
3405 .value_size = sizeof(int),
3412 .descr = "struct, kind_flag, 120-bit int member bitfield",
3414 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3415 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16), /* [2] */
3416 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 16), /* [3] */
3417 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(120, 0)),
3421 .map_type = BPF_MAP_TYPE_ARRAY,
3422 .map_name = "struct_type_check_btf",
3423 .key_size = sizeof(int),
3424 .value_size = sizeof(int),
3430 * typedef int arr_t[16];
3436 .descr = "struct->ptr->typedef->array->int size resolution",
3438 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [1] */
3439 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3440 BTF_PTR_ENC(3), /* [2] */
3441 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
3442 BTF_TYPE_ARRAY_ENC(5, 5, 16), /* [4] */
3443 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [5] */
3446 BTF_STR_SEC("\0s\0a\0arr_t"),
3447 .map_type = BPF_MAP_TYPE_ARRAY,
3448 .map_name = "ptr_mod_chain_size_resolve_map",
3449 .key_size = sizeof(int),
3450 .value_size = sizeof(int) * 16,
3451 .key_type_id = 5 /* int */,
3452 .value_type_id = 3 /* arr_t */,
3456 * typedef int arr_t[16][8][4];
3462 .descr = "struct->ptr->typedef->multi-array->int size resolution",
3464 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [1] */
3465 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3466 BTF_PTR_ENC(3), /* [2] */
3467 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
3468 BTF_TYPE_ARRAY_ENC(5, 7, 16), /* [4] */
3469 BTF_TYPE_ARRAY_ENC(6, 7, 8), /* [5] */
3470 BTF_TYPE_ARRAY_ENC(7, 7, 4), /* [6] */
3471 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [7] */
3474 BTF_STR_SEC("\0s\0a\0arr_t"),
3475 .map_type = BPF_MAP_TYPE_ARRAY,
3476 .map_name = "multi_arr_size_resolve_map",
3477 .key_size = sizeof(int),
3478 .value_size = sizeof(int) * 16 * 8 * 4,
3479 .key_type_id = 7 /* int */,
3480 .value_type_id = 3 /* arr_t */,
3484 * typedef int int_t;
3485 * typedef int_t arr3_t[4];
3486 * typedef arr3_t arr2_t[8];
3487 * typedef arr2_t arr1_t[16];
3493 .descr = "typedef/multi-arr mix size resolution",
3495 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [1] */
3496 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3497 BTF_PTR_ENC(3), /* [2] */
3498 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
3499 BTF_TYPE_ARRAY_ENC(5, 10, 16), /* [4] */
3500 BTF_TYPEDEF_ENC(NAME_TBD, 6), /* [5] */
3501 BTF_TYPE_ARRAY_ENC(7, 10, 8), /* [6] */
3502 BTF_TYPEDEF_ENC(NAME_TBD, 8), /* [7] */
3503 BTF_TYPE_ARRAY_ENC(9, 10, 4), /* [8] */
3504 BTF_TYPEDEF_ENC(NAME_TBD, 10), /* [9] */
3505 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [10] */
3508 BTF_STR_SEC("\0s\0a\0arr1_t\0arr2_t\0arr3_t\0int_t"),
3509 .map_type = BPF_MAP_TYPE_ARRAY,
3510 .map_name = "typedef_arra_mix_size_resolve_map",
3511 .key_size = sizeof(int),
3512 .value_size = sizeof(int) * 16 * 8 * 4,
3513 .key_type_id = 10 /* int */,
3514 .value_type_id = 3 /* arr_t */,
3518 * elf .rodata section size 4 and btf .rodata section vlen 0.
3521 .descr = "datasec: vlen == 0",
3524 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3525 /* .rodata section */
3526 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 0), 4),
3530 BTF_STR_SEC("\0.rodata"),
3531 .map_type = BPF_MAP_TYPE_ARRAY,
3532 .key_size = sizeof(int),
3533 .value_size = sizeof(int),
3539 .descr = "datasec: name '?.foo bar:buz' is ok",
3542 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3543 /* VAR x */ /* [2] */
3544 BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
3546 /* DATASEC ?.data */ /* [3] */
3547 BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
3548 BTF_VAR_SECINFO_ENC(2, 0, 4),
3551 BTF_STR_SEC("\0x\0?.foo bar:buz"),
3554 .descr = "datasec: name with non-printable first char not is ok",
3557 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3558 /* VAR x */ /* [2] */
3559 BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
3561 /* DATASEC ?.data */ /* [3] */
3562 BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
3563 BTF_VAR_SECINFO_ENC(2, 0, 4),
3566 BTF_STR_SEC("\0x\0\7foo"),
3567 .err_str = "Invalid name",
3568 .btf_load_err = true,
3571 .descr = "datasec: name '\\0' is not ok",
3574 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3575 /* VAR x */ /* [2] */
3576 BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
3578 /* DATASEC \0 */ /* [3] */
3579 BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
3580 BTF_VAR_SECINFO_ENC(2, 0, 4),
3583 BTF_STR_SEC("\0x\0"),
3584 .err_str = "Invalid name",
3585 .btf_load_err = true,
3588 .descr = "type name '?foo' is not ok",
3591 BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [1] */
3594 BTF_STR_SEC("\0?foo"),
3595 .err_str = "Invalid name",
3596 .btf_load_err = true,
3600 .descr = "float test #1, well-formed",
3602 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3604 BTF_TYPE_FLOAT_ENC(NAME_TBD, 2), /* [2] */
3605 BTF_TYPE_FLOAT_ENC(NAME_TBD, 4), /* [3] */
3606 BTF_TYPE_FLOAT_ENC(NAME_TBD, 8), /* [4] */
3607 BTF_TYPE_FLOAT_ENC(NAME_TBD, 12), /* [5] */
3608 BTF_TYPE_FLOAT_ENC(NAME_TBD, 16), /* [6] */
3609 BTF_STRUCT_ENC(NAME_TBD, 5, 48), /* [7] */
3610 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3611 BTF_MEMBER_ENC(NAME_TBD, 3, 32),
3612 BTF_MEMBER_ENC(NAME_TBD, 4, 64),
3613 BTF_MEMBER_ENC(NAME_TBD, 5, 128),
3614 BTF_MEMBER_ENC(NAME_TBD, 6, 256),
3617 BTF_STR_SEC("\0int\0_Float16\0float\0double\0_Float80\0long_double"
3618 "\0floats\0a\0b\0c\0d\0e"),
3619 .map_type = BPF_MAP_TYPE_ARRAY,
3620 .map_name = "float_type_check_btf",
3621 .key_size = sizeof(int),
3628 .descr = "float test #2, invalid vlen",
3630 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3632 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 1), 4),
3636 BTF_STR_SEC("\0int\0float"),
3637 .map_type = BPF_MAP_TYPE_ARRAY,
3638 .map_name = "float_type_check_btf",
3639 .key_size = sizeof(int),
3644 .btf_load_err = true,
3645 .err_str = "vlen != 0",
3648 .descr = "float test #3, invalid kind_flag",
3650 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3652 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FLOAT, 1, 0), 4),
3656 BTF_STR_SEC("\0int\0float"),
3657 .map_type = BPF_MAP_TYPE_ARRAY,
3658 .map_name = "float_type_check_btf",
3659 .key_size = sizeof(int),
3664 .btf_load_err = true,
3665 .err_str = "Invalid btf_info kind_flag",
3668 .descr = "float test #4, member does not fit",
3670 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3672 BTF_TYPE_FLOAT_ENC(NAME_TBD, 4), /* [2] */
3673 BTF_STRUCT_ENC(NAME_TBD, 1, 2), /* [3] */
3674 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3677 BTF_STR_SEC("\0int\0float\0floats\0x"),
3678 .map_type = BPF_MAP_TYPE_ARRAY,
3679 .map_name = "float_type_check_btf",
3680 .key_size = sizeof(int),
3685 .btf_load_err = true,
3686 .err_str = "Member exceeds struct_size",
3689 .descr = "float test #5, member is not properly aligned",
3691 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3693 BTF_TYPE_FLOAT_ENC(NAME_TBD, 4), /* [2] */
3694 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [3] */
3695 BTF_MEMBER_ENC(NAME_TBD, 2, 8),
3698 BTF_STR_SEC("\0int\0float\0floats\0x"),
3699 .map_type = BPF_MAP_TYPE_ARRAY,
3700 .map_name = "float_type_check_btf",
3701 .key_size = sizeof(int),
3706 .btf_load_err = true,
3707 .err_str = "Member is not properly aligned",
3710 .descr = "float test #6, invalid size",
3712 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3714 BTF_TYPE_FLOAT_ENC(NAME_TBD, 6), /* [2] */
3717 BTF_STR_SEC("\0int\0float"),
3718 .map_type = BPF_MAP_TYPE_ARRAY,
3719 .map_name = "float_type_check_btf",
3720 .key_size = sizeof(int),
3725 .btf_load_err = true,
3726 .err_str = "Invalid type_size",
3730 .descr = "decl_tag test #1, struct/member, well-formed",
3732 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3733 BTF_STRUCT_ENC(0, 2, 8), /* [2] */
3734 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3735 BTF_MEMBER_ENC(NAME_TBD, 1, 32),
3736 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3737 BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3738 BTF_DECL_TAG_ENC(NAME_TBD, 2, 1),
3741 BTF_STR_SEC("\0m1\0m2\0tag1\0tag2\0tag3"),
3742 .map_type = BPF_MAP_TYPE_ARRAY,
3743 .map_name = "tag_type_check_btf",
3744 .key_size = sizeof(int),
3751 .descr = "decl_tag test #2, union/member, well-formed",
3753 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3754 BTF_UNION_ENC(NAME_TBD, 2, 4), /* [2] */
3755 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3756 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3757 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3758 BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3759 BTF_DECL_TAG_ENC(NAME_TBD, 2, 1),
3762 BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
3763 .map_type = BPF_MAP_TYPE_ARRAY,
3764 .map_name = "tag_type_check_btf",
3765 .key_size = sizeof(int),
3772 .descr = "decl_tag test #3, variable, well-formed",
3774 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3775 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3776 BTF_VAR_ENC(NAME_TBD, 1, 1), /* [3] */
3777 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3778 BTF_DECL_TAG_ENC(NAME_TBD, 3, -1),
3781 BTF_STR_SEC("\0local\0global\0tag1\0tag2"),
3782 .map_type = BPF_MAP_TYPE_ARRAY,
3783 .map_name = "tag_type_check_btf",
3784 .key_size = sizeof(int),
3791 .descr = "decl_tag test #4, func/parameter, well-formed",
3793 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3794 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
3795 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3796 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3797 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
3798 BTF_DECL_TAG_ENC(NAME_TBD, 3, -1),
3799 BTF_DECL_TAG_ENC(NAME_TBD, 3, 0),
3800 BTF_DECL_TAG_ENC(NAME_TBD, 3, 1),
3803 BTF_STR_SEC("\0arg1\0arg2\0f\0tag1\0tag2\0tag3"),
3804 .map_type = BPF_MAP_TYPE_ARRAY,
3805 .map_name = "tag_type_check_btf",
3806 .key_size = sizeof(int),
3813 .descr = "decl_tag test #5, invalid value",
3815 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3816 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3817 BTF_DECL_TAG_ENC(0, 2, -1),
3820 BTF_STR_SEC("\0local\0tag"),
3821 .map_type = BPF_MAP_TYPE_ARRAY,
3822 .map_name = "tag_type_check_btf",
3823 .key_size = sizeof(int),
3828 .btf_load_err = true,
3829 .err_str = "Invalid value",
3832 .descr = "decl_tag test #6, invalid target type",
3834 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3835 BTF_DECL_TAG_ENC(NAME_TBD, 1, -1),
3838 BTF_STR_SEC("\0tag1"),
3839 .map_type = BPF_MAP_TYPE_ARRAY,
3840 .map_name = "tag_type_check_btf",
3841 .key_size = sizeof(int),
3846 .btf_load_err = true,
3847 .err_str = "Invalid type",
3850 .descr = "decl_tag test #7, invalid vlen",
3852 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3853 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3854 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 1), 2), (0),
3857 BTF_STR_SEC("\0local\0tag1"),
3858 .map_type = BPF_MAP_TYPE_ARRAY,
3859 .map_name = "tag_type_check_btf",
3860 .key_size = sizeof(int),
3865 .btf_load_err = true,
3866 .err_str = "vlen != 0",
3869 .descr = "decl_tag test #8, invalid kflag",
3871 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3872 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3873 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 1, 0), 2), (-1),
3876 BTF_STR_SEC("\0local\0tag1"),
3877 .map_type = BPF_MAP_TYPE_ARRAY,
3878 .map_name = "tag_type_check_btf",
3879 .key_size = sizeof(int),
3884 .btf_load_err = true,
3885 .err_str = "Invalid btf_info kind_flag",
3888 .descr = "decl_tag test #9, var, invalid component_idx",
3890 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3891 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3892 BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3895 BTF_STR_SEC("\0local\0tag"),
3896 .map_type = BPF_MAP_TYPE_ARRAY,
3897 .map_name = "tag_type_check_btf",
3898 .key_size = sizeof(int),
3903 .btf_load_err = true,
3904 .err_str = "Invalid component_idx",
3907 .descr = "decl_tag test #10, struct member, invalid component_idx",
3909 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3910 BTF_STRUCT_ENC(0, 2, 8), /* [2] */
3911 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3912 BTF_MEMBER_ENC(NAME_TBD, 1, 32),
3913 BTF_DECL_TAG_ENC(NAME_TBD, 2, 2),
3916 BTF_STR_SEC("\0m1\0m2\0tag"),
3917 .map_type = BPF_MAP_TYPE_ARRAY,
3918 .map_name = "tag_type_check_btf",
3919 .key_size = sizeof(int),
3924 .btf_load_err = true,
3925 .err_str = "Invalid component_idx",
3928 .descr = "decl_tag test #11, func parameter, invalid component_idx",
3930 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3931 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
3932 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3933 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3934 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
3935 BTF_DECL_TAG_ENC(NAME_TBD, 3, 2),
3938 BTF_STR_SEC("\0arg1\0arg2\0f\0tag"),
3939 .map_type = BPF_MAP_TYPE_ARRAY,
3940 .map_name = "tag_type_check_btf",
3941 .key_size = sizeof(int),
3946 .btf_load_err = true,
3947 .err_str = "Invalid component_idx",
3950 .descr = "decl_tag test #12, < -1 component_idx",
3952 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3953 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
3954 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3955 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3956 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
3957 BTF_DECL_TAG_ENC(NAME_TBD, 3, -2),
3960 BTF_STR_SEC("\0arg1\0arg2\0f\0tag"),
3961 .map_type = BPF_MAP_TYPE_ARRAY,
3962 .map_name = "tag_type_check_btf",
3963 .key_size = sizeof(int),
3968 .btf_load_err = true,
3969 .err_str = "Invalid component_idx",
3972 .descr = "decl_tag test #13, typedef, well-formed",
3974 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3975 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [2] */
3976 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3979 BTF_STR_SEC("\0t\0tag"),
3980 .map_type = BPF_MAP_TYPE_ARRAY,
3981 .map_name = "tag_type_check_btf",
3982 .key_size = sizeof(int),
3989 .descr = "decl_tag test #14, typedef, invalid component_idx",
3991 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3992 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [2] */
3993 BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3996 BTF_STR_SEC("\0local\0tag"),
3997 .map_type = BPF_MAP_TYPE_ARRAY,
3998 .map_name = "tag_type_check_btf",
3999 .key_size = sizeof(int),
4004 .btf_load_err = true,
4005 .err_str = "Invalid component_idx",
4008 .descr = "decl_tag test #15, func, invalid func proto",
4010 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4011 BTF_DECL_TAG_ENC(NAME_TBD, 3, 0), /* [2] */
4012 BTF_FUNC_ENC(NAME_TBD, 8), /* [3] */
4015 BTF_STR_SEC("\0tag\0func"),
4016 .map_type = BPF_MAP_TYPE_ARRAY,
4017 .map_name = "tag_type_check_btf",
4018 .key_size = sizeof(int),
4023 .btf_load_err = true,
4024 .err_str = "Invalid type_id",
4027 .descr = "decl_tag test #16, func proto, return type",
4029 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4030 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
4031 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), 2), (-1), /* [3] */
4032 BTF_FUNC_PROTO_ENC(3, 0), /* [4] */
4035 BTF_STR_SEC("\0local\0tag1"),
4036 .btf_load_err = true,
4037 .err_str = "Invalid return type",
4040 .descr = "decl_tag test #17, func proto, argument",
4042 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), 4), (-1), /* [1] */
4043 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0), /* [2] */
4044 BTF_FUNC_PROTO_ENC(0, 1), /* [3] */
4045 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
4046 BTF_VAR_ENC(NAME_TBD, 2, 0), /* [4] */
4049 BTF_STR_SEC("\0local\0tag1\0var"),
4050 .btf_load_err = true,
4051 .err_str = "Invalid arg#1",
4054 .descr = "decl_tag test #18, decl_tag as the map key type",
4056 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4057 BTF_STRUCT_ENC(0, 2, 8), /* [2] */
4058 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
4059 BTF_MEMBER_ENC(NAME_TBD, 1, 32),
4060 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1), /* [3] */
4063 BTF_STR_SEC("\0m1\0m2\0tag"),
4064 .map_type = BPF_MAP_TYPE_HASH,
4065 .map_name = "tag_type_check_btf",
4071 .map_create_err = true,
4074 .descr = "decl_tag test #19, decl_tag as the map value type",
4076 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4077 BTF_STRUCT_ENC(0, 2, 8), /* [2] */
4078 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
4079 BTF_MEMBER_ENC(NAME_TBD, 1, 32),
4080 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1), /* [3] */
4083 BTF_STR_SEC("\0m1\0m2\0tag"),
4084 .map_type = BPF_MAP_TYPE_HASH,
4085 .map_name = "tag_type_check_btf",
4091 .map_create_err = true,
4094 .descr = "type_tag test #1",
4096 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4097 BTF_TYPE_TAG_ENC(NAME_TBD, 1), /* [2] */
4098 BTF_PTR_ENC(2), /* [3] */
4101 BTF_STR_SEC("\0tag"),
4102 .map_type = BPF_MAP_TYPE_ARRAY,
4103 .map_name = "tag_type_check_btf",
4104 .key_size = sizeof(int),
4111 .descr = "type_tag test #2, type tag order",
4113 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4114 BTF_CONST_ENC(3), /* [2] */
4115 BTF_TYPE_TAG_ENC(NAME_TBD, 1), /* [3] */
4118 BTF_STR_SEC("\0tag"),
4119 .map_type = BPF_MAP_TYPE_ARRAY,
4120 .map_name = "tag_type_check_btf",
4121 .key_size = sizeof(int),
4126 .btf_load_err = true,
4127 .err_str = "Type tags don't precede modifiers",
4130 .descr = "type_tag test #3, type tag order",
4132 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4133 BTF_TYPE_TAG_ENC(NAME_TBD, 3), /* [2] */
4134 BTF_CONST_ENC(4), /* [3] */
4135 BTF_TYPE_TAG_ENC(NAME_TBD, 1), /* [4] */
4138 BTF_STR_SEC("\0tag\0tag"),
4139 .map_type = BPF_MAP_TYPE_ARRAY,
4140 .map_name = "tag_type_check_btf",
4141 .key_size = sizeof(int),
4146 .btf_load_err = true,
4147 .err_str = "Type tags don't precede modifiers",
4150 .descr = "type_tag test #4, type tag order",
4152 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4153 BTF_TYPEDEF_ENC(NAME_TBD, 3), /* [2] */
4154 BTF_CONST_ENC(4), /* [3] */
4155 BTF_TYPE_TAG_ENC(NAME_TBD, 1), /* [4] */
4158 BTF_STR_SEC("\0tag\0tag"),
4159 .map_type = BPF_MAP_TYPE_ARRAY,
4160 .map_name = "tag_type_check_btf",
4161 .key_size = sizeof(int),
4166 .btf_load_err = true,
4167 .err_str = "Type tags don't precede modifiers",
4170 .descr = "type_tag test #5, type tag order",
4172 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4173 BTF_TYPE_TAG_ENC(NAME_TBD, 3), /* [2] */
4174 BTF_CONST_ENC(1), /* [3] */
4175 BTF_TYPE_TAG_ENC(NAME_TBD, 2), /* [4] */
4178 BTF_STR_SEC("\0tag\0tag"),
4179 .map_type = BPF_MAP_TYPE_ARRAY,
4180 .map_name = "tag_type_check_btf",
4181 .key_size = sizeof(int),
4188 .descr = "type_tag test #6, type tag order",
4190 BTF_PTR_ENC(2), /* [1] */
4191 BTF_TYPE_TAG_ENC(NAME_TBD, 3), /* [2] */
4192 BTF_CONST_ENC(4), /* [3] */
4193 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [4] */
4194 BTF_PTR_ENC(6), /* [5] */
4195 BTF_CONST_ENC(2), /* [6] */
4198 BTF_STR_SEC("\0tag"),
4199 .map_type = BPF_MAP_TYPE_ARRAY,
4200 .map_name = "tag_type_check_btf",
4201 .key_size = sizeof(int),
4206 .btf_load_err = true,
4207 .err_str = "Type tags don't precede modifiers",
4210 .descr = "enum64 test #1, unsigned, size 8",
4212 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4213 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 2), 8), /* [2] */
4214 BTF_ENUM64_ENC(NAME_TBD, 0, 0),
4215 BTF_ENUM64_ENC(NAME_TBD, 1, 1),
4218 BTF_STR_SEC("\0a\0b\0c"),
4219 .map_type = BPF_MAP_TYPE_ARRAY,
4220 .map_name = "tag_type_check_btf",
4221 .key_size = sizeof(int),
4228 .descr = "enum64 test #2, signed, size 4",
4230 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4231 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 1, 2), 4), /* [2] */
4232 BTF_ENUM64_ENC(NAME_TBD, -1, 0),
4233 BTF_ENUM64_ENC(NAME_TBD, 1, 0),
4236 BTF_STR_SEC("\0a\0b\0c"),
4237 .map_type = BPF_MAP_TYPE_ARRAY,
4238 .map_name = "tag_type_check_btf",
4239 .key_size = sizeof(int),
4246 }; /* struct btf_raw_test raw_tests[] */
4248 static const char *get_next_str(const char *start, const char *end)
4250 return start < end - 1 ? start + 1 : NULL;
4253 static int get_raw_sec_size(const __u32 *raw_types)
4257 for (i = MAX_NR_RAW_U32 - 1;
4258 i >= 0 && raw_types[i] != BTF_END_RAW;
4262 return i < 0 ? i : i * sizeof(raw_types[0]);
4265 static void *btf_raw_create(const struct btf_header *hdr,
4266 const __u32 *raw_types,
4268 unsigned int str_sec_size,
4269 unsigned int *btf_size,
4270 const char **ret_next_str)
4272 const char *next_str = str, *end_str = str + str_sec_size;
4273 const char **strs_idx = NULL, **tmp_strs_idx;
4274 int strs_cap = 0, strs_cnt = 0, next_str_idx = 0;
4275 unsigned int size_needed, offset;
4276 struct btf_header *ret_hdr;
4277 int i, type_sec_size, err = 0;
4278 uint32_t *ret_types;
4279 void *raw_btf = NULL;
4281 type_sec_size = get_raw_sec_size(raw_types);
4282 if (CHECK(type_sec_size < 0, "Cannot get nr_raw_types"))
4285 size_needed = sizeof(*hdr) + type_sec_size + str_sec_size;
4286 raw_btf = malloc(size_needed);
4287 if (CHECK(!raw_btf, "Cannot allocate memory for raw_btf"))
4291 memcpy(raw_btf, hdr, sizeof(*hdr));
4292 offset = sizeof(*hdr);
4295 while ((next_str = get_next_str(next_str, end_str))) {
4296 if (strs_cnt == strs_cap) {
4297 strs_cap += max(16, strs_cap / 2);
4298 tmp_strs_idx = realloc(strs_idx,
4299 sizeof(*strs_idx) * strs_cap);
4300 if (CHECK(!tmp_strs_idx,
4301 "Cannot allocate memory for strs_idx")) {
4305 strs_idx = tmp_strs_idx;
4307 strs_idx[strs_cnt++] = next_str;
4308 next_str += strlen(next_str);
4311 /* Copy type section */
4312 ret_types = raw_btf + offset;
4313 for (i = 0; i < type_sec_size / sizeof(raw_types[0]); i++) {
4314 if (raw_types[i] == NAME_TBD) {
4315 if (CHECK(next_str_idx == strs_cnt,
4316 "Error in getting next_str #%d",
4321 ret_types[i] = strs_idx[next_str_idx++] - str;
4322 } else if (IS_NAME_NTH(raw_types[i])) {
4323 int idx = GET_NAME_NTH_IDX(raw_types[i]);
4325 if (CHECK(idx <= 0 || idx > strs_cnt,
4326 "Error getting string #%d, strs_cnt:%d",
4331 ret_types[i] = strs_idx[idx-1] - str;
4333 ret_types[i] = raw_types[i];
4336 offset += type_sec_size;
4338 /* Copy string section */
4339 memcpy(raw_btf + offset, str, str_sec_size);
4341 ret_hdr = (struct btf_header *)raw_btf;
4342 ret_hdr->type_len = type_sec_size;
4343 ret_hdr->str_off = type_sec_size;
4344 ret_hdr->str_len = str_sec_size;
4346 *btf_size = size_needed;
4349 next_str_idx < strs_cnt ? strs_idx[next_str_idx] : NULL;
4360 static int load_raw_btf(const void *raw_data, size_t raw_size)
4362 LIBBPF_OPTS(bpf_btf_load_opts, opts);
4366 opts.log_buf = btf_log_buf,
4367 opts.log_size = BTF_LOG_BUF_SIZE,
4371 btf_fd = bpf_btf_load(raw_data, raw_size, &opts);
4372 if (btf_fd < 0 && !always_log) {
4373 opts.log_buf = btf_log_buf,
4374 opts.log_size = BTF_LOG_BUF_SIZE,
4376 btf_fd = bpf_btf_load(raw_data, raw_size, &opts);
4382 static void do_test_raw(unsigned int test_num)
4384 struct btf_raw_test *test = &raw_tests[test_num - 1];
4385 LIBBPF_OPTS(bpf_map_create_opts, opts);
4386 int map_fd = -1, btf_fd = -1;
4387 unsigned int raw_btf_size;
4388 struct btf_header *hdr;
4392 if (!test__start_subtest(test->descr))
4395 raw_btf = btf_raw_create(&hdr_tmpl,
4399 &raw_btf_size, NULL);
4405 hdr->hdr_len = (int)hdr->hdr_len + test->hdr_len_delta;
4406 hdr->type_off = (int)hdr->type_off + test->type_off_delta;
4407 hdr->str_off = (int)hdr->str_off + test->str_off_delta;
4408 hdr->str_len = (int)hdr->str_len + test->str_len_delta;
4410 *btf_log_buf = '\0';
4411 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
4414 err = ((btf_fd < 0) != test->btf_load_err);
4415 if (CHECK(err, "btf_fd:%d test->btf_load_err:%u",
4416 btf_fd, test->btf_load_err) ||
4417 CHECK(test->err_str && !strstr(btf_log_buf, test->err_str),
4418 "expected err_str:%s\n", test->err_str)) {
4423 if (err || btf_fd < 0)
4426 if (!test->map_type)
4429 opts.btf_fd = btf_fd;
4430 opts.btf_key_type_id = test->key_type_id;
4431 opts.btf_value_type_id = test->value_type_id;
4432 map_fd = bpf_map_create(test->map_type, test->map_name,
4433 test->key_size, test->value_size, test->max_entries, &opts);
4435 err = ((map_fd < 0) != test->map_create_err);
4436 CHECK(err, "map_fd:%d test->map_create_err:%u",
4437 map_fd, test->map_create_err);
4440 if (*btf_log_buf && (err || always_log))
4441 fprintf(stderr, "\n%s", btf_log_buf);
4448 struct btf_get_info_test {
4450 const char *str_sec;
4451 __u32 raw_types[MAX_NR_RAW_U32];
4454 int (*special_test)(unsigned int test_num);
4457 static int test_big_btf_info(unsigned int test_num);
4458 static int test_btf_id(unsigned int test_num);
4460 const struct btf_get_info_test get_info_tests[] = {
4462 .descr = "== raw_btf_size+1",
4465 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4469 .str_sec_size = sizeof(""),
4470 .btf_size_delta = 1,
4473 .descr = "== raw_btf_size-3",
4476 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4480 .str_sec_size = sizeof(""),
4481 .btf_size_delta = -3,
4484 .descr = "Large bpf_btf_info",
4487 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4491 .str_sec_size = sizeof(""),
4492 .special_test = test_big_btf_info,
4498 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4499 /* unsigned int */ /* [2] */
4500 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),
4504 .str_sec_size = sizeof(""),
4505 .special_test = test_btf_id,
4509 static int test_big_btf_info(unsigned int test_num)
4511 const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
4512 uint8_t *raw_btf = NULL, *user_btf = NULL;
4513 unsigned int raw_btf_size;
4515 struct bpf_btf_info info;
4518 struct bpf_btf_info *info;
4519 int btf_fd = -1, err;
4522 raw_btf = btf_raw_create(&hdr_tmpl,
4526 &raw_btf_size, NULL);
4531 *btf_log_buf = '\0';
4533 user_btf = malloc(raw_btf_size);
4534 if (CHECK(!user_btf, "!user_btf")) {
4539 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
4540 if (CHECK(btf_fd < 0, "errno:%d", errno)) {
4546 * GET_INFO should error out if the userspace info
4547 * has non zero tailing bytes.
4549 info = &info_garbage.info;
4550 memset(info, 0, sizeof(*info));
4551 info_garbage.garbage = 0xdeadbeef;
4552 info_len = sizeof(info_garbage);
4553 info->btf = ptr_to_u64(user_btf);
4554 info->btf_size = raw_btf_size;
4556 err = bpf_btf_get_info_by_fd(btf_fd, info, &info_len);
4557 if (CHECK(!err, "!err")) {
4563 * GET_INFO should succeed even info_len is larger than
4564 * the kernel supported as long as tailing bytes are zero.
4565 * The kernel supported info len should also be returned
4568 info_garbage.garbage = 0;
4569 err = bpf_btf_get_info_by_fd(btf_fd, info, &info_len);
4570 if (CHECK(err || info_len != sizeof(*info),
4571 "err:%d errno:%d info_len:%u sizeof(*info):%zu",
4572 err, errno, info_len, sizeof(*info))) {
4577 fprintf(stderr, "OK");
4580 if (*btf_log_buf && (err || always_log))
4581 fprintf(stderr, "\n%s", btf_log_buf);
4592 static int test_btf_id(unsigned int test_num)
4594 const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
4595 LIBBPF_OPTS(bpf_map_create_opts, opts);
4596 uint8_t *raw_btf = NULL, *user_btf[2] = {};
4597 int btf_fd[2] = {-1, -1}, map_fd = -1;
4598 struct bpf_map_info map_info = {};
4599 struct bpf_btf_info info[2] = {};
4600 unsigned int raw_btf_size;
4604 raw_btf = btf_raw_create(&hdr_tmpl,
4608 &raw_btf_size, NULL);
4613 *btf_log_buf = '\0';
4615 for (i = 0; i < 2; i++) {
4616 user_btf[i] = malloc(raw_btf_size);
4617 if (CHECK(!user_btf[i], "!user_btf[%d]", i)) {
4621 info[i].btf = ptr_to_u64(user_btf[i]);
4622 info[i].btf_size = raw_btf_size;
4625 btf_fd[0] = load_raw_btf(raw_btf, raw_btf_size);
4626 if (CHECK(btf_fd[0] < 0, "errno:%d", errno)) {
4631 /* Test BPF_OBJ_GET_INFO_BY_ID on btf_id */
4632 info_len = sizeof(info[0]);
4633 err = bpf_btf_get_info_by_fd(btf_fd[0], &info[0], &info_len);
4634 if (CHECK(err, "errno:%d", errno)) {
4639 btf_fd[1] = bpf_btf_get_fd_by_id(info[0].id);
4640 if (CHECK(btf_fd[1] < 0, "errno:%d", errno)) {
4646 err = bpf_btf_get_info_by_fd(btf_fd[1], &info[1], &info_len);
4647 if (CHECK(err || info[0].id != info[1].id ||
4648 info[0].btf_size != info[1].btf_size ||
4649 (ret = memcmp(user_btf[0], user_btf[1], info[0].btf_size)),
4650 "err:%d errno:%d id0:%u id1:%u btf_size0:%u btf_size1:%u memcmp:%d",
4651 err, errno, info[0].id, info[1].id,
4652 info[0].btf_size, info[1].btf_size, ret)) {
4657 /* Test btf members in struct bpf_map_info */
4658 opts.btf_fd = btf_fd[0];
4659 opts.btf_key_type_id = 1;
4660 opts.btf_value_type_id = 2;
4661 map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "test_btf_id",
4662 sizeof(int), sizeof(int), 4, &opts);
4663 if (CHECK(map_fd < 0, "errno:%d", errno)) {
4668 info_len = sizeof(map_info);
4669 err = bpf_map_get_info_by_fd(map_fd, &map_info, &info_len);
4670 if (CHECK(err || map_info.btf_id != info[0].id ||
4671 map_info.btf_key_type_id != 1 || map_info.btf_value_type_id != 2,
4672 "err:%d errno:%d info.id:%u btf_id:%u btf_key_type_id:%u btf_value_type_id:%u",
4673 err, errno, info[0].id, map_info.btf_id, map_info.btf_key_type_id,
4674 map_info.btf_value_type_id)) {
4679 for (i = 0; i < 2; i++) {
4684 /* Test BTF ID is removed from the kernel */
4685 btf_fd[0] = bpf_btf_get_fd_by_id(map_info.btf_id);
4686 if (CHECK(btf_fd[0] < 0, "errno:%d", errno)) {
4693 /* The map holds the last ref to BTF and its btf_id */
4697 fprintf(stderr, "OK");
4700 if (*btf_log_buf && (err || always_log))
4701 fprintf(stderr, "\n%s", btf_log_buf);
4706 for (i = 0; i < 2; i++) {
4715 static void do_test_get_info(unsigned int test_num)
4717 const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
4718 unsigned int raw_btf_size, user_btf_size, expected_nbytes;
4719 uint8_t *raw_btf = NULL, *user_btf = NULL;
4720 struct bpf_btf_info info = {};
4721 int btf_fd = -1, err, ret;
4724 if (!test__start_subtest(test->descr))
4727 if (test->special_test) {
4728 err = test->special_test(test_num);
4729 if (CHECK(err, "failed: %d\n", err))
4733 raw_btf = btf_raw_create(&hdr_tmpl,
4737 &raw_btf_size, NULL);
4742 *btf_log_buf = '\0';
4744 user_btf = malloc(raw_btf_size);
4745 if (CHECK(!user_btf, "!user_btf")) {
4750 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
4751 if (CHECK(btf_fd <= 0, "errno:%d", errno)) {
4756 user_btf_size = (int)raw_btf_size + test->btf_size_delta;
4757 expected_nbytes = min(raw_btf_size, user_btf_size);
4758 if (raw_btf_size > expected_nbytes)
4759 memset(user_btf + expected_nbytes, 0xff,
4760 raw_btf_size - expected_nbytes);
4762 info_len = sizeof(info);
4763 info.btf = ptr_to_u64(user_btf);
4764 info.btf_size = user_btf_size;
4767 err = bpf_btf_get_info_by_fd(btf_fd, &info, &info_len);
4768 if (CHECK(err || !info.id || info_len != sizeof(info) ||
4769 info.btf_size != raw_btf_size ||
4770 (ret = memcmp(raw_btf, user_btf, expected_nbytes)),
4771 "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",
4772 err, errno, info.id, info_len, sizeof(info),
4773 raw_btf_size, info.btf_size, expected_nbytes, ret)) {
4778 while (expected_nbytes < raw_btf_size) {
4779 fprintf(stderr, "%u...", expected_nbytes);
4780 if (CHECK(user_btf[expected_nbytes++] != 0xff,
4781 "user_btf[%u]:%x != 0xff", expected_nbytes - 1,
4782 user_btf[expected_nbytes - 1])) {
4788 fprintf(stderr, "OK");
4791 if (*btf_log_buf && (err || always_log))
4792 fprintf(stderr, "\n%s", btf_log_buf);
4801 struct btf_file_test {
4803 bool btf_kv_notfound;
4806 static struct btf_file_test file_tests[] = {
4807 { .file = "test_btf_newkv.bpf.o", },
4808 { .file = "test_btf_nokv.bpf.o", .btf_kv_notfound = true, },
4811 static void do_test_file(unsigned int test_num)
4813 const struct btf_file_test *test = &file_tests[test_num - 1];
4814 const char *expected_fnames[] = {"_dummy_tracepoint",
4815 "test_long_fname_1",
4816 "test_long_fname_2"};
4817 struct btf_ext *btf_ext = NULL;
4818 struct bpf_prog_info info = {};
4819 struct bpf_object *obj = NULL;
4820 struct bpf_func_info *finfo;
4821 struct bpf_program *prog;
4822 __u32 info_len, rec_size;
4823 bool has_btf_ext = false;
4824 struct btf *btf = NULL;
4825 void *func_info = NULL;
4826 struct bpf_map *map;
4827 int i, err, prog_fd;
4829 if (!test__start_subtest(test->file))
4832 btf = btf__parse_elf(test->file, &btf_ext);
4833 err = libbpf_get_error(btf);
4835 if (err == -ENOENT) {
4836 printf("%s:SKIP: No ELF %s found", __func__, BTF_ELF_SEC);
4844 has_btf_ext = btf_ext != NULL;
4845 btf_ext__free(btf_ext);
4847 /* temporary disable LIBBPF_STRICT_MAP_DEFINITIONS to test legacy maps */
4848 libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
4849 obj = bpf_object__open(test->file);
4850 err = libbpf_get_error(obj);
4851 if (CHECK(err, "obj: %d", err))
4854 prog = bpf_object__next_program(obj, NULL);
4855 if (CHECK(!prog, "Cannot find bpf_prog")) {
4860 bpf_program__set_type(prog, BPF_PROG_TYPE_TRACEPOINT);
4861 err = bpf_object__load(obj);
4862 if (CHECK(err < 0, "bpf_object__load: %d", err))
4864 prog_fd = bpf_program__fd(prog);
4866 map = bpf_object__find_map_by_name(obj, "btf_map");
4867 if (CHECK(!map, "btf_map not found")) {
4872 err = (bpf_map__btf_key_type_id(map) == 0 || bpf_map__btf_value_type_id(map) == 0)
4873 != test->btf_kv_notfound;
4874 if (CHECK(err, "btf_key_type_id:%u btf_value_type_id:%u test->btf_kv_notfound:%u",
4875 bpf_map__btf_key_type_id(map), bpf_map__btf_value_type_id(map),
4876 test->btf_kv_notfound))
4882 /* get necessary program info */
4883 info_len = sizeof(struct bpf_prog_info);
4884 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
4886 if (CHECK(err < 0, "invalid get info (1st) errno:%d", errno)) {
4887 fprintf(stderr, "%s\n", btf_log_buf);
4891 if (CHECK(info.nr_func_info != 3,
4892 "incorrect info.nr_func_info (1st) %d",
4893 info.nr_func_info)) {
4897 rec_size = info.func_info_rec_size;
4898 if (CHECK(rec_size != sizeof(struct bpf_func_info),
4899 "incorrect info.func_info_rec_size (1st) %d\n", rec_size)) {
4904 func_info = malloc(info.nr_func_info * rec_size);
4905 if (CHECK(!func_info, "out of memory")) {
4910 /* reset info to only retrieve func_info related data */
4911 memset(&info, 0, sizeof(info));
4912 info.nr_func_info = 3;
4913 info.func_info_rec_size = rec_size;
4914 info.func_info = ptr_to_u64(func_info);
4916 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
4918 if (CHECK(err < 0, "invalid get info (2nd) errno:%d", errno)) {
4919 fprintf(stderr, "%s\n", btf_log_buf);
4923 if (CHECK(info.nr_func_info != 3,
4924 "incorrect info.nr_func_info (2nd) %d",
4925 info.nr_func_info)) {
4929 if (CHECK(info.func_info_rec_size != rec_size,
4930 "incorrect info.func_info_rec_size (2nd) %d",
4931 info.func_info_rec_size)) {
4936 btf = btf__load_from_kernel_by_id(info.btf_id);
4937 err = libbpf_get_error(btf);
4938 if (CHECK(err, "cannot get btf from kernel, err: %d", err))
4941 /* check three functions */
4943 for (i = 0; i < 3; i++) {
4944 const struct btf_type *t;
4947 t = btf__type_by_id(btf, finfo->type_id);
4948 if (CHECK(!t, "btf__type_by_id failure: id %u",
4954 fname = btf__name_by_offset(btf, t->name_off);
4955 err = strcmp(fname, expected_fnames[i]);
4956 /* for the second and third functions in .text section,
4957 * the compiler may order them either way.
4960 err = strcmp(fname, expected_fnames[3 - i]);
4961 if (CHECK(err, "incorrect fname %s", fname ? : "")) {
4966 finfo = (void *)finfo + rec_size;
4970 fprintf(stderr, "OK");
4973 libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
4977 bpf_object__close(obj);
4980 const char *pprint_enum_str[] = {
4987 struct pprint_mapv {
4992 uint32_t unused_bits2a:2,
5007 uint8_t si8_4[2][2];
5010 #ifdef __SIZEOF_INT128__
5011 struct pprint_mapv_int128 {
5014 unsigned __int128 bits3:3;
5015 unsigned __int128 bits80:80;
5016 unsigned __int128 ui128;
5020 static struct btf_raw_test pprint_test_template[] = {
5023 /* unsigned char */ /* [1] */
5024 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 8, 1),
5025 /* unsigned short */ /* [2] */
5026 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 16, 2),
5027 /* unsigned int */ /* [3] */
5028 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
5030 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
5031 /* unsigned long long */ /* [5] */
5032 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),
5033 /* 2 bits */ /* [6] */
5034 BTF_TYPE_INT_ENC(0, 0, 0, 2, 2),
5035 /* 28 bits */ /* [7] */
5036 BTF_TYPE_INT_ENC(0, 0, 0, 28, 4),
5037 /* uint8_t[8] */ /* [8] */
5038 BTF_TYPE_ARRAY_ENC(9, 1, 8),
5039 /* typedef unsigned char uint8_t */ /* [9] */
5040 BTF_TYPEDEF_ENC(NAME_TBD, 1),
5041 /* typedef unsigned short uint16_t */ /* [10] */
5042 BTF_TYPEDEF_ENC(NAME_TBD, 2),
5043 /* typedef unsigned int uint32_t */ /* [11] */
5044 BTF_TYPEDEF_ENC(NAME_TBD, 3),
5045 /* typedef int int32_t */ /* [12] */
5046 BTF_TYPEDEF_ENC(NAME_TBD, 4),
5047 /* typedef unsigned long long uint64_t *//* [13] */
5048 BTF_TYPEDEF_ENC(NAME_TBD, 5),
5049 /* union (anon) */ /* [14] */
5050 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 0, 2), 8),
5051 BTF_MEMBER_ENC(NAME_TBD, 13, 0),/* uint64_t ui64; */
5052 BTF_MEMBER_ENC(NAME_TBD, 8, 0), /* uint8_t ui8a[8]; */
5053 /* enum (anon) */ /* [15] */
5054 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 4), 4),
5055 BTF_ENUM_ENC(NAME_TBD, 0),
5056 BTF_ENUM_ENC(NAME_TBD, 1),
5057 BTF_ENUM_ENC(NAME_TBD, 2),
5058 BTF_ENUM_ENC(NAME_TBD, 3),
5059 /* struct pprint_mapv */ /* [16] */
5060 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 11), 40),
5061 BTF_MEMBER_ENC(NAME_TBD, 11, 0), /* uint32_t ui32 */
5062 BTF_MEMBER_ENC(NAME_TBD, 10, 32), /* uint16_t ui16 */
5063 BTF_MEMBER_ENC(NAME_TBD, 12, 64), /* int32_t si32 */
5064 BTF_MEMBER_ENC(NAME_TBD, 6, 96), /* unused_bits2a */
5065 BTF_MEMBER_ENC(NAME_TBD, 7, 98), /* bits28 */
5066 BTF_MEMBER_ENC(NAME_TBD, 6, 126), /* unused_bits2b */
5067 BTF_MEMBER_ENC(0, 14, 128), /* union (anon) */
5068 BTF_MEMBER_ENC(NAME_TBD, 15, 192), /* aenum */
5069 BTF_MEMBER_ENC(NAME_TBD, 11, 224), /* uint32_t ui32b */
5070 BTF_MEMBER_ENC(NAME_TBD, 6, 256), /* bits2c */
5071 BTF_MEMBER_ENC(NAME_TBD, 17, 264), /* si8_4 */
5072 BTF_TYPE_ARRAY_ENC(18, 1, 2), /* [17] */
5073 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [18] */
5076 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"),
5077 .key_size = sizeof(unsigned int),
5078 .value_size = sizeof(struct pprint_mapv),
5079 .key_type_id = 3, /* unsigned int */
5080 .value_type_id = 16, /* struct pprint_mapv */
5085 /* this type will have the same type as the
5086 * first .raw_types definition, but struct type will
5087 * be encoded with kind_flag set.
5090 /* unsigned char */ /* [1] */
5091 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 8, 1),
5092 /* unsigned short */ /* [2] */
5093 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 16, 2),
5094 /* unsigned int */ /* [3] */
5095 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
5097 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
5098 /* unsigned long long */ /* [5] */
5099 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),
5100 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [6] */
5101 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [7] */
5102 /* uint8_t[8] */ /* [8] */
5103 BTF_TYPE_ARRAY_ENC(9, 1, 8),
5104 /* typedef unsigned char uint8_t */ /* [9] */
5105 BTF_TYPEDEF_ENC(NAME_TBD, 1),
5106 /* typedef unsigned short uint16_t */ /* [10] */
5107 BTF_TYPEDEF_ENC(NAME_TBD, 2),
5108 /* typedef unsigned int uint32_t */ /* [11] */
5109 BTF_TYPEDEF_ENC(NAME_TBD, 3),
5110 /* typedef int int32_t */ /* [12] */
5111 BTF_TYPEDEF_ENC(NAME_TBD, 4),
5112 /* typedef unsigned long long uint64_t *//* [13] */
5113 BTF_TYPEDEF_ENC(NAME_TBD, 5),
5114 /* union (anon) */ /* [14] */
5115 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 0, 2), 8),
5116 BTF_MEMBER_ENC(NAME_TBD, 13, 0),/* uint64_t ui64; */
5117 BTF_MEMBER_ENC(NAME_TBD, 8, 0), /* uint8_t ui8a[8]; */
5118 /* enum (anon) */ /* [15] */
5119 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 4), 4),
5120 BTF_ENUM_ENC(NAME_TBD, 0),
5121 BTF_ENUM_ENC(NAME_TBD, 1),
5122 BTF_ENUM_ENC(NAME_TBD, 2),
5123 BTF_ENUM_ENC(NAME_TBD, 3),
5124 /* struct pprint_mapv */ /* [16] */
5125 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 11), 40),
5126 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
5127 BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
5128 BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
5129 BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 96)), /* unused_bits2a */
5130 BTF_MEMBER_ENC(NAME_TBD, 7, BTF_MEMBER_OFFSET(28, 98)), /* bits28 */
5131 BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 126)), /* unused_bits2b */
5132 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
5133 BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
5134 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
5135 BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
5136 BTF_MEMBER_ENC(NAME_TBD, 17, 264), /* si8_4 */
5137 BTF_TYPE_ARRAY_ENC(18, 1, 2), /* [17] */
5138 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [18] */
5141 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"),
5142 .key_size = sizeof(unsigned int),
5143 .value_size = sizeof(struct pprint_mapv),
5144 .key_type_id = 3, /* unsigned int */
5145 .value_type_id = 16, /* struct pprint_mapv */
5150 /* this type will have the same layout as the
5151 * first .raw_types definition. The struct type will
5152 * be encoded with kind_flag set, bitfield members
5153 * are added typedef/const/volatile, and bitfield members
5154 * will have both int and enum types.
5157 /* unsigned char */ /* [1] */
5158 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 8, 1),
5159 /* unsigned short */ /* [2] */
5160 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 16, 2),
5161 /* unsigned int */ /* [3] */
5162 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
5164 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
5165 /* unsigned long long */ /* [5] */
5166 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),
5167 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [6] */
5168 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [7] */
5169 /* uint8_t[8] */ /* [8] */
5170 BTF_TYPE_ARRAY_ENC(9, 1, 8),
5171 /* typedef unsigned char uint8_t */ /* [9] */
5172 BTF_TYPEDEF_ENC(NAME_TBD, 1),
5173 /* typedef unsigned short uint16_t */ /* [10] */
5174 BTF_TYPEDEF_ENC(NAME_TBD, 2),
5175 /* typedef unsigned int uint32_t */ /* [11] */
5176 BTF_TYPEDEF_ENC(NAME_TBD, 3),
5177 /* typedef int int32_t */ /* [12] */
5178 BTF_TYPEDEF_ENC(NAME_TBD, 4),
5179 /* typedef unsigned long long uint64_t *//* [13] */
5180 BTF_TYPEDEF_ENC(NAME_TBD, 5),
5181 /* union (anon) */ /* [14] */
5182 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 0, 2), 8),
5183 BTF_MEMBER_ENC(NAME_TBD, 13, 0),/* uint64_t ui64; */
5184 BTF_MEMBER_ENC(NAME_TBD, 8, 0), /* uint8_t ui8a[8]; */
5185 /* enum (anon) */ /* [15] */
5186 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 4), 4),
5187 BTF_ENUM_ENC(NAME_TBD, 0),
5188 BTF_ENUM_ENC(NAME_TBD, 1),
5189 BTF_ENUM_ENC(NAME_TBD, 2),
5190 BTF_ENUM_ENC(NAME_TBD, 3),
5191 /* struct pprint_mapv */ /* [16] */
5192 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 11), 40),
5193 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
5194 BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
5195 BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
5196 BTF_MEMBER_ENC(NAME_TBD, 17, BTF_MEMBER_OFFSET(2, 96)), /* unused_bits2a */
5197 BTF_MEMBER_ENC(NAME_TBD, 7, BTF_MEMBER_OFFSET(28, 98)), /* bits28 */
5198 BTF_MEMBER_ENC(NAME_TBD, 19, BTF_MEMBER_OFFSET(2, 126)),/* unused_bits2b */
5199 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
5200 BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
5201 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
5202 BTF_MEMBER_ENC(NAME_TBD, 17, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
5203 BTF_MEMBER_ENC(NAME_TBD, 20, BTF_MEMBER_OFFSET(0, 264)), /* si8_4 */
5204 /* typedef unsigned int ___int */ /* [17] */
5205 BTF_TYPEDEF_ENC(NAME_TBD, 18),
5206 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), 6), /* [18] */
5207 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 15), /* [19] */
5208 BTF_TYPE_ARRAY_ENC(21, 1, 2), /* [20] */
5209 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [21] */
5212 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"),
5213 .key_size = sizeof(unsigned int),
5214 .value_size = sizeof(struct pprint_mapv),
5215 .key_type_id = 3, /* unsigned int */
5216 .value_type_id = 16, /* struct pprint_mapv */
5220 #ifdef __SIZEOF_INT128__
5224 /* unsigned int */ /* [1] */
5225 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
5226 /* __int128 */ /* [2] */
5227 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 128, 16),
5228 /* unsigned __int128 */ /* [3] */
5229 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 128, 16),
5230 /* struct pprint_mapv_int128 */ /* [4] */
5231 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 5), 64),
5232 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)), /* si128a */
5233 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 128)), /* si128b */
5234 BTF_MEMBER_ENC(NAME_TBD, 3, BTF_MEMBER_OFFSET(3, 256)), /* bits3 */
5235 BTF_MEMBER_ENC(NAME_TBD, 3, BTF_MEMBER_OFFSET(80, 259)), /* bits80 */
5236 BTF_MEMBER_ENC(NAME_TBD, 3, BTF_MEMBER_OFFSET(0, 384)), /* ui128 */
5239 BTF_STR_SEC("\0unsigned int\0__int128\0unsigned __int128\0pprint_mapv_int128\0si128a\0si128b\0bits3\0bits80\0ui128"),
5240 .key_size = sizeof(unsigned int),
5241 .value_size = sizeof(struct pprint_mapv_int128),
5245 .mapv_kind = PPRINT_MAPV_KIND_INT128,
5251 static struct btf_pprint_test_meta {
5253 enum bpf_map_type map_type;
5254 const char *map_name;
5258 } pprint_tests_meta[] = {
5260 .descr = "BTF pretty print array",
5261 .map_type = BPF_MAP_TYPE_ARRAY,
5262 .map_name = "pprint_test_array",
5263 .ordered_map = true,
5264 .lossless_map = true,
5265 .percpu_map = false,
5269 .descr = "BTF pretty print hash",
5270 .map_type = BPF_MAP_TYPE_HASH,
5271 .map_name = "pprint_test_hash",
5272 .ordered_map = false,
5273 .lossless_map = true,
5274 .percpu_map = false,
5278 .descr = "BTF pretty print lru hash",
5279 .map_type = BPF_MAP_TYPE_LRU_HASH,
5280 .map_name = "pprint_test_lru_hash",
5281 .ordered_map = false,
5282 .lossless_map = false,
5283 .percpu_map = false,
5287 .descr = "BTF pretty print percpu array",
5288 .map_type = BPF_MAP_TYPE_PERCPU_ARRAY,
5289 .map_name = "pprint_test_percpu_array",
5290 .ordered_map = true,
5291 .lossless_map = true,
5296 .descr = "BTF pretty print percpu hash",
5297 .map_type = BPF_MAP_TYPE_PERCPU_HASH,
5298 .map_name = "pprint_test_percpu_hash",
5299 .ordered_map = false,
5300 .lossless_map = true,
5305 .descr = "BTF pretty print lru percpu hash",
5306 .map_type = BPF_MAP_TYPE_LRU_PERCPU_HASH,
5307 .map_name = "pprint_test_lru_percpu_hash",
5308 .ordered_map = false,
5309 .lossless_map = false,
5315 static size_t get_pprint_mapv_size(enum pprint_mapv_kind_t mapv_kind)
5317 if (mapv_kind == PPRINT_MAPV_KIND_BASIC)
5318 return sizeof(struct pprint_mapv);
5320 #ifdef __SIZEOF_INT128__
5321 if (mapv_kind == PPRINT_MAPV_KIND_INT128)
5322 return sizeof(struct pprint_mapv_int128);
5329 static void set_pprint_mapv(enum pprint_mapv_kind_t mapv_kind,
5330 void *mapv, uint32_t i,
5331 int num_cpus, int rounded_value_size)
5335 if (mapv_kind == PPRINT_MAPV_KIND_BASIC) {
5336 struct pprint_mapv *v = mapv;
5338 for (cpu = 0; cpu < num_cpus; cpu++) {
5341 v->unused_bits2a = 3;
5343 v->unused_bits2b = 3;
5345 v->aenum = i & 0x03;
5348 v->si8_4[0][0] = (cpu + i) & 0xff;
5349 v->si8_4[0][1] = (cpu + i + 1) & 0xff;
5350 v->si8_4[1][0] = (cpu + i + 2) & 0xff;
5351 v->si8_4[1][1] = (cpu + i + 3) & 0xff;
5352 v = (void *)v + rounded_value_size;
5356 #ifdef __SIZEOF_INT128__
5357 if (mapv_kind == PPRINT_MAPV_KIND_INT128) {
5358 struct pprint_mapv_int128 *v = mapv;
5360 for (cpu = 0; cpu < num_cpus; cpu++) {
5363 v->bits3 = i & 0x07;
5364 v->bits80 = (((unsigned __int128)1) << 64) + i;
5365 v->ui128 = (((unsigned __int128)2) << 64) + i;
5366 v = (void *)v + rounded_value_size;
5372 ssize_t get_pprint_expected_line(enum pprint_mapv_kind_t mapv_kind,
5373 char *expected_line, ssize_t line_size,
5374 bool percpu_map, unsigned int next_key,
5375 int cpu, void *mapv)
5377 ssize_t nexpected_line = -1;
5379 if (mapv_kind == PPRINT_MAPV_KIND_BASIC) {
5380 struct pprint_mapv *v = mapv;
5382 nexpected_line = snprintf(expected_line, line_size,
5383 "%s%u: {%u,0,%d,0x%x,0x%x,0x%x,"
5384 "{%llu|[%u,%u,%u,%u,%u,%u,%u,%u]},%s,"
5385 "%u,0x%x,[[%d,%d],[%d,%d]]}\n",
5386 percpu_map ? "\tcpu" : "",
5387 percpu_map ? cpu : next_key,
5393 v->ui8a[0], v->ui8a[1],
5394 v->ui8a[2], v->ui8a[3],
5395 v->ui8a[4], v->ui8a[5],
5396 v->ui8a[6], v->ui8a[7],
5397 pprint_enum_str[v->aenum],
5400 v->si8_4[0][0], v->si8_4[0][1],
5401 v->si8_4[1][0], v->si8_4[1][1]);
5404 #ifdef __SIZEOF_INT128__
5405 if (mapv_kind == PPRINT_MAPV_KIND_INT128) {
5406 struct pprint_mapv_int128 *v = mapv;
5408 nexpected_line = snprintf(expected_line, line_size,
5409 "%s%u: {0x%lx,0x%lx,0x%lx,"
5410 "0x%lx%016lx,0x%lx%016lx}\n",
5411 percpu_map ? "\tcpu" : "",
5412 percpu_map ? cpu : next_key,
5413 (uint64_t)v->si128a,
5414 (uint64_t)v->si128b,
5416 (uint64_t)(v->bits80 >> 64),
5417 (uint64_t)v->bits80,
5418 (uint64_t)(v->ui128 >> 64),
5419 (uint64_t)v->ui128);
5423 return nexpected_line;
5426 static int check_line(const char *expected_line, int nexpected_line,
5427 int expected_line_len, const char *line)
5429 if (CHECK(nexpected_line == expected_line_len,
5430 "expected_line is too long"))
5433 if (strcmp(expected_line, line)) {
5434 fprintf(stderr, "unexpected pprint output\n");
5435 fprintf(stderr, "expected: %s", expected_line);
5436 fprintf(stderr, " read: %s", line);
5444 static void do_test_pprint(int test_num)
5446 const struct btf_raw_test *test = &pprint_test_template[test_num];
5447 enum pprint_mapv_kind_t mapv_kind = test->mapv_kind;
5448 LIBBPF_OPTS(bpf_map_create_opts, opts);
5449 bool ordered_map, lossless_map, percpu_map;
5450 int err, ret, num_cpus, rounded_value_size;
5451 unsigned int key, nr_read_elems;
5452 int map_fd = -1, btf_fd = -1;
5453 unsigned int raw_btf_size;
5454 char expected_line[255];
5455 FILE *pin_file = NULL;
5457 size_t line_len = 0;
5463 if (!test__start_subtest(test->descr))
5466 raw_btf = btf_raw_create(&hdr_tmpl, test->raw_types,
5467 test->str_sec, test->str_sec_size,
5468 &raw_btf_size, NULL);
5473 *btf_log_buf = '\0';
5474 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
5477 if (CHECK(btf_fd < 0, "errno:%d\n", errno)) {
5482 opts.btf_fd = btf_fd;
5483 opts.btf_key_type_id = test->key_type_id;
5484 opts.btf_value_type_id = test->value_type_id;
5485 map_fd = bpf_map_create(test->map_type, test->map_name,
5486 test->key_size, test->value_size, test->max_entries, &opts);
5487 if (CHECK(map_fd < 0, "errno:%d", errno)) {
5492 ret = snprintf(pin_path, sizeof(pin_path), "%s/%s",
5493 "/sys/fs/bpf", test->map_name);
5495 if (CHECK(ret >= sizeof(pin_path), "pin_path %s/%s is too long",
5496 "/sys/fs/bpf", test->map_name)) {
5501 err = bpf_obj_pin(map_fd, pin_path);
5502 if (CHECK(err, "bpf_obj_pin(%s): errno:%d.", pin_path, errno))
5505 percpu_map = test->percpu_map;
5506 num_cpus = percpu_map ? bpf_num_possible_cpus() : 1;
5507 rounded_value_size = round_up(get_pprint_mapv_size(mapv_kind), 8);
5508 mapv = calloc(num_cpus, rounded_value_size);
5509 if (CHECK(!mapv, "mapv allocation failure")) {
5514 for (key = 0; key < test->max_entries; key++) {
5515 set_pprint_mapv(mapv_kind, mapv, key, num_cpus, rounded_value_size);
5516 bpf_map_update_elem(map_fd, &key, mapv, 0);
5519 pin_file = fopen(pin_path, "r");
5520 if (CHECK(!pin_file, "fopen(%s): errno:%d", pin_path, errno)) {
5525 /* Skip lines start with '#' */
5526 while ((nread = getline(&line, &line_len, pin_file)) > 0 &&
5530 if (CHECK(nread <= 0, "Unexpected EOF")) {
5536 ordered_map = test->ordered_map;
5537 lossless_map = test->lossless_map;
5539 ssize_t nexpected_line;
5540 unsigned int next_key;
5544 next_key = ordered_map ? nr_read_elems : atoi(line);
5545 set_pprint_mapv(mapv_kind, mapv, next_key, num_cpus, rounded_value_size);
5548 for (cpu = 0; cpu < num_cpus; cpu++) {
5550 /* for percpu map, the format looks like:
5552 * cpu0: <value_on_cpu0>
5553 * cpu1: <value_on_cpu1>
5555 * cpun: <value_on_cpun>
5558 * let us verify the line containing the key here.
5561 nexpected_line = snprintf(expected_line,
5562 sizeof(expected_line),
5566 err = check_line(expected_line, nexpected_line,
5567 sizeof(expected_line), line);
5572 /* read value@cpu */
5573 nread = getline(&line, &line_len, pin_file);
5578 nexpected_line = get_pprint_expected_line(mapv_kind, expected_line,
5579 sizeof(expected_line),
5580 percpu_map, next_key,
5582 err = check_line(expected_line, nexpected_line,
5583 sizeof(expected_line), line);
5587 cmapv = cmapv + rounded_value_size;
5591 /* skip the last bracket for the percpu map */
5592 nread = getline(&line, &line_len, pin_file);
5597 nread = getline(&line, &line_len, pin_file);
5598 } while (++nr_read_elems < test->max_entries && nread > 0);
5601 CHECK(nr_read_elems < test->max_entries,
5602 "Unexpected EOF. nr_read_elems:%u test->max_entries:%u",
5603 nr_read_elems, test->max_entries)) {
5608 if (CHECK(nread > 0, "Unexpected extra pprint output: %s", line)) {
5619 fprintf(stderr, "OK");
5620 if (*btf_log_buf && (err || always_log))
5621 fprintf(stderr, "\n%s", btf_log_buf);
5632 static void test_pprint(void)
5636 /* test various maps with the first test template */
5637 for (i = 0; i < ARRAY_SIZE(pprint_tests_meta); i++) {
5638 pprint_test_template[0].descr = pprint_tests_meta[i].descr;
5639 pprint_test_template[0].map_type = pprint_tests_meta[i].map_type;
5640 pprint_test_template[0].map_name = pprint_tests_meta[i].map_name;
5641 pprint_test_template[0].ordered_map = pprint_tests_meta[i].ordered_map;
5642 pprint_test_template[0].lossless_map = pprint_tests_meta[i].lossless_map;
5643 pprint_test_template[0].percpu_map = pprint_tests_meta[i].percpu_map;
5648 /* test rest test templates with the first map */
5649 for (i = 1; i < ARRAY_SIZE(pprint_test_template); i++) {
5650 pprint_test_template[i].descr = pprint_tests_meta[0].descr;
5651 pprint_test_template[i].map_type = pprint_tests_meta[0].map_type;
5652 pprint_test_template[i].map_name = pprint_tests_meta[0].map_name;
5653 pprint_test_template[i].ordered_map = pprint_tests_meta[0].ordered_map;
5654 pprint_test_template[i].lossless_map = pprint_tests_meta[0].lossless_map;
5655 pprint_test_template[i].percpu_map = pprint_tests_meta[0].percpu_map;
5660 #define BPF_LINE_INFO_ENC(insn_off, file_off, line_off, line_num, line_col) \
5661 (insn_off), (file_off), (line_off), ((line_num) << 10 | ((line_col) & 0x3ff))
5663 static struct prog_info_raw_test {
5665 const char *str_sec;
5666 const char *err_str;
5667 __u32 raw_types[MAX_NR_RAW_U32];
5669 struct bpf_insn insns[MAX_INSNS];
5671 __u32 func_info[MAX_SUBPROGS][2];
5672 __u32 func_info_rec_size;
5673 __u32 func_info_cnt;
5674 __u32 line_info[MAX_NR_RAW_U32];
5675 __u32 line_info_rec_size;
5676 __u32 nr_jited_ksyms;
5677 bool expected_prog_load_failure;
5678 __u32 dead_code_cnt;
5679 __u32 dead_code_mask;
5680 __u32 dead_func_cnt;
5681 __u32 dead_func_mask;
5682 } info_raw_tests[] = {
5684 .descr = "func_type (main func + one sub)",
5686 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5687 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */
5688 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5689 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5690 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5691 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5692 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5693 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5694 BTF_FUNC_ENC(NAME_TBD, 3), /* [5] */
5695 BTF_FUNC_ENC(NAME_TBD, 4), /* [6] */
5698 .str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5699 .str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5701 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5702 BPF_MOV64_IMM(BPF_REG_0, 1),
5704 BPF_MOV64_IMM(BPF_REG_0, 2),
5707 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5708 .func_info = { {0, 5}, {3, 6} },
5709 .func_info_rec_size = 8,
5711 .line_info = { BTF_END_RAW },
5715 .descr = "func_type (Incorrect func_info_rec_size)",
5717 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5718 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */
5719 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5720 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5721 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5722 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5723 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5724 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5725 BTF_FUNC_ENC(NAME_TBD, 3), /* [5] */
5726 BTF_FUNC_ENC(NAME_TBD, 4), /* [6] */
5729 .str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5730 .str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5732 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5733 BPF_MOV64_IMM(BPF_REG_0, 1),
5735 BPF_MOV64_IMM(BPF_REG_0, 2),
5738 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5739 .func_info = { {0, 5}, {3, 6} },
5740 .func_info_rec_size = 4,
5742 .line_info = { BTF_END_RAW },
5743 .expected_prog_load_failure = true,
5747 .descr = "func_type (Incorrect func_info_cnt)",
5749 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5750 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */
5751 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5752 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5753 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5754 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5755 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5756 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5757 BTF_FUNC_ENC(NAME_TBD, 3), /* [5] */
5758 BTF_FUNC_ENC(NAME_TBD, 4), /* [6] */
5761 .str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5762 .str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5764 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5765 BPF_MOV64_IMM(BPF_REG_0, 1),
5767 BPF_MOV64_IMM(BPF_REG_0, 2),
5770 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5771 .func_info = { {0, 5}, {3, 6} },
5772 .func_info_rec_size = 8,
5774 .line_info = { BTF_END_RAW },
5775 .expected_prog_load_failure = true,
5779 .descr = "func_type (Incorrect bpf_func_info.insn_off)",
5781 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5782 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */
5783 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5784 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5785 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5786 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5787 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5788 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5789 BTF_FUNC_ENC(NAME_TBD, 3), /* [5] */
5790 BTF_FUNC_ENC(NAME_TBD, 4), /* [6] */
5793 .str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5794 .str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5796 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5797 BPF_MOV64_IMM(BPF_REG_0, 1),
5799 BPF_MOV64_IMM(BPF_REG_0, 2),
5802 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5803 .func_info = { {0, 5}, {2, 6} },
5804 .func_info_rec_size = 8,
5806 .line_info = { BTF_END_RAW },
5807 .expected_prog_load_failure = true,
5811 .descr = "line_info (No subprog)",
5813 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5816 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5818 BPF_MOV64_IMM(BPF_REG_0, 1),
5819 BPF_MOV64_IMM(BPF_REG_1, 2),
5820 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5823 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5826 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5827 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9),
5828 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5829 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7),
5832 .line_info_rec_size = sizeof(struct bpf_line_info),
5833 .nr_jited_ksyms = 1,
5837 .descr = "line_info (No subprog. insn_off >= prog->len)",
5839 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5842 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5844 BPF_MOV64_IMM(BPF_REG_0, 1),
5845 BPF_MOV64_IMM(BPF_REG_1, 2),
5846 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5849 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5852 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5853 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9),
5854 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5855 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7),
5856 BPF_LINE_INFO_ENC(4, 0, 0, 5, 6),
5859 .line_info_rec_size = sizeof(struct bpf_line_info),
5860 .nr_jited_ksyms = 1,
5861 .err_str = "line_info[4].insn_off",
5862 .expected_prog_load_failure = true,
5866 .descr = "line_info (Zero bpf insn code)",
5868 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5869 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8), /* [2] */
5870 BTF_TYPEDEF_ENC(NAME_TBD, 2), /* [3] */
5873 BTF_STR_SEC("\0int\0unsigned long\0u64\0u64 a=1;\0return a;"),
5875 BPF_LD_IMM64(BPF_REG_0, 1),
5878 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5881 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5882 BPF_LINE_INFO_ENC(1, 0, 0, 2, 9),
5883 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5886 .line_info_rec_size = sizeof(struct bpf_line_info),
5887 .nr_jited_ksyms = 1,
5888 .err_str = "Invalid insn code at line_info[1]",
5889 .expected_prog_load_failure = true,
5893 .descr = "line_info (No subprog. zero tailing line_info",
5895 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5898 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5900 BPF_MOV64_IMM(BPF_REG_0, 1),
5901 BPF_MOV64_IMM(BPF_REG_1, 2),
5902 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5905 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5908 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10), 0,
5909 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9), 0,
5910 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8), 0,
5911 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7), 0,
5914 .line_info_rec_size = sizeof(struct bpf_line_info) + sizeof(__u32),
5915 .nr_jited_ksyms = 1,
5919 .descr = "line_info (No subprog. nonzero tailing line_info)",
5921 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5924 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5926 BPF_MOV64_IMM(BPF_REG_0, 1),
5927 BPF_MOV64_IMM(BPF_REG_1, 2),
5928 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5931 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5934 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10), 0,
5935 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9), 0,
5936 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8), 0,
5937 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7), 1,
5940 .line_info_rec_size = sizeof(struct bpf_line_info) + sizeof(__u32),
5941 .nr_jited_ksyms = 1,
5942 .err_str = "nonzero tailing record in line_info",
5943 .expected_prog_load_failure = true,
5947 .descr = "line_info (subprog)",
5949 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5952 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5954 BPF_MOV64_IMM(BPF_REG_2, 1),
5955 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5956 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5959 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5960 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5963 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5966 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5967 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
5968 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 3, 8),
5969 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
5972 .line_info_rec_size = sizeof(struct bpf_line_info),
5973 .nr_jited_ksyms = 2,
5977 .descr = "line_info (subprog + func_info)",
5979 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5980 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5981 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5982 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
5983 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
5986 BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5988 BPF_MOV64_IMM(BPF_REG_2, 1),
5989 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5990 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5993 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5994 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5997 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5999 .func_info_rec_size = 8,
6000 .func_info = { {0, 4}, {5, 3} },
6002 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6003 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
6004 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 3, 8),
6005 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
6008 .line_info_rec_size = sizeof(struct bpf_line_info),
6009 .nr_jited_ksyms = 2,
6013 .descr = "line_info (subprog. missing 1st func line info)",
6015 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6018 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
6020 BPF_MOV64_IMM(BPF_REG_2, 1),
6021 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
6022 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
6025 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
6026 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6029 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6032 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 1, 10),
6033 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
6034 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 3, 8),
6035 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
6038 .line_info_rec_size = sizeof(struct bpf_line_info),
6039 .nr_jited_ksyms = 2,
6040 .err_str = "missing bpf_line_info for func#0",
6041 .expected_prog_load_failure = true,
6045 .descr = "line_info (subprog. missing 2nd func line info)",
6047 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6050 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
6052 BPF_MOV64_IMM(BPF_REG_2, 1),
6053 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
6054 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
6057 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
6058 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6061 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6064 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6065 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
6066 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 3, 8),
6067 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
6070 .line_info_rec_size = sizeof(struct bpf_line_info),
6071 .nr_jited_ksyms = 2,
6072 .err_str = "missing bpf_line_info for func#1",
6073 .expected_prog_load_failure = true,
6077 .descr = "line_info (subprog. unordered insn offset)",
6079 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6082 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
6084 BPF_MOV64_IMM(BPF_REG_2, 1),
6085 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
6086 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
6089 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
6090 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6093 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6096 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6097 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 2, 9),
6098 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
6099 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
6102 .line_info_rec_size = sizeof(struct bpf_line_info),
6103 .nr_jited_ksyms = 2,
6104 .err_str = "Invalid line_info[2].insn_off",
6105 .expected_prog_load_failure = true,
6109 .descr = "line_info (dead start)",
6111 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6114 BTF_STR_SEC("\0int\0/* dead jmp */\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
6116 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6117 BPF_MOV64_IMM(BPF_REG_0, 1),
6118 BPF_MOV64_IMM(BPF_REG_1, 2),
6119 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
6122 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6125 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6126 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9),
6127 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
6128 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7),
6129 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 5, 6),
6132 .line_info_rec_size = sizeof(struct bpf_line_info),
6133 .nr_jited_ksyms = 1,
6135 .dead_code_mask = 0x01,
6139 .descr = "line_info (dead end)",
6141 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6144 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0/* dead jmp */\0return a + b;\0/* dead exit */"),
6146 BPF_MOV64_IMM(BPF_REG_0, 1),
6147 BPF_MOV64_IMM(BPF_REG_1, 2),
6148 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
6149 BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 10, 1),
6153 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6156 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 12),
6157 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 11),
6158 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 10),
6159 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 9),
6160 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 5, 8),
6161 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 6, 7),
6164 .line_info_rec_size = sizeof(struct bpf_line_info),
6165 .nr_jited_ksyms = 1,
6167 .dead_code_mask = 0x28,
6171 .descr = "line_info (dead code + subprog + func_info)",
6173 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6174 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6175 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6176 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6177 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6180 BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0/* dead jmp */"
6181 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
6182 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
6183 "\0return func(a);\0b+=1;\0return b;"),
6185 BPF_MOV64_IMM(BPF_REG_2, 1),
6186 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
6187 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
6188 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 8),
6189 BPF_MOV64_IMM(BPF_REG_2, 1),
6190 BPF_MOV64_IMM(BPF_REG_2, 1),
6191 BPF_MOV64_IMM(BPF_REG_2, 1),
6192 BPF_MOV64_IMM(BPF_REG_2, 1),
6193 BPF_MOV64_IMM(BPF_REG_2, 1),
6194 BPF_MOV64_IMM(BPF_REG_2, 1),
6195 BPF_MOV64_IMM(BPF_REG_2, 1),
6196 BPF_MOV64_IMM(BPF_REG_2, 1),
6199 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
6200 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6203 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6205 .func_info_rec_size = 8,
6206 .func_info = { {0, 4}, {14, 3} },
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(14, 0, NAME_TBD, 3, 8),
6220 BPF_LINE_INFO_ENC(16, 0, NAME_TBD, 4, 7),
6223 .line_info_rec_size = sizeof(struct bpf_line_info),
6224 .nr_jited_ksyms = 2,
6226 .dead_code_mask = 0x3fe,
6230 .descr = "line_info (dead subprog)",
6232 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6233 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6234 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6235 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6236 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6237 BTF_FUNC_ENC(NAME_TBD, 2), /* [5] */
6240 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
6241 "\0return 0;\0return 0;\0/* dead */\0/* dead */"
6242 "\0/* dead */\0return bla + 1;\0return bla + 1;"
6243 "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
6245 BPF_MOV64_IMM(BPF_REG_2, 1),
6246 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6249 BPF_MOV64_IMM(BPF_REG_0, 0),
6251 BPF_MOV64_IMM(BPF_REG_0, 0),
6254 BPF_MOV64_REG(BPF_REG_0, 2),
6255 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6258 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6260 .func_info_rec_size = 8,
6261 .func_info = { {0, 4}, {6, 3}, {9, 5} },
6263 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6264 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6265 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6266 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6267 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6268 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6269 BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6270 BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6271 BPF_LINE_INFO_ENC(10, 0, NAME_TBD, 1, 10),
6272 BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 2, 9),
6275 .line_info_rec_size = sizeof(struct bpf_line_info),
6276 .nr_jited_ksyms = 2,
6278 .dead_code_mask = 0x70,
6280 .dead_func_mask = 0x2,
6284 .descr = "line_info (dead last subprog)",
6286 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6287 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6288 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6289 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6290 BTF_FUNC_ENC(NAME_TBD, 2), /* [5] */
6293 BTF_STR_SEC("\0int\0x\0dead\0main\0int a=1+1;\0/* live call */"
6294 "\0return 0;\0/* dead */\0/* dead */"),
6296 BPF_MOV64_IMM(BPF_REG_2, 1),
6297 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6299 BPF_MOV64_IMM(BPF_REG_0, 0),
6301 BPF_MOV64_IMM(BPF_REG_0, 0),
6304 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6306 .func_info_rec_size = 8,
6307 .func_info = { {0, 4}, {5, 3} },
6309 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6310 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6311 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6312 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6313 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6316 .line_info_rec_size = sizeof(struct bpf_line_info),
6317 .nr_jited_ksyms = 1,
6319 .dead_code_mask = 0x18,
6321 .dead_func_mask = 0x2,
6325 .descr = "line_info (dead subprog + dead start)",
6327 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6328 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6329 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6330 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6331 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6332 BTF_FUNC_ENC(NAME_TBD, 2), /* [5] */
6335 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* dead */"
6336 "\0return 0;\0return 0;\0return 0;"
6337 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
6338 "\0return b + 1;\0return b + 1;\0return b + 1;"),
6340 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6341 BPF_MOV64_IMM(BPF_REG_2, 1),
6342 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6345 BPF_MOV64_IMM(BPF_REG_0, 0),
6347 BPF_MOV64_IMM(BPF_REG_0, 0),
6350 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6351 BPF_MOV64_REG(BPF_REG_0, 2),
6352 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6355 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6357 .func_info_rec_size = 8,
6358 .func_info = { {0, 4}, {7, 3}, {10, 5} },
6360 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6361 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6362 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6363 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6364 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6365 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6366 BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6367 BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6368 BPF_LINE_INFO_ENC(10, 0, NAME_TBD, 1, 10),
6369 BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 2, 9),
6370 BPF_LINE_INFO_ENC(12, 0, NAME_TBD, 2, 9),
6371 BPF_LINE_INFO_ENC(13, 0, NAME_TBD, 2, 9),
6374 .line_info_rec_size = sizeof(struct bpf_line_info),
6375 .nr_jited_ksyms = 2,
6377 .dead_code_mask = 0x1e2,
6379 .dead_func_mask = 0x2,
6383 .descr = "line_info (dead subprog + dead start w/ move)",
6385 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6386 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6387 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6388 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6389 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6390 BTF_FUNC_ENC(NAME_TBD, 2), /* [5] */
6393 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
6394 "\0return 0;\0return 0;\0/* dead */\0/* dead */"
6395 "\0/* dead */\0return bla + 1;\0return bla + 1;"
6396 "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
6398 BPF_MOV64_IMM(BPF_REG_2, 1),
6399 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6402 BPF_MOV64_IMM(BPF_REG_0, 0),
6404 BPF_MOV64_IMM(BPF_REG_0, 0),
6407 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6408 BPF_MOV64_REG(BPF_REG_0, 2),
6409 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6412 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6414 .func_info_rec_size = 8,
6415 .func_info = { {0, 4}, {6, 3}, {9, 5} },
6417 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6418 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6419 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6420 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6421 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6422 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6423 BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6424 BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6425 BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 1, 10),
6426 BPF_LINE_INFO_ENC(12, 0, NAME_TBD, 2, 9),
6429 .line_info_rec_size = sizeof(struct bpf_line_info),
6430 .nr_jited_ksyms = 2,
6432 .dead_code_mask = 0x70,
6434 .dead_func_mask = 0x2,
6438 .descr = "line_info (dead end + subprog start w/ no linfo)",
6440 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6441 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6442 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6443 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6444 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6447 BTF_STR_SEC("\0int\0x\0main\0func\0/* main linfo */\0/* func linfo */"),
6449 BPF_MOV64_IMM(BPF_REG_0, 0),
6450 BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 1, 3),
6452 BPF_MOV64_IMM(BPF_REG_0, 0),
6455 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6458 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6460 .func_info_rec_size = 8,
6461 .func_info = { {0, 3}, {6, 4}, },
6463 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6464 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6467 .line_info_rec_size = sizeof(struct bpf_line_info),
6468 .nr_jited_ksyms = 2,
6473 static size_t probe_prog_length(const struct bpf_insn *fp)
6477 for (len = MAX_INSNS - 1; len > 0; --len)
6478 if (fp[len].code != 0 || fp[len].imm != 0)
6483 static __u32 *patch_name_tbd(const __u32 *raw_u32,
6484 const char *str, __u32 str_off,
6485 unsigned int str_sec_size,
6486 unsigned int *ret_size)
6488 int i, raw_u32_size = get_raw_sec_size(raw_u32);
6489 const char *end_str = str + str_sec_size;
6490 const char *next_str = str + str_off;
6491 __u32 *new_u32 = NULL;
6493 if (raw_u32_size == -1)
6494 return ERR_PTR(-EINVAL);
6496 if (!raw_u32_size) {
6501 new_u32 = malloc(raw_u32_size);
6503 return ERR_PTR(-ENOMEM);
6505 for (i = 0; i < raw_u32_size / sizeof(raw_u32[0]); i++) {
6506 if (raw_u32[i] == NAME_TBD) {
6507 next_str = get_next_str(next_str, end_str);
6508 if (CHECK(!next_str, "Error in getting next_str\n")) {
6510 return ERR_PTR(-EINVAL);
6512 new_u32[i] = next_str - str;
6513 next_str += strlen(next_str);
6515 new_u32[i] = raw_u32[i];
6519 *ret_size = raw_u32_size;
6523 static int test_get_finfo(const struct prog_info_raw_test *test,
6526 struct bpf_prog_info info = {};
6527 struct bpf_func_info *finfo;
6528 __u32 info_len, rec_size, i;
6529 void *func_info = NULL;
6533 /* get necessary lens */
6534 info_len = sizeof(struct bpf_prog_info);
6535 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6536 if (CHECK(err < 0, "invalid get info (1st) errno:%d", errno)) {
6537 fprintf(stderr, "%s\n", btf_log_buf);
6540 nr_func_info = test->func_info_cnt - test->dead_func_cnt;
6541 if (CHECK(info.nr_func_info != nr_func_info,
6542 "incorrect info.nr_func_info (1st) %d",
6543 info.nr_func_info)) {
6547 rec_size = info.func_info_rec_size;
6548 if (CHECK(rec_size != sizeof(struct bpf_func_info),
6549 "incorrect info.func_info_rec_size (1st) %d", rec_size)) {
6553 if (!info.nr_func_info)
6556 func_info = malloc(info.nr_func_info * rec_size);
6557 if (CHECK(!func_info, "out of memory"))
6560 /* reset info to only retrieve func_info related data */
6561 memset(&info, 0, sizeof(info));
6562 info.nr_func_info = nr_func_info;
6563 info.func_info_rec_size = rec_size;
6564 info.func_info = ptr_to_u64(func_info);
6565 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6566 if (CHECK(err < 0, "invalid get info (2nd) errno:%d", errno)) {
6567 fprintf(stderr, "%s\n", btf_log_buf);
6571 if (CHECK(info.nr_func_info != nr_func_info,
6572 "incorrect info.nr_func_info (2nd) %d",
6573 info.nr_func_info)) {
6577 if (CHECK(info.func_info_rec_size != rec_size,
6578 "incorrect info.func_info_rec_size (2nd) %d",
6579 info.func_info_rec_size)) {
6585 for (i = 0; i < nr_func_info; i++) {
6586 if (test->dead_func_mask & (1 << i))
6588 if (CHECK(finfo->type_id != test->func_info[i][1],
6589 "incorrect func_type %u expected %u",
6590 finfo->type_id, test->func_info[i][1])) {
6594 finfo = (void *)finfo + rec_size;
6604 static int test_get_linfo(const struct prog_info_raw_test *test,
6605 const void *patched_linfo,
6606 __u32 cnt, int prog_fd)
6608 __u32 i, info_len, nr_jited_ksyms, nr_jited_func_lens;
6609 __u64 *jited_linfo = NULL, *jited_ksyms = NULL;
6610 __u32 rec_size, jited_rec_size, jited_cnt;
6611 struct bpf_line_info *linfo = NULL;
6612 __u32 cur_func_len, ksyms_found;
6613 struct bpf_prog_info info = {};
6614 __u32 *jited_func_lens = NULL;
6615 __u64 cur_func_ksyms;
6620 rec_size = sizeof(*linfo);
6621 jited_rec_size = sizeof(*jited_linfo);
6622 if (test->nr_jited_ksyms)
6623 nr_jited_ksyms = test->nr_jited_ksyms;
6625 nr_jited_ksyms = test->func_info_cnt - test->dead_func_cnt;
6626 nr_jited_func_lens = nr_jited_ksyms;
6628 info_len = sizeof(struct bpf_prog_info);
6629 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6630 if (CHECK(err < 0, "err:%d errno:%d", err, errno)) {
6635 if (!info.jited_prog_len) {
6636 /* prog is not jited */
6639 nr_jited_func_lens = 1;
6642 if (CHECK(info.nr_line_info != cnt ||
6643 info.nr_jited_line_info != jited_cnt ||
6644 info.nr_jited_ksyms != nr_jited_ksyms ||
6645 info.nr_jited_func_lens != nr_jited_func_lens ||
6646 (!info.nr_line_info && info.nr_jited_line_info),
6647 "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)",
6648 info.nr_line_info, cnt,
6649 info.nr_jited_line_info, jited_cnt,
6650 info.nr_jited_ksyms, nr_jited_ksyms,
6651 info.nr_jited_func_lens, nr_jited_func_lens)) {
6656 if (CHECK(info.line_info_rec_size != sizeof(struct bpf_line_info) ||
6657 info.jited_line_info_rec_size != sizeof(__u64),
6658 "info: line_info_rec_size:%u(userspace expected:%u) jited_line_info_rec_size:%u(userspace expected:%u)",
6659 info.line_info_rec_size, rec_size,
6660 info.jited_line_info_rec_size, jited_rec_size)) {
6668 rec_size = info.line_info_rec_size;
6669 jited_rec_size = info.jited_line_info_rec_size;
6671 memset(&info, 0, sizeof(info));
6673 linfo = calloc(cnt, rec_size);
6674 if (CHECK(!linfo, "!linfo")) {
6678 info.nr_line_info = cnt;
6679 info.line_info_rec_size = rec_size;
6680 info.line_info = ptr_to_u64(linfo);
6683 jited_linfo = calloc(jited_cnt, jited_rec_size);
6684 jited_ksyms = calloc(nr_jited_ksyms, sizeof(*jited_ksyms));
6685 jited_func_lens = calloc(nr_jited_func_lens,
6686 sizeof(*jited_func_lens));
6687 if (CHECK(!jited_linfo || !jited_ksyms || !jited_func_lens,
6688 "jited_linfo:%p jited_ksyms:%p jited_func_lens:%p",
6689 jited_linfo, jited_ksyms, jited_func_lens)) {
6694 info.nr_jited_line_info = jited_cnt;
6695 info.jited_line_info_rec_size = jited_rec_size;
6696 info.jited_line_info = ptr_to_u64(jited_linfo);
6697 info.nr_jited_ksyms = nr_jited_ksyms;
6698 info.jited_ksyms = ptr_to_u64(jited_ksyms);
6699 info.nr_jited_func_lens = nr_jited_func_lens;
6700 info.jited_func_lens = ptr_to_u64(jited_func_lens);
6703 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6706 * Only recheck the info.*line_info* fields.
6707 * Other fields are not the concern of this test.
6709 if (CHECK(err < 0 ||
6710 info.nr_line_info != cnt ||
6711 (jited_cnt && !info.jited_line_info) ||
6712 info.nr_jited_line_info != jited_cnt ||
6713 info.line_info_rec_size != rec_size ||
6714 info.jited_line_info_rec_size != jited_rec_size,
6715 "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",
6717 info.nr_line_info, cnt,
6718 info.nr_jited_line_info, jited_cnt,
6719 info.line_info_rec_size, rec_size,
6720 info.jited_line_info_rec_size, jited_rec_size,
6721 (void *)(long)info.line_info,
6722 (void *)(long)info.jited_line_info)) {
6728 while (test->dead_code_mask & (1 << dead_insns))
6731 CHECK(linfo[0].insn_off, "linfo[0].insn_off:%u",
6733 for (i = 1; i < cnt; i++) {
6734 const struct bpf_line_info *expected_linfo;
6736 while (test->dead_code_mask & (1 << (i + dead_insns)))
6739 expected_linfo = patched_linfo +
6740 ((i + dead_insns) * test->line_info_rec_size);
6741 if (CHECK(linfo[i].insn_off <= linfo[i - 1].insn_off,
6742 "linfo[%u].insn_off:%u <= linfo[%u].insn_off:%u",
6743 i, linfo[i].insn_off,
6744 i - 1, linfo[i - 1].insn_off)) {
6748 if (CHECK(linfo[i].file_name_off != expected_linfo->file_name_off ||
6749 linfo[i].line_off != expected_linfo->line_off ||
6750 linfo[i].line_col != expected_linfo->line_col,
6751 "linfo[%u] (%u, %u, %u) != (%u, %u, %u)", i,
6752 linfo[i].file_name_off,
6755 expected_linfo->file_name_off,
6756 expected_linfo->line_off,
6757 expected_linfo->line_col)) {
6764 fprintf(stderr, "not jited. skipping jited_line_info check. ");
6769 if (CHECK(jited_linfo[0] != jited_ksyms[0],
6770 "jited_linfo[0]:%lx != jited_ksyms[0]:%lx",
6771 (long)(jited_linfo[0]), (long)(jited_ksyms[0]))) {
6777 cur_func_len = jited_func_lens[0];
6778 cur_func_ksyms = jited_ksyms[0];
6779 for (i = 1; i < jited_cnt; i++) {
6780 if (ksyms_found < nr_jited_ksyms &&
6781 jited_linfo[i] == jited_ksyms[ksyms_found]) {
6782 cur_func_ksyms = jited_ksyms[ksyms_found];
6783 cur_func_len = jited_ksyms[ksyms_found];
6788 if (CHECK(jited_linfo[i] <= jited_linfo[i - 1],
6789 "jited_linfo[%u]:%lx <= jited_linfo[%u]:%lx",
6790 i, (long)jited_linfo[i],
6791 i - 1, (long)(jited_linfo[i - 1]))) {
6796 if (CHECK(jited_linfo[i] - cur_func_ksyms > cur_func_len,
6797 "jited_linfo[%u]:%lx - %lx > %u",
6798 i, (long)jited_linfo[i], (long)cur_func_ksyms,
6805 if (CHECK(ksyms_found != nr_jited_ksyms,
6806 "ksyms_found:%u != nr_jited_ksyms:%u",
6807 ksyms_found, nr_jited_ksyms)) {
6818 free(jited_func_lens);
6822 static void do_test_info_raw(unsigned int test_num)
6824 const struct prog_info_raw_test *test = &info_raw_tests[test_num - 1];
6825 unsigned int raw_btf_size, linfo_str_off, linfo_size = 0;
6826 int btf_fd = -1, prog_fd = -1, err = 0;
6827 void *raw_btf, *patched_linfo = NULL;
6828 const char *ret_next_str;
6829 union bpf_attr attr = {};
6831 if (!test__start_subtest(test->descr))
6834 raw_btf = btf_raw_create(&hdr_tmpl, test->raw_types,
6835 test->str_sec, test->str_sec_size,
6836 &raw_btf_size, &ret_next_str);
6840 *btf_log_buf = '\0';
6841 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
6844 if (CHECK(btf_fd < 0, "invalid btf_fd errno:%d", errno)) {
6849 if (*btf_log_buf && always_log)
6850 fprintf(stderr, "\n%s", btf_log_buf);
6851 *btf_log_buf = '\0';
6853 linfo_str_off = ret_next_str - test->str_sec;
6854 patched_linfo = patch_name_tbd(test->line_info,
6855 test->str_sec, linfo_str_off,
6856 test->str_sec_size, &linfo_size);
6857 err = libbpf_get_error(patched_linfo);
6859 fprintf(stderr, "error in creating raw bpf_line_info");
6864 attr.prog_type = test->prog_type;
6865 attr.insns = ptr_to_u64(test->insns);
6866 attr.insn_cnt = probe_prog_length(test->insns);
6867 attr.license = ptr_to_u64("GPL");
6868 attr.prog_btf_fd = btf_fd;
6869 attr.func_info_rec_size = test->func_info_rec_size;
6870 attr.func_info_cnt = test->func_info_cnt;
6871 attr.func_info = ptr_to_u64(test->func_info);
6872 attr.log_buf = ptr_to_u64(btf_log_buf);
6873 attr.log_size = BTF_LOG_BUF_SIZE;
6876 attr.line_info_rec_size = test->line_info_rec_size;
6877 attr.line_info = ptr_to_u64(patched_linfo);
6878 attr.line_info_cnt = linfo_size / attr.line_info_rec_size;
6881 prog_fd = syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
6882 err = ((prog_fd < 0) != test->expected_prog_load_failure);
6883 if (CHECK(err, "prog_fd:%d expected_prog_load_failure:%u errno:%d",
6884 prog_fd, test->expected_prog_load_failure, errno) ||
6885 CHECK(test->err_str && !strstr(btf_log_buf, test->err_str),
6886 "expected err_str:%s", test->err_str)) {
6894 err = test_get_finfo(test, prog_fd);
6898 err = test_get_linfo(test, patched_linfo,
6899 attr.line_info_cnt - test->dead_code_cnt,
6905 if (*btf_log_buf && (err || always_log))
6906 fprintf(stderr, "\n%s", btf_log_buf);
6913 if (!libbpf_get_error(patched_linfo))
6914 free(patched_linfo);
6917 struct btf_raw_data {
6918 __u32 raw_types[MAX_NR_RAW_U32];
6919 const char *str_sec;
6923 struct btf_dedup_test {
6925 struct btf_raw_data input;
6926 struct btf_raw_data expect;
6927 struct btf_dedup_opts opts;
6930 static struct btf_dedup_test dedup_tests[] = {
6933 .descr = "dedup: unused strings filtering",
6936 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 32, 4),
6937 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED, 0, 64, 8),
6940 BTF_STR_SEC("\0unused\0int\0foo\0bar\0long"),
6944 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
6945 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 64, 8),
6948 BTF_STR_SEC("\0int\0long"),
6952 .descr = "dedup: strings deduplication",
6955 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
6956 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 64, 8),
6957 BTF_TYPE_INT_ENC(NAME_NTH(3), BTF_INT_SIGNED, 0, 32, 4),
6958 BTF_TYPE_INT_ENC(NAME_NTH(4), BTF_INT_SIGNED, 0, 64, 8),
6959 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED, 0, 32, 4),
6962 BTF_STR_SEC("\0int\0long int\0int\0long int\0int"),
6966 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
6967 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 64, 8),
6970 BTF_STR_SEC("\0int\0long int"),
6974 .descr = "dedup: struct example #1",
6986 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6988 BTF_TYPE_ARRAY_ENC(1, 1, 16), /* [2] */
6990 BTF_STRUCT_ENC(NAME_NTH(2), 5, 88), /* [3] */
6991 BTF_MEMBER_ENC(NAME_NTH(3), 4, 0), /* struct s *next; */
6992 BTF_MEMBER_ENC(NAME_NTH(4), 5, 64), /* const int *a; */
6993 BTF_MEMBER_ENC(NAME_NTH(5), 2, 128), /* int b[16]; */
6994 BTF_MEMBER_ENC(NAME_NTH(6), 1, 640), /* int c; */
6995 BTF_MEMBER_ENC(NAME_NTH(8), 15, 672), /* float d; */
6996 /* ptr -> [3] struct s */
6997 BTF_PTR_ENC(3), /* [4] */
6998 /* ptr -> [6] const int */
6999 BTF_PTR_ENC(6), /* [5] */
7000 /* const -> [1] int */
7001 BTF_CONST_ENC(1), /* [6] */
7002 /* tag -> [3] struct s */
7003 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1), /* [7] */
7004 /* tag -> [3] struct s, member 1 */
7005 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, 1), /* [8] */
7007 /* full copy of the above */
7008 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4), /* [9] */
7009 BTF_TYPE_ARRAY_ENC(9, 9, 16), /* [10] */
7010 BTF_STRUCT_ENC(NAME_NTH(2), 5, 88), /* [11] */
7011 BTF_MEMBER_ENC(NAME_NTH(3), 12, 0),
7012 BTF_MEMBER_ENC(NAME_NTH(4), 13, 64),
7013 BTF_MEMBER_ENC(NAME_NTH(5), 10, 128),
7014 BTF_MEMBER_ENC(NAME_NTH(6), 9, 640),
7015 BTF_MEMBER_ENC(NAME_NTH(8), 15, 672),
7016 BTF_PTR_ENC(11), /* [12] */
7017 BTF_PTR_ENC(14), /* [13] */
7018 BTF_CONST_ENC(9), /* [14] */
7019 BTF_TYPE_FLOAT_ENC(NAME_NTH(7), 4), /* [15] */
7020 BTF_DECL_TAG_ENC(NAME_NTH(2), 11, -1), /* [16] */
7021 BTF_DECL_TAG_ENC(NAME_NTH(2), 11, 1), /* [17] */
7024 BTF_STR_SEC("\0int\0s\0next\0a\0b\0c\0float\0d"),
7029 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7031 BTF_TYPE_ARRAY_ENC(1, 1, 16), /* [2] */
7033 BTF_STRUCT_ENC(NAME_NTH(8), 5, 88), /* [3] */
7034 BTF_MEMBER_ENC(NAME_NTH(7), 4, 0), /* struct s *next; */
7035 BTF_MEMBER_ENC(NAME_NTH(1), 5, 64), /* const int *a; */
7036 BTF_MEMBER_ENC(NAME_NTH(2), 2, 128), /* int b[16]; */
7037 BTF_MEMBER_ENC(NAME_NTH(3), 1, 640), /* int c; */
7038 BTF_MEMBER_ENC(NAME_NTH(4), 9, 672), /* float d; */
7039 /* ptr -> [3] struct s */
7040 BTF_PTR_ENC(3), /* [4] */
7041 /* ptr -> [6] const int */
7042 BTF_PTR_ENC(6), /* [5] */
7043 /* const -> [1] int */
7044 BTF_CONST_ENC(1), /* [6] */
7045 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1), /* [7] */
7046 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, 1), /* [8] */
7047 BTF_TYPE_FLOAT_ENC(NAME_NTH(7), 4), /* [9] */
7050 BTF_STR_SEC("\0a\0b\0c\0d\0int\0float\0next\0s"),
7054 .descr = "dedup: struct <-> fwd resolution w/ hash collision",
7070 BTF_FWD_ENC(NAME_TBD, 0 /* struct fwd */), /* [1] fwd x */
7071 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
7072 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [3] struct s */
7073 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
7075 BTF_STRUCT_ENC(NAME_TBD, 0, 0), /* [4] struct x */
7076 BTF_PTR_ENC(4), /* [5] ptr -> [4] */
7077 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [6] struct s */
7078 BTF_MEMBER_ENC(NAME_TBD, 5, 0),
7081 BTF_STR_SEC("\0x\0s\0x\0x\0s\0x\0"),
7085 BTF_PTR_ENC(3), /* [1] ptr -> [3] */
7086 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [2] struct s */
7087 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7088 BTF_STRUCT_ENC(NAME_NTH(2), 0, 0), /* [3] struct x */
7091 BTF_STR_SEC("\0s\0x"),
7094 .force_collisions = true, /* force hash collisions */
7098 .descr = "dedup: void equiv check",
7112 BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
7113 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
7114 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
7115 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7117 BTF_PTR_ENC(0), /* [4] ptr -> void */
7118 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
7119 BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
7122 BTF_STR_SEC("\0s\0x"),
7127 BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
7128 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
7129 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
7130 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7132 BTF_PTR_ENC(0), /* [4] ptr -> void */
7133 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
7134 BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
7137 BTF_STR_SEC("\0s\0x"),
7140 .force_collisions = true, /* force hash collisions */
7144 .descr = "dedup: all possible kinds (no duplicates)",
7147 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 8), /* [1] int */
7148 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 4), /* [2] enum */
7149 BTF_ENUM_ENC(NAME_TBD, 0),
7150 BTF_ENUM_ENC(NAME_TBD, 1),
7151 BTF_FWD_ENC(NAME_TBD, 1 /* union kind_flag */), /* [3] fwd */
7152 BTF_TYPE_ARRAY_ENC(2, 1, 7), /* [4] array */
7153 BTF_STRUCT_ENC(NAME_TBD, 1, 4), /* [5] struct */
7154 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7155 BTF_UNION_ENC(NAME_TBD, 1, 4), /* [6] union */
7156 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7157 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [7] typedef */
7158 BTF_PTR_ENC(0), /* [8] ptr */
7159 BTF_CONST_ENC(8), /* [9] const */
7160 BTF_VOLATILE_ENC(8), /* [10] volatile */
7161 BTF_RESTRICT_ENC(8), /* [11] restrict */
7162 BTF_FUNC_PROTO_ENC(1, 2), /* [12] func_proto */
7163 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
7164 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
7165 BTF_FUNC_ENC(NAME_TBD, 12), /* [13] func */
7166 BTF_TYPE_FLOAT_ENC(NAME_TBD, 2), /* [14] float */
7167 BTF_DECL_TAG_ENC(NAME_TBD, 13, -1), /* [15] decl_tag */
7168 BTF_DECL_TAG_ENC(NAME_TBD, 13, 1), /* [16] decl_tag */
7169 BTF_DECL_TAG_ENC(NAME_TBD, 7, -1), /* [17] decl_tag */
7170 BTF_TYPE_TAG_ENC(NAME_TBD, 8), /* [18] type_tag */
7171 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 2), 8), /* [19] enum64 */
7172 BTF_ENUM64_ENC(NAME_TBD, 0, 0),
7173 BTF_ENUM64_ENC(NAME_TBD, 1, 1),
7176 BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R\0S\0T\0U"),
7180 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 8), /* [1] int */
7181 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 4), /* [2] enum */
7182 BTF_ENUM_ENC(NAME_TBD, 0),
7183 BTF_ENUM_ENC(NAME_TBD, 1),
7184 BTF_FWD_ENC(NAME_TBD, 1 /* union kind_flag */), /* [3] fwd */
7185 BTF_TYPE_ARRAY_ENC(2, 1, 7), /* [4] array */
7186 BTF_STRUCT_ENC(NAME_TBD, 1, 4), /* [5] struct */
7187 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7188 BTF_UNION_ENC(NAME_TBD, 1, 4), /* [6] union */
7189 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7190 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [7] typedef */
7191 BTF_PTR_ENC(0), /* [8] ptr */
7192 BTF_CONST_ENC(8), /* [9] const */
7193 BTF_VOLATILE_ENC(8), /* [10] volatile */
7194 BTF_RESTRICT_ENC(8), /* [11] restrict */
7195 BTF_FUNC_PROTO_ENC(1, 2), /* [12] func_proto */
7196 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
7197 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
7198 BTF_FUNC_ENC(NAME_TBD, 12), /* [13] func */
7199 BTF_TYPE_FLOAT_ENC(NAME_TBD, 2), /* [14] float */
7200 BTF_DECL_TAG_ENC(NAME_TBD, 13, -1), /* [15] decl_tag */
7201 BTF_DECL_TAG_ENC(NAME_TBD, 13, 1), /* [16] decl_tag */
7202 BTF_DECL_TAG_ENC(NAME_TBD, 7, -1), /* [17] decl_tag */
7203 BTF_TYPE_TAG_ENC(NAME_TBD, 8), /* [18] type_tag */
7204 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 2), 8), /* [19] enum64 */
7205 BTF_ENUM64_ENC(NAME_TBD, 0, 0),
7206 BTF_ENUM64_ENC(NAME_TBD, 1, 1),
7209 BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R\0S\0T\0U"),
7213 .descr = "dedup: no int/float duplicates",
7216 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 8),
7217 /* different name */
7218 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 32, 8),
7219 /* different encoding */
7220 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR, 0, 32, 8),
7221 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL, 0, 32, 8),
7222 /* different bit offset */
7223 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 8, 32, 8),
7224 /* different bit size */
7225 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 27, 8),
7226 /* different byte size */
7227 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
7228 /* all allowed sizes */
7229 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 2),
7230 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 4),
7231 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 8),
7232 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 12),
7233 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 16),
7236 BTF_STR_SEC("\0int\0some other int\0float"),
7240 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 8),
7241 /* different name */
7242 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 32, 8),
7243 /* different encoding */
7244 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR, 0, 32, 8),
7245 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL, 0, 32, 8),
7246 /* different bit offset */
7247 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 8, 32, 8),
7248 /* different bit size */
7249 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 27, 8),
7250 /* different byte size */
7251 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
7252 /* all allowed sizes */
7253 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 2),
7254 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 4),
7255 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 8),
7256 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 12),
7257 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 16),
7260 BTF_STR_SEC("\0int\0some other int\0float"),
7264 .descr = "dedup: enum fwd resolution",
7267 /* [1] fwd enum 'e1' before full enum */
7268 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 4),
7269 /* [2] full enum 'e1' after fwd */
7270 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7271 BTF_ENUM_ENC(NAME_NTH(2), 123),
7272 /* [3] full enum 'e2' before fwd */
7273 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7274 BTF_ENUM_ENC(NAME_NTH(4), 456),
7275 /* [4] fwd enum 'e2' after full enum */
7276 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 4),
7277 /* [5] fwd enum with different size, size does not matter for fwd */
7278 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 1),
7279 /* [6] incompatible full enum with different value */
7280 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7281 BTF_ENUM_ENC(NAME_NTH(2), 321),
7284 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7288 /* [1] full enum 'e1' */
7289 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7290 BTF_ENUM_ENC(NAME_NTH(2), 123),
7291 /* [2] full enum 'e2' */
7292 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7293 BTF_ENUM_ENC(NAME_NTH(4), 456),
7294 /* [3] incompatible full enum with different value */
7295 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7296 BTF_ENUM_ENC(NAME_NTH(2), 321),
7299 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7303 .descr = "dedup: datasec and vars pass-through",
7307 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7309 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [2] */
7310 /* .bss section */ /* [3] */
7311 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7312 BTF_VAR_SECINFO_ENC(2, 0, 4),
7313 /* int, referenced from [5] */
7314 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [4] */
7315 /* another static int t */
7316 BTF_VAR_ENC(NAME_NTH(2), 4, 0), /* [5] */
7317 /* another .bss section */ /* [6] */
7318 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7319 BTF_VAR_SECINFO_ENC(5, 0, 4),
7322 BTF_STR_SEC("\0.bss\0t"),
7327 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7329 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [2] */
7330 /* .bss section */ /* [3] */
7331 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7332 BTF_VAR_SECINFO_ENC(2, 0, 4),
7333 /* another static int t */
7334 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [4] */
7335 /* another .bss section */ /* [5] */
7336 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7337 BTF_VAR_SECINFO_ENC(4, 0, 4),
7340 BTF_STR_SEC("\0.bss\0t"),
7343 .force_collisions = true
7347 .descr = "dedup: func/func_arg/var tags",
7351 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7353 BTF_VAR_ENC(NAME_NTH(1), 1, 0), /* [2] */
7354 /* void f(int a1, int a2) */
7355 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
7356 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7357 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(3), 1),
7358 BTF_FUNC_ENC(NAME_NTH(4), 3), /* [4] */
7360 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
7361 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [6] */
7363 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1), /* [7] */
7364 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1), /* [8] */
7365 /* tag -> func arg a1 */
7366 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1), /* [9] */
7367 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1), /* [10] */
7370 BTF_STR_SEC("\0t\0a1\0a2\0f\0tag"),
7374 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7375 BTF_VAR_ENC(NAME_NTH(1), 1, 0), /* [2] */
7376 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
7377 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7378 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(3), 1),
7379 BTF_FUNC_ENC(NAME_NTH(4), 3), /* [4] */
7380 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
7381 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1), /* [6] */
7382 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1), /* [7] */
7385 BTF_STR_SEC("\0t\0a1\0a2\0f\0tag"),
7389 .descr = "dedup: func/func_param tags",
7393 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7394 /* void f(int a1, int a2) */
7395 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
7396 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
7397 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7398 BTF_FUNC_ENC(NAME_NTH(3), 2), /* [3] */
7399 /* void f(int a1, int a2) */
7400 BTF_FUNC_PROTO_ENC(0, 2), /* [4] */
7401 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
7402 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7403 BTF_FUNC_ENC(NAME_NTH(3), 4), /* [5] */
7404 /* tag -> f: tag1, tag2 */
7405 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [6] */
7406 BTF_DECL_TAG_ENC(NAME_NTH(5), 3, -1), /* [7] */
7407 /* tag -> f/a2: tag1, tag2 */
7408 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1), /* [8] */
7409 BTF_DECL_TAG_ENC(NAME_NTH(5), 3, 1), /* [9] */
7410 /* tag -> f: tag1, tag3 */
7411 BTF_DECL_TAG_ENC(NAME_NTH(4), 5, -1), /* [10] */
7412 BTF_DECL_TAG_ENC(NAME_NTH(6), 5, -1), /* [11] */
7413 /* tag -> f/a2: tag1, tag3 */
7414 BTF_DECL_TAG_ENC(NAME_NTH(4), 5, 1), /* [12] */
7415 BTF_DECL_TAG_ENC(NAME_NTH(6), 5, 1), /* [13] */
7418 BTF_STR_SEC("\0a1\0a2\0f\0tag1\0tag2\0tag3"),
7422 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7423 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
7424 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
7425 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7426 BTF_FUNC_ENC(NAME_NTH(3), 2), /* [3] */
7427 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [4] */
7428 BTF_DECL_TAG_ENC(NAME_NTH(5), 3, -1), /* [5] */
7429 BTF_DECL_TAG_ENC(NAME_NTH(6), 3, -1), /* [6] */
7430 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1), /* [7] */
7431 BTF_DECL_TAG_ENC(NAME_NTH(5), 3, 1), /* [8] */
7432 BTF_DECL_TAG_ENC(NAME_NTH(6), 3, 1), /* [9] */
7435 BTF_STR_SEC("\0a1\0a2\0f\0tag1\0tag2\0tag3"),
7439 .descr = "dedup: struct/struct_member tags",
7443 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7444 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [2] */
7445 BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
7446 BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
7447 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [3] */
7448 BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
7449 BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
7450 /* tag -> t: tag1, tag2 */
7451 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1), /* [4] */
7452 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
7453 /* tag -> t/m2: tag1, tag2 */
7454 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, 1), /* [6] */
7455 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, 1), /* [7] */
7456 /* tag -> t: tag1, tag3 */
7457 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [8] */
7458 BTF_DECL_TAG_ENC(NAME_NTH(6), 3, -1), /* [9] */
7459 /* tag -> t/m2: tag1, tag3 */
7460 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1), /* [10] */
7461 BTF_DECL_TAG_ENC(NAME_NTH(6), 3, 1), /* [11] */
7464 BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
7468 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7469 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [2] */
7470 BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
7471 BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
7472 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1), /* [3] */
7473 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [4] */
7474 BTF_DECL_TAG_ENC(NAME_NTH(6), 2, -1), /* [5] */
7475 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, 1), /* [6] */
7476 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, 1), /* [7] */
7477 BTF_DECL_TAG_ENC(NAME_NTH(6), 2, 1), /* [8] */
7480 BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
7484 .descr = "dedup: typedef tags",
7488 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7489 BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */
7490 BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [3] */
7491 /* tag -> t: tag1, tag2 */
7492 BTF_DECL_TAG_ENC(NAME_NTH(2), 2, -1), /* [4] */
7493 BTF_DECL_TAG_ENC(NAME_NTH(3), 2, -1), /* [5] */
7494 /* tag -> t: tag1, tag3 */
7495 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1), /* [6] */
7496 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [7] */
7499 BTF_STR_SEC("\0t\0tag1\0tag2\0tag3"),
7503 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7504 BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */
7505 BTF_DECL_TAG_ENC(NAME_NTH(2), 2, -1), /* [3] */
7506 BTF_DECL_TAG_ENC(NAME_NTH(3), 2, -1), /* [4] */
7507 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1), /* [5] */
7510 BTF_STR_SEC("\0t\0tag1\0tag2\0tag3"),
7514 .descr = "dedup: btf_type_tag #1",
7517 /* ptr -> tag2 -> tag1 -> int */
7518 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7519 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7520 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7521 BTF_PTR_ENC(3), /* [4] */
7522 /* ptr -> tag2 -> tag1 -> int */
7523 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [5] */
7524 BTF_TYPE_TAG_ENC(NAME_NTH(2), 5), /* [6] */
7525 BTF_PTR_ENC(6), /* [7] */
7526 /* ptr -> tag1 -> int */
7527 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [8] */
7528 BTF_PTR_ENC(8), /* [9] */
7531 BTF_STR_SEC("\0tag1\0tag2"),
7535 /* ptr -> tag2 -> tag1 -> int */
7536 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7537 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7538 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7539 BTF_PTR_ENC(3), /* [4] */
7540 /* ptr -> tag1 -> int */
7541 BTF_PTR_ENC(2), /* [5] */
7544 BTF_STR_SEC("\0tag1\0tag2"),
7548 .descr = "dedup: btf_type_tag #2",
7551 /* ptr -> tag2 -> tag1 -> int */
7552 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7553 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7554 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7555 BTF_PTR_ENC(3), /* [4] */
7556 /* ptr -> tag2 -> int */
7557 BTF_TYPE_TAG_ENC(NAME_NTH(2), 1), /* [5] */
7558 BTF_PTR_ENC(5), /* [6] */
7561 BTF_STR_SEC("\0tag1\0tag2"),
7565 /* ptr -> tag2 -> tag1 -> int */
7566 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7567 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7568 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7569 BTF_PTR_ENC(3), /* [4] */
7570 /* ptr -> tag2 -> int */
7571 BTF_TYPE_TAG_ENC(NAME_NTH(2), 1), /* [5] */
7572 BTF_PTR_ENC(5), /* [6] */
7575 BTF_STR_SEC("\0tag1\0tag2"),
7579 .descr = "dedup: btf_type_tag #3",
7582 /* ptr -> tag2 -> tag1 -> int */
7583 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7584 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7585 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7586 BTF_PTR_ENC(3), /* [4] */
7587 /* ptr -> tag1 -> tag2 -> int */
7588 BTF_TYPE_TAG_ENC(NAME_NTH(2), 1), /* [5] */
7589 BTF_TYPE_TAG_ENC(NAME_NTH(1), 5), /* [6] */
7590 BTF_PTR_ENC(6), /* [7] */
7593 BTF_STR_SEC("\0tag1\0tag2"),
7597 /* ptr -> tag2 -> tag1 -> int */
7598 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7599 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7600 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7601 BTF_PTR_ENC(3), /* [4] */
7602 /* ptr -> tag1 -> tag2 -> int */
7603 BTF_TYPE_TAG_ENC(NAME_NTH(2), 1), /* [5] */
7604 BTF_TYPE_TAG_ENC(NAME_NTH(1), 5), /* [6] */
7605 BTF_PTR_ENC(6), /* [7] */
7608 BTF_STR_SEC("\0tag1\0tag2"),
7612 .descr = "dedup: btf_type_tag #4",
7615 /* ptr -> tag1 -> int */
7616 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7617 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7618 BTF_PTR_ENC(2), /* [3] */
7619 /* ptr -> tag1 -> long */
7620 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 64, 8), /* [4] */
7621 BTF_TYPE_TAG_ENC(NAME_NTH(1), 4), /* [5] */
7622 BTF_PTR_ENC(5), /* [6] */
7625 BTF_STR_SEC("\0tag1"),
7629 /* ptr -> tag1 -> int */
7630 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7631 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7632 BTF_PTR_ENC(2), /* [3] */
7633 /* ptr -> tag1 -> long */
7634 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 64, 8), /* [4] */
7635 BTF_TYPE_TAG_ENC(NAME_NTH(1), 4), /* [5] */
7636 BTF_PTR_ENC(5), /* [6] */
7639 BTF_STR_SEC("\0tag1"),
7643 .descr = "dedup: btf_type_tag #5, struct",
7646 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7647 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7648 BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4), /* [3] */
7649 BTF_MEMBER_ENC(NAME_NTH(3), 2, BTF_MEMBER_OFFSET(0, 0)),
7650 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [4] */
7651 BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4), /* [5] */
7652 BTF_MEMBER_ENC(NAME_NTH(3), 4, BTF_MEMBER_OFFSET(0, 0)),
7655 BTF_STR_SEC("\0tag1\0t\0m"),
7659 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7660 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7661 BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4), /* [3] */
7662 BTF_MEMBER_ENC(NAME_NTH(3), 2, BTF_MEMBER_OFFSET(0, 0)),
7665 BTF_STR_SEC("\0tag1\0t\0m"),
7669 .descr = "dedup: enum64, standalone",
7672 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7673 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7674 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7675 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7678 BTF_STR_SEC("\0e1\0e1_val"),
7682 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7683 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7686 BTF_STR_SEC("\0e1\0e1_val"),
7690 .descr = "dedup: enum64, fwd resolution",
7693 /* [1] fwd enum64 'e1' before full enum */
7694 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8),
7695 /* [2] full enum64 'e1' after fwd */
7696 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7697 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7698 /* [3] full enum64 'e2' before fwd */
7699 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7700 BTF_ENUM64_ENC(NAME_NTH(4), 0, 456),
7701 /* [4] fwd enum64 'e2' after full enum */
7702 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8),
7703 /* [5] incompatible full enum64 with different value */
7704 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7705 BTF_ENUM64_ENC(NAME_NTH(2), 0, 321),
7708 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7712 /* [1] full enum64 'e1' */
7713 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7714 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7715 /* [2] full enum64 'e2' */
7716 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7717 BTF_ENUM64_ENC(NAME_NTH(4), 0, 456),
7718 /* [3] incompatible full enum64 with different value */
7719 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7720 BTF_ENUM64_ENC(NAME_NTH(2), 0, 321),
7723 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7727 .descr = "dedup: enum and enum64, no dedup",
7731 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7732 BTF_ENUM_ENC(NAME_NTH(2), 1),
7733 /* [2] enum64 'e1' */
7734 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 4),
7735 BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7738 BTF_STR_SEC("\0e1\0e1_val"),
7743 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7744 BTF_ENUM_ENC(NAME_NTH(2), 1),
7745 /* [2] enum64 'e1' */
7746 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 4),
7747 BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7750 BTF_STR_SEC("\0e1\0e1_val"),
7754 .descr = "dedup: enum of different size: no dedup",
7758 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7759 BTF_ENUM_ENC(NAME_NTH(2), 1),
7761 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 2),
7762 BTF_ENUM_ENC(NAME_NTH(2), 1),
7765 BTF_STR_SEC("\0e1\0e1_val"),
7770 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7771 BTF_ENUM_ENC(NAME_NTH(2), 1),
7773 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 2),
7774 BTF_ENUM_ENC(NAME_NTH(2), 1),
7777 BTF_STR_SEC("\0e1\0e1_val"),
7781 .descr = "dedup: enum fwd to enum64",
7784 /* [1] enum64 'e1' */
7785 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7786 BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7787 /* [2] enum 'e1' fwd */
7788 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 4),
7789 /* [3] typedef enum 'e1' td */
7790 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 2),
7793 BTF_STR_SEC("\0e1\0e1_val\0td"),
7797 /* [1] enum64 'e1' */
7798 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7799 BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7800 /* [2] typedef enum 'e1' td */
7801 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 1),
7804 BTF_STR_SEC("\0e1\0e1_val\0td"),
7808 .descr = "dedup: enum64 fwd to enum",
7812 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7813 BTF_ENUM_ENC(NAME_NTH(2), 1),
7814 /* [2] enum64 'e1' fwd */
7815 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8),
7816 /* [3] typedef enum 'e1' td */
7817 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 2),
7820 BTF_STR_SEC("\0e1\0e1_val\0td"),
7825 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7826 BTF_ENUM_ENC(NAME_NTH(2), 1),
7827 /* [2] typedef enum 'e1' td */
7828 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 1),
7831 BTF_STR_SEC("\0e1\0e1_val\0td"),
7835 .descr = "dedup: standalone fwd declaration struct",
7837 * Verify that CU1:foo and CU2:foo would be unified and that
7838 * typedef/ptr would be updated to point to CU1:foo.
7841 * struct foo { int x; };
7845 * typedef struct foo *foo_ptr;
7850 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7851 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7852 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7854 BTF_FWD_ENC(NAME_NTH(1), 0), /* [3] */
7855 BTF_PTR_ENC(3), /* [4] */
7856 BTF_TYPEDEF_ENC(NAME_NTH(3), 4), /* [5] */
7859 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7863 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7864 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7865 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7866 BTF_PTR_ENC(1), /* [3] */
7867 BTF_TYPEDEF_ENC(NAME_NTH(3), 3), /* [4] */
7870 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7874 .descr = "dedup: standalone fwd declaration union",
7876 * Verify that CU1:foo and CU2:foo would be unified and that
7877 * typedef/ptr would be updated to point to CU1:foo.
7878 * Same as "dedup: standalone fwd declaration struct" but for unions.
7881 * union foo { int x; };
7885 * typedef union foo *foo_ptr;
7890 BTF_UNION_ENC(NAME_NTH(1), 1, 4), /* [1] */
7891 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7892 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7894 BTF_FWD_ENC(NAME_TBD, 1), /* [3] */
7895 BTF_PTR_ENC(3), /* [4] */
7896 BTF_TYPEDEF_ENC(NAME_NTH(3), 4), /* [5] */
7899 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7903 BTF_UNION_ENC(NAME_NTH(1), 1, 4), /* [1] */
7904 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7905 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7906 BTF_PTR_ENC(1), /* [3] */
7907 BTF_TYPEDEF_ENC(NAME_NTH(3), 3), /* [4] */
7910 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7914 .descr = "dedup: standalone fwd declaration wrong kind",
7916 * Negative test for btf_dedup_resolve_fwds:
7917 * - CU1:foo is a struct, C2:foo is a union, thus CU2:foo is not deduped;
7918 * - typedef/ptr should remain unchanged as well.
7921 * struct foo { int x; };
7925 * typedef union foo *foo_ptr;
7930 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7931 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7932 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7934 BTF_FWD_ENC(NAME_NTH(3), 1), /* [3] */
7935 BTF_PTR_ENC(3), /* [4] */
7936 BTF_TYPEDEF_ENC(NAME_NTH(3), 4), /* [5] */
7939 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7944 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7945 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7946 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7948 BTF_FWD_ENC(NAME_NTH(3), 1), /* [3] */
7949 BTF_PTR_ENC(3), /* [4] */
7950 BTF_TYPEDEF_ENC(NAME_NTH(3), 4), /* [5] */
7953 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7957 .descr = "dedup: standalone fwd declaration name conflict",
7959 * Negative test for btf_dedup_resolve_fwds:
7960 * - two candidates for CU2:foo dedup, thus it is unchanged;
7961 * - typedef/ptr should remain unchanged as well.
7964 * struct foo { int x; };
7968 * typedef struct foo *foo_ptr;
7971 * struct foo { int x; int y; };
7976 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7977 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7978 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7980 BTF_FWD_ENC(NAME_NTH(1), 0), /* [3] */
7981 BTF_PTR_ENC(3), /* [4] */
7982 BTF_TYPEDEF_ENC(NAME_NTH(4), 4), /* [5] */
7984 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [6] */
7985 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7986 BTF_MEMBER_ENC(NAME_NTH(3), 2, 0),
7989 BTF_STR_SEC("\0foo\0x\0y\0foo_ptr"),
7994 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7995 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7996 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7998 BTF_FWD_ENC(NAME_NTH(1), 0), /* [3] */
7999 BTF_PTR_ENC(3), /* [4] */
8000 BTF_TYPEDEF_ENC(NAME_NTH(4), 4), /* [5] */
8002 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [6] */
8003 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
8004 BTF_MEMBER_ENC(NAME_NTH(3), 2, 0),
8007 BTF_STR_SEC("\0foo\0x\0y\0foo_ptr"),
8012 static int btf_type_size(const struct btf_type *t)
8014 int base_size = sizeof(struct btf_type);
8015 __u16 vlen = BTF_INFO_VLEN(t->info);
8016 __u16 kind = BTF_INFO_KIND(t->info);
8020 case BTF_KIND_CONST:
8021 case BTF_KIND_VOLATILE:
8022 case BTF_KIND_RESTRICT:
8024 case BTF_KIND_TYPEDEF:
8026 case BTF_KIND_FLOAT:
8027 case BTF_KIND_TYPE_TAG:
8030 return base_size + sizeof(__u32);
8032 return base_size + vlen * sizeof(struct btf_enum);
8033 case BTF_KIND_ENUM64:
8034 return base_size + vlen * sizeof(struct btf_enum64);
8035 case BTF_KIND_ARRAY:
8036 return base_size + sizeof(struct btf_array);
8037 case BTF_KIND_STRUCT:
8038 case BTF_KIND_UNION:
8039 return base_size + vlen * sizeof(struct btf_member);
8040 case BTF_KIND_FUNC_PROTO:
8041 return base_size + vlen * sizeof(struct btf_param);
8043 return base_size + sizeof(struct btf_var);
8044 case BTF_KIND_DATASEC:
8045 return base_size + vlen * sizeof(struct btf_var_secinfo);
8046 case BTF_KIND_DECL_TAG:
8047 return base_size + sizeof(struct btf_decl_tag);
8049 fprintf(stderr, "Unsupported BTF_KIND:%u\n", kind);
8054 static void dump_btf_strings(const char *strs, __u32 len)
8056 const char *cur = strs;
8059 while (cur < strs + len) {
8060 fprintf(stderr, "string #%d: '%s'\n", i, cur);
8061 cur += strlen(cur) + 1;
8066 static void do_test_dedup(unsigned int test_num)
8068 struct btf_dedup_test *test = &dedup_tests[test_num - 1];
8069 __u32 test_nr_types, expect_nr_types, test_btf_size, expect_btf_size;
8070 const struct btf_header *test_hdr, *expect_hdr;
8071 struct btf *test_btf = NULL, *expect_btf = NULL;
8072 const void *test_btf_data, *expect_btf_data;
8073 const char *ret_test_next_str, *ret_expect_next_str;
8074 const char *test_strs, *expect_strs;
8075 const char *test_str_cur;
8076 const char *expect_str_cur, *expect_str_end;
8077 unsigned int raw_btf_size;
8081 if (!test__start_subtest(test->descr))
8084 raw_btf = btf_raw_create(&hdr_tmpl, test->input.raw_types,
8085 test->input.str_sec, test->input.str_sec_size,
8086 &raw_btf_size, &ret_test_next_str);
8090 test_btf = btf__new((__u8 *)raw_btf, raw_btf_size);
8091 err = libbpf_get_error(test_btf);
8093 if (CHECK(err, "invalid test_btf errno:%d", err)) {
8098 raw_btf = btf_raw_create(&hdr_tmpl, test->expect.raw_types,
8099 test->expect.str_sec,
8100 test->expect.str_sec_size,
8101 &raw_btf_size, &ret_expect_next_str);
8104 expect_btf = btf__new((__u8 *)raw_btf, raw_btf_size);
8105 err = libbpf_get_error(expect_btf);
8107 if (CHECK(err, "invalid expect_btf errno:%d", err)) {
8112 test->opts.sz = sizeof(test->opts);
8113 err = btf__dedup(test_btf, &test->opts);
8114 if (CHECK(err, "btf_dedup failed errno:%d", err)) {
8119 test_btf_data = btf__raw_data(test_btf, &test_btf_size);
8120 expect_btf_data = btf__raw_data(expect_btf, &expect_btf_size);
8121 if (CHECK(test_btf_size != expect_btf_size,
8122 "test_btf_size:%u != expect_btf_size:%u",
8123 test_btf_size, expect_btf_size)) {
8128 test_hdr = test_btf_data;
8129 test_strs = test_btf_data + sizeof(*test_hdr) + test_hdr->str_off;
8130 expect_hdr = expect_btf_data;
8131 expect_strs = expect_btf_data + sizeof(*test_hdr) + expect_hdr->str_off;
8132 if (CHECK(test_hdr->str_len != expect_hdr->str_len,
8133 "test_hdr->str_len:%u != expect_hdr->str_len:%u",
8134 test_hdr->str_len, expect_hdr->str_len)) {
8135 fprintf(stderr, "\ntest strings:\n");
8136 dump_btf_strings(test_strs, test_hdr->str_len);
8137 fprintf(stderr, "\nexpected strings:\n");
8138 dump_btf_strings(expect_strs, expect_hdr->str_len);
8143 expect_str_cur = expect_strs;
8144 expect_str_end = expect_strs + expect_hdr->str_len;
8145 while (expect_str_cur < expect_str_end) {
8146 size_t test_len, expect_len;
8149 off = btf__find_str(test_btf, expect_str_cur);
8150 if (CHECK(off < 0, "exp str '%s' not found: %d\n", expect_str_cur, off)) {
8154 test_str_cur = btf__str_by_offset(test_btf, off);
8156 test_len = strlen(test_str_cur);
8157 expect_len = strlen(expect_str_cur);
8158 if (CHECK(test_len != expect_len,
8159 "test_len:%zu != expect_len:%zu "
8160 "(test_str:%s, expect_str:%s)",
8161 test_len, expect_len, test_str_cur, expect_str_cur)) {
8165 if (CHECK(strcmp(test_str_cur, expect_str_cur),
8166 "test_str:%s != expect_str:%s",
8167 test_str_cur, expect_str_cur)) {
8171 expect_str_cur += expect_len + 1;
8174 test_nr_types = btf__type_cnt(test_btf);
8175 expect_nr_types = btf__type_cnt(expect_btf);
8176 if (CHECK(test_nr_types != expect_nr_types,
8177 "test_nr_types:%u != expect_nr_types:%u",
8178 test_nr_types, expect_nr_types)) {
8183 for (i = 1; i < test_nr_types; i++) {
8184 const struct btf_type *test_type, *expect_type;
8185 int test_size, expect_size;
8187 test_type = btf__type_by_id(test_btf, i);
8188 expect_type = btf__type_by_id(expect_btf, i);
8189 test_size = btf_type_size(test_type);
8190 expect_size = btf_type_size(expect_type);
8192 if (CHECK(test_size != expect_size,
8193 "type #%d: test_size:%d != expect_size:%u",
8194 i, test_size, expect_size)) {
8198 if (CHECK(btf_kind(test_type) != btf_kind(expect_type),
8199 "type %d kind: exp %d != got %u\n",
8200 i, btf_kind(expect_type), btf_kind(test_type))) {
8204 if (CHECK(test_type->info != expect_type->info,
8205 "type %d info: exp %d != got %u\n",
8206 i, expect_type->info, test_type->info)) {
8210 if (CHECK(test_type->size != expect_type->size,
8211 "type %d size/type: exp %d != got %u\n",
8212 i, expect_type->size, test_type->size)) {
8219 btf__free(test_btf);
8220 btf__free(expect_btf);
8227 always_log = env.verbosity > VERBOSE_NONE;
8229 for (i = 1; i <= ARRAY_SIZE(raw_tests); i++)
8231 for (i = 1; i <= ARRAY_SIZE(get_info_tests); i++)
8232 do_test_get_info(i);
8233 for (i = 1; i <= ARRAY_SIZE(file_tests); i++)
8235 for (i = 1; i <= ARRAY_SIZE(info_raw_tests); i++)
8236 do_test_info_raw(i);
8237 for (i = 1; i <= ARRAY_SIZE(dedup_tests); i++)