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",
882 /* Test member exceeds the size of struct.
890 .descr = "size check test #1",
893 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
894 /* struct A { */ /* [2] */
895 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 2 - 1),
896 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
897 BTF_MEMBER_ENC(NAME_TBD, 1, 32),/* int n; */
901 .str_sec = "\0A\0m\0n",
902 .str_sec_size = sizeof("\0A\0m\0n"),
903 .map_type = BPF_MAP_TYPE_ARRAY,
904 .map_name = "size_check1_map",
905 .key_size = sizeof(int),
910 .btf_load_err = true,
911 .err_str = "Member exceeds struct_size",
914 /* Test member exceeds the size of struct
922 .descr = "size check test #2",
925 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
926 /* int[2] */ /* [2] */
927 BTF_TYPE_ARRAY_ENC(1, 1, 2),
928 /* struct A { */ /* [3] */
929 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 3 - 1),
930 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
931 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* int n[2]; */
935 .str_sec = "\0A\0m\0n",
936 .str_sec_size = sizeof("\0A\0m\0n"),
937 .map_type = BPF_MAP_TYPE_ARRAY,
938 .map_name = "size_check2_map",
939 .key_size = sizeof(int),
944 .btf_load_err = true,
945 .err_str = "Member exceeds struct_size",
948 /* Test member exceeds the size of struct
956 .descr = "size check test #3",
959 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
960 /* void* */ /* [2] */
961 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0),
962 /* struct A { */ /* [3] */
963 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) + sizeof(void *) - 1),
964 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
965 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* void *n; */
969 .str_sec = "\0A\0m\0n",
970 .str_sec_size = sizeof("\0A\0m\0n"),
971 .map_type = BPF_MAP_TYPE_ARRAY,
972 .map_name = "size_check3_map",
973 .key_size = sizeof(int),
978 .btf_load_err = true,
979 .err_str = "Member exceeds struct_size",
982 /* Test member exceeds the size of struct
995 .descr = "size check test #4",
998 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
999 /* enum E { */ /* [2] */
1000 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), sizeof(int)),
1001 BTF_ENUM_ENC(NAME_TBD, 0),
1002 BTF_ENUM_ENC(NAME_TBD, 1),
1004 /* struct A { */ /* [3] */
1005 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), sizeof(int) * 2 - 1),
1006 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int m; */
1007 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* enum E n; */
1011 .str_sec = "\0E\0E0\0E1\0A\0m\0n",
1012 .str_sec_size = sizeof("\0E\0E0\0E1\0A\0m\0n"),
1013 .map_type = BPF_MAP_TYPE_ARRAY,
1014 .map_name = "size_check4_map",
1015 .key_size = sizeof(int),
1020 .btf_load_err = true,
1021 .err_str = "Member exceeds struct_size",
1024 /* Test member unexceeds the size of struct
1033 * enum E __attribute__((packed)) n;
1037 .descr = "size check test #5",
1040 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, sizeof(int)),
1041 /* char */ /* [2] */
1042 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 8, 1),
1043 /* enum E { */ /* [3] */
1044 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 1),
1045 BTF_ENUM_ENC(NAME_TBD, 0),
1046 BTF_ENUM_ENC(NAME_TBD, 1),
1048 /* struct A { */ /* [4] */
1049 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 2),
1050 BTF_MEMBER_ENC(NAME_TBD, 2, 0), /* char m; */
1051 BTF_MEMBER_ENC(NAME_TBD, 3, 8),/* enum E __attribute__((packed)) n; */
1055 .str_sec = "\0E\0E0\0E1\0A\0m\0n",
1056 .str_sec_size = sizeof("\0E\0E0\0E1\0A\0m\0n"),
1057 .map_type = BPF_MAP_TYPE_ARRAY,
1058 .map_name = "size_check5_map",
1059 .key_size = sizeof(int),
1066 /* typedef const void * const_void_ptr;
1072 .descr = "void test #1",
1075 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1076 /* const void */ /* [2] */
1077 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1078 /* const void* */ /* [3] */
1079 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
1080 /* typedef const void * const_void_ptr */
1081 BTF_TYPEDEF_ENC(NAME_TBD, 3), /* [4] */
1082 /* struct A { */ /* [5] */
1083 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1084 /* const_void_ptr m; */
1085 BTF_MEMBER_ENC(NAME_TBD, 4, 0),
1089 .str_sec = "\0const_void_ptr\0A\0m",
1090 .str_sec_size = sizeof("\0const_void_ptr\0A\0m"),
1091 .map_type = BPF_MAP_TYPE_ARRAY,
1092 .map_name = "void_test1_map",
1093 .key_size = sizeof(int),
1094 .value_size = sizeof(void *),
1105 .descr = "void test #2",
1108 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1109 /* const void */ /* [2] */
1110 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1111 /* struct A { */ /* [3] */
1112 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 8),
1114 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
1118 .str_sec = "\0A\0m",
1119 .str_sec_size = sizeof("\0A\0m"),
1120 .map_type = BPF_MAP_TYPE_ARRAY,
1121 .map_name = "void_test2_map",
1122 .key_size = sizeof(int),
1123 .value_size = sizeof(void *),
1127 .btf_load_err = true,
1128 .err_str = "Invalid member",
1131 /* typedef const void * const_void_ptr;
1135 .descr = "void test #3",
1138 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1139 /* const void */ /* [2] */
1140 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1141 /* const void* */ /* [3] */
1142 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 2),
1143 /* typedef const void * const_void_ptr */
1144 BTF_TYPEDEF_ENC(NAME_TBD, 3), /* [4] */
1145 /* const_void_ptr[4] */
1146 BTF_TYPE_ARRAY_ENC(4, 1, 4), /* [5] */
1149 .str_sec = "\0const_void_ptr",
1150 .str_sec_size = sizeof("\0const_void_ptr"),
1151 .map_type = BPF_MAP_TYPE_ARRAY,
1152 .map_name = "void_test3_map",
1153 .key_size = sizeof(int),
1154 .value_size = sizeof(void *) * 4,
1162 .descr = "void test #4",
1165 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1166 /* const void */ /* [2] */
1167 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1168 /* const void[4] */ /* [3] */
1169 BTF_TYPE_ARRAY_ENC(2, 1, 4),
1172 .str_sec = "\0A\0m",
1173 .str_sec_size = sizeof("\0A\0m"),
1174 .map_type = BPF_MAP_TYPE_ARRAY,
1175 .map_name = "void_test4_map",
1176 .key_size = sizeof(int),
1177 .value_size = sizeof(void *) * 4,
1181 .btf_load_err = true,
1182 .err_str = "Invalid elem",
1185 /* Array_A <------------------+
1186 * elem_type == Array_B |
1189 * Array_B <-------- + |
1190 * elem_type == Array A --+
1193 .descr = "loop test #1",
1196 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1197 /* Array_A */ /* [2] */
1198 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1199 /* Array_B */ /* [3] */
1200 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1204 .str_sec_size = sizeof(""),
1205 .map_type = BPF_MAP_TYPE_ARRAY,
1206 .map_name = "loop_test1_map",
1207 .key_size = sizeof(int),
1208 .value_size = sizeof(sizeof(int) * 8),
1212 .btf_load_err = true,
1213 .err_str = "Loop detected",
1216 /* typedef is _before_ the BTF type of Array_A and Array_B
1218 * typedef Array_B int_array;
1220 * Array_A <------------------+
1221 * elem_type == int_array |
1224 * Array_B <-------- + |
1225 * elem_type == Array_A --+
1228 .descr = "loop test #2",
1231 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1232 /* typedef Array_B int_array */
1233 BTF_TYPEDEF_ENC(1, 4), /* [2] */
1235 BTF_TYPE_ARRAY_ENC(2, 1, 8), /* [3] */
1237 BTF_TYPE_ARRAY_ENC(3, 1, 8), /* [4] */
1240 .str_sec = "\0int_array\0",
1241 .str_sec_size = sizeof("\0int_array"),
1242 .map_type = BPF_MAP_TYPE_ARRAY,
1243 .map_name = "loop_test2_map",
1244 .key_size = sizeof(int),
1245 .value_size = sizeof(sizeof(int) * 8),
1249 .btf_load_err = true,
1250 .err_str = "Loop detected",
1253 /* Array_A <------------------+
1254 * elem_type == Array_B |
1257 * Array_B <-------- + |
1258 * elem_type == Array_A --+
1261 .descr = "loop test #3",
1264 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1265 /* Array_A */ /* [2] */
1266 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1267 /* Array_B */ /* [3] */
1268 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1272 .str_sec_size = sizeof(""),
1273 .map_type = BPF_MAP_TYPE_ARRAY,
1274 .map_name = "loop_test3_map",
1275 .key_size = sizeof(int),
1276 .value_size = sizeof(sizeof(int) * 8),
1280 .btf_load_err = true,
1281 .err_str = "Loop detected",
1284 /* typedef is _between_ the BTF type of Array_A and Array_B
1286 * typedef Array_B int_array;
1288 * Array_A <------------------+
1289 * elem_type == int_array |
1292 * Array_B <-------- + |
1293 * elem_type == Array_A --+
1296 .descr = "loop test #4",
1299 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1300 /* Array_A */ /* [2] */
1301 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1302 /* typedef Array_B int_array */ /* [3] */
1303 BTF_TYPEDEF_ENC(NAME_TBD, 4),
1304 /* Array_B */ /* [4] */
1305 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1308 .str_sec = "\0int_array\0",
1309 .str_sec_size = sizeof("\0int_array"),
1310 .map_type = BPF_MAP_TYPE_ARRAY,
1311 .map_name = "loop_test4_map",
1312 .key_size = sizeof(int),
1313 .value_size = sizeof(sizeof(int) * 8),
1317 .btf_load_err = true,
1318 .err_str = "Loop detected",
1321 /* typedef struct B Struct_B
1334 .descr = "loop test #5",
1337 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1338 /* struct A */ /* [2] */
1339 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
1340 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int x; */
1341 BTF_MEMBER_ENC(NAME_TBD, 3, 32),/* Struct_B y; */
1342 /* typedef struct B Struct_B */
1343 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
1344 /* struct B */ /* [4] */
1345 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
1346 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int x; */
1347 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* struct A y; */
1350 .str_sec = "\0A\0x\0y\0Struct_B\0B\0x\0y",
1351 .str_sec_size = sizeof("\0A\0x\0y\0Struct_B\0B\0x\0y"),
1352 .map_type = BPF_MAP_TYPE_ARRAY,
1353 .map_name = "loop_test5_map",
1354 .key_size = sizeof(int),
1359 .btf_load_err = true,
1360 .err_str = "Loop detected",
1365 * struct A array_a[4];
1369 .descr = "loop test #6",
1372 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1373 BTF_TYPE_ARRAY_ENC(3, 1, 4), /* [2] */
1374 /* struct A */ /* [3] */
1375 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 2), 8),
1376 BTF_MEMBER_ENC(NAME_TBD, 1, 0), /* int x; */
1377 BTF_MEMBER_ENC(NAME_TBD, 2, 32),/* struct A array_a[4]; */
1380 .str_sec = "\0A\0x\0y",
1381 .str_sec_size = sizeof("\0A\0x\0y"),
1382 .map_type = BPF_MAP_TYPE_ARRAY,
1383 .map_name = "loop_test6_map",
1384 .key_size = sizeof(int),
1389 .btf_load_err = true,
1390 .err_str = "Loop detected",
1394 .descr = "loop test #7",
1397 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1398 /* struct A { */ /* [2] */
1399 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1400 /* const void *m; */
1401 BTF_MEMBER_ENC(NAME_TBD, 3, 0),
1402 /* CONST type_id=3 */ /* [3] */
1403 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 4),
1404 /* PTR type_id=2 */ /* [4] */
1405 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 3),
1408 .str_sec = "\0A\0m",
1409 .str_sec_size = sizeof("\0A\0m"),
1410 .map_type = BPF_MAP_TYPE_ARRAY,
1411 .map_name = "loop_test7_map",
1412 .key_size = sizeof(int),
1413 .value_size = sizeof(void *),
1417 .btf_load_err = true,
1418 .err_str = "Loop detected",
1422 .descr = "loop test #8",
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, 4, 0),
1430 /* struct B { */ /* [3] */
1431 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), sizeof(void *)),
1432 /* const void *n; */
1433 BTF_MEMBER_ENC(NAME_TBD, 6, 0),
1434 /* CONST type_id=5 */ /* [4] */
1435 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 5),
1436 /* PTR type_id=6 */ /* [5] */
1437 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 6),
1438 /* CONST type_id=7 */ /* [6] */
1439 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 7),
1440 /* PTR type_id=4 */ /* [7] */
1441 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 4),
1444 .str_sec = "\0A\0m\0B\0n",
1445 .str_sec_size = sizeof("\0A\0m\0B\0n"),
1446 .map_type = BPF_MAP_TYPE_ARRAY,
1447 .map_name = "loop_test8_map",
1448 .key_size = sizeof(int),
1449 .value_size = sizeof(void *),
1453 .btf_load_err = true,
1454 .err_str = "Loop detected",
1458 .descr = "string section does not end with null",
1461 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1465 .str_sec_size = sizeof("\0int") - 1,
1466 .map_type = BPF_MAP_TYPE_ARRAY,
1467 .map_name = "hdr_test_map",
1468 .key_size = sizeof(int),
1469 .value_size = sizeof(int),
1473 .btf_load_err = true,
1474 .err_str = "Invalid string section",
1478 .descr = "empty string section",
1481 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1486 .map_type = BPF_MAP_TYPE_ARRAY,
1487 .map_name = "hdr_test_map",
1488 .key_size = sizeof(int),
1489 .value_size = sizeof(int),
1493 .btf_load_err = true,
1494 .err_str = "Invalid string section",
1498 .descr = "empty type section",
1503 .str_sec_size = sizeof("\0int"),
1504 .map_type = BPF_MAP_TYPE_ARRAY,
1505 .map_name = "hdr_test_map",
1506 .key_size = sizeof(int),
1507 .value_size = sizeof(int),
1511 .btf_load_err = true,
1512 .err_str = "No type found",
1516 .descr = "btf_header test. Longer hdr_len",
1519 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1523 .str_sec_size = sizeof("\0int"),
1524 .map_type = BPF_MAP_TYPE_ARRAY,
1525 .map_name = "hdr_test_map",
1526 .key_size = sizeof(int),
1527 .value_size = sizeof(int),
1531 .btf_load_err = true,
1533 .err_str = "Unsupported btf_header",
1537 .descr = "btf_header test. Gap between hdr and type",
1540 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1544 .str_sec_size = sizeof("\0int"),
1545 .map_type = BPF_MAP_TYPE_ARRAY,
1546 .map_name = "hdr_test_map",
1547 .key_size = sizeof(int),
1548 .value_size = sizeof(int),
1552 .btf_load_err = true,
1553 .type_off_delta = 4,
1554 .err_str = "Unsupported section found",
1558 .descr = "btf_header test. Gap between type and str",
1561 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1565 .str_sec_size = sizeof("\0int"),
1566 .map_type = BPF_MAP_TYPE_ARRAY,
1567 .map_name = "hdr_test_map",
1568 .key_size = sizeof(int),
1569 .value_size = sizeof(int),
1573 .btf_load_err = true,
1575 .err_str = "Unsupported section found",
1579 .descr = "btf_header test. Overlap between type and str",
1582 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1586 .str_sec_size = sizeof("\0int"),
1587 .map_type = BPF_MAP_TYPE_ARRAY,
1588 .map_name = "hdr_test_map",
1589 .key_size = sizeof(int),
1590 .value_size = sizeof(int),
1594 .btf_load_err = true,
1595 .str_off_delta = -4,
1596 .err_str = "Section overlap found",
1600 .descr = "btf_header test. Larger BTF size",
1603 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1607 .str_sec_size = sizeof("\0int"),
1608 .map_type = BPF_MAP_TYPE_ARRAY,
1609 .map_name = "hdr_test_map",
1610 .key_size = sizeof(int),
1611 .value_size = sizeof(int),
1615 .btf_load_err = true,
1616 .str_len_delta = -4,
1617 .err_str = "Unsupported section found",
1621 .descr = "btf_header test. Smaller BTF size",
1624 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
1628 .str_sec_size = sizeof("\0int"),
1629 .map_type = BPF_MAP_TYPE_ARRAY,
1630 .map_name = "hdr_test_map",
1631 .key_size = sizeof(int),
1632 .value_size = sizeof(int),
1636 .btf_load_err = true,
1638 .err_str = "Total section length too long",
1642 .descr = "array test. index_type/elem_type \"int\"",
1645 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1646 /* int[16] */ /* [2] */
1647 BTF_TYPE_ARRAY_ENC(1, 1, 16),
1651 .str_sec_size = sizeof(""),
1652 .map_type = BPF_MAP_TYPE_ARRAY,
1653 .map_name = "array_test_map",
1654 .key_size = sizeof(int),
1655 .value_size = sizeof(int),
1662 .descr = "array test. index_type/elem_type \"const int\"",
1665 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1666 /* int[16] */ /* [2] */
1667 BTF_TYPE_ARRAY_ENC(3, 3, 16),
1668 /* CONST type_id=1 */ /* [3] */
1669 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 1),
1673 .str_sec_size = sizeof(""),
1674 .map_type = BPF_MAP_TYPE_ARRAY,
1675 .map_name = "array_test_map",
1676 .key_size = sizeof(int),
1677 .value_size = sizeof(int),
1684 .descr = "array test. index_type \"const int:31\"",
1687 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1688 /* int:31 */ /* [2] */
1689 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 31, 4),
1690 /* int[16] */ /* [3] */
1691 BTF_TYPE_ARRAY_ENC(1, 4, 16),
1692 /* CONST type_id=2 */ /* [4] */
1693 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
1697 .str_sec_size = sizeof(""),
1698 .map_type = BPF_MAP_TYPE_ARRAY,
1699 .map_name = "array_test_map",
1700 .key_size = sizeof(int),
1701 .value_size = sizeof(int),
1705 .btf_load_err = true,
1706 .err_str = "Invalid index",
1710 .descr = "array test. elem_type \"const int:31\"",
1713 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1714 /* int:31 */ /* [2] */
1715 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 31, 4),
1716 /* int[16] */ /* [3] */
1717 BTF_TYPE_ARRAY_ENC(4, 1, 16),
1718 /* CONST type_id=2 */ /* [4] */
1719 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 2),
1723 .str_sec_size = sizeof(""),
1724 .map_type = BPF_MAP_TYPE_ARRAY,
1725 .map_name = "array_test_map",
1726 .key_size = sizeof(int),
1727 .value_size = sizeof(int),
1731 .btf_load_err = true,
1732 .err_str = "Invalid array of int",
1736 .descr = "array test. index_type \"void\"",
1739 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1740 /* int[16] */ /* [2] */
1741 BTF_TYPE_ARRAY_ENC(1, 0, 16),
1745 .str_sec_size = sizeof(""),
1746 .map_type = BPF_MAP_TYPE_ARRAY,
1747 .map_name = "array_test_map",
1748 .key_size = sizeof(int),
1749 .value_size = sizeof(int),
1753 .btf_load_err = true,
1754 .err_str = "Invalid index",
1758 .descr = "array test. index_type \"const void\"",
1761 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1762 /* int[16] */ /* [2] */
1763 BTF_TYPE_ARRAY_ENC(1, 3, 16),
1764 /* CONST type_id=0 (void) */ /* [3] */
1765 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1769 .str_sec_size = sizeof(""),
1770 .map_type = BPF_MAP_TYPE_ARRAY,
1771 .map_name = "array_test_map",
1772 .key_size = sizeof(int),
1773 .value_size = sizeof(int),
1777 .btf_load_err = true,
1778 .err_str = "Invalid index",
1782 .descr = "array test. elem_type \"const void\"",
1785 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1786 /* int[16] */ /* [2] */
1787 BTF_TYPE_ARRAY_ENC(3, 1, 16),
1788 /* CONST type_id=0 (void) */ /* [3] */
1789 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 0),
1793 .str_sec_size = sizeof(""),
1794 .map_type = BPF_MAP_TYPE_ARRAY,
1795 .map_name = "array_test_map",
1796 .key_size = sizeof(int),
1797 .value_size = sizeof(int),
1801 .btf_load_err = true,
1802 .err_str = "Invalid elem",
1806 .descr = "array test. elem_type \"const void *\"",
1809 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1810 /* const void *[16] */ /* [2] */
1811 BTF_TYPE_ARRAY_ENC(3, 1, 16),
1812 /* CONST type_id=4 */ /* [3] */
1813 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 4),
1814 /* void* */ /* [4] */
1815 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0),
1819 .str_sec_size = sizeof(""),
1820 .map_type = BPF_MAP_TYPE_ARRAY,
1821 .map_name = "array_test_map",
1822 .key_size = sizeof(int),
1823 .value_size = sizeof(int),
1830 .descr = "array test. index_type \"const void *\"",
1833 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1834 /* const void *[16] */ /* [2] */
1835 BTF_TYPE_ARRAY_ENC(3, 3, 16),
1836 /* CONST type_id=4 */ /* [3] */
1837 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 4),
1838 /* void* */ /* [4] */
1839 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0),
1843 .str_sec_size = sizeof(""),
1844 .map_type = BPF_MAP_TYPE_ARRAY,
1845 .map_name = "array_test_map",
1846 .key_size = sizeof(int),
1847 .value_size = sizeof(int),
1851 .btf_load_err = true,
1852 .err_str = "Invalid index",
1856 .descr = "array test. t->size != 0\"",
1859 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1860 /* int[16] */ /* [2] */
1861 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY, 0, 0), 1),
1862 BTF_ARRAY_ENC(1, 1, 16),
1866 .str_sec_size = sizeof(""),
1867 .map_type = BPF_MAP_TYPE_ARRAY,
1868 .map_name = "array_test_map",
1869 .key_size = sizeof(int),
1870 .value_size = sizeof(int),
1874 .btf_load_err = true,
1875 .err_str = "size != 0",
1879 .descr = "int test. invalid int_data",
1881 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), 4),
1886 .str_sec_size = sizeof(""),
1887 .map_type = BPF_MAP_TYPE_ARRAY,
1888 .map_name = "array_test_map",
1889 .key_size = sizeof(int),
1890 .value_size = sizeof(int),
1894 .btf_load_err = true,
1895 .err_str = "Invalid int_data",
1899 .descr = "invalid BTF_INFO",
1902 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1903 BTF_TYPE_ENC(0, 0x20000000, 4),
1907 .str_sec_size = sizeof(""),
1908 .map_type = BPF_MAP_TYPE_ARRAY,
1909 .map_name = "array_test_map",
1910 .key_size = sizeof(int),
1911 .value_size = sizeof(int),
1915 .btf_load_err = true,
1916 .err_str = "Invalid btf_info",
1920 .descr = "fwd test. t->type != 0\"",
1923 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
1924 /* fwd type */ /* [2] */
1925 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD, 0, 0), 1),
1929 .str_sec_size = sizeof(""),
1930 .map_type = BPF_MAP_TYPE_ARRAY,
1931 .map_name = "fwd_test_map",
1932 .key_size = sizeof(int),
1933 .value_size = sizeof(int),
1937 .btf_load_err = true,
1938 .err_str = "type != 0",
1942 .descr = "typedef (invalid name, name_off = 0)",
1944 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1945 BTF_TYPEDEF_ENC(0, 1), /* [2] */
1948 .str_sec = "\0__int",
1949 .str_sec_size = sizeof("\0__int"),
1950 .map_type = BPF_MAP_TYPE_ARRAY,
1951 .map_name = "typedef_check_btf",
1952 .key_size = sizeof(int),
1953 .value_size = sizeof(int),
1957 .btf_load_err = true,
1958 .err_str = "Invalid name",
1962 .descr = "typedef (invalid name, invalid identifier)",
1964 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1965 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [2] */
1968 .str_sec = "\0__!int",
1969 .str_sec_size = sizeof("\0__!int"),
1970 .map_type = BPF_MAP_TYPE_ARRAY,
1971 .map_name = "typedef_check_btf",
1972 .key_size = sizeof(int),
1973 .value_size = sizeof(int),
1977 .btf_load_err = true,
1978 .err_str = "Invalid name",
1982 .descr = "ptr type (invalid name, name_off <> 0)",
1984 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
1985 BTF_TYPE_ENC(NAME_TBD,
1986 BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 1), /* [2] */
1989 .str_sec = "\0__int",
1990 .str_sec_size = sizeof("\0__int"),
1991 .map_type = BPF_MAP_TYPE_ARRAY,
1992 .map_name = "ptr_type_check_btf",
1993 .key_size = sizeof(int),
1994 .value_size = sizeof(int),
1998 .btf_load_err = true,
1999 .err_str = "Invalid name",
2003 .descr = "volatile type (invalid name, name_off <> 0)",
2005 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2006 BTF_TYPE_ENC(NAME_TBD,
2007 BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), 1), /* [2] */
2010 .str_sec = "\0__int",
2011 .str_sec_size = sizeof("\0__int"),
2012 .map_type = BPF_MAP_TYPE_ARRAY,
2013 .map_name = "volatile_type_check_btf",
2014 .key_size = sizeof(int),
2015 .value_size = sizeof(int),
2019 .btf_load_err = true,
2020 .err_str = "Invalid name",
2024 .descr = "const type (invalid name, name_off <> 0)",
2026 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2027 BTF_TYPE_ENC(NAME_TBD,
2028 BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 1), /* [2] */
2031 .str_sec = "\0__int",
2032 .str_sec_size = sizeof("\0__int"),
2033 .map_type = BPF_MAP_TYPE_ARRAY,
2034 .map_name = "const_type_check_btf",
2035 .key_size = sizeof(int),
2036 .value_size = sizeof(int),
2040 .btf_load_err = true,
2041 .err_str = "Invalid name",
2045 .descr = "restrict type (invalid name, name_off <> 0)",
2047 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2048 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 1), /* [2] */
2049 BTF_TYPE_ENC(NAME_TBD,
2050 BTF_INFO_ENC(BTF_KIND_RESTRICT, 0, 0), 2), /* [3] */
2053 .str_sec = "\0__int",
2054 .str_sec_size = sizeof("\0__int"),
2055 .map_type = BPF_MAP_TYPE_ARRAY,
2056 .map_name = "restrict_type_check_btf",
2057 .key_size = sizeof(int),
2058 .value_size = sizeof(int),
2062 .btf_load_err = true,
2063 .err_str = "Invalid name",
2067 .descr = "fwd type (invalid name, name_off = 0)",
2069 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2070 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD, 0, 0), 0), /* [2] */
2073 .str_sec = "\0__skb",
2074 .str_sec_size = sizeof("\0__skb"),
2075 .map_type = BPF_MAP_TYPE_ARRAY,
2076 .map_name = "fwd_type_check_btf",
2077 .key_size = sizeof(int),
2078 .value_size = sizeof(int),
2082 .btf_load_err = true,
2083 .err_str = "Invalid name",
2087 .descr = "fwd type (invalid name, invalid identifier)",
2089 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2090 BTF_TYPE_ENC(NAME_TBD,
2091 BTF_INFO_ENC(BTF_KIND_FWD, 0, 0), 0), /* [2] */
2094 .str_sec = "\0__!skb",
2095 .str_sec_size = sizeof("\0__!skb"),
2096 .map_type = BPF_MAP_TYPE_ARRAY,
2097 .map_name = "fwd_type_check_btf",
2098 .key_size = sizeof(int),
2099 .value_size = sizeof(int),
2103 .btf_load_err = true,
2104 .err_str = "Invalid name",
2108 .descr = "array type (invalid name, name_off <> 0)",
2110 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2111 BTF_TYPE_ENC(NAME_TBD,
2112 BTF_INFO_ENC(BTF_KIND_ARRAY, 0, 0), 0), /* [2] */
2113 BTF_ARRAY_ENC(1, 1, 4),
2116 .str_sec = "\0__skb",
2117 .str_sec_size = sizeof("\0__skb"),
2118 .map_type = BPF_MAP_TYPE_ARRAY,
2119 .map_name = "array_type_check_btf",
2120 .key_size = sizeof(int),
2121 .value_size = sizeof(int),
2125 .btf_load_err = true,
2126 .err_str = "Invalid name",
2130 .descr = "struct type (name_off = 0)",
2132 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2134 BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4), /* [2] */
2135 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2139 .str_sec_size = sizeof("\0A"),
2140 .map_type = BPF_MAP_TYPE_ARRAY,
2141 .map_name = "struct_type_check_btf",
2142 .key_size = sizeof(int),
2143 .value_size = sizeof(int),
2150 .descr = "struct type (invalid name, invalid identifier)",
2152 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2153 BTF_TYPE_ENC(NAME_TBD,
2154 BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4), /* [2] */
2155 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2158 .str_sec = "\0A!\0B",
2159 .str_sec_size = sizeof("\0A!\0B"),
2160 .map_type = BPF_MAP_TYPE_ARRAY,
2161 .map_name = "struct_type_check_btf",
2162 .key_size = sizeof(int),
2163 .value_size = sizeof(int),
2167 .btf_load_err = true,
2168 .err_str = "Invalid name",
2172 .descr = "struct member (name_off = 0)",
2174 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2176 BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4), /* [2] */
2177 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2181 .str_sec_size = sizeof("\0A"),
2182 .map_type = BPF_MAP_TYPE_ARRAY,
2183 .map_name = "struct_type_check_btf",
2184 .key_size = sizeof(int),
2185 .value_size = sizeof(int),
2192 .descr = "struct member (invalid name, invalid identifier)",
2194 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2195 BTF_TYPE_ENC(NAME_TBD,
2196 BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 4), /* [2] */
2197 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
2200 .str_sec = "\0A\0B*",
2201 .str_sec_size = sizeof("\0A\0B*"),
2202 .map_type = BPF_MAP_TYPE_ARRAY,
2203 .map_name = "struct_type_check_btf",
2204 .key_size = sizeof(int),
2205 .value_size = sizeof(int),
2209 .btf_load_err = true,
2210 .err_str = "Invalid name",
2214 .descr = "enum type (name_off = 0)",
2216 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2218 BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2219 sizeof(int)), /* [2] */
2220 BTF_ENUM_ENC(NAME_TBD, 0),
2223 .str_sec = "\0A\0B",
2224 .str_sec_size = sizeof("\0A\0B"),
2225 .map_type = BPF_MAP_TYPE_ARRAY,
2226 .map_name = "enum_type_check_btf",
2227 .key_size = sizeof(int),
2228 .value_size = sizeof(int),
2235 .descr = "enum type (invalid name, invalid identifier)",
2237 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2238 BTF_TYPE_ENC(NAME_TBD,
2239 BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2240 sizeof(int)), /* [2] */
2241 BTF_ENUM_ENC(NAME_TBD, 0),
2244 .str_sec = "\0A!\0B",
2245 .str_sec_size = sizeof("\0A!\0B"),
2246 .map_type = BPF_MAP_TYPE_ARRAY,
2247 .map_name = "enum_type_check_btf",
2248 .key_size = sizeof(int),
2249 .value_size = sizeof(int),
2253 .btf_load_err = true,
2254 .err_str = "Invalid name",
2258 .descr = "enum member (invalid name, name_off = 0)",
2260 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2262 BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2263 sizeof(int)), /* [2] */
2268 .str_sec_size = sizeof(""),
2269 .map_type = BPF_MAP_TYPE_ARRAY,
2270 .map_name = "enum_type_check_btf",
2271 .key_size = sizeof(int),
2272 .value_size = sizeof(int),
2276 .btf_load_err = true,
2277 .err_str = "Invalid name",
2281 .descr = "enum member (invalid name, invalid identifier)",
2283 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2285 BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1),
2286 sizeof(int)), /* [2] */
2287 BTF_ENUM_ENC(NAME_TBD, 0),
2291 .str_sec_size = sizeof("\0A!"),
2292 .map_type = BPF_MAP_TYPE_ARRAY,
2293 .map_name = "enum_type_check_btf",
2294 .key_size = sizeof(int),
2295 .value_size = sizeof(int),
2299 .btf_load_err = true,
2300 .err_str = "Invalid name",
2303 .descr = "arraymap invalid btf key (a bit field)",
2306 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2307 /* 32 bit int with 32 bit offset */ /* [2] */
2308 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 32, 32, 8),
2312 .str_sec_size = sizeof(""),
2313 .map_type = BPF_MAP_TYPE_ARRAY,
2314 .map_name = "array_map_check_btf",
2315 .key_size = sizeof(int),
2316 .value_size = sizeof(int),
2320 .map_create_err = true,
2324 .descr = "arraymap invalid btf key (!= 32 bits)",
2327 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2328 /* 16 bit int with 0 bit offset */ /* [2] */
2329 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 16, 2),
2333 .str_sec_size = sizeof(""),
2334 .map_type = BPF_MAP_TYPE_ARRAY,
2335 .map_name = "array_map_check_btf",
2336 .key_size = sizeof(int),
2337 .value_size = sizeof(int),
2341 .map_create_err = true,
2345 .descr = "arraymap invalid btf value (too small)",
2348 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2352 .str_sec_size = sizeof(""),
2353 .map_type = BPF_MAP_TYPE_ARRAY,
2354 .map_name = "array_map_check_btf",
2355 .key_size = sizeof(int),
2356 /* btf_value_size < map->value_size */
2357 .value_size = sizeof(__u64),
2361 .map_create_err = true,
2365 .descr = "arraymap invalid btf value (too big)",
2368 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
2372 .str_sec_size = sizeof(""),
2373 .map_type = BPF_MAP_TYPE_ARRAY,
2374 .map_name = "array_map_check_btf",
2375 .key_size = sizeof(int),
2376 /* btf_value_size > map->value_size */
2377 .value_size = sizeof(__u16),
2381 .map_create_err = true,
2385 .descr = "func proto (int (*)(int, unsigned int))",
2387 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2388 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2389 /* int (*)(int, unsigned int) */
2390 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
2391 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2392 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2396 .str_sec_size = sizeof(""),
2397 .map_type = BPF_MAP_TYPE_ARRAY,
2398 .map_name = "func_proto_type_check_btf",
2399 .key_size = sizeof(int),
2400 .value_size = sizeof(int),
2407 .descr = "func proto (vararg)",
2409 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2410 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2411 /* void (*)(int, unsigned int, ...) */
2412 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2413 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2414 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2415 BTF_FUNC_PROTO_ARG_ENC(0, 0),
2419 .str_sec_size = sizeof(""),
2420 .map_type = BPF_MAP_TYPE_ARRAY,
2421 .map_name = "func_proto_type_check_btf",
2422 .key_size = sizeof(int),
2423 .value_size = sizeof(int),
2430 .descr = "func proto (vararg with name)",
2432 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2433 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2434 /* void (*)(int a, unsigned int b, ... c) */
2435 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2436 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2437 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2438 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 0),
2441 .str_sec = "\0a\0b\0c",
2442 .str_sec_size = sizeof("\0a\0b\0c"),
2443 .map_type = BPF_MAP_TYPE_ARRAY,
2444 .map_name = "func_proto_type_check_btf",
2445 .key_size = sizeof(int),
2446 .value_size = sizeof(int),
2450 .btf_load_err = true,
2451 .err_str = "Invalid arg#3",
2455 .descr = "func proto (arg after vararg)",
2457 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2458 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2459 /* void (*)(int a, ..., unsigned int b) */
2460 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2461 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2462 BTF_FUNC_PROTO_ARG_ENC(0, 0),
2463 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2466 .str_sec = "\0a\0b",
2467 .str_sec_size = sizeof("\0a\0b"),
2468 .map_type = BPF_MAP_TYPE_ARRAY,
2469 .map_name = "func_proto_type_check_btf",
2470 .key_size = sizeof(int),
2471 .value_size = sizeof(int),
2475 .btf_load_err = true,
2476 .err_str = "Invalid arg#2",
2480 .descr = "func proto (CONST=>TYPEDEF=>PTR=>FUNC_PROTO)",
2482 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2483 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2484 /* typedef void (*func_ptr)(int, unsigned int) */
2485 BTF_TYPEDEF_ENC(NAME_TBD, 5), /* [3] */
2486 /* const func_ptr */
2487 BTF_CONST_ENC(3), /* [4] */
2488 BTF_PTR_ENC(6), /* [5] */
2489 BTF_FUNC_PROTO_ENC(0, 2), /* [6] */
2490 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2491 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2494 .str_sec = "\0func_ptr",
2495 .str_sec_size = sizeof("\0func_ptr"),
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),
2506 .descr = "func proto (TYPEDEF=>FUNC_PROTO)",
2508 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2509 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2510 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
2511 BTF_FUNC_PROTO_ENC(0, 2), /* [4] */
2512 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2513 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2516 .str_sec = "\0func_typedef",
2517 .str_sec_size = sizeof("\0func_typedef"),
2518 .map_type = BPF_MAP_TYPE_ARRAY,
2519 .map_name = "func_proto_type_check_btf",
2520 .key_size = sizeof(int),
2521 .value_size = sizeof(int),
2528 .descr = "func proto (btf_resolve(arg))",
2530 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2531 /* void (*)(const void *) */
2532 BTF_FUNC_PROTO_ENC(0, 1), /* [2] */
2533 BTF_FUNC_PROTO_ARG_ENC(0, 3),
2534 BTF_CONST_ENC(4), /* [3] */
2535 BTF_PTR_ENC(0), /* [4] */
2539 .str_sec_size = sizeof(""),
2540 .map_type = BPF_MAP_TYPE_ARRAY,
2541 .map_name = "func_proto_type_check_btf",
2542 .key_size = sizeof(int),
2543 .value_size = sizeof(int),
2550 .descr = "func proto (Not all arg has name)",
2552 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2553 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2554 /* void (*)(int, unsigned int b) */
2555 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2556 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2557 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2561 .str_sec_size = sizeof("\0b"),
2562 .map_type = BPF_MAP_TYPE_ARRAY,
2563 .map_name = "func_proto_type_check_btf",
2564 .key_size = sizeof(int),
2565 .value_size = sizeof(int),
2572 .descr = "func proto (Bad arg name_off)",
2574 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2575 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2576 /* void (*)(int a, unsigned int <bad_name_off>) */
2577 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2578 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2579 BTF_FUNC_PROTO_ARG_ENC(0x0fffffff, 2),
2583 .str_sec_size = sizeof("\0a"),
2584 .map_type = BPF_MAP_TYPE_ARRAY,
2585 .map_name = "func_proto_type_check_btf",
2586 .key_size = sizeof(int),
2587 .value_size = sizeof(int),
2591 .btf_load_err = true,
2592 .err_str = "Invalid arg#2",
2596 .descr = "func proto (Bad arg name)",
2598 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2599 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2600 /* void (*)(int a, unsigned int !!!) */
2601 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2602 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2603 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2606 .str_sec = "\0a\0!!!",
2607 .str_sec_size = sizeof("\0a\0!!!"),
2608 .map_type = BPF_MAP_TYPE_ARRAY,
2609 .map_name = "func_proto_type_check_btf",
2610 .key_size = sizeof(int),
2611 .value_size = sizeof(int),
2615 .btf_load_err = true,
2616 .err_str = "Invalid arg#2",
2620 .descr = "func proto (Invalid return type)",
2622 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2623 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2624 /* <bad_ret_type> (*)(int, unsigned int) */
2625 BTF_FUNC_PROTO_ENC(100, 2), /* [3] */
2626 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2627 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2631 .str_sec_size = sizeof(""),
2632 .map_type = BPF_MAP_TYPE_ARRAY,
2633 .map_name = "func_proto_type_check_btf",
2634 .key_size = sizeof(int),
2635 .value_size = sizeof(int),
2639 .btf_load_err = true,
2640 .err_str = "Invalid return type",
2644 .descr = "func proto (with func name)",
2646 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2647 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2648 /* void func_proto(int, unsigned int) */
2649 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 0, 2), 0), /* [3] */
2650 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2651 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2654 .str_sec = "\0func_proto",
2655 .str_sec_size = sizeof("\0func_proto"),
2656 .map_type = BPF_MAP_TYPE_ARRAY,
2657 .map_name = "func_proto_type_check_btf",
2658 .key_size = sizeof(int),
2659 .value_size = sizeof(int),
2663 .btf_load_err = true,
2664 .err_str = "Invalid name",
2668 .descr = "func proto (const void arg)",
2670 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2671 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2672 /* void (*)(const void) */
2673 BTF_FUNC_PROTO_ENC(0, 1), /* [3] */
2674 BTF_FUNC_PROTO_ARG_ENC(0, 4),
2675 BTF_CONST_ENC(0), /* [4] */
2679 .str_sec_size = sizeof(""),
2680 .map_type = BPF_MAP_TYPE_ARRAY,
2681 .map_name = "func_proto_type_check_btf",
2682 .key_size = sizeof(int),
2683 .value_size = sizeof(int),
2687 .btf_load_err = true,
2688 .err_str = "Invalid arg#1",
2692 .descr = "func (void func(int a, unsigned int b))",
2694 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2695 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2696 /* void (*)(int a, unsigned int b) */
2697 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2698 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2699 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2700 /* void func(int a, unsigned int b) */
2701 BTF_FUNC_ENC(NAME_TBD, 3), /* [4] */
2704 .str_sec = "\0a\0b\0func",
2705 .str_sec_size = sizeof("\0a\0b\0func"),
2706 .map_type = BPF_MAP_TYPE_ARRAY,
2707 .map_name = "func_type_check_btf",
2708 .key_size = sizeof(int),
2709 .value_size = sizeof(int),
2716 .descr = "func (No func name)",
2718 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2719 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2720 /* void (*)(int a, unsigned int b) */
2721 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2722 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2723 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2724 /* void <no_name>(int a, unsigned int b) */
2725 BTF_FUNC_ENC(0, 3), /* [4] */
2728 .str_sec = "\0a\0b",
2729 .str_sec_size = sizeof("\0a\0b"),
2730 .map_type = BPF_MAP_TYPE_ARRAY,
2731 .map_name = "func_type_check_btf",
2732 .key_size = sizeof(int),
2733 .value_size = sizeof(int),
2737 .btf_load_err = true,
2738 .err_str = "Invalid name",
2742 .descr = "func (Invalid func name)",
2744 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2745 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2746 /* void (*)(int a, unsigned int b) */
2747 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2748 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2749 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2750 /* void !!!(int a, unsigned int b) */
2751 BTF_FUNC_ENC(NAME_TBD, 3), /* [4] */
2754 .str_sec = "\0a\0b\0!!!",
2755 .str_sec_size = sizeof("\0a\0b\0!!!"),
2756 .map_type = BPF_MAP_TYPE_ARRAY,
2757 .map_name = "func_type_check_btf",
2758 .key_size = sizeof(int),
2759 .value_size = sizeof(int),
2763 .btf_load_err = true,
2764 .err_str = "Invalid name",
2768 .descr = "func (Some arg has no name)",
2770 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2771 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2772 /* void (*)(int a, unsigned int) */
2773 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2774 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2775 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2776 /* void func(int a, unsigned int) */
2777 BTF_FUNC_ENC(NAME_TBD, 3), /* [4] */
2780 .str_sec = "\0a\0func",
2781 .str_sec_size = sizeof("\0a\0func"),
2782 .map_type = BPF_MAP_TYPE_ARRAY,
2783 .map_name = "func_type_check_btf",
2784 .key_size = sizeof(int),
2785 .value_size = sizeof(int),
2789 .btf_load_err = true,
2790 .err_str = "Invalid arg#2",
2794 .descr = "func (Non zero vlen)",
2796 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2797 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2798 /* void (*)(int a, unsigned int b) */
2799 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2800 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
2801 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
2802 /* void func(int a, unsigned int b) */
2803 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FUNC, 0, 2), 3), /* [4] */
2806 .str_sec = "\0a\0b\0func",
2807 .str_sec_size = sizeof("\0a\0b\0func"),
2808 .map_type = BPF_MAP_TYPE_ARRAY,
2809 .map_name = "func_type_check_btf",
2810 .key_size = sizeof(int),
2811 .value_size = sizeof(int),
2815 .btf_load_err = true,
2816 .err_str = "Invalid func linkage",
2820 .descr = "func (Not referring to FUNC_PROTO)",
2822 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2823 BTF_FUNC_ENC(NAME_TBD, 1), /* [2] */
2826 .str_sec = "\0func",
2827 .str_sec_size = sizeof("\0func"),
2828 .map_type = BPF_MAP_TYPE_ARRAY,
2829 .map_name = "func_type_check_btf",
2830 .key_size = sizeof(int),
2831 .value_size = sizeof(int),
2835 .btf_load_err = true,
2836 .err_str = "Invalid type_id",
2840 .descr = "invalid int kind_flag",
2842 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2843 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT, 1, 0), 4), /* [2] */
2844 BTF_INT_ENC(0, 0, 32),
2848 .map_type = BPF_MAP_TYPE_ARRAY,
2849 .map_name = "int_type_check_btf",
2850 .key_size = sizeof(int),
2851 .value_size = sizeof(int),
2855 .btf_load_err = true,
2856 .err_str = "Invalid btf_info kind_flag",
2860 .descr = "invalid ptr kind_flag",
2862 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2863 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 1, 0), 1), /* [2] */
2867 .map_type = BPF_MAP_TYPE_ARRAY,
2868 .map_name = "ptr_type_check_btf",
2869 .key_size = sizeof(int),
2870 .value_size = sizeof(int),
2874 .btf_load_err = true,
2875 .err_str = "Invalid btf_info kind_flag",
2879 .descr = "invalid array kind_flag",
2881 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2882 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY, 1, 0), 0), /* [2] */
2883 BTF_ARRAY_ENC(1, 1, 1),
2887 .map_type = BPF_MAP_TYPE_ARRAY,
2888 .map_name = "array_type_check_btf",
2889 .key_size = sizeof(int),
2890 .value_size = sizeof(int),
2894 .btf_load_err = true,
2895 .err_str = "Invalid btf_info kind_flag",
2899 .descr = "valid fwd kind_flag",
2901 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2902 BTF_TYPE_ENC(NAME_TBD,
2903 BTF_INFO_ENC(BTF_KIND_FWD, 1, 0), 0), /* [2] */
2907 .map_type = BPF_MAP_TYPE_ARRAY,
2908 .map_name = "fwd_type_check_btf",
2909 .key_size = sizeof(int),
2910 .value_size = sizeof(int),
2917 .descr = "invalid typedef kind_flag",
2919 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2920 BTF_TYPE_ENC(NAME_TBD,
2921 BTF_INFO_ENC(BTF_KIND_TYPEDEF, 1, 0), 1), /* [2] */
2925 .map_type = BPF_MAP_TYPE_ARRAY,
2926 .map_name = "typedef_type_check_btf",
2927 .key_size = sizeof(int),
2928 .value_size = sizeof(int),
2932 .btf_load_err = true,
2933 .err_str = "Invalid btf_info kind_flag",
2937 .descr = "invalid volatile kind_flag",
2939 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2940 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 1, 0), 1), /* [2] */
2944 .map_type = BPF_MAP_TYPE_ARRAY,
2945 .map_name = "volatile_type_check_btf",
2946 .key_size = sizeof(int),
2947 .value_size = sizeof(int),
2951 .btf_load_err = true,
2952 .err_str = "Invalid btf_info kind_flag",
2956 .descr = "invalid const kind_flag",
2958 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2959 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 1, 0), 1), /* [2] */
2963 .map_type = BPF_MAP_TYPE_ARRAY,
2964 .map_name = "const_type_check_btf",
2965 .key_size = sizeof(int),
2966 .value_size = sizeof(int),
2970 .btf_load_err = true,
2971 .err_str = "Invalid btf_info kind_flag",
2975 .descr = "invalid restrict kind_flag",
2977 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2978 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_RESTRICT, 1, 0), 1), /* [2] */
2982 .map_type = BPF_MAP_TYPE_ARRAY,
2983 .map_name = "restrict_type_check_btf",
2984 .key_size = sizeof(int),
2985 .value_size = sizeof(int),
2989 .btf_load_err = true,
2990 .err_str = "Invalid btf_info kind_flag",
2994 .descr = "invalid func kind_flag",
2996 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
2997 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 0, 0), 0), /* [2] */
2998 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FUNC, 1, 0), 2), /* [3] */
3002 .map_type = BPF_MAP_TYPE_ARRAY,
3003 .map_name = "func_type_check_btf",
3004 .key_size = sizeof(int),
3005 .value_size = sizeof(int),
3009 .btf_load_err = true,
3010 .err_str = "Invalid btf_info kind_flag",
3014 .descr = "invalid func_proto kind_flag",
3016 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3017 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 1, 0), 0), /* [2] */
3021 .map_type = BPF_MAP_TYPE_ARRAY,
3022 .map_name = "func_proto_type_check_btf",
3023 .key_size = sizeof(int),
3024 .value_size = sizeof(int),
3028 .btf_load_err = true,
3029 .err_str = "Invalid btf_info kind_flag",
3033 .descr = "valid struct, kind_flag, bitfield_size = 0",
3035 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3036 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 8), /* [2] */
3037 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(0, 0)),
3038 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(0, 32)),
3041 BTF_STR_SEC("\0A\0B"),
3042 .map_type = BPF_MAP_TYPE_ARRAY,
3043 .map_name = "struct_type_check_btf",
3044 .key_size = sizeof(int),
3045 .value_size = sizeof(int),
3052 .descr = "valid struct, kind_flag, int member, bitfield_size != 0",
3054 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3055 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4), /* [2] */
3056 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 0)),
3057 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 4)),
3060 BTF_STR_SEC("\0A\0B"),
3061 .map_type = BPF_MAP_TYPE_ARRAY,
3062 .map_name = "struct_type_check_btf",
3063 .key_size = sizeof(int),
3064 .value_size = sizeof(int),
3071 .descr = "valid union, kind_flag, int member, bitfield_size != 0",
3073 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3074 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 4), /* [2] */
3075 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 0)),
3076 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(4, 0)),
3079 BTF_STR_SEC("\0A\0B"),
3080 .map_type = BPF_MAP_TYPE_ARRAY,
3081 .map_name = "union_type_check_btf",
3082 .key_size = sizeof(int),
3083 .value_size = sizeof(int),
3090 .descr = "valid struct, kind_flag, enum member, bitfield_size != 0",
3092 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3093 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3094 BTF_ENUM_ENC(NAME_TBD, 0),
3095 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),/* [3] */
3096 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 0)),
3097 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 4)),
3100 BTF_STR_SEC("\0A\0B\0C"),
3101 .map_type = BPF_MAP_TYPE_ARRAY,
3102 .map_name = "struct_type_check_btf",
3103 .key_size = sizeof(int),
3104 .value_size = sizeof(int),
3111 .descr = "valid union, kind_flag, enum member, bitfield_size != 0",
3113 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3114 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3115 BTF_ENUM_ENC(NAME_TBD, 0),
3116 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 4), /* [3] */
3117 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 0)),
3118 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(4, 0)),
3121 BTF_STR_SEC("\0A\0B\0C"),
3122 .map_type = BPF_MAP_TYPE_ARRAY,
3123 .map_name = "union_type_check_btf",
3124 .key_size = sizeof(int),
3125 .value_size = sizeof(int),
3132 .descr = "valid struct, kind_flag, typedef member, bitfield_size != 0",
3134 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3135 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3136 BTF_ENUM_ENC(NAME_TBD, 0),
3137 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4),/* [3] */
3138 BTF_MEMBER_ENC(NAME_TBD, 4, BTF_MEMBER_OFFSET(4, 0)),
3139 BTF_MEMBER_ENC(NAME_TBD, 5, BTF_MEMBER_OFFSET(4, 4)),
3140 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [4] */
3141 BTF_TYPEDEF_ENC(NAME_TBD, 2), /* [5] */
3144 BTF_STR_SEC("\0A\0B\0C\0D\0E"),
3145 .map_type = BPF_MAP_TYPE_ARRAY,
3146 .map_name = "struct_type_check_btf",
3147 .key_size = sizeof(int),
3148 .value_size = sizeof(int),
3155 .descr = "valid union, kind_flag, typedef member, bitfield_size != 0",
3157 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3158 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3159 BTF_ENUM_ENC(NAME_TBD, 0),
3160 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 4), /* [3] */
3161 BTF_MEMBER_ENC(NAME_TBD, 4, BTF_MEMBER_OFFSET(4, 0)),
3162 BTF_MEMBER_ENC(NAME_TBD, 5, BTF_MEMBER_OFFSET(4, 0)),
3163 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [4] */
3164 BTF_TYPEDEF_ENC(NAME_TBD, 2), /* [5] */
3167 BTF_STR_SEC("\0A\0B\0C\0D\0E"),
3168 .map_type = BPF_MAP_TYPE_ARRAY,
3169 .map_name = "union_type_check_btf",
3170 .key_size = sizeof(int),
3171 .value_size = sizeof(int),
3178 .descr = "invalid struct, kind_flag, bitfield_size greater than struct size",
3180 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3181 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4), /* [2] */
3182 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(20, 0)),
3183 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(20, 20)),
3186 BTF_STR_SEC("\0A\0B"),
3187 .map_type = BPF_MAP_TYPE_ARRAY,
3188 .map_name = "struct_type_check_btf",
3189 .key_size = sizeof(int),
3190 .value_size = sizeof(int),
3194 .btf_load_err = true,
3195 .err_str = "Member exceeds struct_size",
3199 .descr = "invalid struct, kind_flag, bitfield base_type int not regular",
3201 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3202 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 20, 4), /* [2] */
3203 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4), /* [3] */
3204 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(20, 0)),
3205 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(20, 20)),
3208 BTF_STR_SEC("\0A\0B"),
3209 .map_type = BPF_MAP_TYPE_ARRAY,
3210 .map_name = "struct_type_check_btf",
3211 .key_size = sizeof(int),
3212 .value_size = sizeof(int),
3216 .btf_load_err = true,
3217 .err_str = "Invalid member base type",
3221 .descr = "invalid struct, kind_flag, base_type int not regular",
3223 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3224 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 12, 4), /* [2] */
3225 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 4), /* [3] */
3226 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(8, 0)),
3227 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(8, 8)),
3230 BTF_STR_SEC("\0A\0B"),
3231 .map_type = BPF_MAP_TYPE_ARRAY,
3232 .map_name = "struct_type_check_btf",
3233 .key_size = sizeof(int),
3234 .value_size = sizeof(int),
3238 .btf_load_err = true,
3239 .err_str = "Invalid member base type",
3243 .descr = "invalid union, kind_flag, bitfield_size greater than struct size",
3245 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3246 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 1, 2), 2), /* [2] */
3247 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(8, 0)),
3248 BTF_MEMBER_ENC(NAME_TBD, 1, BTF_MEMBER_OFFSET(20, 0)),
3251 BTF_STR_SEC("\0A\0B"),
3252 .map_type = BPF_MAP_TYPE_ARRAY,
3253 .map_name = "union_type_check_btf",
3254 .key_size = sizeof(int),
3255 .value_size = sizeof(int),
3259 .btf_load_err = true,
3260 .err_str = "Member exceeds struct_size",
3264 .descr = "invalid struct, kind_flag, int member, bitfield_size = 0, wrong byte alignment",
3266 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3267 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
3268 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 12), /* [3] */
3269 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),
3270 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 36)),
3273 BTF_STR_SEC("\0A\0B"),
3274 .map_type = BPF_MAP_TYPE_ARRAY,
3275 .map_name = "struct_type_check_btf",
3276 .key_size = sizeof(int),
3277 .value_size = sizeof(int),
3281 .btf_load_err = true,
3282 .err_str = "Invalid member offset",
3286 .descr = "invalid struct, kind_flag, enum member, bitfield_size = 0, wrong byte alignment",
3288 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3289 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
3290 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4), /* [2] */
3291 BTF_ENUM_ENC(NAME_TBD, 0),
3292 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 2), 12), /* [3] */
3293 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),
3294 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 36)),
3297 BTF_STR_SEC("\0A\0B\0C"),
3298 .map_type = BPF_MAP_TYPE_ARRAY,
3299 .map_name = "struct_type_check_btf",
3300 .key_size = sizeof(int),
3301 .value_size = sizeof(int),
3305 .btf_load_err = true,
3306 .err_str = "Invalid member offset",
3310 .descr = "128-bit int",
3312 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3313 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16), /* [2] */
3317 .map_type = BPF_MAP_TYPE_ARRAY,
3318 .map_name = "int_type_check_btf",
3319 .key_size = sizeof(int),
3320 .value_size = sizeof(int),
3327 .descr = "struct, 128-bit int member",
3329 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3330 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16), /* [2] */
3331 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 16), /* [3] */
3332 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3336 .map_type = BPF_MAP_TYPE_ARRAY,
3337 .map_name = "struct_type_check_btf",
3338 .key_size = sizeof(int),
3339 .value_size = sizeof(int),
3346 .descr = "struct, 120-bit int member bitfield",
3348 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3349 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 120, 16), /* [2] */
3350 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 1), 16), /* [3] */
3351 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3355 .map_type = BPF_MAP_TYPE_ARRAY,
3356 .map_name = "struct_type_check_btf",
3357 .key_size = sizeof(int),
3358 .value_size = sizeof(int),
3365 .descr = "struct, kind_flag, 128-bit int member",
3367 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3368 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16), /* [2] */
3369 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 16), /* [3] */
3370 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)),
3374 .map_type = BPF_MAP_TYPE_ARRAY,
3375 .map_name = "struct_type_check_btf",
3376 .key_size = sizeof(int),
3377 .value_size = sizeof(int),
3384 .descr = "struct, kind_flag, 120-bit int member bitfield",
3386 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3387 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 128, 16), /* [2] */
3388 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 16), /* [3] */
3389 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(120, 0)),
3393 .map_type = BPF_MAP_TYPE_ARRAY,
3394 .map_name = "struct_type_check_btf",
3395 .key_size = sizeof(int),
3396 .value_size = sizeof(int),
3402 * typedef int arr_t[16];
3408 .descr = "struct->ptr->typedef->array->int size resolution",
3410 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [1] */
3411 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3412 BTF_PTR_ENC(3), /* [2] */
3413 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
3414 BTF_TYPE_ARRAY_ENC(5, 5, 16), /* [4] */
3415 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [5] */
3418 BTF_STR_SEC("\0s\0a\0arr_t"),
3419 .map_type = BPF_MAP_TYPE_ARRAY,
3420 .map_name = "ptr_mod_chain_size_resolve_map",
3421 .key_size = sizeof(int),
3422 .value_size = sizeof(int) * 16,
3423 .key_type_id = 5 /* int */,
3424 .value_type_id = 3 /* arr_t */,
3428 * typedef int arr_t[16][8][4];
3434 .descr = "struct->ptr->typedef->multi-array->int size resolution",
3436 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [1] */
3437 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3438 BTF_PTR_ENC(3), /* [2] */
3439 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
3440 BTF_TYPE_ARRAY_ENC(5, 7, 16), /* [4] */
3441 BTF_TYPE_ARRAY_ENC(6, 7, 8), /* [5] */
3442 BTF_TYPE_ARRAY_ENC(7, 7, 4), /* [6] */
3443 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [7] */
3446 BTF_STR_SEC("\0s\0a\0arr_t"),
3447 .map_type = BPF_MAP_TYPE_ARRAY,
3448 .map_name = "multi_arr_size_resolve_map",
3449 .key_size = sizeof(int),
3450 .value_size = sizeof(int) * 16 * 8 * 4,
3451 .key_type_id = 7 /* int */,
3452 .value_type_id = 3 /* arr_t */,
3456 * typedef int int_t;
3457 * typedef int_t arr3_t[4];
3458 * typedef arr3_t arr2_t[8];
3459 * typedef arr2_t arr1_t[16];
3465 .descr = "typedef/multi-arr mix size resolution",
3467 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [1] */
3468 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3469 BTF_PTR_ENC(3), /* [2] */
3470 BTF_TYPEDEF_ENC(NAME_TBD, 4), /* [3] */
3471 BTF_TYPE_ARRAY_ENC(5, 10, 16), /* [4] */
3472 BTF_TYPEDEF_ENC(NAME_TBD, 6), /* [5] */
3473 BTF_TYPE_ARRAY_ENC(7, 10, 8), /* [6] */
3474 BTF_TYPEDEF_ENC(NAME_TBD, 8), /* [7] */
3475 BTF_TYPE_ARRAY_ENC(9, 10, 4), /* [8] */
3476 BTF_TYPEDEF_ENC(NAME_TBD, 10), /* [9] */
3477 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [10] */
3480 BTF_STR_SEC("\0s\0a\0arr1_t\0arr2_t\0arr3_t\0int_t"),
3481 .map_type = BPF_MAP_TYPE_ARRAY,
3482 .map_name = "typedef_arra_mix_size_resolve_map",
3483 .key_size = sizeof(int),
3484 .value_size = sizeof(int) * 16 * 8 * 4,
3485 .key_type_id = 10 /* int */,
3486 .value_type_id = 3 /* arr_t */,
3490 * elf .rodata section size 4 and btf .rodata section vlen 0.
3493 .descr = "datasec: vlen == 0",
3496 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3497 /* .rodata section */
3498 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 0), 4),
3502 BTF_STR_SEC("\0.rodata"),
3503 .map_type = BPF_MAP_TYPE_ARRAY,
3504 .key_size = sizeof(int),
3505 .value_size = sizeof(int),
3512 .descr = "float test #1, well-formed",
3514 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3516 BTF_TYPE_FLOAT_ENC(NAME_TBD, 2), /* [2] */
3517 BTF_TYPE_FLOAT_ENC(NAME_TBD, 4), /* [3] */
3518 BTF_TYPE_FLOAT_ENC(NAME_TBD, 8), /* [4] */
3519 BTF_TYPE_FLOAT_ENC(NAME_TBD, 12), /* [5] */
3520 BTF_TYPE_FLOAT_ENC(NAME_TBD, 16), /* [6] */
3521 BTF_STRUCT_ENC(NAME_TBD, 5, 48), /* [7] */
3522 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3523 BTF_MEMBER_ENC(NAME_TBD, 3, 32),
3524 BTF_MEMBER_ENC(NAME_TBD, 4, 64),
3525 BTF_MEMBER_ENC(NAME_TBD, 5, 128),
3526 BTF_MEMBER_ENC(NAME_TBD, 6, 256),
3529 BTF_STR_SEC("\0int\0_Float16\0float\0double\0_Float80\0long_double"
3530 "\0floats\0a\0b\0c\0d\0e"),
3531 .map_type = BPF_MAP_TYPE_ARRAY,
3532 .map_name = "float_type_check_btf",
3533 .key_size = sizeof(int),
3540 .descr = "float test #2, invalid vlen",
3542 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3544 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 1), 4),
3548 BTF_STR_SEC("\0int\0float"),
3549 .map_type = BPF_MAP_TYPE_ARRAY,
3550 .map_name = "float_type_check_btf",
3551 .key_size = sizeof(int),
3556 .btf_load_err = true,
3557 .err_str = "vlen != 0",
3560 .descr = "float test #3, invalid kind_flag",
3562 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3564 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FLOAT, 1, 0), 4),
3568 BTF_STR_SEC("\0int\0float"),
3569 .map_type = BPF_MAP_TYPE_ARRAY,
3570 .map_name = "float_type_check_btf",
3571 .key_size = sizeof(int),
3576 .btf_load_err = true,
3577 .err_str = "Invalid btf_info kind_flag",
3580 .descr = "float test #4, member does not fit",
3582 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3584 BTF_TYPE_FLOAT_ENC(NAME_TBD, 4), /* [2] */
3585 BTF_STRUCT_ENC(NAME_TBD, 1, 2), /* [3] */
3586 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
3589 BTF_STR_SEC("\0int\0float\0floats\0x"),
3590 .map_type = BPF_MAP_TYPE_ARRAY,
3591 .map_name = "float_type_check_btf",
3592 .key_size = sizeof(int),
3597 .btf_load_err = true,
3598 .err_str = "Member exceeds struct_size",
3601 .descr = "float test #5, member is not properly aligned",
3603 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3605 BTF_TYPE_FLOAT_ENC(NAME_TBD, 4), /* [2] */
3606 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [3] */
3607 BTF_MEMBER_ENC(NAME_TBD, 2, 8),
3610 BTF_STR_SEC("\0int\0float\0floats\0x"),
3611 .map_type = BPF_MAP_TYPE_ARRAY,
3612 .map_name = "float_type_check_btf",
3613 .key_size = sizeof(int),
3618 .btf_load_err = true,
3619 .err_str = "Member is not properly aligned",
3622 .descr = "float test #6, invalid size",
3624 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
3626 BTF_TYPE_FLOAT_ENC(NAME_TBD, 6), /* [2] */
3629 BTF_STR_SEC("\0int\0float"),
3630 .map_type = BPF_MAP_TYPE_ARRAY,
3631 .map_name = "float_type_check_btf",
3632 .key_size = sizeof(int),
3637 .btf_load_err = true,
3638 .err_str = "Invalid type_size",
3642 .descr = "decl_tag test #1, struct/member, well-formed",
3644 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3645 BTF_STRUCT_ENC(0, 2, 8), /* [2] */
3646 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3647 BTF_MEMBER_ENC(NAME_TBD, 1, 32),
3648 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3649 BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3650 BTF_DECL_TAG_ENC(NAME_TBD, 2, 1),
3653 BTF_STR_SEC("\0m1\0m2\0tag1\0tag2\0tag3"),
3654 .map_type = BPF_MAP_TYPE_ARRAY,
3655 .map_name = "tag_type_check_btf",
3656 .key_size = sizeof(int),
3663 .descr = "decl_tag test #2, union/member, well-formed",
3665 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3666 BTF_UNION_ENC(NAME_TBD, 2, 4), /* [2] */
3667 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3668 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3669 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3670 BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3671 BTF_DECL_TAG_ENC(NAME_TBD, 2, 1),
3674 BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
3675 .map_type = BPF_MAP_TYPE_ARRAY,
3676 .map_name = "tag_type_check_btf",
3677 .key_size = sizeof(int),
3684 .descr = "decl_tag test #3, variable, well-formed",
3686 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3687 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3688 BTF_VAR_ENC(NAME_TBD, 1, 1), /* [3] */
3689 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3690 BTF_DECL_TAG_ENC(NAME_TBD, 3, -1),
3693 BTF_STR_SEC("\0local\0global\0tag1\0tag2"),
3694 .map_type = BPF_MAP_TYPE_ARRAY,
3695 .map_name = "tag_type_check_btf",
3696 .key_size = sizeof(int),
3703 .descr = "decl_tag test #4, func/parameter, well-formed",
3705 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3706 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
3707 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3708 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3709 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
3710 BTF_DECL_TAG_ENC(NAME_TBD, 3, -1),
3711 BTF_DECL_TAG_ENC(NAME_TBD, 3, 0),
3712 BTF_DECL_TAG_ENC(NAME_TBD, 3, 1),
3715 BTF_STR_SEC("\0arg1\0arg2\0f\0tag1\0tag2\0tag3"),
3716 .map_type = BPF_MAP_TYPE_ARRAY,
3717 .map_name = "tag_type_check_btf",
3718 .key_size = sizeof(int),
3725 .descr = "decl_tag test #5, invalid value",
3727 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3728 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3729 BTF_DECL_TAG_ENC(0, 2, -1),
3732 BTF_STR_SEC("\0local\0tag"),
3733 .map_type = BPF_MAP_TYPE_ARRAY,
3734 .map_name = "tag_type_check_btf",
3735 .key_size = sizeof(int),
3740 .btf_load_err = true,
3741 .err_str = "Invalid value",
3744 .descr = "decl_tag test #6, invalid target type",
3746 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3747 BTF_DECL_TAG_ENC(NAME_TBD, 1, -1),
3750 BTF_STR_SEC("\0tag1"),
3751 .map_type = BPF_MAP_TYPE_ARRAY,
3752 .map_name = "tag_type_check_btf",
3753 .key_size = sizeof(int),
3758 .btf_load_err = true,
3759 .err_str = "Invalid type",
3762 .descr = "decl_tag test #7, invalid vlen",
3764 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3765 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3766 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 1), 2), (0),
3769 BTF_STR_SEC("\0local\0tag1"),
3770 .map_type = BPF_MAP_TYPE_ARRAY,
3771 .map_name = "tag_type_check_btf",
3772 .key_size = sizeof(int),
3777 .btf_load_err = true,
3778 .err_str = "vlen != 0",
3781 .descr = "decl_tag test #8, invalid kflag",
3783 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3784 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3785 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 1, 0), 2), (-1),
3788 BTF_STR_SEC("\0local\0tag1"),
3789 .map_type = BPF_MAP_TYPE_ARRAY,
3790 .map_name = "tag_type_check_btf",
3791 .key_size = sizeof(int),
3796 .btf_load_err = true,
3797 .err_str = "Invalid btf_info kind_flag",
3800 .descr = "decl_tag test #9, var, invalid component_idx",
3802 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3803 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3804 BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3807 BTF_STR_SEC("\0local\0tag"),
3808 .map_type = BPF_MAP_TYPE_ARRAY,
3809 .map_name = "tag_type_check_btf",
3810 .key_size = sizeof(int),
3815 .btf_load_err = true,
3816 .err_str = "Invalid component_idx",
3819 .descr = "decl_tag test #10, struct member, invalid component_idx",
3821 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3822 BTF_STRUCT_ENC(0, 2, 8), /* [2] */
3823 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
3824 BTF_MEMBER_ENC(NAME_TBD, 1, 32),
3825 BTF_DECL_TAG_ENC(NAME_TBD, 2, 2),
3828 BTF_STR_SEC("\0m1\0m2\0tag"),
3829 .map_type = BPF_MAP_TYPE_ARRAY,
3830 .map_name = "tag_type_check_btf",
3831 .key_size = sizeof(int),
3836 .btf_load_err = true,
3837 .err_str = "Invalid component_idx",
3840 .descr = "decl_tag test #11, func parameter, invalid component_idx",
3842 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3843 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
3844 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3845 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3846 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
3847 BTF_DECL_TAG_ENC(NAME_TBD, 3, 2),
3850 BTF_STR_SEC("\0arg1\0arg2\0f\0tag"),
3851 .map_type = BPF_MAP_TYPE_ARRAY,
3852 .map_name = "tag_type_check_btf",
3853 .key_size = sizeof(int),
3858 .btf_load_err = true,
3859 .err_str = "Invalid component_idx",
3862 .descr = "decl_tag test #12, < -1 component_idx",
3864 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3865 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
3866 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3867 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3868 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
3869 BTF_DECL_TAG_ENC(NAME_TBD, 3, -2),
3872 BTF_STR_SEC("\0arg1\0arg2\0f\0tag"),
3873 .map_type = BPF_MAP_TYPE_ARRAY,
3874 .map_name = "tag_type_check_btf",
3875 .key_size = sizeof(int),
3880 .btf_load_err = true,
3881 .err_str = "Invalid component_idx",
3884 .descr = "decl_tag test #13, typedef, well-formed",
3886 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3887 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [2] */
3888 BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3891 BTF_STR_SEC("\0t\0tag"),
3892 .map_type = BPF_MAP_TYPE_ARRAY,
3893 .map_name = "tag_type_check_btf",
3894 .key_size = sizeof(int),
3901 .descr = "decl_tag test #14, typedef, invalid component_idx",
3903 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3904 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [2] */
3905 BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3908 BTF_STR_SEC("\0local\0tag"),
3909 .map_type = BPF_MAP_TYPE_ARRAY,
3910 .map_name = "tag_type_check_btf",
3911 .key_size = sizeof(int),
3916 .btf_load_err = true,
3917 .err_str = "Invalid component_idx",
3920 .descr = "decl_tag test #15, func, invalid func proto",
3922 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3923 BTF_DECL_TAG_ENC(NAME_TBD, 3, 0), /* [2] */
3924 BTF_FUNC_ENC(NAME_TBD, 8), /* [3] */
3927 BTF_STR_SEC("\0tag\0func"),
3928 .map_type = BPF_MAP_TYPE_ARRAY,
3929 .map_name = "tag_type_check_btf",
3930 .key_size = sizeof(int),
3935 .btf_load_err = true,
3936 .err_str = "Invalid type_id",
3939 .descr = "decl_tag test #16, func proto, return type",
3941 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3942 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */
3943 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), 2), (-1), /* [3] */
3944 BTF_FUNC_PROTO_ENC(3, 0), /* [4] */
3947 BTF_STR_SEC("\0local\0tag1"),
3948 .btf_load_err = true,
3949 .err_str = "Invalid return type",
3952 .descr = "decl_tag test #17, func proto, argument",
3954 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), 4), (-1), /* [1] */
3955 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), 0), /* [2] */
3956 BTF_FUNC_PROTO_ENC(0, 1), /* [3] */
3957 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
3958 BTF_VAR_ENC(NAME_TBD, 2, 0), /* [4] */
3961 BTF_STR_SEC("\0local\0tag1\0var"),
3962 .btf_load_err = true,
3963 .err_str = "Invalid arg#1",
3966 .descr = "type_tag test #1",
3968 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3969 BTF_TYPE_TAG_ENC(NAME_TBD, 1), /* [2] */
3970 BTF_PTR_ENC(2), /* [3] */
3973 BTF_STR_SEC("\0tag"),
3974 .map_type = BPF_MAP_TYPE_ARRAY,
3975 .map_name = "tag_type_check_btf",
3976 .key_size = sizeof(int),
3983 .descr = "type_tag test #2, type tag order",
3985 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3986 BTF_CONST_ENC(3), /* [2] */
3987 BTF_TYPE_TAG_ENC(NAME_TBD, 1), /* [3] */
3990 BTF_STR_SEC("\0tag"),
3991 .map_type = BPF_MAP_TYPE_ARRAY,
3992 .map_name = "tag_type_check_btf",
3993 .key_size = sizeof(int),
3998 .btf_load_err = true,
3999 .err_str = "Type tags don't precede modifiers",
4002 .descr = "type_tag test #3, type tag order",
4004 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4005 BTF_TYPE_TAG_ENC(NAME_TBD, 3), /* [2] */
4006 BTF_CONST_ENC(4), /* [3] */
4007 BTF_TYPE_TAG_ENC(NAME_TBD, 1), /* [4] */
4010 BTF_STR_SEC("\0tag\0tag"),
4011 .map_type = BPF_MAP_TYPE_ARRAY,
4012 .map_name = "tag_type_check_btf",
4013 .key_size = sizeof(int),
4018 .btf_load_err = true,
4019 .err_str = "Type tags don't precede modifiers",
4022 .descr = "type_tag test #4, type tag order",
4024 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4025 BTF_TYPEDEF_ENC(NAME_TBD, 3), /* [2] */
4026 BTF_CONST_ENC(4), /* [3] */
4027 BTF_TYPE_TAG_ENC(NAME_TBD, 1), /* [4] */
4030 BTF_STR_SEC("\0tag\0tag"),
4031 .map_type = BPF_MAP_TYPE_ARRAY,
4032 .map_name = "tag_type_check_btf",
4033 .key_size = sizeof(int),
4038 .btf_load_err = true,
4039 .err_str = "Type tags don't precede modifiers",
4042 .descr = "type_tag test #5, type tag order",
4044 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4045 BTF_TYPE_TAG_ENC(NAME_TBD, 3), /* [2] */
4046 BTF_CONST_ENC(1), /* [3] */
4047 BTF_TYPE_TAG_ENC(NAME_TBD, 2), /* [4] */
4050 BTF_STR_SEC("\0tag\0tag"),
4051 .map_type = BPF_MAP_TYPE_ARRAY,
4052 .map_name = "tag_type_check_btf",
4053 .key_size = sizeof(int),
4060 .descr = "type_tag test #6, type tag order",
4062 BTF_PTR_ENC(2), /* [1] */
4063 BTF_TYPE_TAG_ENC(NAME_TBD, 3), /* [2] */
4064 BTF_CONST_ENC(4), /* [3] */
4065 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [4] */
4066 BTF_PTR_ENC(6), /* [5] */
4067 BTF_CONST_ENC(2), /* [6] */
4070 BTF_STR_SEC("\0tag"),
4071 .map_type = BPF_MAP_TYPE_ARRAY,
4072 .map_name = "tag_type_check_btf",
4073 .key_size = sizeof(int),
4078 .btf_load_err = true,
4079 .err_str = "Type tags don't precede modifiers",
4082 .descr = "enum64 test #1, unsigned, size 8",
4084 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4085 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 2), 8), /* [2] */
4086 BTF_ENUM64_ENC(NAME_TBD, 0, 0),
4087 BTF_ENUM64_ENC(NAME_TBD, 1, 1),
4090 BTF_STR_SEC("\0a\0b\0c"),
4091 .map_type = BPF_MAP_TYPE_ARRAY,
4092 .map_name = "tag_type_check_btf",
4093 .key_size = sizeof(int),
4100 .descr = "enum64 test #2, signed, size 4",
4102 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
4103 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 1, 2), 4), /* [2] */
4104 BTF_ENUM64_ENC(NAME_TBD, -1, 0),
4105 BTF_ENUM64_ENC(NAME_TBD, 1, 0),
4108 BTF_STR_SEC("\0a\0b\0c"),
4109 .map_type = BPF_MAP_TYPE_ARRAY,
4110 .map_name = "tag_type_check_btf",
4111 .key_size = sizeof(int),
4118 }; /* struct btf_raw_test raw_tests[] */
4120 static const char *get_next_str(const char *start, const char *end)
4122 return start < end - 1 ? start + 1 : NULL;
4125 static int get_raw_sec_size(const __u32 *raw_types)
4129 for (i = MAX_NR_RAW_U32 - 1;
4130 i >= 0 && raw_types[i] != BTF_END_RAW;
4134 return i < 0 ? i : i * sizeof(raw_types[0]);
4137 static void *btf_raw_create(const struct btf_header *hdr,
4138 const __u32 *raw_types,
4140 unsigned int str_sec_size,
4141 unsigned int *btf_size,
4142 const char **ret_next_str)
4144 const char *next_str = str, *end_str = str + str_sec_size;
4145 const char **strs_idx = NULL, **tmp_strs_idx;
4146 int strs_cap = 0, strs_cnt = 0, next_str_idx = 0;
4147 unsigned int size_needed, offset;
4148 struct btf_header *ret_hdr;
4149 int i, type_sec_size, err = 0;
4150 uint32_t *ret_types;
4151 void *raw_btf = NULL;
4153 type_sec_size = get_raw_sec_size(raw_types);
4154 if (CHECK(type_sec_size < 0, "Cannot get nr_raw_types"))
4157 size_needed = sizeof(*hdr) + type_sec_size + str_sec_size;
4158 raw_btf = malloc(size_needed);
4159 if (CHECK(!raw_btf, "Cannot allocate memory for raw_btf"))
4163 memcpy(raw_btf, hdr, sizeof(*hdr));
4164 offset = sizeof(*hdr);
4167 while ((next_str = get_next_str(next_str, end_str))) {
4168 if (strs_cnt == strs_cap) {
4169 strs_cap += max(16, strs_cap / 2);
4170 tmp_strs_idx = realloc(strs_idx,
4171 sizeof(*strs_idx) * strs_cap);
4172 if (CHECK(!tmp_strs_idx,
4173 "Cannot allocate memory for strs_idx")) {
4177 strs_idx = tmp_strs_idx;
4179 strs_idx[strs_cnt++] = next_str;
4180 next_str += strlen(next_str);
4183 /* Copy type section */
4184 ret_types = raw_btf + offset;
4185 for (i = 0; i < type_sec_size / sizeof(raw_types[0]); i++) {
4186 if (raw_types[i] == NAME_TBD) {
4187 if (CHECK(next_str_idx == strs_cnt,
4188 "Error in getting next_str #%d",
4193 ret_types[i] = strs_idx[next_str_idx++] - str;
4194 } else if (IS_NAME_NTH(raw_types[i])) {
4195 int idx = GET_NAME_NTH_IDX(raw_types[i]);
4197 if (CHECK(idx <= 0 || idx > strs_cnt,
4198 "Error getting string #%d, strs_cnt:%d",
4203 ret_types[i] = strs_idx[idx-1] - str;
4205 ret_types[i] = raw_types[i];
4208 offset += type_sec_size;
4210 /* Copy string section */
4211 memcpy(raw_btf + offset, str, str_sec_size);
4213 ret_hdr = (struct btf_header *)raw_btf;
4214 ret_hdr->type_len = type_sec_size;
4215 ret_hdr->str_off = type_sec_size;
4216 ret_hdr->str_len = str_sec_size;
4218 *btf_size = size_needed;
4221 next_str_idx < strs_cnt ? strs_idx[next_str_idx] : NULL;
4232 static int load_raw_btf(const void *raw_data, size_t raw_size)
4234 LIBBPF_OPTS(bpf_btf_load_opts, opts);
4238 opts.log_buf = btf_log_buf,
4239 opts.log_size = BTF_LOG_BUF_SIZE,
4243 btf_fd = bpf_btf_load(raw_data, raw_size, &opts);
4244 if (btf_fd < 0 && !always_log) {
4245 opts.log_buf = btf_log_buf,
4246 opts.log_size = BTF_LOG_BUF_SIZE,
4248 btf_fd = bpf_btf_load(raw_data, raw_size, &opts);
4254 static void do_test_raw(unsigned int test_num)
4256 struct btf_raw_test *test = &raw_tests[test_num - 1];
4257 LIBBPF_OPTS(bpf_map_create_opts, opts);
4258 int map_fd = -1, btf_fd = -1;
4259 unsigned int raw_btf_size;
4260 struct btf_header *hdr;
4264 if (!test__start_subtest(test->descr))
4267 raw_btf = btf_raw_create(&hdr_tmpl,
4271 &raw_btf_size, NULL);
4277 hdr->hdr_len = (int)hdr->hdr_len + test->hdr_len_delta;
4278 hdr->type_off = (int)hdr->type_off + test->type_off_delta;
4279 hdr->str_off = (int)hdr->str_off + test->str_off_delta;
4280 hdr->str_len = (int)hdr->str_len + test->str_len_delta;
4282 *btf_log_buf = '\0';
4283 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
4286 err = ((btf_fd < 0) != test->btf_load_err);
4287 if (CHECK(err, "btf_fd:%d test->btf_load_err:%u",
4288 btf_fd, test->btf_load_err) ||
4289 CHECK(test->err_str && !strstr(btf_log_buf, test->err_str),
4290 "expected err_str:%s\n", test->err_str)) {
4295 if (err || btf_fd < 0)
4298 opts.btf_fd = btf_fd;
4299 opts.btf_key_type_id = test->key_type_id;
4300 opts.btf_value_type_id = test->value_type_id;
4301 map_fd = bpf_map_create(test->map_type, test->map_name,
4302 test->key_size, test->value_size, test->max_entries, &opts);
4304 err = ((map_fd < 0) != test->map_create_err);
4305 CHECK(err, "map_fd:%d test->map_create_err:%u",
4306 map_fd, test->map_create_err);
4309 if (*btf_log_buf && (err || always_log))
4310 fprintf(stderr, "\n%s", btf_log_buf);
4317 struct btf_get_info_test {
4319 const char *str_sec;
4320 __u32 raw_types[MAX_NR_RAW_U32];
4323 int (*special_test)(unsigned int test_num);
4326 static int test_big_btf_info(unsigned int test_num);
4327 static int test_btf_id(unsigned int test_num);
4329 const struct btf_get_info_test get_info_tests[] = {
4331 .descr = "== raw_btf_size+1",
4334 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4338 .str_sec_size = sizeof(""),
4339 .btf_size_delta = 1,
4342 .descr = "== raw_btf_size-3",
4345 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4349 .str_sec_size = sizeof(""),
4350 .btf_size_delta = -3,
4353 .descr = "Large bpf_btf_info",
4356 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4360 .str_sec_size = sizeof(""),
4361 .special_test = test_big_btf_info,
4367 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),
4368 /* unsigned int */ /* [2] */
4369 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),
4373 .str_sec_size = sizeof(""),
4374 .special_test = test_btf_id,
4378 static int test_big_btf_info(unsigned int test_num)
4380 const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
4381 uint8_t *raw_btf = NULL, *user_btf = NULL;
4382 unsigned int raw_btf_size;
4384 struct bpf_btf_info info;
4387 struct bpf_btf_info *info;
4388 int btf_fd = -1, err;
4391 raw_btf = btf_raw_create(&hdr_tmpl,
4395 &raw_btf_size, NULL);
4400 *btf_log_buf = '\0';
4402 user_btf = malloc(raw_btf_size);
4403 if (CHECK(!user_btf, "!user_btf")) {
4408 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
4409 if (CHECK(btf_fd < 0, "errno:%d", errno)) {
4415 * GET_INFO should error out if the userspace info
4416 * has non zero tailing bytes.
4418 info = &info_garbage.info;
4419 memset(info, 0, sizeof(*info));
4420 info_garbage.garbage = 0xdeadbeef;
4421 info_len = sizeof(info_garbage);
4422 info->btf = ptr_to_u64(user_btf);
4423 info->btf_size = raw_btf_size;
4425 err = bpf_btf_get_info_by_fd(btf_fd, info, &info_len);
4426 if (CHECK(!err, "!err")) {
4432 * GET_INFO should succeed even info_len is larger than
4433 * the kernel supported as long as tailing bytes are zero.
4434 * The kernel supported info len should also be returned
4437 info_garbage.garbage = 0;
4438 err = bpf_btf_get_info_by_fd(btf_fd, info, &info_len);
4439 if (CHECK(err || info_len != sizeof(*info),
4440 "err:%d errno:%d info_len:%u sizeof(*info):%zu",
4441 err, errno, info_len, sizeof(*info))) {
4446 fprintf(stderr, "OK");
4449 if (*btf_log_buf && (err || always_log))
4450 fprintf(stderr, "\n%s", btf_log_buf);
4461 static int test_btf_id(unsigned int test_num)
4463 const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
4464 LIBBPF_OPTS(bpf_map_create_opts, opts);
4465 uint8_t *raw_btf = NULL, *user_btf[2] = {};
4466 int btf_fd[2] = {-1, -1}, map_fd = -1;
4467 struct bpf_map_info map_info = {};
4468 struct bpf_btf_info info[2] = {};
4469 unsigned int raw_btf_size;
4473 raw_btf = btf_raw_create(&hdr_tmpl,
4477 &raw_btf_size, NULL);
4482 *btf_log_buf = '\0';
4484 for (i = 0; i < 2; i++) {
4485 user_btf[i] = malloc(raw_btf_size);
4486 if (CHECK(!user_btf[i], "!user_btf[%d]", i)) {
4490 info[i].btf = ptr_to_u64(user_btf[i]);
4491 info[i].btf_size = raw_btf_size;
4494 btf_fd[0] = load_raw_btf(raw_btf, raw_btf_size);
4495 if (CHECK(btf_fd[0] < 0, "errno:%d", errno)) {
4500 /* Test BPF_OBJ_GET_INFO_BY_ID on btf_id */
4501 info_len = sizeof(info[0]);
4502 err = bpf_btf_get_info_by_fd(btf_fd[0], &info[0], &info_len);
4503 if (CHECK(err, "errno:%d", errno)) {
4508 btf_fd[1] = bpf_btf_get_fd_by_id(info[0].id);
4509 if (CHECK(btf_fd[1] < 0, "errno:%d", errno)) {
4515 err = bpf_btf_get_info_by_fd(btf_fd[1], &info[1], &info_len);
4516 if (CHECK(err || info[0].id != info[1].id ||
4517 info[0].btf_size != info[1].btf_size ||
4518 (ret = memcmp(user_btf[0], user_btf[1], info[0].btf_size)),
4519 "err:%d errno:%d id0:%u id1:%u btf_size0:%u btf_size1:%u memcmp:%d",
4520 err, errno, info[0].id, info[1].id,
4521 info[0].btf_size, info[1].btf_size, ret)) {
4526 /* Test btf members in struct bpf_map_info */
4527 opts.btf_fd = btf_fd[0];
4528 opts.btf_key_type_id = 1;
4529 opts.btf_value_type_id = 2;
4530 map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, "test_btf_id",
4531 sizeof(int), sizeof(int), 4, &opts);
4532 if (CHECK(map_fd < 0, "errno:%d", errno)) {
4537 info_len = sizeof(map_info);
4538 err = bpf_map_get_info_by_fd(map_fd, &map_info, &info_len);
4539 if (CHECK(err || map_info.btf_id != info[0].id ||
4540 map_info.btf_key_type_id != 1 || map_info.btf_value_type_id != 2,
4541 "err:%d errno:%d info.id:%u btf_id:%u btf_key_type_id:%u btf_value_type_id:%u",
4542 err, errno, info[0].id, map_info.btf_id, map_info.btf_key_type_id,
4543 map_info.btf_value_type_id)) {
4548 for (i = 0; i < 2; i++) {
4553 /* Test BTF ID is removed from the kernel */
4554 btf_fd[0] = bpf_btf_get_fd_by_id(map_info.btf_id);
4555 if (CHECK(btf_fd[0] < 0, "errno:%d", errno)) {
4562 /* The map holds the last ref to BTF and its btf_id */
4565 btf_fd[0] = bpf_btf_get_fd_by_id(map_info.btf_id);
4566 if (CHECK(btf_fd[0] >= 0, "BTF lingers")) {
4571 fprintf(stderr, "OK");
4574 if (*btf_log_buf && (err || always_log))
4575 fprintf(stderr, "\n%s", btf_log_buf);
4580 for (i = 0; i < 2; i++) {
4589 static void do_test_get_info(unsigned int test_num)
4591 const struct btf_get_info_test *test = &get_info_tests[test_num - 1];
4592 unsigned int raw_btf_size, user_btf_size, expected_nbytes;
4593 uint8_t *raw_btf = NULL, *user_btf = NULL;
4594 struct bpf_btf_info info = {};
4595 int btf_fd = -1, err, ret;
4598 if (!test__start_subtest(test->descr))
4601 if (test->special_test) {
4602 err = test->special_test(test_num);
4603 if (CHECK(err, "failed: %d\n", err))
4607 raw_btf = btf_raw_create(&hdr_tmpl,
4611 &raw_btf_size, NULL);
4616 *btf_log_buf = '\0';
4618 user_btf = malloc(raw_btf_size);
4619 if (CHECK(!user_btf, "!user_btf")) {
4624 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
4625 if (CHECK(btf_fd <= 0, "errno:%d", errno)) {
4630 user_btf_size = (int)raw_btf_size + test->btf_size_delta;
4631 expected_nbytes = min(raw_btf_size, user_btf_size);
4632 if (raw_btf_size > expected_nbytes)
4633 memset(user_btf + expected_nbytes, 0xff,
4634 raw_btf_size - expected_nbytes);
4636 info_len = sizeof(info);
4637 info.btf = ptr_to_u64(user_btf);
4638 info.btf_size = user_btf_size;
4641 err = bpf_btf_get_info_by_fd(btf_fd, &info, &info_len);
4642 if (CHECK(err || !info.id || info_len != sizeof(info) ||
4643 info.btf_size != raw_btf_size ||
4644 (ret = memcmp(raw_btf, user_btf, expected_nbytes)),
4645 "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",
4646 err, errno, info.id, info_len, sizeof(info),
4647 raw_btf_size, info.btf_size, expected_nbytes, ret)) {
4652 while (expected_nbytes < raw_btf_size) {
4653 fprintf(stderr, "%u...", expected_nbytes);
4654 if (CHECK(user_btf[expected_nbytes++] != 0xff,
4655 "user_btf[%u]:%x != 0xff", expected_nbytes - 1,
4656 user_btf[expected_nbytes - 1])) {
4662 fprintf(stderr, "OK");
4665 if (*btf_log_buf && (err || always_log))
4666 fprintf(stderr, "\n%s", btf_log_buf);
4675 struct btf_file_test {
4677 bool btf_kv_notfound;
4680 static struct btf_file_test file_tests[] = {
4681 { .file = "test_btf_newkv.bpf.o", },
4682 { .file = "test_btf_nokv.bpf.o", .btf_kv_notfound = true, },
4685 static void do_test_file(unsigned int test_num)
4687 const struct btf_file_test *test = &file_tests[test_num - 1];
4688 const char *expected_fnames[] = {"_dummy_tracepoint",
4689 "test_long_fname_1",
4690 "test_long_fname_2"};
4691 struct btf_ext *btf_ext = NULL;
4692 struct bpf_prog_info info = {};
4693 struct bpf_object *obj = NULL;
4694 struct bpf_func_info *finfo;
4695 struct bpf_program *prog;
4696 __u32 info_len, rec_size;
4697 bool has_btf_ext = false;
4698 struct btf *btf = NULL;
4699 void *func_info = NULL;
4700 struct bpf_map *map;
4701 int i, err, prog_fd;
4703 if (!test__start_subtest(test->file))
4706 btf = btf__parse_elf(test->file, &btf_ext);
4707 err = libbpf_get_error(btf);
4709 if (err == -ENOENT) {
4710 printf("%s:SKIP: No ELF %s found", __func__, BTF_ELF_SEC);
4718 has_btf_ext = btf_ext != NULL;
4719 btf_ext__free(btf_ext);
4721 /* temporary disable LIBBPF_STRICT_MAP_DEFINITIONS to test legacy maps */
4722 libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
4723 obj = bpf_object__open(test->file);
4724 err = libbpf_get_error(obj);
4725 if (CHECK(err, "obj: %d", err))
4728 prog = bpf_object__next_program(obj, NULL);
4729 if (CHECK(!prog, "Cannot find bpf_prog")) {
4734 bpf_program__set_type(prog, BPF_PROG_TYPE_TRACEPOINT);
4735 err = bpf_object__load(obj);
4736 if (CHECK(err < 0, "bpf_object__load: %d", err))
4738 prog_fd = bpf_program__fd(prog);
4740 map = bpf_object__find_map_by_name(obj, "btf_map");
4741 if (CHECK(!map, "btf_map not found")) {
4746 err = (bpf_map__btf_key_type_id(map) == 0 || bpf_map__btf_value_type_id(map) == 0)
4747 != test->btf_kv_notfound;
4748 if (CHECK(err, "btf_key_type_id:%u btf_value_type_id:%u test->btf_kv_notfound:%u",
4749 bpf_map__btf_key_type_id(map), bpf_map__btf_value_type_id(map),
4750 test->btf_kv_notfound))
4756 /* get necessary program info */
4757 info_len = sizeof(struct bpf_prog_info);
4758 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
4760 if (CHECK(err < 0, "invalid get info (1st) errno:%d", errno)) {
4761 fprintf(stderr, "%s\n", btf_log_buf);
4765 if (CHECK(info.nr_func_info != 3,
4766 "incorrect info.nr_func_info (1st) %d",
4767 info.nr_func_info)) {
4771 rec_size = info.func_info_rec_size;
4772 if (CHECK(rec_size != sizeof(struct bpf_func_info),
4773 "incorrect info.func_info_rec_size (1st) %d\n", rec_size)) {
4778 func_info = malloc(info.nr_func_info * rec_size);
4779 if (CHECK(!func_info, "out of memory")) {
4784 /* reset info to only retrieve func_info related data */
4785 memset(&info, 0, sizeof(info));
4786 info.nr_func_info = 3;
4787 info.func_info_rec_size = rec_size;
4788 info.func_info = ptr_to_u64(func_info);
4790 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
4792 if (CHECK(err < 0, "invalid get info (2nd) errno:%d", errno)) {
4793 fprintf(stderr, "%s\n", btf_log_buf);
4797 if (CHECK(info.nr_func_info != 3,
4798 "incorrect info.nr_func_info (2nd) %d",
4799 info.nr_func_info)) {
4803 if (CHECK(info.func_info_rec_size != rec_size,
4804 "incorrect info.func_info_rec_size (2nd) %d",
4805 info.func_info_rec_size)) {
4810 btf = btf__load_from_kernel_by_id(info.btf_id);
4811 err = libbpf_get_error(btf);
4812 if (CHECK(err, "cannot get btf from kernel, err: %d", err))
4815 /* check three functions */
4817 for (i = 0; i < 3; i++) {
4818 const struct btf_type *t;
4821 t = btf__type_by_id(btf, finfo->type_id);
4822 if (CHECK(!t, "btf__type_by_id failure: id %u",
4828 fname = btf__name_by_offset(btf, t->name_off);
4829 err = strcmp(fname, expected_fnames[i]);
4830 /* for the second and third functions in .text section,
4831 * the compiler may order them either way.
4834 err = strcmp(fname, expected_fnames[3 - i]);
4835 if (CHECK(err, "incorrect fname %s", fname ? : "")) {
4840 finfo = (void *)finfo + rec_size;
4844 fprintf(stderr, "OK");
4847 libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
4851 bpf_object__close(obj);
4854 const char *pprint_enum_str[] = {
4861 struct pprint_mapv {
4866 uint32_t unused_bits2a:2,
4881 uint8_t si8_4[2][2];
4884 #ifdef __SIZEOF_INT128__
4885 struct pprint_mapv_int128 {
4888 unsigned __int128 bits3:3;
4889 unsigned __int128 bits80:80;
4890 unsigned __int128 ui128;
4894 static struct btf_raw_test pprint_test_template[] = {
4897 /* unsighed char */ /* [1] */
4898 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 8, 1),
4899 /* unsigned short */ /* [2] */
4900 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 16, 2),
4901 /* unsigned int */ /* [3] */
4902 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
4904 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
4905 /* unsigned long long */ /* [5] */
4906 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),
4907 /* 2 bits */ /* [6] */
4908 BTF_TYPE_INT_ENC(0, 0, 0, 2, 2),
4909 /* 28 bits */ /* [7] */
4910 BTF_TYPE_INT_ENC(0, 0, 0, 28, 4),
4911 /* uint8_t[8] */ /* [8] */
4912 BTF_TYPE_ARRAY_ENC(9, 1, 8),
4913 /* typedef unsigned char uint8_t */ /* [9] */
4914 BTF_TYPEDEF_ENC(NAME_TBD, 1),
4915 /* typedef unsigned short uint16_t */ /* [10] */
4916 BTF_TYPEDEF_ENC(NAME_TBD, 2),
4917 /* typedef unsigned int uint32_t */ /* [11] */
4918 BTF_TYPEDEF_ENC(NAME_TBD, 3),
4919 /* typedef int int32_t */ /* [12] */
4920 BTF_TYPEDEF_ENC(NAME_TBD, 4),
4921 /* typedef unsigned long long uint64_t *//* [13] */
4922 BTF_TYPEDEF_ENC(NAME_TBD, 5),
4923 /* union (anon) */ /* [14] */
4924 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 0, 2), 8),
4925 BTF_MEMBER_ENC(NAME_TBD, 13, 0),/* uint64_t ui64; */
4926 BTF_MEMBER_ENC(NAME_TBD, 8, 0), /* uint8_t ui8a[8]; */
4927 /* enum (anon) */ /* [15] */
4928 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 4), 4),
4929 BTF_ENUM_ENC(NAME_TBD, 0),
4930 BTF_ENUM_ENC(NAME_TBD, 1),
4931 BTF_ENUM_ENC(NAME_TBD, 2),
4932 BTF_ENUM_ENC(NAME_TBD, 3),
4933 /* struct pprint_mapv */ /* [16] */
4934 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, 11), 40),
4935 BTF_MEMBER_ENC(NAME_TBD, 11, 0), /* uint32_t ui32 */
4936 BTF_MEMBER_ENC(NAME_TBD, 10, 32), /* uint16_t ui16 */
4937 BTF_MEMBER_ENC(NAME_TBD, 12, 64), /* int32_t si32 */
4938 BTF_MEMBER_ENC(NAME_TBD, 6, 96), /* unused_bits2a */
4939 BTF_MEMBER_ENC(NAME_TBD, 7, 98), /* bits28 */
4940 BTF_MEMBER_ENC(NAME_TBD, 6, 126), /* unused_bits2b */
4941 BTF_MEMBER_ENC(0, 14, 128), /* union (anon) */
4942 BTF_MEMBER_ENC(NAME_TBD, 15, 192), /* aenum */
4943 BTF_MEMBER_ENC(NAME_TBD, 11, 224), /* uint32_t ui32b */
4944 BTF_MEMBER_ENC(NAME_TBD, 6, 256), /* bits2c */
4945 BTF_MEMBER_ENC(NAME_TBD, 17, 264), /* si8_4 */
4946 BTF_TYPE_ARRAY_ENC(18, 1, 2), /* [17] */
4947 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [18] */
4950 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"),
4951 .key_size = sizeof(unsigned int),
4952 .value_size = sizeof(struct pprint_mapv),
4953 .key_type_id = 3, /* unsigned int */
4954 .value_type_id = 16, /* struct pprint_mapv */
4959 /* this type will have the same type as the
4960 * first .raw_types definition, but struct type will
4961 * be encoded with kind_flag set.
4964 /* unsighed char */ /* [1] */
4965 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 8, 1),
4966 /* unsigned short */ /* [2] */
4967 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 16, 2),
4968 /* unsigned int */ /* [3] */
4969 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
4971 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
4972 /* unsigned long long */ /* [5] */
4973 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),
4974 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [6] */
4975 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [7] */
4976 /* uint8_t[8] */ /* [8] */
4977 BTF_TYPE_ARRAY_ENC(9, 1, 8),
4978 /* typedef unsigned char uint8_t */ /* [9] */
4979 BTF_TYPEDEF_ENC(NAME_TBD, 1),
4980 /* typedef unsigned short uint16_t */ /* [10] */
4981 BTF_TYPEDEF_ENC(NAME_TBD, 2),
4982 /* typedef unsigned int uint32_t */ /* [11] */
4983 BTF_TYPEDEF_ENC(NAME_TBD, 3),
4984 /* typedef int int32_t */ /* [12] */
4985 BTF_TYPEDEF_ENC(NAME_TBD, 4),
4986 /* typedef unsigned long long uint64_t *//* [13] */
4987 BTF_TYPEDEF_ENC(NAME_TBD, 5),
4988 /* union (anon) */ /* [14] */
4989 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 0, 2), 8),
4990 BTF_MEMBER_ENC(NAME_TBD, 13, 0),/* uint64_t ui64; */
4991 BTF_MEMBER_ENC(NAME_TBD, 8, 0), /* uint8_t ui8a[8]; */
4992 /* enum (anon) */ /* [15] */
4993 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 4), 4),
4994 BTF_ENUM_ENC(NAME_TBD, 0),
4995 BTF_ENUM_ENC(NAME_TBD, 1),
4996 BTF_ENUM_ENC(NAME_TBD, 2),
4997 BTF_ENUM_ENC(NAME_TBD, 3),
4998 /* struct pprint_mapv */ /* [16] */
4999 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 11), 40),
5000 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
5001 BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
5002 BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
5003 BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 96)), /* unused_bits2a */
5004 BTF_MEMBER_ENC(NAME_TBD, 7, BTF_MEMBER_OFFSET(28, 98)), /* bits28 */
5005 BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 126)), /* unused_bits2b */
5006 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
5007 BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
5008 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
5009 BTF_MEMBER_ENC(NAME_TBD, 6, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
5010 BTF_MEMBER_ENC(NAME_TBD, 17, 264), /* si8_4 */
5011 BTF_TYPE_ARRAY_ENC(18, 1, 2), /* [17] */
5012 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [18] */
5015 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"),
5016 .key_size = sizeof(unsigned int),
5017 .value_size = sizeof(struct pprint_mapv),
5018 .key_type_id = 3, /* unsigned int */
5019 .value_type_id = 16, /* struct pprint_mapv */
5024 /* this type will have the same layout as the
5025 * first .raw_types definition. The struct type will
5026 * be encoded with kind_flag set, bitfield members
5027 * are added typedef/const/volatile, and bitfield members
5028 * will have both int and enum types.
5031 /* unsighed char */ /* [1] */
5032 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 8, 1),
5033 /* unsigned short */ /* [2] */
5034 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 16, 2),
5035 /* unsigned int */ /* [3] */
5036 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
5038 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
5039 /* unsigned long long */ /* [5] */
5040 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8),
5041 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [6] */
5042 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [7] */
5043 /* uint8_t[8] */ /* [8] */
5044 BTF_TYPE_ARRAY_ENC(9, 1, 8),
5045 /* typedef unsigned char uint8_t */ /* [9] */
5046 BTF_TYPEDEF_ENC(NAME_TBD, 1),
5047 /* typedef unsigned short uint16_t */ /* [10] */
5048 BTF_TYPEDEF_ENC(NAME_TBD, 2),
5049 /* typedef unsigned int uint32_t */ /* [11] */
5050 BTF_TYPEDEF_ENC(NAME_TBD, 3),
5051 /* typedef int int32_t */ /* [12] */
5052 BTF_TYPEDEF_ENC(NAME_TBD, 4),
5053 /* typedef unsigned long long uint64_t *//* [13] */
5054 BTF_TYPEDEF_ENC(NAME_TBD, 5),
5055 /* union (anon) */ /* [14] */
5056 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION, 0, 2), 8),
5057 BTF_MEMBER_ENC(NAME_TBD, 13, 0),/* uint64_t ui64; */
5058 BTF_MEMBER_ENC(NAME_TBD, 8, 0), /* uint8_t ui8a[8]; */
5059 /* enum (anon) */ /* [15] */
5060 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 4), 4),
5061 BTF_ENUM_ENC(NAME_TBD, 0),
5062 BTF_ENUM_ENC(NAME_TBD, 1),
5063 BTF_ENUM_ENC(NAME_TBD, 2),
5064 BTF_ENUM_ENC(NAME_TBD, 3),
5065 /* struct pprint_mapv */ /* [16] */
5066 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 11), 40),
5067 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
5068 BTF_MEMBER_ENC(NAME_TBD, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
5069 BTF_MEMBER_ENC(NAME_TBD, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
5070 BTF_MEMBER_ENC(NAME_TBD, 17, BTF_MEMBER_OFFSET(2, 96)), /* unused_bits2a */
5071 BTF_MEMBER_ENC(NAME_TBD, 7, BTF_MEMBER_OFFSET(28, 98)), /* bits28 */
5072 BTF_MEMBER_ENC(NAME_TBD, 19, BTF_MEMBER_OFFSET(2, 126)),/* unused_bits2b */
5073 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
5074 BTF_MEMBER_ENC(NAME_TBD, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
5075 BTF_MEMBER_ENC(NAME_TBD, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
5076 BTF_MEMBER_ENC(NAME_TBD, 17, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
5077 BTF_MEMBER_ENC(NAME_TBD, 20, BTF_MEMBER_OFFSET(0, 264)), /* si8_4 */
5078 /* typedef unsigned int ___int */ /* [17] */
5079 BTF_TYPEDEF_ENC(NAME_TBD, 18),
5080 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), 6), /* [18] */
5081 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), 15), /* [19] */
5082 BTF_TYPE_ARRAY_ENC(21, 1, 2), /* [20] */
5083 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [21] */
5086 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"),
5087 .key_size = sizeof(unsigned int),
5088 .value_size = sizeof(struct pprint_mapv),
5089 .key_type_id = 3, /* unsigned int */
5090 .value_type_id = 16, /* struct pprint_mapv */
5094 #ifdef __SIZEOF_INT128__
5098 /* unsigned int */ /* [1] */
5099 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4),
5100 /* __int128 */ /* [2] */
5101 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 128, 16),
5102 /* unsigned __int128 */ /* [3] */
5103 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 128, 16),
5104 /* struct pprint_mapv_int128 */ /* [4] */
5105 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 5), 64),
5106 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 0)), /* si128a */
5107 BTF_MEMBER_ENC(NAME_TBD, 2, BTF_MEMBER_OFFSET(0, 128)), /* si128b */
5108 BTF_MEMBER_ENC(NAME_TBD, 3, BTF_MEMBER_OFFSET(3, 256)), /* bits3 */
5109 BTF_MEMBER_ENC(NAME_TBD, 3, BTF_MEMBER_OFFSET(80, 259)), /* bits80 */
5110 BTF_MEMBER_ENC(NAME_TBD, 3, BTF_MEMBER_OFFSET(0, 384)), /* ui128 */
5113 BTF_STR_SEC("\0unsigned int\0__int128\0unsigned __int128\0pprint_mapv_int128\0si128a\0si128b\0bits3\0bits80\0ui128"),
5114 .key_size = sizeof(unsigned int),
5115 .value_size = sizeof(struct pprint_mapv_int128),
5119 .mapv_kind = PPRINT_MAPV_KIND_INT128,
5125 static struct btf_pprint_test_meta {
5127 enum bpf_map_type map_type;
5128 const char *map_name;
5132 } pprint_tests_meta[] = {
5134 .descr = "BTF pretty print array",
5135 .map_type = BPF_MAP_TYPE_ARRAY,
5136 .map_name = "pprint_test_array",
5137 .ordered_map = true,
5138 .lossless_map = true,
5139 .percpu_map = false,
5143 .descr = "BTF pretty print hash",
5144 .map_type = BPF_MAP_TYPE_HASH,
5145 .map_name = "pprint_test_hash",
5146 .ordered_map = false,
5147 .lossless_map = true,
5148 .percpu_map = false,
5152 .descr = "BTF pretty print lru hash",
5153 .map_type = BPF_MAP_TYPE_LRU_HASH,
5154 .map_name = "pprint_test_lru_hash",
5155 .ordered_map = false,
5156 .lossless_map = false,
5157 .percpu_map = false,
5161 .descr = "BTF pretty print percpu array",
5162 .map_type = BPF_MAP_TYPE_PERCPU_ARRAY,
5163 .map_name = "pprint_test_percpu_array",
5164 .ordered_map = true,
5165 .lossless_map = true,
5170 .descr = "BTF pretty print percpu hash",
5171 .map_type = BPF_MAP_TYPE_PERCPU_HASH,
5172 .map_name = "pprint_test_percpu_hash",
5173 .ordered_map = false,
5174 .lossless_map = true,
5179 .descr = "BTF pretty print lru percpu hash",
5180 .map_type = BPF_MAP_TYPE_LRU_PERCPU_HASH,
5181 .map_name = "pprint_test_lru_percpu_hash",
5182 .ordered_map = false,
5183 .lossless_map = false,
5189 static size_t get_pprint_mapv_size(enum pprint_mapv_kind_t mapv_kind)
5191 if (mapv_kind == PPRINT_MAPV_KIND_BASIC)
5192 return sizeof(struct pprint_mapv);
5194 #ifdef __SIZEOF_INT128__
5195 if (mapv_kind == PPRINT_MAPV_KIND_INT128)
5196 return sizeof(struct pprint_mapv_int128);
5202 static void set_pprint_mapv(enum pprint_mapv_kind_t mapv_kind,
5203 void *mapv, uint32_t i,
5204 int num_cpus, int rounded_value_size)
5208 if (mapv_kind == PPRINT_MAPV_KIND_BASIC) {
5209 struct pprint_mapv *v = mapv;
5211 for (cpu = 0; cpu < num_cpus; cpu++) {
5214 v->unused_bits2a = 3;
5216 v->unused_bits2b = 3;
5218 v->aenum = i & 0x03;
5221 v->si8_4[0][0] = (cpu + i) & 0xff;
5222 v->si8_4[0][1] = (cpu + i + 1) & 0xff;
5223 v->si8_4[1][0] = (cpu + i + 2) & 0xff;
5224 v->si8_4[1][1] = (cpu + i + 3) & 0xff;
5225 v = (void *)v + rounded_value_size;
5229 #ifdef __SIZEOF_INT128__
5230 if (mapv_kind == PPRINT_MAPV_KIND_INT128) {
5231 struct pprint_mapv_int128 *v = mapv;
5233 for (cpu = 0; cpu < num_cpus; cpu++) {
5236 v->bits3 = i & 0x07;
5237 v->bits80 = (((unsigned __int128)1) << 64) + i;
5238 v->ui128 = (((unsigned __int128)2) << 64) + i;
5239 v = (void *)v + rounded_value_size;
5245 ssize_t get_pprint_expected_line(enum pprint_mapv_kind_t mapv_kind,
5246 char *expected_line, ssize_t line_size,
5247 bool percpu_map, unsigned int next_key,
5248 int cpu, void *mapv)
5250 ssize_t nexpected_line = -1;
5252 if (mapv_kind == PPRINT_MAPV_KIND_BASIC) {
5253 struct pprint_mapv *v = mapv;
5255 nexpected_line = snprintf(expected_line, line_size,
5256 "%s%u: {%u,0,%d,0x%x,0x%x,0x%x,"
5257 "{%llu|[%u,%u,%u,%u,%u,%u,%u,%u]},%s,"
5258 "%u,0x%x,[[%d,%d],[%d,%d]]}\n",
5259 percpu_map ? "\tcpu" : "",
5260 percpu_map ? cpu : next_key,
5266 v->ui8a[0], v->ui8a[1],
5267 v->ui8a[2], v->ui8a[3],
5268 v->ui8a[4], v->ui8a[5],
5269 v->ui8a[6], v->ui8a[7],
5270 pprint_enum_str[v->aenum],
5273 v->si8_4[0][0], v->si8_4[0][1],
5274 v->si8_4[1][0], v->si8_4[1][1]);
5277 #ifdef __SIZEOF_INT128__
5278 if (mapv_kind == PPRINT_MAPV_KIND_INT128) {
5279 struct pprint_mapv_int128 *v = mapv;
5281 nexpected_line = snprintf(expected_line, line_size,
5282 "%s%u: {0x%lx,0x%lx,0x%lx,"
5283 "0x%lx%016lx,0x%lx%016lx}\n",
5284 percpu_map ? "\tcpu" : "",
5285 percpu_map ? cpu : next_key,
5286 (uint64_t)v->si128a,
5287 (uint64_t)v->si128b,
5289 (uint64_t)(v->bits80 >> 64),
5290 (uint64_t)v->bits80,
5291 (uint64_t)(v->ui128 >> 64),
5292 (uint64_t)v->ui128);
5296 return nexpected_line;
5299 static int check_line(const char *expected_line, int nexpected_line,
5300 int expected_line_len, const char *line)
5302 if (CHECK(nexpected_line == expected_line_len,
5303 "expected_line is too long"))
5306 if (strcmp(expected_line, line)) {
5307 fprintf(stderr, "unexpected pprint output\n");
5308 fprintf(stderr, "expected: %s", expected_line);
5309 fprintf(stderr, " read: %s", line);
5317 static void do_test_pprint(int test_num)
5319 const struct btf_raw_test *test = &pprint_test_template[test_num];
5320 enum pprint_mapv_kind_t mapv_kind = test->mapv_kind;
5321 LIBBPF_OPTS(bpf_map_create_opts, opts);
5322 bool ordered_map, lossless_map, percpu_map;
5323 int err, ret, num_cpus, rounded_value_size;
5324 unsigned int key, nr_read_elems;
5325 int map_fd = -1, btf_fd = -1;
5326 unsigned int raw_btf_size;
5327 char expected_line[255];
5328 FILE *pin_file = NULL;
5330 size_t line_len = 0;
5336 if (!test__start_subtest(test->descr))
5339 raw_btf = btf_raw_create(&hdr_tmpl, test->raw_types,
5340 test->str_sec, test->str_sec_size,
5341 &raw_btf_size, NULL);
5346 *btf_log_buf = '\0';
5347 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
5350 if (CHECK(btf_fd < 0, "errno:%d\n", errno)) {
5355 opts.btf_fd = btf_fd;
5356 opts.btf_key_type_id = test->key_type_id;
5357 opts.btf_value_type_id = test->value_type_id;
5358 map_fd = bpf_map_create(test->map_type, test->map_name,
5359 test->key_size, test->value_size, test->max_entries, &opts);
5360 if (CHECK(map_fd < 0, "errno:%d", errno)) {
5365 ret = snprintf(pin_path, sizeof(pin_path), "%s/%s",
5366 "/sys/fs/bpf", test->map_name);
5368 if (CHECK(ret >= sizeof(pin_path), "pin_path %s/%s is too long",
5369 "/sys/fs/bpf", test->map_name)) {
5374 err = bpf_obj_pin(map_fd, pin_path);
5375 if (CHECK(err, "bpf_obj_pin(%s): errno:%d.", pin_path, errno))
5378 percpu_map = test->percpu_map;
5379 num_cpus = percpu_map ? bpf_num_possible_cpus() : 1;
5380 rounded_value_size = round_up(get_pprint_mapv_size(mapv_kind), 8);
5381 mapv = calloc(num_cpus, rounded_value_size);
5382 if (CHECK(!mapv, "mapv allocation failure")) {
5387 for (key = 0; key < test->max_entries; key++) {
5388 set_pprint_mapv(mapv_kind, mapv, key, num_cpus, rounded_value_size);
5389 bpf_map_update_elem(map_fd, &key, mapv, 0);
5392 pin_file = fopen(pin_path, "r");
5393 if (CHECK(!pin_file, "fopen(%s): errno:%d", pin_path, errno)) {
5398 /* Skip lines start with '#' */
5399 while ((nread = getline(&line, &line_len, pin_file)) > 0 &&
5403 if (CHECK(nread <= 0, "Unexpected EOF")) {
5409 ordered_map = test->ordered_map;
5410 lossless_map = test->lossless_map;
5412 ssize_t nexpected_line;
5413 unsigned int next_key;
5417 next_key = ordered_map ? nr_read_elems : atoi(line);
5418 set_pprint_mapv(mapv_kind, mapv, next_key, num_cpus, rounded_value_size);
5421 for (cpu = 0; cpu < num_cpus; cpu++) {
5423 /* for percpu map, the format looks like:
5425 * cpu0: <value_on_cpu0>
5426 * cpu1: <value_on_cpu1>
5428 * cpun: <value_on_cpun>
5431 * let us verify the line containing the key here.
5434 nexpected_line = snprintf(expected_line,
5435 sizeof(expected_line),
5439 err = check_line(expected_line, nexpected_line,
5440 sizeof(expected_line), line);
5445 /* read value@cpu */
5446 nread = getline(&line, &line_len, pin_file);
5451 nexpected_line = get_pprint_expected_line(mapv_kind, expected_line,
5452 sizeof(expected_line),
5453 percpu_map, next_key,
5455 err = check_line(expected_line, nexpected_line,
5456 sizeof(expected_line), line);
5460 cmapv = cmapv + rounded_value_size;
5464 /* skip the last bracket for the percpu map */
5465 nread = getline(&line, &line_len, pin_file);
5470 nread = getline(&line, &line_len, pin_file);
5471 } while (++nr_read_elems < test->max_entries && nread > 0);
5474 CHECK(nr_read_elems < test->max_entries,
5475 "Unexpected EOF. nr_read_elems:%u test->max_entries:%u",
5476 nr_read_elems, test->max_entries)) {
5481 if (CHECK(nread > 0, "Unexpected extra pprint output: %s", line)) {
5492 fprintf(stderr, "OK");
5493 if (*btf_log_buf && (err || always_log))
5494 fprintf(stderr, "\n%s", btf_log_buf);
5505 static void test_pprint(void)
5509 /* test various maps with the first test template */
5510 for (i = 0; i < ARRAY_SIZE(pprint_tests_meta); i++) {
5511 pprint_test_template[0].descr = pprint_tests_meta[i].descr;
5512 pprint_test_template[0].map_type = pprint_tests_meta[i].map_type;
5513 pprint_test_template[0].map_name = pprint_tests_meta[i].map_name;
5514 pprint_test_template[0].ordered_map = pprint_tests_meta[i].ordered_map;
5515 pprint_test_template[0].lossless_map = pprint_tests_meta[i].lossless_map;
5516 pprint_test_template[0].percpu_map = pprint_tests_meta[i].percpu_map;
5521 /* test rest test templates with the first map */
5522 for (i = 1; i < ARRAY_SIZE(pprint_test_template); i++) {
5523 pprint_test_template[i].descr = pprint_tests_meta[0].descr;
5524 pprint_test_template[i].map_type = pprint_tests_meta[0].map_type;
5525 pprint_test_template[i].map_name = pprint_tests_meta[0].map_name;
5526 pprint_test_template[i].ordered_map = pprint_tests_meta[0].ordered_map;
5527 pprint_test_template[i].lossless_map = pprint_tests_meta[0].lossless_map;
5528 pprint_test_template[i].percpu_map = pprint_tests_meta[0].percpu_map;
5533 #define BPF_LINE_INFO_ENC(insn_off, file_off, line_off, line_num, line_col) \
5534 (insn_off), (file_off), (line_off), ((line_num) << 10 | ((line_col) & 0x3ff))
5536 static struct prog_info_raw_test {
5538 const char *str_sec;
5539 const char *err_str;
5540 __u32 raw_types[MAX_NR_RAW_U32];
5542 struct bpf_insn insns[MAX_INSNS];
5544 __u32 func_info[MAX_SUBPROGS][2];
5545 __u32 func_info_rec_size;
5546 __u32 func_info_cnt;
5547 __u32 line_info[MAX_NR_RAW_U32];
5548 __u32 line_info_rec_size;
5549 __u32 nr_jited_ksyms;
5550 bool expected_prog_load_failure;
5551 __u32 dead_code_cnt;
5552 __u32 dead_code_mask;
5553 __u32 dead_func_cnt;
5554 __u32 dead_func_mask;
5555 } info_raw_tests[] = {
5557 .descr = "func_type (main func + one sub)",
5559 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5560 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */
5561 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5562 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5563 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5564 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5565 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5566 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5567 BTF_FUNC_ENC(NAME_TBD, 3), /* [5] */
5568 BTF_FUNC_ENC(NAME_TBD, 4), /* [6] */
5571 .str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5572 .str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5574 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5575 BPF_MOV64_IMM(BPF_REG_0, 1),
5577 BPF_MOV64_IMM(BPF_REG_0, 2),
5580 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5581 .func_info = { {0, 5}, {3, 6} },
5582 .func_info_rec_size = 8,
5584 .line_info = { BTF_END_RAW },
5588 .descr = "func_type (Incorrect func_info_rec_size)",
5590 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5591 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */
5592 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5593 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5594 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5595 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5596 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5597 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5598 BTF_FUNC_ENC(NAME_TBD, 3), /* [5] */
5599 BTF_FUNC_ENC(NAME_TBD, 4), /* [6] */
5602 .str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5603 .str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5605 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5606 BPF_MOV64_IMM(BPF_REG_0, 1),
5608 BPF_MOV64_IMM(BPF_REG_0, 2),
5611 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5612 .func_info = { {0, 5}, {3, 6} },
5613 .func_info_rec_size = 4,
5615 .line_info = { BTF_END_RAW },
5616 .expected_prog_load_failure = true,
5620 .descr = "func_type (Incorrect func_info_cnt)",
5622 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5623 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */
5624 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5625 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5626 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5627 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5628 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5629 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5630 BTF_FUNC_ENC(NAME_TBD, 3), /* [5] */
5631 BTF_FUNC_ENC(NAME_TBD, 4), /* [6] */
5634 .str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5635 .str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5637 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5638 BPF_MOV64_IMM(BPF_REG_0, 1),
5640 BPF_MOV64_IMM(BPF_REG_0, 2),
5643 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5644 .func_info = { {0, 5}, {3, 6} },
5645 .func_info_rec_size = 8,
5647 .line_info = { BTF_END_RAW },
5648 .expected_prog_load_failure = true,
5652 .descr = "func_type (Incorrect bpf_func_info.insn_off)",
5654 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5655 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 32, 4), /* [2] */
5656 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5657 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5658 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5659 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5660 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 2),
5661 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5662 BTF_FUNC_ENC(NAME_TBD, 3), /* [5] */
5663 BTF_FUNC_ENC(NAME_TBD, 4), /* [6] */
5666 .str_sec = "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5667 .str_sec_size = sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5669 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
5670 BPF_MOV64_IMM(BPF_REG_0, 1),
5672 BPF_MOV64_IMM(BPF_REG_0, 2),
5675 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5676 .func_info = { {0, 5}, {2, 6} },
5677 .func_info_rec_size = 8,
5679 .line_info = { BTF_END_RAW },
5680 .expected_prog_load_failure = true,
5684 .descr = "line_info (No subprog)",
5686 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5689 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5691 BPF_MOV64_IMM(BPF_REG_0, 1),
5692 BPF_MOV64_IMM(BPF_REG_1, 2),
5693 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5696 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5699 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5700 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9),
5701 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5702 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7),
5705 .line_info_rec_size = sizeof(struct bpf_line_info),
5706 .nr_jited_ksyms = 1,
5710 .descr = "line_info (No subprog. insn_off >= prog->len)",
5712 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5715 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5717 BPF_MOV64_IMM(BPF_REG_0, 1),
5718 BPF_MOV64_IMM(BPF_REG_1, 2),
5719 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5722 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5725 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5726 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9),
5727 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5728 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7),
5729 BPF_LINE_INFO_ENC(4, 0, 0, 5, 6),
5732 .line_info_rec_size = sizeof(struct bpf_line_info),
5733 .nr_jited_ksyms = 1,
5734 .err_str = "line_info[4].insn_off",
5735 .expected_prog_load_failure = true,
5739 .descr = "line_info (Zero bpf insn code)",
5741 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5742 BTF_TYPE_INT_ENC(NAME_TBD, 0, 0, 64, 8), /* [2] */
5743 BTF_TYPEDEF_ENC(NAME_TBD, 2), /* [3] */
5746 BTF_STR_SEC("\0int\0unsigned long\0u64\0u64 a=1;\0return a;"),
5748 BPF_LD_IMM64(BPF_REG_0, 1),
5751 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5754 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5755 BPF_LINE_INFO_ENC(1, 0, 0, 2, 9),
5756 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5759 .line_info_rec_size = sizeof(struct bpf_line_info),
5760 .nr_jited_ksyms = 1,
5761 .err_str = "Invalid insn code at line_info[1]",
5762 .expected_prog_load_failure = true,
5766 .descr = "line_info (No subprog. zero tailing line_info",
5768 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5771 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5773 BPF_MOV64_IMM(BPF_REG_0, 1),
5774 BPF_MOV64_IMM(BPF_REG_1, 2),
5775 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5778 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5781 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10), 0,
5782 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9), 0,
5783 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8), 0,
5784 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7), 0,
5787 .line_info_rec_size = sizeof(struct bpf_line_info) + sizeof(__u32),
5788 .nr_jited_ksyms = 1,
5792 .descr = "line_info (No subprog. nonzero tailing line_info)",
5794 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5797 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5799 BPF_MOV64_IMM(BPF_REG_0, 1),
5800 BPF_MOV64_IMM(BPF_REG_1, 2),
5801 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5804 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5807 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10), 0,
5808 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9), 0,
5809 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8), 0,
5810 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7), 1,
5813 .line_info_rec_size = sizeof(struct bpf_line_info) + sizeof(__u32),
5814 .nr_jited_ksyms = 1,
5815 .err_str = "nonzero tailing record in line_info",
5816 .expected_prog_load_failure = true,
5820 .descr = "line_info (subprog)",
5822 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5825 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5827 BPF_MOV64_IMM(BPF_REG_2, 1),
5828 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5829 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5832 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5833 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5836 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5839 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5840 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
5841 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 3, 8),
5842 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
5845 .line_info_rec_size = sizeof(struct bpf_line_info),
5846 .nr_jited_ksyms = 2,
5850 .descr = "line_info (subprog + func_info)",
5852 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5853 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5854 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
5855 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
5856 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
5859 BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5861 BPF_MOV64_IMM(BPF_REG_2, 1),
5862 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5863 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5866 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5867 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5870 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5872 .func_info_rec_size = 8,
5873 .func_info = { {0, 4}, {5, 3} },
5875 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5876 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
5877 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 3, 8),
5878 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
5881 .line_info_rec_size = sizeof(struct bpf_line_info),
5882 .nr_jited_ksyms = 2,
5886 .descr = "line_info (subprog. missing 1st func line info)",
5888 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5891 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5893 BPF_MOV64_IMM(BPF_REG_2, 1),
5894 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5895 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5898 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5899 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5902 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5905 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 1, 10),
5906 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
5907 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 3, 8),
5908 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
5911 .line_info_rec_size = sizeof(struct bpf_line_info),
5912 .nr_jited_ksyms = 2,
5913 .err_str = "missing bpf_line_info for func#0",
5914 .expected_prog_load_failure = true,
5918 .descr = "line_info (subprog. missing 2nd func line info)",
5920 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5923 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5925 BPF_MOV64_IMM(BPF_REG_2, 1),
5926 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5927 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5930 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5931 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5934 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5937 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5938 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 2, 9),
5939 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 3, 8),
5940 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
5943 .line_info_rec_size = sizeof(struct bpf_line_info),
5944 .nr_jited_ksyms = 2,
5945 .err_str = "missing bpf_line_info for func#1",
5946 .expected_prog_load_failure = true,
5950 .descr = "line_info (subprog. unordered insn offset)",
5952 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5955 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5957 BPF_MOV64_IMM(BPF_REG_2, 1),
5958 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
5959 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
5962 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
5963 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
5966 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5969 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5970 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 2, 9),
5971 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
5972 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 4, 7),
5975 .line_info_rec_size = sizeof(struct bpf_line_info),
5976 .nr_jited_ksyms = 2,
5977 .err_str = "Invalid line_info[2].insn_off",
5978 .expected_prog_load_failure = true,
5982 .descr = "line_info (dead start)",
5984 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
5987 BTF_STR_SEC("\0int\0/* dead jmp */\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5989 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
5990 BPF_MOV64_IMM(BPF_REG_0, 1),
5991 BPF_MOV64_IMM(BPF_REG_1, 2),
5992 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
5995 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
5998 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
5999 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 9),
6000 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 8),
6001 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 7),
6002 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 5, 6),
6005 .line_info_rec_size = sizeof(struct bpf_line_info),
6006 .nr_jited_ksyms = 1,
6008 .dead_code_mask = 0x01,
6012 .descr = "line_info (dead end)",
6014 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6017 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0/* dead jmp */\0return a + b;\0/* dead exit */"),
6019 BPF_MOV64_IMM(BPF_REG_0, 1),
6020 BPF_MOV64_IMM(BPF_REG_1, 2),
6021 BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1),
6022 BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 10, 1),
6026 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6029 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 12),
6030 BPF_LINE_INFO_ENC(1, 0, NAME_TBD, 2, 11),
6031 BPF_LINE_INFO_ENC(2, 0, NAME_TBD, 3, 10),
6032 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 4, 9),
6033 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 5, 8),
6034 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 6, 7),
6037 .line_info_rec_size = sizeof(struct bpf_line_info),
6038 .nr_jited_ksyms = 1,
6040 .dead_code_mask = 0x28,
6044 .descr = "line_info (dead code + subprog + func_info)",
6046 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6047 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6048 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6049 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6050 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6053 BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0/* dead jmp */"
6054 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
6055 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
6056 "\0return func(a);\0b+=1;\0return b;"),
6058 BPF_MOV64_IMM(BPF_REG_2, 1),
6059 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
6060 BPF_MOV64_REG(BPF_REG_1, BPF_REG_2),
6061 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 8),
6062 BPF_MOV64_IMM(BPF_REG_2, 1),
6063 BPF_MOV64_IMM(BPF_REG_2, 1),
6064 BPF_MOV64_IMM(BPF_REG_2, 1),
6065 BPF_MOV64_IMM(BPF_REG_2, 1),
6066 BPF_MOV64_IMM(BPF_REG_2, 1),
6067 BPF_MOV64_IMM(BPF_REG_2, 1),
6068 BPF_MOV64_IMM(BPF_REG_2, 1),
6069 BPF_MOV64_IMM(BPF_REG_2, 1),
6072 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
6073 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6076 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6078 .func_info_rec_size = 8,
6079 .func_info = { {0, 4}, {14, 3} },
6081 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6082 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6083 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6084 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6085 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6086 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6087 BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6088 BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6089 BPF_LINE_INFO_ENC(10, 0, NAME_TBD, 1, 10),
6090 BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 2, 9),
6091 BPF_LINE_INFO_ENC(12, 0, NAME_TBD, 2, 9),
6092 BPF_LINE_INFO_ENC(14, 0, NAME_TBD, 3, 8),
6093 BPF_LINE_INFO_ENC(16, 0, NAME_TBD, 4, 7),
6096 .line_info_rec_size = sizeof(struct bpf_line_info),
6097 .nr_jited_ksyms = 2,
6099 .dead_code_mask = 0x3fe,
6103 .descr = "line_info (dead subprog)",
6105 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6106 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6107 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6108 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6109 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6110 BTF_FUNC_ENC(NAME_TBD, 2), /* [5] */
6113 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
6114 "\0return 0;\0return 0;\0/* dead */\0/* dead */"
6115 "\0/* dead */\0return bla + 1;\0return bla + 1;"
6116 "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
6118 BPF_MOV64_IMM(BPF_REG_2, 1),
6119 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6122 BPF_MOV64_IMM(BPF_REG_0, 0),
6124 BPF_MOV64_IMM(BPF_REG_0, 0),
6127 BPF_MOV64_REG(BPF_REG_0, 2),
6128 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6131 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6133 .func_info_rec_size = 8,
6134 .func_info = { {0, 4}, {6, 3}, {9, 5} },
6136 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6137 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6138 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6139 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6140 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6141 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6142 BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6143 BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6144 BPF_LINE_INFO_ENC(10, 0, NAME_TBD, 1, 10),
6145 BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 2, 9),
6148 .line_info_rec_size = sizeof(struct bpf_line_info),
6149 .nr_jited_ksyms = 2,
6151 .dead_code_mask = 0x70,
6153 .dead_func_mask = 0x2,
6157 .descr = "line_info (dead last subprog)",
6159 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6160 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6161 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6162 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6163 BTF_FUNC_ENC(NAME_TBD, 2), /* [5] */
6166 BTF_STR_SEC("\0int\0x\0dead\0main\0int a=1+1;\0/* live call */"
6167 "\0return 0;\0/* dead */\0/* dead */"),
6169 BPF_MOV64_IMM(BPF_REG_2, 1),
6170 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6172 BPF_MOV64_IMM(BPF_REG_0, 0),
6174 BPF_MOV64_IMM(BPF_REG_0, 0),
6177 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6179 .func_info_rec_size = 8,
6180 .func_info = { {0, 4}, {5, 3} },
6182 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6183 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6184 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6185 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6186 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6189 .line_info_rec_size = sizeof(struct bpf_line_info),
6190 .nr_jited_ksyms = 1,
6192 .dead_code_mask = 0x18,
6194 .dead_func_mask = 0x2,
6198 .descr = "line_info (dead subprog + dead start)",
6200 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6201 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6202 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6203 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6204 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6205 BTF_FUNC_ENC(NAME_TBD, 2), /* [5] */
6208 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* dead */"
6209 "\0return 0;\0return 0;\0return 0;"
6210 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
6211 "\0return b + 1;\0return b + 1;\0return b + 1;"),
6213 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6214 BPF_MOV64_IMM(BPF_REG_2, 1),
6215 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6218 BPF_MOV64_IMM(BPF_REG_0, 0),
6220 BPF_MOV64_IMM(BPF_REG_0, 0),
6223 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6224 BPF_MOV64_REG(BPF_REG_0, 2),
6225 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6228 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6230 .func_info_rec_size = 8,
6231 .func_info = { {0, 4}, {7, 3}, {10, 5} },
6233 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6234 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6235 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6236 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6237 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6238 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6239 BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6240 BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6241 BPF_LINE_INFO_ENC(10, 0, NAME_TBD, 1, 10),
6242 BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 2, 9),
6243 BPF_LINE_INFO_ENC(12, 0, NAME_TBD, 2, 9),
6244 BPF_LINE_INFO_ENC(13, 0, NAME_TBD, 2, 9),
6247 .line_info_rec_size = sizeof(struct bpf_line_info),
6248 .nr_jited_ksyms = 2,
6250 .dead_code_mask = 0x1e2,
6252 .dead_func_mask = 0x2,
6256 .descr = "line_info (dead subprog + dead start w/ move)",
6258 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6259 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6260 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6261 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6262 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6263 BTF_FUNC_ENC(NAME_TBD, 2), /* [5] */
6266 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
6267 "\0return 0;\0return 0;\0/* dead */\0/* dead */"
6268 "\0/* dead */\0return bla + 1;\0return bla + 1;"
6269 "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
6271 BPF_MOV64_IMM(BPF_REG_2, 1),
6272 BPF_JMP_IMM(BPF_JGE, BPF_REG_2, 0, 1),
6275 BPF_MOV64_IMM(BPF_REG_0, 0),
6277 BPF_MOV64_IMM(BPF_REG_0, 0),
6280 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6281 BPF_MOV64_REG(BPF_REG_0, 2),
6282 BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1),
6285 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6287 .func_info_rec_size = 8,
6288 .func_info = { {0, 4}, {6, 3}, {9, 5} },
6290 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6291 BPF_LINE_INFO_ENC(3, 0, NAME_TBD, 1, 10),
6292 BPF_LINE_INFO_ENC(4, 0, NAME_TBD, 1, 10),
6293 BPF_LINE_INFO_ENC(5, 0, NAME_TBD, 1, 10),
6294 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6295 BPF_LINE_INFO_ENC(7, 0, NAME_TBD, 1, 10),
6296 BPF_LINE_INFO_ENC(8, 0, NAME_TBD, 1, 10),
6297 BPF_LINE_INFO_ENC(9, 0, NAME_TBD, 1, 10),
6298 BPF_LINE_INFO_ENC(11, 0, NAME_TBD, 1, 10),
6299 BPF_LINE_INFO_ENC(12, 0, NAME_TBD, 2, 9),
6302 .line_info_rec_size = sizeof(struct bpf_line_info),
6303 .nr_jited_ksyms = 2,
6305 .dead_code_mask = 0x70,
6307 .dead_func_mask = 0x2,
6311 .descr = "line_info (dead end + subprog start w/ no linfo)",
6313 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6314 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
6315 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
6316 BTF_FUNC_ENC(NAME_TBD, 2), /* [3] */
6317 BTF_FUNC_ENC(NAME_TBD, 2), /* [4] */
6320 BTF_STR_SEC("\0int\0x\0main\0func\0/* main linfo */\0/* func linfo */"),
6322 BPF_MOV64_IMM(BPF_REG_0, 0),
6323 BPF_JMP_IMM(BPF_JGE, BPF_REG_0, 1, 3),
6325 BPF_MOV64_IMM(BPF_REG_0, 0),
6328 BPF_JMP_IMM(BPF_JA, 0, 0, 0),
6331 .prog_type = BPF_PROG_TYPE_TRACEPOINT,
6333 .func_info_rec_size = 8,
6334 .func_info = { {0, 3}, {6, 4}, },
6336 BPF_LINE_INFO_ENC(0, 0, NAME_TBD, 1, 10),
6337 BPF_LINE_INFO_ENC(6, 0, NAME_TBD, 1, 10),
6340 .line_info_rec_size = sizeof(struct bpf_line_info),
6341 .nr_jited_ksyms = 2,
6346 static size_t probe_prog_length(const struct bpf_insn *fp)
6350 for (len = MAX_INSNS - 1; len > 0; --len)
6351 if (fp[len].code != 0 || fp[len].imm != 0)
6356 static __u32 *patch_name_tbd(const __u32 *raw_u32,
6357 const char *str, __u32 str_off,
6358 unsigned int str_sec_size,
6359 unsigned int *ret_size)
6361 int i, raw_u32_size = get_raw_sec_size(raw_u32);
6362 const char *end_str = str + str_sec_size;
6363 const char *next_str = str + str_off;
6364 __u32 *new_u32 = NULL;
6366 if (raw_u32_size == -1)
6367 return ERR_PTR(-EINVAL);
6369 if (!raw_u32_size) {
6374 new_u32 = malloc(raw_u32_size);
6376 return ERR_PTR(-ENOMEM);
6378 for (i = 0; i < raw_u32_size / sizeof(raw_u32[0]); i++) {
6379 if (raw_u32[i] == NAME_TBD) {
6380 next_str = get_next_str(next_str, end_str);
6381 if (CHECK(!next_str, "Error in getting next_str\n")) {
6383 return ERR_PTR(-EINVAL);
6385 new_u32[i] = next_str - str;
6386 next_str += strlen(next_str);
6388 new_u32[i] = raw_u32[i];
6392 *ret_size = raw_u32_size;
6396 static int test_get_finfo(const struct prog_info_raw_test *test,
6399 struct bpf_prog_info info = {};
6400 struct bpf_func_info *finfo;
6401 __u32 info_len, rec_size, i;
6402 void *func_info = NULL;
6406 /* get necessary lens */
6407 info_len = sizeof(struct bpf_prog_info);
6408 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6409 if (CHECK(err < 0, "invalid get info (1st) errno:%d", errno)) {
6410 fprintf(stderr, "%s\n", btf_log_buf);
6413 nr_func_info = test->func_info_cnt - test->dead_func_cnt;
6414 if (CHECK(info.nr_func_info != nr_func_info,
6415 "incorrect info.nr_func_info (1st) %d",
6416 info.nr_func_info)) {
6420 rec_size = info.func_info_rec_size;
6421 if (CHECK(rec_size != sizeof(struct bpf_func_info),
6422 "incorrect info.func_info_rec_size (1st) %d", rec_size)) {
6426 if (!info.nr_func_info)
6429 func_info = malloc(info.nr_func_info * rec_size);
6430 if (CHECK(!func_info, "out of memory"))
6433 /* reset info to only retrieve func_info related data */
6434 memset(&info, 0, sizeof(info));
6435 info.nr_func_info = nr_func_info;
6436 info.func_info_rec_size = rec_size;
6437 info.func_info = ptr_to_u64(func_info);
6438 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6439 if (CHECK(err < 0, "invalid get info (2nd) errno:%d", errno)) {
6440 fprintf(stderr, "%s\n", btf_log_buf);
6444 if (CHECK(info.nr_func_info != nr_func_info,
6445 "incorrect info.nr_func_info (2nd) %d",
6446 info.nr_func_info)) {
6450 if (CHECK(info.func_info_rec_size != rec_size,
6451 "incorrect info.func_info_rec_size (2nd) %d",
6452 info.func_info_rec_size)) {
6458 for (i = 0; i < nr_func_info; i++) {
6459 if (test->dead_func_mask & (1 << i))
6461 if (CHECK(finfo->type_id != test->func_info[i][1],
6462 "incorrect func_type %u expected %u",
6463 finfo->type_id, test->func_info[i][1])) {
6467 finfo = (void *)finfo + rec_size;
6477 static int test_get_linfo(const struct prog_info_raw_test *test,
6478 const void *patched_linfo,
6479 __u32 cnt, int prog_fd)
6481 __u32 i, info_len, nr_jited_ksyms, nr_jited_func_lens;
6482 __u64 *jited_linfo = NULL, *jited_ksyms = NULL;
6483 __u32 rec_size, jited_rec_size, jited_cnt;
6484 struct bpf_line_info *linfo = NULL;
6485 __u32 cur_func_len, ksyms_found;
6486 struct bpf_prog_info info = {};
6487 __u32 *jited_func_lens = NULL;
6488 __u64 cur_func_ksyms;
6493 rec_size = sizeof(*linfo);
6494 jited_rec_size = sizeof(*jited_linfo);
6495 if (test->nr_jited_ksyms)
6496 nr_jited_ksyms = test->nr_jited_ksyms;
6498 nr_jited_ksyms = test->func_info_cnt - test->dead_func_cnt;
6499 nr_jited_func_lens = nr_jited_ksyms;
6501 info_len = sizeof(struct bpf_prog_info);
6502 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6503 if (CHECK(err < 0, "err:%d errno:%d", err, errno)) {
6508 if (!info.jited_prog_len) {
6509 /* prog is not jited */
6512 nr_jited_func_lens = 1;
6515 if (CHECK(info.nr_line_info != cnt ||
6516 info.nr_jited_line_info != jited_cnt ||
6517 info.nr_jited_ksyms != nr_jited_ksyms ||
6518 info.nr_jited_func_lens != nr_jited_func_lens ||
6519 (!info.nr_line_info && info.nr_jited_line_info),
6520 "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)",
6521 info.nr_line_info, cnt,
6522 info.nr_jited_line_info, jited_cnt,
6523 info.nr_jited_ksyms, nr_jited_ksyms,
6524 info.nr_jited_func_lens, nr_jited_func_lens)) {
6529 if (CHECK(info.line_info_rec_size != sizeof(struct bpf_line_info) ||
6530 info.jited_line_info_rec_size != sizeof(__u64),
6531 "info: line_info_rec_size:%u(userspace expected:%u) jited_line_info_rec_size:%u(userspace expected:%u)",
6532 info.line_info_rec_size, rec_size,
6533 info.jited_line_info_rec_size, jited_rec_size)) {
6541 rec_size = info.line_info_rec_size;
6542 jited_rec_size = info.jited_line_info_rec_size;
6544 memset(&info, 0, sizeof(info));
6546 linfo = calloc(cnt, rec_size);
6547 if (CHECK(!linfo, "!linfo")) {
6551 info.nr_line_info = cnt;
6552 info.line_info_rec_size = rec_size;
6553 info.line_info = ptr_to_u64(linfo);
6556 jited_linfo = calloc(jited_cnt, jited_rec_size);
6557 jited_ksyms = calloc(nr_jited_ksyms, sizeof(*jited_ksyms));
6558 jited_func_lens = calloc(nr_jited_func_lens,
6559 sizeof(*jited_func_lens));
6560 if (CHECK(!jited_linfo || !jited_ksyms || !jited_func_lens,
6561 "jited_linfo:%p jited_ksyms:%p jited_func_lens:%p",
6562 jited_linfo, jited_ksyms, jited_func_lens)) {
6567 info.nr_jited_line_info = jited_cnt;
6568 info.jited_line_info_rec_size = jited_rec_size;
6569 info.jited_line_info = ptr_to_u64(jited_linfo);
6570 info.nr_jited_ksyms = nr_jited_ksyms;
6571 info.jited_ksyms = ptr_to_u64(jited_ksyms);
6572 info.nr_jited_func_lens = nr_jited_func_lens;
6573 info.jited_func_lens = ptr_to_u64(jited_func_lens);
6576 err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
6579 * Only recheck the info.*line_info* fields.
6580 * Other fields are not the concern of this test.
6582 if (CHECK(err < 0 ||
6583 info.nr_line_info != cnt ||
6584 (jited_cnt && !info.jited_line_info) ||
6585 info.nr_jited_line_info != jited_cnt ||
6586 info.line_info_rec_size != rec_size ||
6587 info.jited_line_info_rec_size != jited_rec_size,
6588 "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",
6590 info.nr_line_info, cnt,
6591 info.nr_jited_line_info, jited_cnt,
6592 info.line_info_rec_size, rec_size,
6593 info.jited_line_info_rec_size, jited_rec_size,
6594 (void *)(long)info.line_info,
6595 (void *)(long)info.jited_line_info)) {
6601 while (test->dead_code_mask & (1 << dead_insns))
6604 CHECK(linfo[0].insn_off, "linfo[0].insn_off:%u",
6606 for (i = 1; i < cnt; i++) {
6607 const struct bpf_line_info *expected_linfo;
6609 while (test->dead_code_mask & (1 << (i + dead_insns)))
6612 expected_linfo = patched_linfo +
6613 ((i + dead_insns) * test->line_info_rec_size);
6614 if (CHECK(linfo[i].insn_off <= linfo[i - 1].insn_off,
6615 "linfo[%u].insn_off:%u <= linfo[%u].insn_off:%u",
6616 i, linfo[i].insn_off,
6617 i - 1, linfo[i - 1].insn_off)) {
6621 if (CHECK(linfo[i].file_name_off != expected_linfo->file_name_off ||
6622 linfo[i].line_off != expected_linfo->line_off ||
6623 linfo[i].line_col != expected_linfo->line_col,
6624 "linfo[%u] (%u, %u, %u) != (%u, %u, %u)", i,
6625 linfo[i].file_name_off,
6628 expected_linfo->file_name_off,
6629 expected_linfo->line_off,
6630 expected_linfo->line_col)) {
6637 fprintf(stderr, "not jited. skipping jited_line_info check. ");
6642 if (CHECK(jited_linfo[0] != jited_ksyms[0],
6643 "jited_linfo[0]:%lx != jited_ksyms[0]:%lx",
6644 (long)(jited_linfo[0]), (long)(jited_ksyms[0]))) {
6650 cur_func_len = jited_func_lens[0];
6651 cur_func_ksyms = jited_ksyms[0];
6652 for (i = 1; i < jited_cnt; i++) {
6653 if (ksyms_found < nr_jited_ksyms &&
6654 jited_linfo[i] == jited_ksyms[ksyms_found]) {
6655 cur_func_ksyms = jited_ksyms[ksyms_found];
6656 cur_func_len = jited_ksyms[ksyms_found];
6661 if (CHECK(jited_linfo[i] <= jited_linfo[i - 1],
6662 "jited_linfo[%u]:%lx <= jited_linfo[%u]:%lx",
6663 i, (long)jited_linfo[i],
6664 i - 1, (long)(jited_linfo[i - 1]))) {
6669 if (CHECK(jited_linfo[i] - cur_func_ksyms > cur_func_len,
6670 "jited_linfo[%u]:%lx - %lx > %u",
6671 i, (long)jited_linfo[i], (long)cur_func_ksyms,
6678 if (CHECK(ksyms_found != nr_jited_ksyms,
6679 "ksyms_found:%u != nr_jited_ksyms:%u",
6680 ksyms_found, nr_jited_ksyms)) {
6691 free(jited_func_lens);
6695 static void do_test_info_raw(unsigned int test_num)
6697 const struct prog_info_raw_test *test = &info_raw_tests[test_num - 1];
6698 unsigned int raw_btf_size, linfo_str_off, linfo_size = 0;
6699 int btf_fd = -1, prog_fd = -1, err = 0;
6700 void *raw_btf, *patched_linfo = NULL;
6701 const char *ret_next_str;
6702 union bpf_attr attr = {};
6704 if (!test__start_subtest(test->descr))
6707 raw_btf = btf_raw_create(&hdr_tmpl, test->raw_types,
6708 test->str_sec, test->str_sec_size,
6709 &raw_btf_size, &ret_next_str);
6713 *btf_log_buf = '\0';
6714 btf_fd = load_raw_btf(raw_btf, raw_btf_size);
6717 if (CHECK(btf_fd < 0, "invalid btf_fd errno:%d", errno)) {
6722 if (*btf_log_buf && always_log)
6723 fprintf(stderr, "\n%s", btf_log_buf);
6724 *btf_log_buf = '\0';
6726 linfo_str_off = ret_next_str - test->str_sec;
6727 patched_linfo = patch_name_tbd(test->line_info,
6728 test->str_sec, linfo_str_off,
6729 test->str_sec_size, &linfo_size);
6730 err = libbpf_get_error(patched_linfo);
6732 fprintf(stderr, "error in creating raw bpf_line_info");
6737 attr.prog_type = test->prog_type;
6738 attr.insns = ptr_to_u64(test->insns);
6739 attr.insn_cnt = probe_prog_length(test->insns);
6740 attr.license = ptr_to_u64("GPL");
6741 attr.prog_btf_fd = btf_fd;
6742 attr.func_info_rec_size = test->func_info_rec_size;
6743 attr.func_info_cnt = test->func_info_cnt;
6744 attr.func_info = ptr_to_u64(test->func_info);
6745 attr.log_buf = ptr_to_u64(btf_log_buf);
6746 attr.log_size = BTF_LOG_BUF_SIZE;
6749 attr.line_info_rec_size = test->line_info_rec_size;
6750 attr.line_info = ptr_to_u64(patched_linfo);
6751 attr.line_info_cnt = linfo_size / attr.line_info_rec_size;
6754 prog_fd = syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
6755 err = ((prog_fd < 0) != test->expected_prog_load_failure);
6756 if (CHECK(err, "prog_fd:%d expected_prog_load_failure:%u errno:%d",
6757 prog_fd, test->expected_prog_load_failure, errno) ||
6758 CHECK(test->err_str && !strstr(btf_log_buf, test->err_str),
6759 "expected err_str:%s", test->err_str)) {
6767 err = test_get_finfo(test, prog_fd);
6771 err = test_get_linfo(test, patched_linfo,
6772 attr.line_info_cnt - test->dead_code_cnt,
6778 if (*btf_log_buf && (err || always_log))
6779 fprintf(stderr, "\n%s", btf_log_buf);
6786 if (!libbpf_get_error(patched_linfo))
6787 free(patched_linfo);
6790 struct btf_raw_data {
6791 __u32 raw_types[MAX_NR_RAW_U32];
6792 const char *str_sec;
6796 struct btf_dedup_test {
6798 struct btf_raw_data input;
6799 struct btf_raw_data expect;
6800 struct btf_dedup_opts opts;
6803 static struct btf_dedup_test dedup_tests[] = {
6806 .descr = "dedup: unused strings filtering",
6809 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 32, 4),
6810 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED, 0, 64, 8),
6813 BTF_STR_SEC("\0unused\0int\0foo\0bar\0long"),
6817 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
6818 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 64, 8),
6821 BTF_STR_SEC("\0int\0long"),
6825 .descr = "dedup: strings deduplication",
6828 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
6829 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 64, 8),
6830 BTF_TYPE_INT_ENC(NAME_NTH(3), BTF_INT_SIGNED, 0, 32, 4),
6831 BTF_TYPE_INT_ENC(NAME_NTH(4), BTF_INT_SIGNED, 0, 64, 8),
6832 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED, 0, 32, 4),
6835 BTF_STR_SEC("\0int\0long int\0int\0long int\0int"),
6839 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
6840 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 64, 8),
6843 BTF_STR_SEC("\0int\0long int"),
6847 .descr = "dedup: struct example #1",
6859 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6861 BTF_TYPE_ARRAY_ENC(1, 1, 16), /* [2] */
6863 BTF_STRUCT_ENC(NAME_NTH(2), 5, 88), /* [3] */
6864 BTF_MEMBER_ENC(NAME_NTH(3), 4, 0), /* struct s *next; */
6865 BTF_MEMBER_ENC(NAME_NTH(4), 5, 64), /* const int *a; */
6866 BTF_MEMBER_ENC(NAME_NTH(5), 2, 128), /* int b[16]; */
6867 BTF_MEMBER_ENC(NAME_NTH(6), 1, 640), /* int c; */
6868 BTF_MEMBER_ENC(NAME_NTH(8), 15, 672), /* float d; */
6869 /* ptr -> [3] struct s */
6870 BTF_PTR_ENC(3), /* [4] */
6871 /* ptr -> [6] const int */
6872 BTF_PTR_ENC(6), /* [5] */
6873 /* const -> [1] int */
6874 BTF_CONST_ENC(1), /* [6] */
6875 /* tag -> [3] struct s */
6876 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1), /* [7] */
6877 /* tag -> [3] struct s, member 1 */
6878 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, 1), /* [8] */
6880 /* full copy of the above */
6881 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4), /* [9] */
6882 BTF_TYPE_ARRAY_ENC(9, 9, 16), /* [10] */
6883 BTF_STRUCT_ENC(NAME_NTH(2), 5, 88), /* [11] */
6884 BTF_MEMBER_ENC(NAME_NTH(3), 12, 0),
6885 BTF_MEMBER_ENC(NAME_NTH(4), 13, 64),
6886 BTF_MEMBER_ENC(NAME_NTH(5), 10, 128),
6887 BTF_MEMBER_ENC(NAME_NTH(6), 9, 640),
6888 BTF_MEMBER_ENC(NAME_NTH(8), 15, 672),
6889 BTF_PTR_ENC(11), /* [12] */
6890 BTF_PTR_ENC(14), /* [13] */
6891 BTF_CONST_ENC(9), /* [14] */
6892 BTF_TYPE_FLOAT_ENC(NAME_NTH(7), 4), /* [15] */
6893 BTF_DECL_TAG_ENC(NAME_NTH(2), 11, -1), /* [16] */
6894 BTF_DECL_TAG_ENC(NAME_NTH(2), 11, 1), /* [17] */
6897 BTF_STR_SEC("\0int\0s\0next\0a\0b\0c\0float\0d"),
6902 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED, 0, 32, 4), /* [1] */
6904 BTF_TYPE_ARRAY_ENC(1, 1, 16), /* [2] */
6906 BTF_STRUCT_ENC(NAME_NTH(8), 5, 88), /* [3] */
6907 BTF_MEMBER_ENC(NAME_NTH(7), 4, 0), /* struct s *next; */
6908 BTF_MEMBER_ENC(NAME_NTH(1), 5, 64), /* const int *a; */
6909 BTF_MEMBER_ENC(NAME_NTH(2), 2, 128), /* int b[16]; */
6910 BTF_MEMBER_ENC(NAME_NTH(3), 1, 640), /* int c; */
6911 BTF_MEMBER_ENC(NAME_NTH(4), 9, 672), /* float d; */
6912 /* ptr -> [3] struct s */
6913 BTF_PTR_ENC(3), /* [4] */
6914 /* ptr -> [6] const int */
6915 BTF_PTR_ENC(6), /* [5] */
6916 /* const -> [1] int */
6917 BTF_CONST_ENC(1), /* [6] */
6918 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1), /* [7] */
6919 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, 1), /* [8] */
6920 BTF_TYPE_FLOAT_ENC(NAME_NTH(7), 4), /* [9] */
6923 BTF_STR_SEC("\0a\0b\0c\0d\0int\0float\0next\0s"),
6927 .descr = "dedup: struct <-> fwd resolution w/ hash collision",
6943 BTF_FWD_ENC(NAME_TBD, 0 /* struct fwd */), /* [1] fwd x */
6944 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
6945 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [3] struct s */
6946 BTF_MEMBER_ENC(NAME_TBD, 2, 0),
6948 BTF_STRUCT_ENC(NAME_TBD, 0, 0), /* [4] struct x */
6949 BTF_PTR_ENC(4), /* [5] ptr -> [4] */
6950 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [6] struct s */
6951 BTF_MEMBER_ENC(NAME_TBD, 5, 0),
6954 BTF_STR_SEC("\0x\0s\0x\0x\0s\0x\0"),
6958 BTF_PTR_ENC(3), /* [1] ptr -> [3] */
6959 BTF_STRUCT_ENC(NAME_TBD, 1, 8), /* [2] struct s */
6960 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
6961 BTF_STRUCT_ENC(NAME_NTH(2), 0, 0), /* [3] struct x */
6964 BTF_STR_SEC("\0s\0x"),
6967 .force_collisions = true, /* force hash collisions */
6971 .descr = "dedup: void equiv check",
6985 BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
6986 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
6987 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
6988 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
6990 BTF_PTR_ENC(0), /* [4] ptr -> void */
6991 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
6992 BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
6995 BTF_STR_SEC("\0s\0x"),
7000 BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
7001 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
7002 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
7003 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7005 BTF_PTR_ENC(0), /* [4] ptr -> void */
7006 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
7007 BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
7010 BTF_STR_SEC("\0s\0x"),
7013 .force_collisions = true, /* force hash collisions */
7017 .descr = "dedup: all possible kinds (no duplicates)",
7020 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 8), /* [1] int */
7021 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 4), /* [2] enum */
7022 BTF_ENUM_ENC(NAME_TBD, 0),
7023 BTF_ENUM_ENC(NAME_TBD, 1),
7024 BTF_FWD_ENC(NAME_TBD, 1 /* union kind_flag */), /* [3] fwd */
7025 BTF_TYPE_ARRAY_ENC(2, 1, 7), /* [4] array */
7026 BTF_STRUCT_ENC(NAME_TBD, 1, 4), /* [5] struct */
7027 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7028 BTF_UNION_ENC(NAME_TBD, 1, 4), /* [6] union */
7029 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7030 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [7] typedef */
7031 BTF_PTR_ENC(0), /* [8] ptr */
7032 BTF_CONST_ENC(8), /* [9] const */
7033 BTF_VOLATILE_ENC(8), /* [10] volatile */
7034 BTF_RESTRICT_ENC(8), /* [11] restrict */
7035 BTF_FUNC_PROTO_ENC(1, 2), /* [12] func_proto */
7036 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
7037 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
7038 BTF_FUNC_ENC(NAME_TBD, 12), /* [13] func */
7039 BTF_TYPE_FLOAT_ENC(NAME_TBD, 2), /* [14] float */
7040 BTF_DECL_TAG_ENC(NAME_TBD, 13, -1), /* [15] decl_tag */
7041 BTF_DECL_TAG_ENC(NAME_TBD, 13, 1), /* [16] decl_tag */
7042 BTF_DECL_TAG_ENC(NAME_TBD, 7, -1), /* [17] decl_tag */
7043 BTF_TYPE_TAG_ENC(NAME_TBD, 8), /* [18] type_tag */
7044 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 2), 8), /* [19] enum64 */
7045 BTF_ENUM64_ENC(NAME_TBD, 0, 0),
7046 BTF_ENUM64_ENC(NAME_TBD, 1, 1),
7049 BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R\0S\0T\0U"),
7053 BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 8), /* [1] int */
7054 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM, 0, 2), 4), /* [2] enum */
7055 BTF_ENUM_ENC(NAME_TBD, 0),
7056 BTF_ENUM_ENC(NAME_TBD, 1),
7057 BTF_FWD_ENC(NAME_TBD, 1 /* union kind_flag */), /* [3] fwd */
7058 BTF_TYPE_ARRAY_ENC(2, 1, 7), /* [4] array */
7059 BTF_STRUCT_ENC(NAME_TBD, 1, 4), /* [5] struct */
7060 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7061 BTF_UNION_ENC(NAME_TBD, 1, 4), /* [6] union */
7062 BTF_MEMBER_ENC(NAME_TBD, 1, 0),
7063 BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [7] typedef */
7064 BTF_PTR_ENC(0), /* [8] ptr */
7065 BTF_CONST_ENC(8), /* [9] const */
7066 BTF_VOLATILE_ENC(8), /* [10] volatile */
7067 BTF_RESTRICT_ENC(8), /* [11] restrict */
7068 BTF_FUNC_PROTO_ENC(1, 2), /* [12] func_proto */
7069 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
7070 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
7071 BTF_FUNC_ENC(NAME_TBD, 12), /* [13] func */
7072 BTF_TYPE_FLOAT_ENC(NAME_TBD, 2), /* [14] float */
7073 BTF_DECL_TAG_ENC(NAME_TBD, 13, -1), /* [15] decl_tag */
7074 BTF_DECL_TAG_ENC(NAME_TBD, 13, 1), /* [16] decl_tag */
7075 BTF_DECL_TAG_ENC(NAME_TBD, 7, -1), /* [17] decl_tag */
7076 BTF_TYPE_TAG_ENC(NAME_TBD, 8), /* [18] type_tag */
7077 BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 2), 8), /* [19] enum64 */
7078 BTF_ENUM64_ENC(NAME_TBD, 0, 0),
7079 BTF_ENUM64_ENC(NAME_TBD, 1, 1),
7082 BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R\0S\0T\0U"),
7086 .descr = "dedup: no int/float duplicates",
7089 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 8),
7090 /* different name */
7091 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 32, 8),
7092 /* different encoding */
7093 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR, 0, 32, 8),
7094 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL, 0, 32, 8),
7095 /* different bit offset */
7096 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 8, 32, 8),
7097 /* different bit size */
7098 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 27, 8),
7099 /* different byte size */
7100 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
7101 /* all allowed sizes */
7102 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 2),
7103 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 4),
7104 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 8),
7105 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 12),
7106 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 16),
7109 BTF_STR_SEC("\0int\0some other int\0float"),
7113 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 8),
7114 /* different name */
7115 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED, 0, 32, 8),
7116 /* different encoding */
7117 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR, 0, 32, 8),
7118 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL, 0, 32, 8),
7119 /* different bit offset */
7120 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 8, 32, 8),
7121 /* different bit size */
7122 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 27, 8),
7123 /* different byte size */
7124 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED, 0, 32, 4),
7125 /* all allowed sizes */
7126 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 2),
7127 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 4),
7128 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 8),
7129 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 12),
7130 BTF_TYPE_FLOAT_ENC(NAME_NTH(3), 16),
7133 BTF_STR_SEC("\0int\0some other int\0float"),
7137 .descr = "dedup: enum fwd resolution",
7140 /* [1] fwd enum 'e1' before full enum */
7141 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 4),
7142 /* [2] full enum 'e1' after fwd */
7143 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7144 BTF_ENUM_ENC(NAME_NTH(2), 123),
7145 /* [3] full enum 'e2' before fwd */
7146 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7147 BTF_ENUM_ENC(NAME_NTH(4), 456),
7148 /* [4] fwd enum 'e2' after full enum */
7149 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 4),
7150 /* [5] fwd enum with different size, size does not matter for fwd */
7151 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 1),
7152 /* [6] incompatible full enum with different value */
7153 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7154 BTF_ENUM_ENC(NAME_NTH(2), 321),
7157 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7161 /* [1] full enum 'e1' */
7162 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7163 BTF_ENUM_ENC(NAME_NTH(2), 123),
7164 /* [2] full enum 'e2' */
7165 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7166 BTF_ENUM_ENC(NAME_NTH(4), 456),
7167 /* [3] incompatible full enum with different value */
7168 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7169 BTF_ENUM_ENC(NAME_NTH(2), 321),
7172 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7176 .descr = "dedup: datasec and vars pass-through",
7180 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7182 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [2] */
7183 /* .bss section */ /* [3] */
7184 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7185 BTF_VAR_SECINFO_ENC(2, 0, 4),
7186 /* int, referenced from [5] */
7187 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [4] */
7188 /* another static int t */
7189 BTF_VAR_ENC(NAME_NTH(2), 4, 0), /* [5] */
7190 /* another .bss section */ /* [6] */
7191 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7192 BTF_VAR_SECINFO_ENC(5, 0, 4),
7195 BTF_STR_SEC("\0.bss\0t"),
7200 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7202 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [2] */
7203 /* .bss section */ /* [3] */
7204 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7205 BTF_VAR_SECINFO_ENC(2, 0, 4),
7206 /* another static int t */
7207 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [4] */
7208 /* another .bss section */ /* [5] */
7209 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
7210 BTF_VAR_SECINFO_ENC(4, 0, 4),
7213 BTF_STR_SEC("\0.bss\0t"),
7216 .force_collisions = true
7220 .descr = "dedup: func/func_arg/var tags",
7224 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7226 BTF_VAR_ENC(NAME_NTH(1), 1, 0), /* [2] */
7227 /* void f(int a1, int a2) */
7228 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
7229 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7230 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(3), 1),
7231 BTF_FUNC_ENC(NAME_NTH(4), 2), /* [4] */
7233 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
7234 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [6] */
7236 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1), /* [7] */
7237 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1), /* [8] */
7238 /* tag -> func arg a1 */
7239 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1), /* [9] */
7240 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1), /* [10] */
7243 BTF_STR_SEC("\0t\0a1\0a2\0f\0tag"),
7247 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7248 BTF_VAR_ENC(NAME_NTH(1), 1, 0), /* [2] */
7249 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
7250 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7251 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(3), 1),
7252 BTF_FUNC_ENC(NAME_NTH(4), 2), /* [4] */
7253 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
7254 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, -1), /* [6] */
7255 BTF_DECL_TAG_ENC(NAME_NTH(5), 4, 1), /* [7] */
7258 BTF_STR_SEC("\0t\0a1\0a2\0f\0tag"),
7262 .descr = "dedup: func/func_param tags",
7266 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7267 /* void f(int a1, int a2) */
7268 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
7269 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
7270 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7271 BTF_FUNC_ENC(NAME_NTH(3), 2), /* [3] */
7272 /* void f(int a1, int a2) */
7273 BTF_FUNC_PROTO_ENC(0, 2), /* [4] */
7274 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
7275 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7276 BTF_FUNC_ENC(NAME_NTH(3), 4), /* [5] */
7277 /* tag -> f: tag1, tag2 */
7278 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [6] */
7279 BTF_DECL_TAG_ENC(NAME_NTH(5), 3, -1), /* [7] */
7280 /* tag -> f/a2: tag1, tag2 */
7281 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1), /* [8] */
7282 BTF_DECL_TAG_ENC(NAME_NTH(5), 3, 1), /* [9] */
7283 /* tag -> f: tag1, tag3 */
7284 BTF_DECL_TAG_ENC(NAME_NTH(4), 5, -1), /* [10] */
7285 BTF_DECL_TAG_ENC(NAME_NTH(6), 5, -1), /* [11] */
7286 /* tag -> f/a2: tag1, tag3 */
7287 BTF_DECL_TAG_ENC(NAME_NTH(4), 5, 1), /* [12] */
7288 BTF_DECL_TAG_ENC(NAME_NTH(6), 5, 1), /* [13] */
7291 BTF_STR_SEC("\0a1\0a2\0f\0tag1\0tag2\0tag3"),
7295 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7296 BTF_FUNC_PROTO_ENC(0, 2), /* [2] */
7297 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(1), 1),
7298 BTF_FUNC_PROTO_ARG_ENC(NAME_NTH(2), 1),
7299 BTF_FUNC_ENC(NAME_NTH(3), 2), /* [3] */
7300 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [4] */
7301 BTF_DECL_TAG_ENC(NAME_NTH(5), 3, -1), /* [5] */
7302 BTF_DECL_TAG_ENC(NAME_NTH(6), 3, -1), /* [6] */
7303 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1), /* [7] */
7304 BTF_DECL_TAG_ENC(NAME_NTH(5), 3, 1), /* [8] */
7305 BTF_DECL_TAG_ENC(NAME_NTH(6), 3, 1), /* [9] */
7308 BTF_STR_SEC("\0a1\0a2\0f\0tag1\0tag2\0tag3"),
7312 .descr = "dedup: struct/struct_member tags",
7316 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7317 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [2] */
7318 BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
7319 BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
7320 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [3] */
7321 BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
7322 BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
7323 /* tag -> t: tag1, tag2 */
7324 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1), /* [4] */
7325 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [5] */
7326 /* tag -> t/m2: tag1, tag2 */
7327 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, 1), /* [6] */
7328 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, 1), /* [7] */
7329 /* tag -> t: tag1, tag3 */
7330 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [8] */
7331 BTF_DECL_TAG_ENC(NAME_NTH(6), 3, -1), /* [9] */
7332 /* tag -> t/m2: tag1, tag3 */
7333 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, 1), /* [10] */
7334 BTF_DECL_TAG_ENC(NAME_NTH(6), 3, 1), /* [11] */
7337 BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
7341 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7342 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [2] */
7343 BTF_MEMBER_ENC(NAME_NTH(2), 1, 0),
7344 BTF_MEMBER_ENC(NAME_NTH(3), 1, 32),
7345 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1), /* [3] */
7346 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, -1), /* [4] */
7347 BTF_DECL_TAG_ENC(NAME_NTH(6), 2, -1), /* [5] */
7348 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, 1), /* [6] */
7349 BTF_DECL_TAG_ENC(NAME_NTH(5), 2, 1), /* [7] */
7350 BTF_DECL_TAG_ENC(NAME_NTH(6), 2, 1), /* [8] */
7353 BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
7357 .descr = "dedup: typedef tags",
7361 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7362 BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */
7363 BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [3] */
7364 /* tag -> t: tag1, tag2 */
7365 BTF_DECL_TAG_ENC(NAME_NTH(2), 2, -1), /* [4] */
7366 BTF_DECL_TAG_ENC(NAME_NTH(3), 2, -1), /* [5] */
7367 /* tag -> t: tag1, tag3 */
7368 BTF_DECL_TAG_ENC(NAME_NTH(2), 3, -1), /* [6] */
7369 BTF_DECL_TAG_ENC(NAME_NTH(4), 3, -1), /* [7] */
7372 BTF_STR_SEC("\0t\0tag1\0tag2\0tag3"),
7376 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7377 BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */
7378 BTF_DECL_TAG_ENC(NAME_NTH(2), 2, -1), /* [3] */
7379 BTF_DECL_TAG_ENC(NAME_NTH(3), 2, -1), /* [4] */
7380 BTF_DECL_TAG_ENC(NAME_NTH(4), 2, -1), /* [5] */
7383 BTF_STR_SEC("\0t\0tag1\0tag2\0tag3"),
7387 .descr = "dedup: btf_type_tag #1",
7390 /* ptr -> tag2 -> tag1 -> int */
7391 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7392 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7393 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7394 BTF_PTR_ENC(3), /* [4] */
7395 /* ptr -> tag2 -> tag1 -> int */
7396 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [5] */
7397 BTF_TYPE_TAG_ENC(NAME_NTH(2), 5), /* [6] */
7398 BTF_PTR_ENC(6), /* [7] */
7399 /* ptr -> tag1 -> int */
7400 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [8] */
7401 BTF_PTR_ENC(8), /* [9] */
7404 BTF_STR_SEC("\0tag1\0tag2"),
7408 /* ptr -> tag2 -> tag1 -> int */
7409 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7410 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7411 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7412 BTF_PTR_ENC(3), /* [4] */
7413 /* ptr -> tag1 -> int */
7414 BTF_PTR_ENC(2), /* [5] */
7417 BTF_STR_SEC("\0tag1\0tag2"),
7421 .descr = "dedup: btf_type_tag #2",
7424 /* ptr -> tag2 -> tag1 -> int */
7425 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7426 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7427 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7428 BTF_PTR_ENC(3), /* [4] */
7429 /* ptr -> tag2 -> int */
7430 BTF_TYPE_TAG_ENC(NAME_NTH(2), 1), /* [5] */
7431 BTF_PTR_ENC(5), /* [6] */
7434 BTF_STR_SEC("\0tag1\0tag2"),
7438 /* ptr -> tag2 -> tag1 -> int */
7439 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7440 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7441 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7442 BTF_PTR_ENC(3), /* [4] */
7443 /* ptr -> tag2 -> int */
7444 BTF_TYPE_TAG_ENC(NAME_NTH(2), 1), /* [5] */
7445 BTF_PTR_ENC(5), /* [6] */
7448 BTF_STR_SEC("\0tag1\0tag2"),
7452 .descr = "dedup: btf_type_tag #3",
7455 /* ptr -> tag2 -> tag1 -> int */
7456 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7457 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7458 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7459 BTF_PTR_ENC(3), /* [4] */
7460 /* ptr -> tag1 -> tag2 -> int */
7461 BTF_TYPE_TAG_ENC(NAME_NTH(2), 1), /* [5] */
7462 BTF_TYPE_TAG_ENC(NAME_NTH(1), 5), /* [6] */
7463 BTF_PTR_ENC(6), /* [7] */
7466 BTF_STR_SEC("\0tag1\0tag2"),
7470 /* ptr -> tag2 -> tag1 -> int */
7471 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7472 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7473 BTF_TYPE_TAG_ENC(NAME_NTH(2), 2), /* [3] */
7474 BTF_PTR_ENC(3), /* [4] */
7475 /* ptr -> tag1 -> tag2 -> int */
7476 BTF_TYPE_TAG_ENC(NAME_NTH(2), 1), /* [5] */
7477 BTF_TYPE_TAG_ENC(NAME_NTH(1), 5), /* [6] */
7478 BTF_PTR_ENC(6), /* [7] */
7481 BTF_STR_SEC("\0tag1\0tag2"),
7485 .descr = "dedup: btf_type_tag #4",
7488 /* ptr -> tag1 -> int */
7489 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7490 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7491 BTF_PTR_ENC(2), /* [3] */
7492 /* ptr -> tag1 -> long */
7493 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 64, 8), /* [4] */
7494 BTF_TYPE_TAG_ENC(NAME_NTH(1), 4), /* [5] */
7495 BTF_PTR_ENC(5), /* [6] */
7498 BTF_STR_SEC("\0tag1"),
7502 /* ptr -> tag1 -> int */
7503 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7504 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7505 BTF_PTR_ENC(2), /* [3] */
7506 /* ptr -> tag1 -> long */
7507 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 64, 8), /* [4] */
7508 BTF_TYPE_TAG_ENC(NAME_NTH(1), 4), /* [5] */
7509 BTF_PTR_ENC(5), /* [6] */
7512 BTF_STR_SEC("\0tag1"),
7516 .descr = "dedup: btf_type_tag #5, struct",
7519 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7520 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7521 BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4), /* [3] */
7522 BTF_MEMBER_ENC(NAME_NTH(3), 2, BTF_MEMBER_OFFSET(0, 0)),
7523 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [4] */
7524 BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4), /* [5] */
7525 BTF_MEMBER_ENC(NAME_NTH(3), 4, BTF_MEMBER_OFFSET(0, 0)),
7528 BTF_STR_SEC("\0tag1\0t\0m"),
7532 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7533 BTF_TYPE_TAG_ENC(NAME_NTH(1), 1), /* [2] */
7534 BTF_TYPE_ENC(NAME_NTH(2), BTF_INFO_ENC(BTF_KIND_STRUCT, 1, 1), 4), /* [3] */
7535 BTF_MEMBER_ENC(NAME_NTH(3), 2, BTF_MEMBER_OFFSET(0, 0)),
7538 BTF_STR_SEC("\0tag1\0t\0m"),
7542 .descr = "dedup: enum64, standalone",
7545 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7546 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7547 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7548 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7551 BTF_STR_SEC("\0e1\0e1_val"),
7555 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7556 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7559 BTF_STR_SEC("\0e1\0e1_val"),
7563 .descr = "dedup: enum64, fwd resolution",
7566 /* [1] fwd enum64 'e1' before full enum */
7567 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8),
7568 /* [2] full enum64 'e1' after fwd */
7569 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7570 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7571 /* [3] full enum64 'e2' before fwd */
7572 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7573 BTF_ENUM64_ENC(NAME_NTH(4), 0, 456),
7574 /* [4] fwd enum64 'e2' after full enum */
7575 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8),
7576 /* [5] incompatible full enum64 with different value */
7577 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7578 BTF_ENUM64_ENC(NAME_NTH(2), 0, 321),
7581 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7585 /* [1] full enum64 'e1' */
7586 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7587 BTF_ENUM64_ENC(NAME_NTH(2), 1, 123),
7588 /* [2] full enum64 'e2' */
7589 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7590 BTF_ENUM64_ENC(NAME_NTH(4), 0, 456),
7591 /* [3] incompatible full enum64 with different value */
7592 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7593 BTF_ENUM64_ENC(NAME_NTH(2), 0, 321),
7596 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
7600 .descr = "dedup: enum and enum64, no dedup",
7604 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7605 BTF_ENUM_ENC(NAME_NTH(2), 1),
7606 /* [2] enum64 'e1' */
7607 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 4),
7608 BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7611 BTF_STR_SEC("\0e1\0e1_val"),
7616 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7617 BTF_ENUM_ENC(NAME_NTH(2), 1),
7618 /* [2] enum64 'e1' */
7619 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 4),
7620 BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7623 BTF_STR_SEC("\0e1\0e1_val"),
7627 .descr = "dedup: enum of different size: no dedup",
7631 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7632 BTF_ENUM_ENC(NAME_NTH(2), 1),
7634 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 2),
7635 BTF_ENUM_ENC(NAME_NTH(2), 1),
7638 BTF_STR_SEC("\0e1\0e1_val"),
7643 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7644 BTF_ENUM_ENC(NAME_NTH(2), 1),
7646 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 2),
7647 BTF_ENUM_ENC(NAME_NTH(2), 1),
7650 BTF_STR_SEC("\0e1\0e1_val"),
7654 .descr = "dedup: enum fwd to enum64",
7657 /* [1] enum64 'e1' */
7658 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7659 BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7660 /* [2] enum 'e1' fwd */
7661 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 0), 4),
7662 /* [3] typedef enum 'e1' td */
7663 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 2),
7666 BTF_STR_SEC("\0e1\0e1_val\0td"),
7670 /* [1] enum64 'e1' */
7671 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 1), 8),
7672 BTF_ENUM64_ENC(NAME_NTH(2), 1, 0),
7673 /* [2] typedef enum 'e1' td */
7674 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 1),
7677 BTF_STR_SEC("\0e1\0e1_val\0td"),
7681 .descr = "dedup: enum64 fwd to enum",
7685 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7686 BTF_ENUM_ENC(NAME_NTH(2), 1),
7687 /* [2] enum64 'e1' fwd */
7688 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8),
7689 /* [3] typedef enum 'e1' td */
7690 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 2),
7693 BTF_STR_SEC("\0e1\0e1_val\0td"),
7698 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM, 0, 1), 4),
7699 BTF_ENUM_ENC(NAME_NTH(2), 1),
7700 /* [2] typedef enum 'e1' td */
7701 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), 1),
7704 BTF_STR_SEC("\0e1\0e1_val\0td"),
7708 .descr = "dedup: standalone fwd declaration struct",
7710 * Verify that CU1:foo and CU2:foo would be unified and that
7711 * typedef/ptr would be updated to point to CU1:foo.
7714 * struct foo { int x; };
7718 * typedef struct foo *foo_ptr;
7723 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7724 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7725 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7727 BTF_FWD_ENC(NAME_NTH(1), 0), /* [3] */
7728 BTF_PTR_ENC(3), /* [4] */
7729 BTF_TYPEDEF_ENC(NAME_NTH(3), 4), /* [5] */
7732 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7736 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7737 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7738 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7739 BTF_PTR_ENC(1), /* [3] */
7740 BTF_TYPEDEF_ENC(NAME_NTH(3), 3), /* [4] */
7743 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7747 .descr = "dedup: standalone fwd declaration union",
7749 * Verify that CU1:foo and CU2:foo would be unified and that
7750 * typedef/ptr would be updated to point to CU1:foo.
7751 * Same as "dedup: standalone fwd declaration struct" but for unions.
7754 * union foo { int x; };
7758 * typedef union foo *foo_ptr;
7763 BTF_UNION_ENC(NAME_NTH(1), 1, 4), /* [1] */
7764 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7765 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7767 BTF_FWD_ENC(NAME_TBD, 1), /* [3] */
7768 BTF_PTR_ENC(3), /* [4] */
7769 BTF_TYPEDEF_ENC(NAME_NTH(3), 4), /* [5] */
7772 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7776 BTF_UNION_ENC(NAME_NTH(1), 1, 4), /* [1] */
7777 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7778 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7779 BTF_PTR_ENC(1), /* [3] */
7780 BTF_TYPEDEF_ENC(NAME_NTH(3), 3), /* [4] */
7783 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7787 .descr = "dedup: standalone fwd declaration wrong kind",
7789 * Negative test for btf_dedup_resolve_fwds:
7790 * - CU1:foo is a struct, C2:foo is a union, thus CU2:foo is not deduped;
7791 * - typedef/ptr should remain unchanged as well.
7794 * struct foo { int x; };
7798 * typedef union foo *foo_ptr;
7803 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7804 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7805 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7807 BTF_FWD_ENC(NAME_NTH(3), 1), /* [3] */
7808 BTF_PTR_ENC(3), /* [4] */
7809 BTF_TYPEDEF_ENC(NAME_NTH(3), 4), /* [5] */
7812 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7817 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7818 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7819 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7821 BTF_FWD_ENC(NAME_NTH(3), 1), /* [3] */
7822 BTF_PTR_ENC(3), /* [4] */
7823 BTF_TYPEDEF_ENC(NAME_NTH(3), 4), /* [5] */
7826 BTF_STR_SEC("\0foo\0x\0foo_ptr"),
7830 .descr = "dedup: standalone fwd declaration name conflict",
7832 * Negative test for btf_dedup_resolve_fwds:
7833 * - two candidates for CU2:foo dedup, thus it is unchanged;
7834 * - typedef/ptr should remain unchanged as well.
7837 * struct foo { int x; };
7841 * typedef struct foo *foo_ptr;
7844 * struct foo { int x; int y; };
7849 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7850 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7851 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7853 BTF_FWD_ENC(NAME_NTH(1), 0), /* [3] */
7854 BTF_PTR_ENC(3), /* [4] */
7855 BTF_TYPEDEF_ENC(NAME_NTH(4), 4), /* [5] */
7857 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [6] */
7858 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7859 BTF_MEMBER_ENC(NAME_NTH(3), 2, 0),
7862 BTF_STR_SEC("\0foo\0x\0y\0foo_ptr"),
7867 BTF_STRUCT_ENC(NAME_NTH(1), 1, 4), /* [1] */
7868 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7869 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [2] */
7871 BTF_FWD_ENC(NAME_NTH(1), 0), /* [3] */
7872 BTF_PTR_ENC(3), /* [4] */
7873 BTF_TYPEDEF_ENC(NAME_NTH(4), 4), /* [5] */
7875 BTF_STRUCT_ENC(NAME_NTH(1), 2, 8), /* [6] */
7876 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
7877 BTF_MEMBER_ENC(NAME_NTH(3), 2, 0),
7880 BTF_STR_SEC("\0foo\0x\0y\0foo_ptr"),
7885 static int btf_type_size(const struct btf_type *t)
7887 int base_size = sizeof(struct btf_type);
7888 __u16 vlen = BTF_INFO_VLEN(t->info);
7889 __u16 kind = BTF_INFO_KIND(t->info);
7893 case BTF_KIND_CONST:
7894 case BTF_KIND_VOLATILE:
7895 case BTF_KIND_RESTRICT:
7897 case BTF_KIND_TYPEDEF:
7899 case BTF_KIND_FLOAT:
7900 case BTF_KIND_TYPE_TAG:
7903 return base_size + sizeof(__u32);
7905 return base_size + vlen * sizeof(struct btf_enum);
7906 case BTF_KIND_ENUM64:
7907 return base_size + vlen * sizeof(struct btf_enum64);
7908 case BTF_KIND_ARRAY:
7909 return base_size + sizeof(struct btf_array);
7910 case BTF_KIND_STRUCT:
7911 case BTF_KIND_UNION:
7912 return base_size + vlen * sizeof(struct btf_member);
7913 case BTF_KIND_FUNC_PROTO:
7914 return base_size + vlen * sizeof(struct btf_param);
7916 return base_size + sizeof(struct btf_var);
7917 case BTF_KIND_DATASEC:
7918 return base_size + vlen * sizeof(struct btf_var_secinfo);
7919 case BTF_KIND_DECL_TAG:
7920 return base_size + sizeof(struct btf_decl_tag);
7922 fprintf(stderr, "Unsupported BTF_KIND:%u\n", kind);
7927 static void dump_btf_strings(const char *strs, __u32 len)
7929 const char *cur = strs;
7932 while (cur < strs + len) {
7933 fprintf(stderr, "string #%d: '%s'\n", i, cur);
7934 cur += strlen(cur) + 1;
7939 static void do_test_dedup(unsigned int test_num)
7941 struct btf_dedup_test *test = &dedup_tests[test_num - 1];
7942 __u32 test_nr_types, expect_nr_types, test_btf_size, expect_btf_size;
7943 const struct btf_header *test_hdr, *expect_hdr;
7944 struct btf *test_btf = NULL, *expect_btf = NULL;
7945 const void *test_btf_data, *expect_btf_data;
7946 const char *ret_test_next_str, *ret_expect_next_str;
7947 const char *test_strs, *expect_strs;
7948 const char *test_str_cur;
7949 const char *expect_str_cur, *expect_str_end;
7950 unsigned int raw_btf_size;
7954 if (!test__start_subtest(test->descr))
7957 raw_btf = btf_raw_create(&hdr_tmpl, test->input.raw_types,
7958 test->input.str_sec, test->input.str_sec_size,
7959 &raw_btf_size, &ret_test_next_str);
7963 test_btf = btf__new((__u8 *)raw_btf, raw_btf_size);
7964 err = libbpf_get_error(test_btf);
7966 if (CHECK(err, "invalid test_btf errno:%d", err)) {
7971 raw_btf = btf_raw_create(&hdr_tmpl, test->expect.raw_types,
7972 test->expect.str_sec,
7973 test->expect.str_sec_size,
7974 &raw_btf_size, &ret_expect_next_str);
7977 expect_btf = btf__new((__u8 *)raw_btf, raw_btf_size);
7978 err = libbpf_get_error(expect_btf);
7980 if (CHECK(err, "invalid expect_btf errno:%d", err)) {
7985 test->opts.sz = sizeof(test->opts);
7986 err = btf__dedup(test_btf, &test->opts);
7987 if (CHECK(err, "btf_dedup failed errno:%d", err)) {
7992 test_btf_data = btf__raw_data(test_btf, &test_btf_size);
7993 expect_btf_data = btf__raw_data(expect_btf, &expect_btf_size);
7994 if (CHECK(test_btf_size != expect_btf_size,
7995 "test_btf_size:%u != expect_btf_size:%u",
7996 test_btf_size, expect_btf_size)) {
8001 test_hdr = test_btf_data;
8002 test_strs = test_btf_data + sizeof(*test_hdr) + test_hdr->str_off;
8003 expect_hdr = expect_btf_data;
8004 expect_strs = expect_btf_data + sizeof(*test_hdr) + expect_hdr->str_off;
8005 if (CHECK(test_hdr->str_len != expect_hdr->str_len,
8006 "test_hdr->str_len:%u != expect_hdr->str_len:%u",
8007 test_hdr->str_len, expect_hdr->str_len)) {
8008 fprintf(stderr, "\ntest strings:\n");
8009 dump_btf_strings(test_strs, test_hdr->str_len);
8010 fprintf(stderr, "\nexpected strings:\n");
8011 dump_btf_strings(expect_strs, expect_hdr->str_len);
8016 expect_str_cur = expect_strs;
8017 expect_str_end = expect_strs + expect_hdr->str_len;
8018 while (expect_str_cur < expect_str_end) {
8019 size_t test_len, expect_len;
8022 off = btf__find_str(test_btf, expect_str_cur);
8023 if (CHECK(off < 0, "exp str '%s' not found: %d\n", expect_str_cur, off)) {
8027 test_str_cur = btf__str_by_offset(test_btf, off);
8029 test_len = strlen(test_str_cur);
8030 expect_len = strlen(expect_str_cur);
8031 if (CHECK(test_len != expect_len,
8032 "test_len:%zu != expect_len:%zu "
8033 "(test_str:%s, expect_str:%s)",
8034 test_len, expect_len, test_str_cur, expect_str_cur)) {
8038 if (CHECK(strcmp(test_str_cur, expect_str_cur),
8039 "test_str:%s != expect_str:%s",
8040 test_str_cur, expect_str_cur)) {
8044 expect_str_cur += expect_len + 1;
8047 test_nr_types = btf__type_cnt(test_btf);
8048 expect_nr_types = btf__type_cnt(expect_btf);
8049 if (CHECK(test_nr_types != expect_nr_types,
8050 "test_nr_types:%u != expect_nr_types:%u",
8051 test_nr_types, expect_nr_types)) {
8056 for (i = 1; i < test_nr_types; i++) {
8057 const struct btf_type *test_type, *expect_type;
8058 int test_size, expect_size;
8060 test_type = btf__type_by_id(test_btf, i);
8061 expect_type = btf__type_by_id(expect_btf, i);
8062 test_size = btf_type_size(test_type);
8063 expect_size = btf_type_size(expect_type);
8065 if (CHECK(test_size != expect_size,
8066 "type #%d: test_size:%d != expect_size:%u",
8067 i, test_size, expect_size)) {
8071 if (CHECK(btf_kind(test_type) != btf_kind(expect_type),
8072 "type %d kind: exp %d != got %u\n",
8073 i, btf_kind(expect_type), btf_kind(test_type))) {
8077 if (CHECK(test_type->info != expect_type->info,
8078 "type %d info: exp %d != got %u\n",
8079 i, expect_type->info, test_type->info)) {
8083 if (CHECK(test_type->size != expect_type->size,
8084 "type %d size/type: exp %d != got %u\n",
8085 i, expect_type->size, test_type->size)) {
8092 btf__free(test_btf);
8093 btf__free(expect_btf);
8100 always_log = env.verbosity > VERBOSE_NONE;
8102 for (i = 1; i <= ARRAY_SIZE(raw_tests); i++)
8104 for (i = 1; i <= ARRAY_SIZE(get_info_tests); i++)
8105 do_test_get_info(i);
8106 for (i = 1; i <= ARRAY_SIZE(file_tests); i++)
8108 for (i = 1; i <= ARRAY_SIZE(info_raw_tests); i++)
8109 do_test_info_raw(i);
8110 for (i = 1; i <= ARRAY_SIZE(dedup_tests); i++)