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>
11 #include <sys/resource.h>
22 #include <bpf/libbpf.h>
25 #include "bpf_rlimit.h"
27 #include "../test_btf.h"
28 #include "test_progs.h"
31 #define MAX_SUBPROGS 16
33 static int duration
= 0;
34 static bool always_log
;
37 #define CHECK(condition, format...) _CHECK(condition, "check", duration, format)
39 #define BTF_END_RAW 0xdeadbeef
40 #define NAME_TBD 0xdeadb33f
42 #define NAME_NTH(N) (0xffff0000 | N)
43 #define IS_NAME_NTH(X) ((X & 0xffff0000) == 0xffff0000)
44 #define GET_NAME_NTH_IDX(X) (X & 0x0000ffff)
46 #define MAX_NR_RAW_U32 1024
47 #define BTF_LOG_BUF_SIZE 65535
49 static char btf_log_buf
[BTF_LOG_BUF_SIZE
];
51 static struct btf_header hdr_tmpl
= {
53 .version
= BTF_VERSION
,
54 .hdr_len
= sizeof(struct btf_header
),
57 /* several different mapv kinds(types) supported by pprint */
58 enum pprint_mapv_kind_t
{
59 PPRINT_MAPV_KIND_BASIC
= 0,
60 PPRINT_MAPV_KIND_INT128
,
68 __u32 raw_types
[MAX_NR_RAW_U32
];
70 enum bpf_map_type map_type
;
85 enum pprint_mapv_kind_t mapv_kind
;
88 #define BTF_STR_SEC(str) \
89 .str_sec = str, .str_sec_size = sizeof(str)
91 static struct btf_raw_test raw_tests
[] = {
98 * unsigned long long m;
108 .descr
= "struct test #1",
111 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
112 /* unsigned long long */
113 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
115 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
117 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
118 /* struct A { */ /* [5] */
119 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 6), 180),
120 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
121 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
122 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
123 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
124 BTF_MEMBER_ENC(NAME_TBD
, 6, 384),/* int q[4][8] */
125 BTF_MEMBER_ENC(NAME_TBD
, 7, 1408), /* enum E r */
128 BTF_TYPE_ARRAY_ENC(4, 1, 4), /* [6] */
129 /* enum E */ /* [7] */
130 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), sizeof(int)),
131 BTF_ENUM_ENC(NAME_TBD
, 0),
132 BTF_ENUM_ENC(NAME_TBD
, 1),
135 .str_sec
= "\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1",
136 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0q\0r\0E\0E0\0E1"),
137 .map_type
= BPF_MAP_TYPE_ARRAY
,
138 .map_name
= "struct_test1_map",
139 .key_size
= sizeof(int),
146 /* typedef struct b Struct_B;
151 * const Struct_B o[4];
160 .descr
= "struct test #2",
163 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
164 /* struct b [4] */ /* [2] */
165 BTF_TYPE_ARRAY_ENC(4, 1, 4),
167 /* struct A { */ /* [3] */
168 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 3), 68),
169 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
170 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* struct B n[4] */
171 BTF_MEMBER_ENC(NAME_TBD
, 8, 288),/* const Struct_B o[4];*/
174 /* struct B { */ /* [4] */
175 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 8),
176 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
177 BTF_MEMBER_ENC(NAME_TBD
, 1, 32),/* int n; */
180 /* const int */ /* [5] */
181 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 1),
182 /* typedef struct b Struct_B */ /* [6] */
183 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_TYPEDEF
, 0, 0), 4),
184 /* const Struct_B */ /* [7] */
185 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 6),
186 /* const Struct_B [4] */ /* [8] */
187 BTF_TYPE_ARRAY_ENC(7, 1, 4),
190 .str_sec
= "\0A\0m\0n\0o\0B\0m\0n\0Struct_B",
191 .str_sec_size
= sizeof("\0A\0m\0n\0o\0B\0m\0n\0Struct_B"),
192 .map_type
= BPF_MAP_TYPE_ARRAY
,
193 .map_name
= "struct_test2_map",
194 .key_size
= sizeof(int),
201 .descr
= "struct test #3 Invalid member offset",
204 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
205 /* int64 */ /* [2] */
206 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 64, 8),
208 /* struct A { */ /* [3] */
209 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 16),
210 BTF_MEMBER_ENC(NAME_TBD
, 1, 64), /* int m; */
211 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* int64 n; */
215 .str_sec
= "\0A\0m\0n\0",
216 .str_sec_size
= sizeof("\0A\0m\0n\0"),
217 .map_type
= BPF_MAP_TYPE_ARRAY
,
218 .map_name
= "struct_test3_map",
219 .key_size
= sizeof(int),
224 .btf_load_err
= true,
225 .err_str
= "Invalid member bits_offset",
229 * unsigned long long m;
237 .descr
= "global data test #1",
240 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
241 /* unsigned long long */
242 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
244 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
246 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
247 /* struct A { */ /* [5] */
248 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
249 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
250 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
251 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
252 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
256 .str_sec
= "\0A\0m\0n\0o\0p",
257 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p"),
258 .map_type
= BPF_MAP_TYPE_ARRAY
,
259 .map_name
= "struct_test1_map",
260 .key_size
= sizeof(int),
268 * unsigned long long m;
274 * static struct A t; <- in .bss
277 .descr
= "global data test #2",
280 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
281 /* unsigned long long */
282 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
284 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
286 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
287 /* struct A { */ /* [5] */
288 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
289 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
290 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
291 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
292 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
294 /* static struct A t */
295 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
296 /* .bss section */ /* [7] */
297 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 48),
298 BTF_VAR_SECINFO_ENC(6, 0, 48),
301 .str_sec
= "\0A\0m\0n\0o\0p\0t\0.bss",
302 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
303 .map_type
= BPF_MAP_TYPE_ARRAY
,
305 .key_size
= sizeof(int),
312 .descr
= "global data test #3",
315 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
317 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
318 /* .bss section */ /* [3] */
319 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
320 BTF_VAR_SECINFO_ENC(2, 0, 4),
323 .str_sec
= "\0t\0.bss",
324 .str_sec_size
= sizeof("\0t\0.bss"),
325 .map_type
= BPF_MAP_TYPE_ARRAY
,
327 .key_size
= sizeof(int),
334 .descr
= "global data test #4, unsupported linkage",
337 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
339 BTF_VAR_ENC(NAME_TBD
, 1, 2), /* [2] */
340 /* .bss section */ /* [3] */
341 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
342 BTF_VAR_SECINFO_ENC(2, 0, 4),
345 .str_sec
= "\0t\0.bss",
346 .str_sec_size
= sizeof("\0t\0.bss"),
347 .map_type
= BPF_MAP_TYPE_ARRAY
,
349 .key_size
= sizeof(int),
354 .btf_load_err
= true,
355 .err_str
= "Linkage not supported",
358 .descr
= "global data test #5, invalid var type",
361 BTF_VAR_ENC(NAME_TBD
, 0, 0), /* [1] */
362 /* .bss section */ /* [2] */
363 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
364 BTF_VAR_SECINFO_ENC(1, 0, 4),
367 .str_sec
= "\0t\0.bss",
368 .str_sec_size
= sizeof("\0t\0.bss"),
369 .map_type
= BPF_MAP_TYPE_ARRAY
,
371 .key_size
= sizeof(int),
376 .btf_load_err
= true,
377 .err_str
= "Invalid type_id",
380 .descr
= "global data test #6, invalid var type (fwd type)",
383 BTF_TYPE_ENC(NAME_TBD
,
384 BTF_INFO_ENC(BTF_KIND_FWD
, 1, 0), 0), /* [1] */
385 /* static union A t */
386 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
387 /* .bss section */ /* [3] */
388 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
389 BTF_VAR_SECINFO_ENC(2, 0, 4),
392 .str_sec
= "\0A\0t\0.bss",
393 .str_sec_size
= sizeof("\0A\0t\0.bss"),
394 .map_type
= BPF_MAP_TYPE_ARRAY
,
396 .key_size
= sizeof(int),
401 .btf_load_err
= true,
402 .err_str
= "Invalid type",
405 .descr
= "global data test #7, invalid var type (fwd type)",
408 BTF_TYPE_ENC(NAME_TBD
,
409 BTF_INFO_ENC(BTF_KIND_FWD
, 1, 0), 0), /* [1] */
410 /* static union A t */
411 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
412 /* .bss section */ /* [3] */
413 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
414 BTF_VAR_SECINFO_ENC(1, 0, 4),
417 .str_sec
= "\0A\0t\0.bss",
418 .str_sec_size
= sizeof("\0A\0t\0.bss"),
419 .map_type
= BPF_MAP_TYPE_ARRAY
,
421 .key_size
= sizeof(int),
426 .btf_load_err
= true,
427 .err_str
= "Invalid type",
430 .descr
= "global data test #8, invalid var size",
433 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
434 /* unsigned long long */
435 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
437 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
439 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
440 /* struct A { */ /* [5] */
441 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
442 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
443 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
444 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
445 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
447 /* static struct A t */
448 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
449 /* .bss section */ /* [7] */
450 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 48),
451 BTF_VAR_SECINFO_ENC(6, 0, 47),
454 .str_sec
= "\0A\0m\0n\0o\0p\0t\0.bss",
455 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
456 .map_type
= BPF_MAP_TYPE_ARRAY
,
458 .key_size
= sizeof(int),
463 .btf_load_err
= true,
464 .err_str
= "Invalid size",
467 .descr
= "global data test #9, invalid var size",
470 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
471 /* unsigned long long */
472 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
474 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
476 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
477 /* struct A { */ /* [5] */
478 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
479 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
480 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
481 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
482 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
484 /* static struct A t */
485 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
486 /* .bss section */ /* [7] */
487 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 46),
488 BTF_VAR_SECINFO_ENC(6, 0, 48),
491 .str_sec
= "\0A\0m\0n\0o\0p\0t\0.bss",
492 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
493 .map_type
= BPF_MAP_TYPE_ARRAY
,
495 .key_size
= sizeof(int),
500 .btf_load_err
= true,
501 .err_str
= "Invalid size",
504 .descr
= "global data test #10, invalid var size",
507 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
508 /* unsigned long long */
509 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
511 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
513 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
514 /* struct A { */ /* [5] */
515 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
516 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
517 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
518 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
519 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
521 /* static struct A t */
522 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
523 /* .bss section */ /* [7] */
524 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 46),
525 BTF_VAR_SECINFO_ENC(6, 0, 46),
528 .str_sec
= "\0A\0m\0n\0o\0p\0t\0.bss",
529 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0.bss"),
530 .map_type
= BPF_MAP_TYPE_ARRAY
,
532 .key_size
= sizeof(int),
537 .btf_load_err
= true,
538 .err_str
= "Invalid size",
541 .descr
= "global data test #11, multiple section members",
544 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
545 /* unsigned long long */
546 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
548 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
550 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
551 /* struct A { */ /* [5] */
552 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
553 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
554 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
555 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
556 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
558 /* static struct A t */
559 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
561 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [7] */
562 /* .bss section */ /* [8] */
563 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 2), 62),
564 BTF_VAR_SECINFO_ENC(6, 10, 48),
565 BTF_VAR_SECINFO_ENC(7, 58, 4),
568 .str_sec
= "\0A\0m\0n\0o\0p\0t\0u\0.bss",
569 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
570 .map_type
= BPF_MAP_TYPE_ARRAY
,
572 .key_size
= sizeof(int),
579 .descr
= "global data test #12, invalid offset",
582 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
583 /* unsigned long long */
584 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
586 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
588 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
589 /* struct A { */ /* [5] */
590 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
591 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
592 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
593 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
594 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
596 /* static struct A t */
597 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
599 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [7] */
600 /* .bss section */ /* [8] */
601 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 2), 62),
602 BTF_VAR_SECINFO_ENC(6, 10, 48),
603 BTF_VAR_SECINFO_ENC(7, 60, 4),
606 .str_sec
= "\0A\0m\0n\0o\0p\0t\0u\0.bss",
607 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
608 .map_type
= BPF_MAP_TYPE_ARRAY
,
610 .key_size
= sizeof(int),
615 .btf_load_err
= true,
616 .err_str
= "Invalid offset+size",
619 .descr
= "global data test #13, invalid offset",
622 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
623 /* unsigned long long */
624 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
626 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
628 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
629 /* struct A { */ /* [5] */
630 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
631 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
632 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
633 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
634 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
636 /* static struct A t */
637 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
639 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [7] */
640 /* .bss section */ /* [8] */
641 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 2), 62),
642 BTF_VAR_SECINFO_ENC(6, 10, 48),
643 BTF_VAR_SECINFO_ENC(7, 12, 4),
646 .str_sec
= "\0A\0m\0n\0o\0p\0t\0u\0.bss",
647 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
648 .map_type
= BPF_MAP_TYPE_ARRAY
,
650 .key_size
= sizeof(int),
655 .btf_load_err
= true,
656 .err_str
= "Invalid offset",
659 .descr
= "global data test #14, invalid offset",
662 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
663 /* unsigned long long */
664 BTF_TYPE_INT_ENC(0, 0, 0, 64, 8), /* [2] */
666 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1), /* [3] */
668 BTF_TYPE_ARRAY_ENC(1, 1, 8), /* [4] */
669 /* struct A { */ /* [5] */
670 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 4), 48),
671 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* unsigned long long m;*/
672 BTF_MEMBER_ENC(NAME_TBD
, 1, 64),/* int n; */
673 BTF_MEMBER_ENC(NAME_TBD
, 3, 96),/* char o; */
674 BTF_MEMBER_ENC(NAME_TBD
, 4, 128),/* int p[8] */
676 /* static struct A t */
677 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [6] */
679 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [7] */
680 /* .bss section */ /* [8] */
681 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 2), 62),
682 BTF_VAR_SECINFO_ENC(7, 58, 4),
683 BTF_VAR_SECINFO_ENC(6, 10, 48),
686 .str_sec
= "\0A\0m\0n\0o\0p\0t\0u\0.bss",
687 .str_sec_size
= sizeof("\0A\0m\0n\0o\0p\0t\0u\0.bss"),
688 .map_type
= BPF_MAP_TYPE_ARRAY
,
690 .key_size
= sizeof(int),
695 .btf_load_err
= true,
696 .err_str
= "Invalid offset",
699 .descr
= "global data test #15, not var kind",
702 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
703 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
704 /* .bss section */ /* [3] */
705 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
706 BTF_VAR_SECINFO_ENC(1, 0, 4),
709 .str_sec
= "\0A\0t\0.bss",
710 .str_sec_size
= sizeof("\0A\0t\0.bss"),
711 .map_type
= BPF_MAP_TYPE_ARRAY
,
713 .key_size
= sizeof(int),
718 .btf_load_err
= true,
719 .err_str
= "Not a VAR kind member",
722 .descr
= "global data test #16, invalid var referencing sec",
725 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
726 BTF_VAR_ENC(NAME_TBD
, 5, 0), /* [2] */
727 BTF_VAR_ENC(NAME_TBD
, 2, 0), /* [3] */
728 /* a section */ /* [4] */
729 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
730 BTF_VAR_SECINFO_ENC(3, 0, 4),
731 /* a section */ /* [5] */
732 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
733 BTF_VAR_SECINFO_ENC(6, 0, 4),
734 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [6] */
737 .str_sec
= "\0A\0t\0s\0a\0a",
738 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
739 .map_type
= BPF_MAP_TYPE_ARRAY
,
741 .key_size
= sizeof(int),
746 .btf_load_err
= true,
747 .err_str
= "Invalid type_id",
750 .descr
= "global data test #17, invalid var referencing var",
753 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
754 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [2] */
755 BTF_VAR_ENC(NAME_TBD
, 2, 0), /* [3] */
756 /* a section */ /* [4] */
757 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
758 BTF_VAR_SECINFO_ENC(3, 0, 4),
761 .str_sec
= "\0A\0t\0s\0a\0a",
762 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
763 .map_type
= BPF_MAP_TYPE_ARRAY
,
765 .key_size
= sizeof(int),
770 .btf_load_err
= true,
771 .err_str
= "Invalid type_id",
774 .descr
= "global data test #18, invalid var loop",
777 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
778 BTF_VAR_ENC(NAME_TBD
, 2, 0), /* [2] */
779 /* .bss section */ /* [3] */
780 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
781 BTF_VAR_SECINFO_ENC(2, 0, 4),
784 .str_sec
= "\0A\0t\0aaa",
785 .str_sec_size
= sizeof("\0A\0t\0aaa"),
786 .map_type
= BPF_MAP_TYPE_ARRAY
,
788 .key_size
= sizeof(int),
793 .btf_load_err
= true,
794 .err_str
= "Invalid type_id",
797 .descr
= "global data test #19, invalid var referencing var",
800 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
801 BTF_VAR_ENC(NAME_TBD
, 3, 0), /* [2] */
802 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [3] */
805 .str_sec
= "\0A\0t\0s\0a\0a",
806 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
807 .map_type
= BPF_MAP_TYPE_ARRAY
,
809 .key_size
= sizeof(int),
814 .btf_load_err
= true,
815 .err_str
= "Invalid type_id",
818 .descr
= "global data test #20, invalid ptr referencing var",
821 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
822 /* PTR type_id=3 */ /* [2] */
823 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 3),
824 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [3] */
827 .str_sec
= "\0A\0t\0s\0a\0a",
828 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
829 .map_type
= BPF_MAP_TYPE_ARRAY
,
831 .key_size
= sizeof(int),
836 .btf_load_err
= true,
837 .err_str
= "Invalid type_id",
840 .descr
= "global data test #21, var included in struct",
843 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
844 /* struct A { */ /* [2] */
845 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) * 2),
846 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
847 BTF_MEMBER_ENC(NAME_TBD
, 3, 32),/* VAR type_id=3; */
849 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [3] */
852 .str_sec
= "\0A\0t\0s\0a\0a",
853 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
854 .map_type
= BPF_MAP_TYPE_ARRAY
,
856 .key_size
= sizeof(int),
861 .btf_load_err
= true,
862 .err_str
= "Invalid member",
865 .descr
= "global data test #22, array of var",
868 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
869 BTF_TYPE_ARRAY_ENC(3, 1, 4), /* [2] */
870 BTF_VAR_ENC(NAME_TBD
, 1, 0), /* [3] */
873 .str_sec
= "\0A\0t\0s\0a\0a",
874 .str_sec_size
= sizeof("\0A\0t\0s\0a\0a"),
875 .map_type
= BPF_MAP_TYPE_ARRAY
,
877 .key_size
= sizeof(int),
882 .btf_load_err
= true,
883 .err_str
= "Invalid elem",
885 /* Test member exceeds the size of struct.
893 .descr
= "size check test #1",
896 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
897 /* struct A { */ /* [2] */
898 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) * 2 - 1),
899 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
900 BTF_MEMBER_ENC(NAME_TBD
, 1, 32),/* int n; */
904 .str_sec
= "\0A\0m\0n",
905 .str_sec_size
= sizeof("\0A\0m\0n"),
906 .map_type
= BPF_MAP_TYPE_ARRAY
,
907 .map_name
= "size_check1_map",
908 .key_size
= sizeof(int),
913 .btf_load_err
= true,
914 .err_str
= "Member exceeds struct_size",
917 /* Test member exeeds the size of struct
925 .descr
= "size check test #2",
928 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, sizeof(int)),
929 /* int[2] */ /* [2] */
930 BTF_TYPE_ARRAY_ENC(1, 1, 2),
931 /* struct A { */ /* [3] */
932 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) * 3 - 1),
933 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
934 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* int n[2]; */
938 .str_sec
= "\0A\0m\0n",
939 .str_sec_size
= sizeof("\0A\0m\0n"),
940 .map_type
= BPF_MAP_TYPE_ARRAY
,
941 .map_name
= "size_check2_map",
942 .key_size
= sizeof(int),
947 .btf_load_err
= true,
948 .err_str
= "Member exceeds struct_size",
951 /* Test member exeeds the size of struct
959 .descr
= "size check test #3",
962 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, sizeof(int)),
963 /* void* */ /* [2] */
964 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 0),
965 /* struct A { */ /* [3] */
966 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) + sizeof(void *) - 1),
967 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
968 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* void *n; */
972 .str_sec
= "\0A\0m\0n",
973 .str_sec_size
= sizeof("\0A\0m\0n"),
974 .map_type
= BPF_MAP_TYPE_ARRAY
,
975 .map_name
= "size_check3_map",
976 .key_size
= sizeof(int),
981 .btf_load_err
= true,
982 .err_str
= "Member exceeds struct_size",
985 /* Test member exceeds the size of struct
998 .descr
= "size check test #4",
1001 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, sizeof(int)),
1002 /* enum E { */ /* [2] */
1003 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), sizeof(int)),
1004 BTF_ENUM_ENC(NAME_TBD
, 0),
1005 BTF_ENUM_ENC(NAME_TBD
, 1),
1007 /* struct A { */ /* [3] */
1008 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), sizeof(int) * 2 - 1),
1009 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int m; */
1010 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* enum E n; */
1014 .str_sec
= "\0E\0E0\0E1\0A\0m\0n",
1015 .str_sec_size
= sizeof("\0E\0E0\0E1\0A\0m\0n"),
1016 .map_type
= BPF_MAP_TYPE_ARRAY
,
1017 .map_name
= "size_check4_map",
1018 .key_size
= sizeof(int),
1023 .btf_load_err
= true,
1024 .err_str
= "Member exceeds struct_size",
1027 /* Test member unexceeds the size of struct
1036 * enum E __attribute__((packed)) n;
1040 .descr
= "size check test #5",
1043 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, sizeof(int)),
1044 /* char */ /* [2] */
1045 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 8, 1),
1046 /* enum E { */ /* [3] */
1047 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), 1),
1048 BTF_ENUM_ENC(NAME_TBD
, 0),
1049 BTF_ENUM_ENC(NAME_TBD
, 1),
1051 /* struct A { */ /* [4] */
1052 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 2),
1053 BTF_MEMBER_ENC(NAME_TBD
, 2, 0), /* char m; */
1054 BTF_MEMBER_ENC(NAME_TBD
, 3, 8),/* enum E __attribute__((packed)) n; */
1058 .str_sec
= "\0E\0E0\0E1\0A\0m\0n",
1059 .str_sec_size
= sizeof("\0E\0E0\0E1\0A\0m\0n"),
1060 .map_type
= BPF_MAP_TYPE_ARRAY
,
1061 .map_name
= "size_check5_map",
1062 .key_size
= sizeof(int),
1069 /* typedef const void * const_void_ptr;
1075 .descr
= "void test #1",
1078 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1079 /* const void */ /* [2] */
1080 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1081 /* const void* */ /* [3] */
1082 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 2),
1083 /* typedef const void * const_void_ptr */
1084 BTF_TYPEDEF_ENC(NAME_TBD
, 3), /* [4] */
1085 /* struct A { */ /* [5] */
1086 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), sizeof(void *)),
1087 /* const_void_ptr m; */
1088 BTF_MEMBER_ENC(NAME_TBD
, 4, 0),
1092 .str_sec
= "\0const_void_ptr\0A\0m",
1093 .str_sec_size
= sizeof("\0const_void_ptr\0A\0m"),
1094 .map_type
= BPF_MAP_TYPE_ARRAY
,
1095 .map_name
= "void_test1_map",
1096 .key_size
= sizeof(int),
1097 .value_size
= sizeof(void *),
1108 .descr
= "void test #2",
1111 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1112 /* const void */ /* [2] */
1113 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1114 /* struct A { */ /* [3] */
1115 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 8),
1117 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
1121 .str_sec
= "\0A\0m",
1122 .str_sec_size
= sizeof("\0A\0m"),
1123 .map_type
= BPF_MAP_TYPE_ARRAY
,
1124 .map_name
= "void_test2_map",
1125 .key_size
= sizeof(int),
1126 .value_size
= sizeof(void *),
1130 .btf_load_err
= true,
1131 .err_str
= "Invalid member",
1134 /* typedef const void * const_void_ptr;
1138 .descr
= "void test #3",
1141 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1142 /* const void */ /* [2] */
1143 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1144 /* const void* */ /* [3] */
1145 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 2),
1146 /* typedef const void * const_void_ptr */
1147 BTF_TYPEDEF_ENC(NAME_TBD
, 3), /* [4] */
1148 /* const_void_ptr[4] */
1149 BTF_TYPE_ARRAY_ENC(4, 1, 4), /* [5] */
1152 .str_sec
= "\0const_void_ptr",
1153 .str_sec_size
= sizeof("\0const_void_ptr"),
1154 .map_type
= BPF_MAP_TYPE_ARRAY
,
1155 .map_name
= "void_test3_map",
1156 .key_size
= sizeof(int),
1157 .value_size
= sizeof(void *) * 4,
1165 .descr
= "void test #4",
1168 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1169 /* const void */ /* [2] */
1170 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1171 /* const void[4] */ /* [3] */
1172 BTF_TYPE_ARRAY_ENC(2, 1, 4),
1175 .str_sec
= "\0A\0m",
1176 .str_sec_size
= sizeof("\0A\0m"),
1177 .map_type
= BPF_MAP_TYPE_ARRAY
,
1178 .map_name
= "void_test4_map",
1179 .key_size
= sizeof(int),
1180 .value_size
= sizeof(void *) * 4,
1184 .btf_load_err
= true,
1185 .err_str
= "Invalid elem",
1188 /* Array_A <------------------+
1189 * elem_type == Array_B |
1192 * Array_B <-------- + |
1193 * elem_type == Array A --+
1196 .descr
= "loop test #1",
1199 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1200 /* Array_A */ /* [2] */
1201 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1202 /* Array_B */ /* [3] */
1203 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1207 .str_sec_size
= sizeof(""),
1208 .map_type
= BPF_MAP_TYPE_ARRAY
,
1209 .map_name
= "loop_test1_map",
1210 .key_size
= sizeof(int),
1211 .value_size
= sizeof(sizeof(int) * 8),
1215 .btf_load_err
= true,
1216 .err_str
= "Loop detected",
1219 /* typedef is _before_ the BTF type of Array_A and Array_B
1221 * typedef Array_B int_array;
1223 * Array_A <------------------+
1224 * elem_type == int_array |
1227 * Array_B <-------- + |
1228 * elem_type == Array_A --+
1231 .descr
= "loop test #2",
1234 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1235 /* typedef Array_B int_array */
1236 BTF_TYPEDEF_ENC(1, 4), /* [2] */
1238 BTF_TYPE_ARRAY_ENC(2, 1, 8), /* [3] */
1240 BTF_TYPE_ARRAY_ENC(3, 1, 8), /* [4] */
1243 .str_sec
= "\0int_array\0",
1244 .str_sec_size
= sizeof("\0int_array"),
1245 .map_type
= BPF_MAP_TYPE_ARRAY
,
1246 .map_name
= "loop_test2_map",
1247 .key_size
= sizeof(int),
1248 .value_size
= sizeof(sizeof(int) * 8),
1252 .btf_load_err
= true,
1253 .err_str
= "Loop detected",
1256 /* Array_A <------------------+
1257 * elem_type == Array_B |
1260 * Array_B <-------- + |
1261 * elem_type == Array_A --+
1264 .descr
= "loop test #3",
1267 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1268 /* Array_A */ /* [2] */
1269 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1270 /* Array_B */ /* [3] */
1271 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1275 .str_sec_size
= sizeof(""),
1276 .map_type
= BPF_MAP_TYPE_ARRAY
,
1277 .map_name
= "loop_test3_map",
1278 .key_size
= sizeof(int),
1279 .value_size
= sizeof(sizeof(int) * 8),
1283 .btf_load_err
= true,
1284 .err_str
= "Loop detected",
1287 /* typedef is _between_ the BTF type of Array_A and Array_B
1289 * typedef Array_B int_array;
1291 * Array_A <------------------+
1292 * elem_type == int_array |
1295 * Array_B <-------- + |
1296 * elem_type == Array_A --+
1299 .descr
= "loop test #4",
1302 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1303 /* Array_A */ /* [2] */
1304 BTF_TYPE_ARRAY_ENC(3, 1, 8),
1305 /* typedef Array_B int_array */ /* [3] */
1306 BTF_TYPEDEF_ENC(NAME_TBD
, 4),
1307 /* Array_B */ /* [4] */
1308 BTF_TYPE_ARRAY_ENC(2, 1, 8),
1311 .str_sec
= "\0int_array\0",
1312 .str_sec_size
= sizeof("\0int_array"),
1313 .map_type
= BPF_MAP_TYPE_ARRAY
,
1314 .map_name
= "loop_test4_map",
1315 .key_size
= sizeof(int),
1316 .value_size
= sizeof(sizeof(int) * 8),
1320 .btf_load_err
= true,
1321 .err_str
= "Loop detected",
1324 /* typedef struct B Struct_B
1337 .descr
= "loop test #5",
1340 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1341 /* struct A */ /* [2] */
1342 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 8),
1343 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int x; */
1344 BTF_MEMBER_ENC(NAME_TBD
, 3, 32),/* Struct_B y; */
1345 /* typedef struct B Struct_B */
1346 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
1347 /* struct B */ /* [4] */
1348 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 8),
1349 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int x; */
1350 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* struct A y; */
1353 .str_sec
= "\0A\0x\0y\0Struct_B\0B\0x\0y",
1354 .str_sec_size
= sizeof("\0A\0x\0y\0Struct_B\0B\0x\0y"),
1355 .map_type
= BPF_MAP_TYPE_ARRAY
,
1356 .map_name
= "loop_test5_map",
1357 .key_size
= sizeof(int),
1362 .btf_load_err
= true,
1363 .err_str
= "Loop detected",
1368 * struct A array_a[4];
1372 .descr
= "loop test #6",
1375 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1376 BTF_TYPE_ARRAY_ENC(3, 1, 4), /* [2] */
1377 /* struct A */ /* [3] */
1378 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 2), 8),
1379 BTF_MEMBER_ENC(NAME_TBD
, 1, 0), /* int x; */
1380 BTF_MEMBER_ENC(NAME_TBD
, 2, 32),/* struct A array_a[4]; */
1383 .str_sec
= "\0A\0x\0y",
1384 .str_sec_size
= sizeof("\0A\0x\0y"),
1385 .map_type
= BPF_MAP_TYPE_ARRAY
,
1386 .map_name
= "loop_test6_map",
1387 .key_size
= sizeof(int),
1392 .btf_load_err
= true,
1393 .err_str
= "Loop detected",
1397 .descr
= "loop test #7",
1400 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1401 /* struct A { */ /* [2] */
1402 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), sizeof(void *)),
1403 /* const void *m; */
1404 BTF_MEMBER_ENC(NAME_TBD
, 3, 0),
1405 /* CONST type_id=3 */ /* [3] */
1406 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 4),
1407 /* PTR type_id=2 */ /* [4] */
1408 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 3),
1411 .str_sec
= "\0A\0m",
1412 .str_sec_size
= sizeof("\0A\0m"),
1413 .map_type
= BPF_MAP_TYPE_ARRAY
,
1414 .map_name
= "loop_test7_map",
1415 .key_size
= sizeof(int),
1416 .value_size
= sizeof(void *),
1420 .btf_load_err
= true,
1421 .err_str
= "Loop detected",
1425 .descr
= "loop test #8",
1428 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1429 /* struct A { */ /* [2] */
1430 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), sizeof(void *)),
1431 /* const void *m; */
1432 BTF_MEMBER_ENC(NAME_TBD
, 4, 0),
1433 /* struct B { */ /* [3] */
1434 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), sizeof(void *)),
1435 /* const void *n; */
1436 BTF_MEMBER_ENC(NAME_TBD
, 6, 0),
1437 /* CONST type_id=5 */ /* [4] */
1438 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 5),
1439 /* PTR type_id=6 */ /* [5] */
1440 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 6),
1441 /* CONST type_id=7 */ /* [6] */
1442 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 7),
1443 /* PTR type_id=4 */ /* [7] */
1444 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 4),
1447 .str_sec
= "\0A\0m\0B\0n",
1448 .str_sec_size
= sizeof("\0A\0m\0B\0n"),
1449 .map_type
= BPF_MAP_TYPE_ARRAY
,
1450 .map_name
= "loop_test8_map",
1451 .key_size
= sizeof(int),
1452 .value_size
= sizeof(void *),
1456 .btf_load_err
= true,
1457 .err_str
= "Loop detected",
1461 .descr
= "string section does not end with null",
1464 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1468 .str_sec_size
= sizeof("\0int") - 1,
1469 .map_type
= BPF_MAP_TYPE_ARRAY
,
1470 .map_name
= "hdr_test_map",
1471 .key_size
= sizeof(int),
1472 .value_size
= sizeof(int),
1476 .btf_load_err
= true,
1477 .err_str
= "Invalid string section",
1481 .descr
= "empty string section",
1484 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1489 .map_type
= BPF_MAP_TYPE_ARRAY
,
1490 .map_name
= "hdr_test_map",
1491 .key_size
= sizeof(int),
1492 .value_size
= sizeof(int),
1496 .btf_load_err
= true,
1497 .err_str
= "Invalid string section",
1501 .descr
= "empty type section",
1506 .str_sec_size
= sizeof("\0int"),
1507 .map_type
= BPF_MAP_TYPE_ARRAY
,
1508 .map_name
= "hdr_test_map",
1509 .key_size
= sizeof(int),
1510 .value_size
= sizeof(int),
1514 .btf_load_err
= true,
1515 .err_str
= "No type found",
1519 .descr
= "btf_header test. Longer hdr_len",
1522 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1526 .str_sec_size
= sizeof("\0int"),
1527 .map_type
= BPF_MAP_TYPE_ARRAY
,
1528 .map_name
= "hdr_test_map",
1529 .key_size
= sizeof(int),
1530 .value_size
= sizeof(int),
1534 .btf_load_err
= true,
1536 .err_str
= "Unsupported btf_header",
1540 .descr
= "btf_header test. Gap between hdr and type",
1543 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1547 .str_sec_size
= sizeof("\0int"),
1548 .map_type
= BPF_MAP_TYPE_ARRAY
,
1549 .map_name
= "hdr_test_map",
1550 .key_size
= sizeof(int),
1551 .value_size
= sizeof(int),
1555 .btf_load_err
= true,
1556 .type_off_delta
= 4,
1557 .err_str
= "Unsupported section found",
1561 .descr
= "btf_header test. Gap between type and str",
1564 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1568 .str_sec_size
= sizeof("\0int"),
1569 .map_type
= BPF_MAP_TYPE_ARRAY
,
1570 .map_name
= "hdr_test_map",
1571 .key_size
= sizeof(int),
1572 .value_size
= sizeof(int),
1576 .btf_load_err
= true,
1578 .err_str
= "Unsupported section found",
1582 .descr
= "btf_header test. Overlap between type and str",
1585 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1589 .str_sec_size
= sizeof("\0int"),
1590 .map_type
= BPF_MAP_TYPE_ARRAY
,
1591 .map_name
= "hdr_test_map",
1592 .key_size
= sizeof(int),
1593 .value_size
= sizeof(int),
1597 .btf_load_err
= true,
1598 .str_off_delta
= -4,
1599 .err_str
= "Section overlap found",
1603 .descr
= "btf_header test. Larger BTF size",
1606 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1610 .str_sec_size
= sizeof("\0int"),
1611 .map_type
= BPF_MAP_TYPE_ARRAY
,
1612 .map_name
= "hdr_test_map",
1613 .key_size
= sizeof(int),
1614 .value_size
= sizeof(int),
1618 .btf_load_err
= true,
1619 .str_len_delta
= -4,
1620 .err_str
= "Unsupported section found",
1624 .descr
= "btf_header test. Smaller BTF size",
1627 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
1631 .str_sec_size
= sizeof("\0int"),
1632 .map_type
= BPF_MAP_TYPE_ARRAY
,
1633 .map_name
= "hdr_test_map",
1634 .key_size
= sizeof(int),
1635 .value_size
= sizeof(int),
1639 .btf_load_err
= true,
1641 .err_str
= "Total section length too long",
1645 .descr
= "array test. index_type/elem_type \"int\"",
1648 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1649 /* int[16] */ /* [2] */
1650 BTF_TYPE_ARRAY_ENC(1, 1, 16),
1654 .str_sec_size
= sizeof(""),
1655 .map_type
= BPF_MAP_TYPE_ARRAY
,
1656 .map_name
= "array_test_map",
1657 .key_size
= sizeof(int),
1658 .value_size
= sizeof(int),
1665 .descr
= "array test. index_type/elem_type \"const int\"",
1668 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1669 /* int[16] */ /* [2] */
1670 BTF_TYPE_ARRAY_ENC(3, 3, 16),
1671 /* CONST type_id=1 */ /* [3] */
1672 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 1),
1676 .str_sec_size
= sizeof(""),
1677 .map_type
= BPF_MAP_TYPE_ARRAY
,
1678 .map_name
= "array_test_map",
1679 .key_size
= sizeof(int),
1680 .value_size
= sizeof(int),
1687 .descr
= "array test. index_type \"const int:31\"",
1690 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1691 /* int:31 */ /* [2] */
1692 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 31, 4),
1693 /* int[16] */ /* [3] */
1694 BTF_TYPE_ARRAY_ENC(1, 4, 16),
1695 /* CONST type_id=2 */ /* [4] */
1696 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 2),
1700 .str_sec_size
= sizeof(""),
1701 .map_type
= BPF_MAP_TYPE_ARRAY
,
1702 .map_name
= "array_test_map",
1703 .key_size
= sizeof(int),
1704 .value_size
= sizeof(int),
1708 .btf_load_err
= true,
1709 .err_str
= "Invalid index",
1713 .descr
= "array test. elem_type \"const int:31\"",
1716 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1717 /* int:31 */ /* [2] */
1718 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 31, 4),
1719 /* int[16] */ /* [3] */
1720 BTF_TYPE_ARRAY_ENC(4, 1, 16),
1721 /* CONST type_id=2 */ /* [4] */
1722 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 2),
1726 .str_sec_size
= sizeof(""),
1727 .map_type
= BPF_MAP_TYPE_ARRAY
,
1728 .map_name
= "array_test_map",
1729 .key_size
= sizeof(int),
1730 .value_size
= sizeof(int),
1734 .btf_load_err
= true,
1735 .err_str
= "Invalid array of int",
1739 .descr
= "array test. index_type \"void\"",
1742 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1743 /* int[16] */ /* [2] */
1744 BTF_TYPE_ARRAY_ENC(1, 0, 16),
1748 .str_sec_size
= sizeof(""),
1749 .map_type
= BPF_MAP_TYPE_ARRAY
,
1750 .map_name
= "array_test_map",
1751 .key_size
= sizeof(int),
1752 .value_size
= sizeof(int),
1756 .btf_load_err
= true,
1757 .err_str
= "Invalid index",
1761 .descr
= "array test. index_type \"const void\"",
1764 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1765 /* int[16] */ /* [2] */
1766 BTF_TYPE_ARRAY_ENC(1, 3, 16),
1767 /* CONST type_id=0 (void) */ /* [3] */
1768 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1772 .str_sec_size
= sizeof(""),
1773 .map_type
= BPF_MAP_TYPE_ARRAY
,
1774 .map_name
= "array_test_map",
1775 .key_size
= sizeof(int),
1776 .value_size
= sizeof(int),
1780 .btf_load_err
= true,
1781 .err_str
= "Invalid index",
1785 .descr
= "array test. elem_type \"const void\"",
1788 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1789 /* int[16] */ /* [2] */
1790 BTF_TYPE_ARRAY_ENC(3, 1, 16),
1791 /* CONST type_id=0 (void) */ /* [3] */
1792 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 0),
1796 .str_sec_size
= sizeof(""),
1797 .map_type
= BPF_MAP_TYPE_ARRAY
,
1798 .map_name
= "array_test_map",
1799 .key_size
= sizeof(int),
1800 .value_size
= sizeof(int),
1804 .btf_load_err
= true,
1805 .err_str
= "Invalid elem",
1809 .descr
= "array test. elem_type \"const void *\"",
1812 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1813 /* const void *[16] */ /* [2] */
1814 BTF_TYPE_ARRAY_ENC(3, 1, 16),
1815 /* CONST type_id=4 */ /* [3] */
1816 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 4),
1817 /* void* */ /* [4] */
1818 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 0),
1822 .str_sec_size
= sizeof(""),
1823 .map_type
= BPF_MAP_TYPE_ARRAY
,
1824 .map_name
= "array_test_map",
1825 .key_size
= sizeof(int),
1826 .value_size
= sizeof(int),
1833 .descr
= "array test. index_type \"const void *\"",
1836 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1837 /* const void *[16] */ /* [2] */
1838 BTF_TYPE_ARRAY_ENC(3, 3, 16),
1839 /* CONST type_id=4 */ /* [3] */
1840 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 4),
1841 /* void* */ /* [4] */
1842 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 0),
1846 .str_sec_size
= sizeof(""),
1847 .map_type
= BPF_MAP_TYPE_ARRAY
,
1848 .map_name
= "array_test_map",
1849 .key_size
= sizeof(int),
1850 .value_size
= sizeof(int),
1854 .btf_load_err
= true,
1855 .err_str
= "Invalid index",
1859 .descr
= "array test. t->size != 0\"",
1862 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1863 /* int[16] */ /* [2] */
1864 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY
, 0, 0), 1),
1865 BTF_ARRAY_ENC(1, 1, 16),
1869 .str_sec_size
= sizeof(""),
1870 .map_type
= BPF_MAP_TYPE_ARRAY
,
1871 .map_name
= "array_test_map",
1872 .key_size
= sizeof(int),
1873 .value_size
= sizeof(int),
1877 .btf_load_err
= true,
1878 .err_str
= "size != 0",
1882 .descr
= "int test. invalid int_data",
1884 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT
, 0, 0), 4),
1889 .str_sec_size
= sizeof(""),
1890 .map_type
= BPF_MAP_TYPE_ARRAY
,
1891 .map_name
= "array_test_map",
1892 .key_size
= sizeof(int),
1893 .value_size
= sizeof(int),
1897 .btf_load_err
= true,
1898 .err_str
= "Invalid int_data",
1902 .descr
= "invalid BTF_INFO",
1905 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1906 BTF_TYPE_ENC(0, 0x10000000, 4),
1910 .str_sec_size
= sizeof(""),
1911 .map_type
= BPF_MAP_TYPE_ARRAY
,
1912 .map_name
= "array_test_map",
1913 .key_size
= sizeof(int),
1914 .value_size
= sizeof(int),
1918 .btf_load_err
= true,
1919 .err_str
= "Invalid btf_info",
1923 .descr
= "fwd test. t->type != 0\"",
1926 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
1927 /* fwd type */ /* [2] */
1928 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD
, 0, 0), 1),
1932 .str_sec_size
= sizeof(""),
1933 .map_type
= BPF_MAP_TYPE_ARRAY
,
1934 .map_name
= "fwd_test_map",
1935 .key_size
= sizeof(int),
1936 .value_size
= sizeof(int),
1940 .btf_load_err
= true,
1941 .err_str
= "type != 0",
1945 .descr
= "typedef (invalid name, name_off = 0)",
1947 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1948 BTF_TYPEDEF_ENC(0, 1), /* [2] */
1951 .str_sec
= "\0__int",
1952 .str_sec_size
= sizeof("\0__int"),
1953 .map_type
= BPF_MAP_TYPE_ARRAY
,
1954 .map_name
= "typedef_check_btf",
1955 .key_size
= sizeof(int),
1956 .value_size
= sizeof(int),
1960 .btf_load_err
= true,
1961 .err_str
= "Invalid name",
1965 .descr
= "typedef (invalid name, invalid identifier)",
1967 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1968 BTF_TYPEDEF_ENC(NAME_TBD
, 1), /* [2] */
1971 .str_sec
= "\0__!int",
1972 .str_sec_size
= sizeof("\0__!int"),
1973 .map_type
= BPF_MAP_TYPE_ARRAY
,
1974 .map_name
= "typedef_check_btf",
1975 .key_size
= sizeof(int),
1976 .value_size
= sizeof(int),
1980 .btf_load_err
= true,
1981 .err_str
= "Invalid name",
1985 .descr
= "ptr type (invalid name, name_off <> 0)",
1987 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
1988 BTF_TYPE_ENC(NAME_TBD
,
1989 BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 1), /* [2] */
1992 .str_sec
= "\0__int",
1993 .str_sec_size
= sizeof("\0__int"),
1994 .map_type
= BPF_MAP_TYPE_ARRAY
,
1995 .map_name
= "ptr_type_check_btf",
1996 .key_size
= sizeof(int),
1997 .value_size
= sizeof(int),
2001 .btf_load_err
= true,
2002 .err_str
= "Invalid name",
2006 .descr
= "volatile type (invalid name, name_off <> 0)",
2008 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2009 BTF_TYPE_ENC(NAME_TBD
,
2010 BTF_INFO_ENC(BTF_KIND_VOLATILE
, 0, 0), 1), /* [2] */
2013 .str_sec
= "\0__int",
2014 .str_sec_size
= sizeof("\0__int"),
2015 .map_type
= BPF_MAP_TYPE_ARRAY
,
2016 .map_name
= "volatile_type_check_btf",
2017 .key_size
= sizeof(int),
2018 .value_size
= sizeof(int),
2022 .btf_load_err
= true,
2023 .err_str
= "Invalid name",
2027 .descr
= "const type (invalid name, name_off <> 0)",
2029 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2030 BTF_TYPE_ENC(NAME_TBD
,
2031 BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 1), /* [2] */
2034 .str_sec
= "\0__int",
2035 .str_sec_size
= sizeof("\0__int"),
2036 .map_type
= BPF_MAP_TYPE_ARRAY
,
2037 .map_name
= "const_type_check_btf",
2038 .key_size
= sizeof(int),
2039 .value_size
= sizeof(int),
2043 .btf_load_err
= true,
2044 .err_str
= "Invalid name",
2048 .descr
= "restrict type (invalid name, name_off <> 0)",
2050 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2051 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 0, 0), 1), /* [2] */
2052 BTF_TYPE_ENC(NAME_TBD
,
2053 BTF_INFO_ENC(BTF_KIND_RESTRICT
, 0, 0), 2), /* [3] */
2056 .str_sec
= "\0__int",
2057 .str_sec_size
= sizeof("\0__int"),
2058 .map_type
= BPF_MAP_TYPE_ARRAY
,
2059 .map_name
= "restrict_type_check_btf",
2060 .key_size
= sizeof(int),
2061 .value_size
= sizeof(int),
2065 .btf_load_err
= true,
2066 .err_str
= "Invalid name",
2070 .descr
= "fwd type (invalid name, name_off = 0)",
2072 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2073 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FWD
, 0, 0), 0), /* [2] */
2076 .str_sec
= "\0__skb",
2077 .str_sec_size
= sizeof("\0__skb"),
2078 .map_type
= BPF_MAP_TYPE_ARRAY
,
2079 .map_name
= "fwd_type_check_btf",
2080 .key_size
= sizeof(int),
2081 .value_size
= sizeof(int),
2085 .btf_load_err
= true,
2086 .err_str
= "Invalid name",
2090 .descr
= "fwd type (invalid name, invalid identifier)",
2092 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2093 BTF_TYPE_ENC(NAME_TBD
,
2094 BTF_INFO_ENC(BTF_KIND_FWD
, 0, 0), 0), /* [2] */
2097 .str_sec
= "\0__!skb",
2098 .str_sec_size
= sizeof("\0__!skb"),
2099 .map_type
= BPF_MAP_TYPE_ARRAY
,
2100 .map_name
= "fwd_type_check_btf",
2101 .key_size
= sizeof(int),
2102 .value_size
= sizeof(int),
2106 .btf_load_err
= true,
2107 .err_str
= "Invalid name",
2111 .descr
= "array type (invalid name, name_off <> 0)",
2113 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2114 BTF_TYPE_ENC(NAME_TBD
,
2115 BTF_INFO_ENC(BTF_KIND_ARRAY
, 0, 0), 0), /* [2] */
2116 BTF_ARRAY_ENC(1, 1, 4),
2119 .str_sec
= "\0__skb",
2120 .str_sec_size
= sizeof("\0__skb"),
2121 .map_type
= BPF_MAP_TYPE_ARRAY
,
2122 .map_name
= "array_type_check_btf",
2123 .key_size
= sizeof(int),
2124 .value_size
= sizeof(int),
2128 .btf_load_err
= true,
2129 .err_str
= "Invalid name",
2133 .descr
= "struct type (name_off = 0)",
2135 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2137 BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 4), /* [2] */
2138 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
2142 .str_sec_size
= sizeof("\0A"),
2143 .map_type
= BPF_MAP_TYPE_ARRAY
,
2144 .map_name
= "struct_type_check_btf",
2145 .key_size
= sizeof(int),
2146 .value_size
= sizeof(int),
2153 .descr
= "struct type (invalid name, invalid identifier)",
2155 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2156 BTF_TYPE_ENC(NAME_TBD
,
2157 BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 4), /* [2] */
2158 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
2161 .str_sec
= "\0A!\0B",
2162 .str_sec_size
= sizeof("\0A!\0B"),
2163 .map_type
= BPF_MAP_TYPE_ARRAY
,
2164 .map_name
= "struct_type_check_btf",
2165 .key_size
= sizeof(int),
2166 .value_size
= sizeof(int),
2170 .btf_load_err
= true,
2171 .err_str
= "Invalid name",
2175 .descr
= "struct member (name_off = 0)",
2177 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2179 BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 4), /* [2] */
2180 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
2184 .str_sec_size
= sizeof("\0A"),
2185 .map_type
= BPF_MAP_TYPE_ARRAY
,
2186 .map_name
= "struct_type_check_btf",
2187 .key_size
= sizeof(int),
2188 .value_size
= sizeof(int),
2195 .descr
= "struct member (invalid name, invalid identifier)",
2197 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2198 BTF_TYPE_ENC(NAME_TBD
,
2199 BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 4), /* [2] */
2200 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
2203 .str_sec
= "\0A\0B*",
2204 .str_sec_size
= sizeof("\0A\0B*"),
2205 .map_type
= BPF_MAP_TYPE_ARRAY
,
2206 .map_name
= "struct_type_check_btf",
2207 .key_size
= sizeof(int),
2208 .value_size
= sizeof(int),
2212 .btf_load_err
= true,
2213 .err_str
= "Invalid name",
2217 .descr
= "enum type (name_off = 0)",
2219 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2221 BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1),
2222 sizeof(int)), /* [2] */
2223 BTF_ENUM_ENC(NAME_TBD
, 0),
2226 .str_sec
= "\0A\0B",
2227 .str_sec_size
= sizeof("\0A\0B"),
2228 .map_type
= BPF_MAP_TYPE_ARRAY
,
2229 .map_name
= "enum_type_check_btf",
2230 .key_size
= sizeof(int),
2231 .value_size
= sizeof(int),
2238 .descr
= "enum type (invalid name, invalid identifier)",
2240 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2241 BTF_TYPE_ENC(NAME_TBD
,
2242 BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1),
2243 sizeof(int)), /* [2] */
2244 BTF_ENUM_ENC(NAME_TBD
, 0),
2247 .str_sec
= "\0A!\0B",
2248 .str_sec_size
= sizeof("\0A!\0B"),
2249 .map_type
= BPF_MAP_TYPE_ARRAY
,
2250 .map_name
= "enum_type_check_btf",
2251 .key_size
= sizeof(int),
2252 .value_size
= sizeof(int),
2256 .btf_load_err
= true,
2257 .err_str
= "Invalid name",
2261 .descr
= "enum member (invalid name, name_off = 0)",
2263 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2265 BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1),
2266 sizeof(int)), /* [2] */
2271 .str_sec_size
= sizeof(""),
2272 .map_type
= BPF_MAP_TYPE_ARRAY
,
2273 .map_name
= "enum_type_check_btf",
2274 .key_size
= sizeof(int),
2275 .value_size
= sizeof(int),
2279 .btf_load_err
= true,
2280 .err_str
= "Invalid name",
2284 .descr
= "enum member (invalid name, invalid identifier)",
2286 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2288 BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1),
2289 sizeof(int)), /* [2] */
2290 BTF_ENUM_ENC(NAME_TBD
, 0),
2294 .str_sec_size
= sizeof("\0A!"),
2295 .map_type
= BPF_MAP_TYPE_ARRAY
,
2296 .map_name
= "enum_type_check_btf",
2297 .key_size
= sizeof(int),
2298 .value_size
= sizeof(int),
2302 .btf_load_err
= true,
2303 .err_str
= "Invalid name",
2306 .descr
= "arraymap invalid btf key (a bit field)",
2309 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
2310 /* 32 bit int with 32 bit offset */ /* [2] */
2311 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 32, 32, 8),
2315 .str_sec_size
= sizeof(""),
2316 .map_type
= BPF_MAP_TYPE_ARRAY
,
2317 .map_name
= "array_map_check_btf",
2318 .key_size
= sizeof(int),
2319 .value_size
= sizeof(int),
2323 .map_create_err
= true,
2327 .descr
= "arraymap invalid btf key (!= 32 bits)",
2330 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
2331 /* 16 bit int with 0 bit offset */ /* [2] */
2332 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 16, 2),
2336 .str_sec_size
= sizeof(""),
2337 .map_type
= BPF_MAP_TYPE_ARRAY
,
2338 .map_name
= "array_map_check_btf",
2339 .key_size
= sizeof(int),
2340 .value_size
= sizeof(int),
2344 .map_create_err
= true,
2348 .descr
= "arraymap invalid btf value (too small)",
2351 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
2355 .str_sec_size
= sizeof(""),
2356 .map_type
= BPF_MAP_TYPE_ARRAY
,
2357 .map_name
= "array_map_check_btf",
2358 .key_size
= sizeof(int),
2359 /* btf_value_size < map->value_size */
2360 .value_size
= sizeof(__u64
),
2364 .map_create_err
= true,
2368 .descr
= "arraymap invalid btf value (too big)",
2371 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
2375 .str_sec_size
= sizeof(""),
2376 .map_type
= BPF_MAP_TYPE_ARRAY
,
2377 .map_name
= "array_map_check_btf",
2378 .key_size
= sizeof(int),
2379 /* btf_value_size > map->value_size */
2380 .value_size
= sizeof(__u16
),
2384 .map_create_err
= true,
2388 .descr
= "func proto (int (*)(int, unsigned int))",
2390 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2391 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2392 /* int (*)(int, unsigned int) */
2393 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
2394 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2395 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2399 .str_sec_size
= sizeof(""),
2400 .map_type
= BPF_MAP_TYPE_ARRAY
,
2401 .map_name
= "func_proto_type_check_btf",
2402 .key_size
= sizeof(int),
2403 .value_size
= sizeof(int),
2410 .descr
= "func proto (vararg)",
2412 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2413 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2414 /* void (*)(int, unsigned int, ...) */
2415 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2416 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2417 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2418 BTF_FUNC_PROTO_ARG_ENC(0, 0),
2422 .str_sec_size
= sizeof(""),
2423 .map_type
= BPF_MAP_TYPE_ARRAY
,
2424 .map_name
= "func_proto_type_check_btf",
2425 .key_size
= sizeof(int),
2426 .value_size
= sizeof(int),
2433 .descr
= "func proto (vararg with name)",
2435 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2436 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2437 /* void (*)(int a, unsigned int b, ... c) */
2438 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2439 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2440 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2441 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 0),
2444 .str_sec
= "\0a\0b\0c",
2445 .str_sec_size
= sizeof("\0a\0b\0c"),
2446 .map_type
= BPF_MAP_TYPE_ARRAY
,
2447 .map_name
= "func_proto_type_check_btf",
2448 .key_size
= sizeof(int),
2449 .value_size
= sizeof(int),
2453 .btf_load_err
= true,
2454 .err_str
= "Invalid arg#3",
2458 .descr
= "func proto (arg after vararg)",
2460 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2461 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2462 /* void (*)(int a, ..., unsigned int b) */
2463 BTF_FUNC_PROTO_ENC(0, 3), /* [3] */
2464 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2465 BTF_FUNC_PROTO_ARG_ENC(0, 0),
2466 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2469 .str_sec
= "\0a\0b",
2470 .str_sec_size
= sizeof("\0a\0b"),
2471 .map_type
= BPF_MAP_TYPE_ARRAY
,
2472 .map_name
= "func_proto_type_check_btf",
2473 .key_size
= sizeof(int),
2474 .value_size
= sizeof(int),
2478 .btf_load_err
= true,
2479 .err_str
= "Invalid arg#2",
2483 .descr
= "func proto (CONST=>TYPEDEF=>PTR=>FUNC_PROTO)",
2485 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2486 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2487 /* typedef void (*func_ptr)(int, unsigned int) */
2488 BTF_TYPEDEF_ENC(NAME_TBD
, 5), /* [3] */
2489 /* const func_ptr */
2490 BTF_CONST_ENC(3), /* [4] */
2491 BTF_PTR_ENC(6), /* [5] */
2492 BTF_FUNC_PROTO_ENC(0, 2), /* [6] */
2493 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2494 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2497 .str_sec
= "\0func_ptr",
2498 .str_sec_size
= sizeof("\0func_ptr"),
2499 .map_type
= BPF_MAP_TYPE_ARRAY
,
2500 .map_name
= "func_proto_type_check_btf",
2501 .key_size
= sizeof(int),
2502 .value_size
= sizeof(int),
2509 .descr
= "func proto (TYPEDEF=>FUNC_PROTO)",
2511 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2512 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2513 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
2514 BTF_FUNC_PROTO_ENC(0, 2), /* [4] */
2515 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2516 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2519 .str_sec
= "\0func_typedef",
2520 .str_sec_size
= sizeof("\0func_typedef"),
2521 .map_type
= BPF_MAP_TYPE_ARRAY
,
2522 .map_name
= "func_proto_type_check_btf",
2523 .key_size
= sizeof(int),
2524 .value_size
= sizeof(int),
2531 .descr
= "func proto (btf_resolve(arg))",
2533 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2534 /* void (*)(const void *) */
2535 BTF_FUNC_PROTO_ENC(0, 1), /* [2] */
2536 BTF_FUNC_PROTO_ARG_ENC(0, 3),
2537 BTF_CONST_ENC(4), /* [3] */
2538 BTF_PTR_ENC(0), /* [4] */
2542 .str_sec_size
= sizeof(""),
2543 .map_type
= BPF_MAP_TYPE_ARRAY
,
2544 .map_name
= "func_proto_type_check_btf",
2545 .key_size
= sizeof(int),
2546 .value_size
= sizeof(int),
2553 .descr
= "func proto (Not all arg has name)",
2555 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2556 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2557 /* void (*)(int, unsigned int b) */
2558 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2559 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2560 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2564 .str_sec_size
= sizeof("\0b"),
2565 .map_type
= BPF_MAP_TYPE_ARRAY
,
2566 .map_name
= "func_proto_type_check_btf",
2567 .key_size
= sizeof(int),
2568 .value_size
= sizeof(int),
2575 .descr
= "func proto (Bad arg name_off)",
2577 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2578 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2579 /* void (*)(int a, unsigned int <bad_name_off>) */
2580 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2581 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2582 BTF_FUNC_PROTO_ARG_ENC(0x0fffffff, 2),
2586 .str_sec_size
= sizeof("\0a"),
2587 .map_type
= BPF_MAP_TYPE_ARRAY
,
2588 .map_name
= "func_proto_type_check_btf",
2589 .key_size
= sizeof(int),
2590 .value_size
= sizeof(int),
2594 .btf_load_err
= true,
2595 .err_str
= "Invalid arg#2",
2599 .descr
= "func proto (Bad arg name)",
2601 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2602 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2603 /* void (*)(int a, unsigned int !!!) */
2604 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2605 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2606 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2609 .str_sec
= "\0a\0!!!",
2610 .str_sec_size
= sizeof("\0a\0!!!"),
2611 .map_type
= BPF_MAP_TYPE_ARRAY
,
2612 .map_name
= "func_proto_type_check_btf",
2613 .key_size
= sizeof(int),
2614 .value_size
= sizeof(int),
2618 .btf_load_err
= true,
2619 .err_str
= "Invalid arg#2",
2623 .descr
= "func proto (Invalid return type)",
2625 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2626 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2627 /* <bad_ret_type> (*)(int, unsigned int) */
2628 BTF_FUNC_PROTO_ENC(100, 2), /* [3] */
2629 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2630 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2634 .str_sec_size
= sizeof(""),
2635 .map_type
= BPF_MAP_TYPE_ARRAY
,
2636 .map_name
= "func_proto_type_check_btf",
2637 .key_size
= sizeof(int),
2638 .value_size
= sizeof(int),
2642 .btf_load_err
= true,
2643 .err_str
= "Invalid return type",
2647 .descr
= "func proto (with func name)",
2649 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2650 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2651 /* void func_proto(int, unsigned int) */
2652 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO
, 0, 2), 0), /* [3] */
2653 BTF_FUNC_PROTO_ARG_ENC(0, 1),
2654 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2657 .str_sec
= "\0func_proto",
2658 .str_sec_size
= sizeof("\0func_proto"),
2659 .map_type
= BPF_MAP_TYPE_ARRAY
,
2660 .map_name
= "func_proto_type_check_btf",
2661 .key_size
= sizeof(int),
2662 .value_size
= sizeof(int),
2666 .btf_load_err
= true,
2667 .err_str
= "Invalid name",
2671 .descr
= "func proto (const void arg)",
2673 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2674 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2675 /* void (*)(const void) */
2676 BTF_FUNC_PROTO_ENC(0, 1), /* [3] */
2677 BTF_FUNC_PROTO_ARG_ENC(0, 4),
2678 BTF_CONST_ENC(0), /* [4] */
2682 .str_sec_size
= sizeof(""),
2683 .map_type
= BPF_MAP_TYPE_ARRAY
,
2684 .map_name
= "func_proto_type_check_btf",
2685 .key_size
= sizeof(int),
2686 .value_size
= sizeof(int),
2690 .btf_load_err
= true,
2691 .err_str
= "Invalid arg#1",
2695 .descr
= "func (void func(int a, unsigned int b))",
2697 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2698 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2699 /* void (*)(int a, unsigned int b) */
2700 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2701 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2702 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2703 /* void func(int a, unsigned int b) */
2704 BTF_FUNC_ENC(NAME_TBD
, 3), /* [4] */
2707 .str_sec
= "\0a\0b\0func",
2708 .str_sec_size
= sizeof("\0a\0b\0func"),
2709 .map_type
= BPF_MAP_TYPE_ARRAY
,
2710 .map_name
= "func_type_check_btf",
2711 .key_size
= sizeof(int),
2712 .value_size
= sizeof(int),
2719 .descr
= "func (No func name)",
2721 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2722 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2723 /* void (*)(int a, unsigned int b) */
2724 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2725 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2726 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2727 /* void <no_name>(int a, unsigned int b) */
2728 BTF_FUNC_ENC(0, 3), /* [4] */
2731 .str_sec
= "\0a\0b",
2732 .str_sec_size
= sizeof("\0a\0b"),
2733 .map_type
= BPF_MAP_TYPE_ARRAY
,
2734 .map_name
= "func_type_check_btf",
2735 .key_size
= sizeof(int),
2736 .value_size
= sizeof(int),
2740 .btf_load_err
= true,
2741 .err_str
= "Invalid name",
2745 .descr
= "func (Invalid func name)",
2747 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2748 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2749 /* void (*)(int a, unsigned int b) */
2750 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2751 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2752 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2753 /* void !!!(int a, unsigned int b) */
2754 BTF_FUNC_ENC(NAME_TBD
, 3), /* [4] */
2757 .str_sec
= "\0a\0b\0!!!",
2758 .str_sec_size
= sizeof("\0a\0b\0!!!"),
2759 .map_type
= BPF_MAP_TYPE_ARRAY
,
2760 .map_name
= "func_type_check_btf",
2761 .key_size
= sizeof(int),
2762 .value_size
= sizeof(int),
2766 .btf_load_err
= true,
2767 .err_str
= "Invalid name",
2771 .descr
= "func (Some arg has no name)",
2773 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2774 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2775 /* void (*)(int a, unsigned int) */
2776 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2777 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2778 BTF_FUNC_PROTO_ARG_ENC(0, 2),
2779 /* void func(int a, unsigned int) */
2780 BTF_FUNC_ENC(NAME_TBD
, 3), /* [4] */
2783 .str_sec
= "\0a\0func",
2784 .str_sec_size
= sizeof("\0a\0func"),
2785 .map_type
= BPF_MAP_TYPE_ARRAY
,
2786 .map_name
= "func_type_check_btf",
2787 .key_size
= sizeof(int),
2788 .value_size
= sizeof(int),
2792 .btf_load_err
= true,
2793 .err_str
= "Invalid arg#2",
2797 .descr
= "func (Non zero vlen)",
2799 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2800 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [2] */
2801 /* void (*)(int a, unsigned int b) */
2802 BTF_FUNC_PROTO_ENC(0, 2), /* [3] */
2803 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
2804 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
2805 /* void func(int a, unsigned int b) */
2806 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_FUNC
, 0, 2), 3), /* [4] */
2809 .str_sec
= "\0a\0b\0func",
2810 .str_sec_size
= sizeof("\0a\0b\0func"),
2811 .map_type
= BPF_MAP_TYPE_ARRAY
,
2812 .map_name
= "func_type_check_btf",
2813 .key_size
= sizeof(int),
2814 .value_size
= sizeof(int),
2818 .btf_load_err
= true,
2819 .err_str
= "Invalid func linkage",
2823 .descr
= "func (Not referring to FUNC_PROTO)",
2825 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2826 BTF_FUNC_ENC(NAME_TBD
, 1), /* [2] */
2829 .str_sec
= "\0func",
2830 .str_sec_size
= sizeof("\0func"),
2831 .map_type
= BPF_MAP_TYPE_ARRAY
,
2832 .map_name
= "func_type_check_btf",
2833 .key_size
= sizeof(int),
2834 .value_size
= sizeof(int),
2838 .btf_load_err
= true,
2839 .err_str
= "Invalid type_id",
2843 .descr
= "invalid int kind_flag",
2845 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2846 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_INT
, 1, 0), 4), /* [2] */
2847 BTF_INT_ENC(0, 0, 32),
2851 .map_type
= BPF_MAP_TYPE_ARRAY
,
2852 .map_name
= "int_type_check_btf",
2853 .key_size
= sizeof(int),
2854 .value_size
= sizeof(int),
2858 .btf_load_err
= true,
2859 .err_str
= "Invalid btf_info kind_flag",
2863 .descr
= "invalid ptr kind_flag",
2865 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2866 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR
, 1, 0), 1), /* [2] */
2870 .map_type
= BPF_MAP_TYPE_ARRAY
,
2871 .map_name
= "ptr_type_check_btf",
2872 .key_size
= sizeof(int),
2873 .value_size
= sizeof(int),
2877 .btf_load_err
= true,
2878 .err_str
= "Invalid btf_info kind_flag",
2882 .descr
= "invalid array kind_flag",
2884 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2885 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY
, 1, 0), 0), /* [2] */
2886 BTF_ARRAY_ENC(1, 1, 1),
2890 .map_type
= BPF_MAP_TYPE_ARRAY
,
2891 .map_name
= "array_type_check_btf",
2892 .key_size
= sizeof(int),
2893 .value_size
= sizeof(int),
2897 .btf_load_err
= true,
2898 .err_str
= "Invalid btf_info kind_flag",
2902 .descr
= "invalid enum kind_flag",
2904 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2905 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 1, 1), 4), /* [2] */
2906 BTF_ENUM_ENC(NAME_TBD
, 0),
2910 .map_type
= BPF_MAP_TYPE_ARRAY
,
2911 .map_name
= "enum_type_check_btf",
2912 .key_size
= sizeof(int),
2913 .value_size
= sizeof(int),
2917 .btf_load_err
= true,
2918 .err_str
= "Invalid btf_info kind_flag",
2922 .descr
= "valid fwd kind_flag",
2924 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2925 BTF_TYPE_ENC(NAME_TBD
,
2926 BTF_INFO_ENC(BTF_KIND_FWD
, 1, 0), 0), /* [2] */
2930 .map_type
= BPF_MAP_TYPE_ARRAY
,
2931 .map_name
= "fwd_type_check_btf",
2932 .key_size
= sizeof(int),
2933 .value_size
= sizeof(int),
2940 .descr
= "invalid typedef kind_flag",
2942 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2943 BTF_TYPE_ENC(NAME_TBD
,
2944 BTF_INFO_ENC(BTF_KIND_TYPEDEF
, 1, 0), 1), /* [2] */
2948 .map_type
= BPF_MAP_TYPE_ARRAY
,
2949 .map_name
= "typedef_type_check_btf",
2950 .key_size
= sizeof(int),
2951 .value_size
= sizeof(int),
2955 .btf_load_err
= true,
2956 .err_str
= "Invalid btf_info kind_flag",
2960 .descr
= "invalid volatile kind_flag",
2962 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2963 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE
, 1, 0), 1), /* [2] */
2967 .map_type
= BPF_MAP_TYPE_ARRAY
,
2968 .map_name
= "volatile_type_check_btf",
2969 .key_size
= sizeof(int),
2970 .value_size
= sizeof(int),
2974 .btf_load_err
= true,
2975 .err_str
= "Invalid btf_info kind_flag",
2979 .descr
= "invalid const kind_flag",
2981 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
2982 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 1, 0), 1), /* [2] */
2986 .map_type
= BPF_MAP_TYPE_ARRAY
,
2987 .map_name
= "const_type_check_btf",
2988 .key_size
= sizeof(int),
2989 .value_size
= sizeof(int),
2993 .btf_load_err
= true,
2994 .err_str
= "Invalid btf_info kind_flag",
2998 .descr
= "invalid restrict kind_flag",
3000 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3001 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_RESTRICT
, 1, 0), 1), /* [2] */
3005 .map_type
= BPF_MAP_TYPE_ARRAY
,
3006 .map_name
= "restrict_type_check_btf",
3007 .key_size
= sizeof(int),
3008 .value_size
= sizeof(int),
3012 .btf_load_err
= true,
3013 .err_str
= "Invalid btf_info kind_flag",
3017 .descr
= "invalid func kind_flag",
3019 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3020 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO
, 0, 0), 0), /* [2] */
3021 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_FUNC
, 1, 0), 2), /* [3] */
3025 .map_type
= BPF_MAP_TYPE_ARRAY
,
3026 .map_name
= "func_type_check_btf",
3027 .key_size
= sizeof(int),
3028 .value_size
= sizeof(int),
3032 .btf_load_err
= true,
3033 .err_str
= "Invalid btf_info kind_flag",
3037 .descr
= "invalid func_proto kind_flag",
3039 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3040 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO
, 1, 0), 0), /* [2] */
3044 .map_type
= BPF_MAP_TYPE_ARRAY
,
3045 .map_name
= "func_proto_type_check_btf",
3046 .key_size
= sizeof(int),
3047 .value_size
= sizeof(int),
3051 .btf_load_err
= true,
3052 .err_str
= "Invalid btf_info kind_flag",
3056 .descr
= "valid struct, kind_flag, bitfield_size = 0",
3058 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3059 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 8), /* [2] */
3060 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(0, 0)),
3061 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(0, 32)),
3064 BTF_STR_SEC("\0A\0B"),
3065 .map_type
= BPF_MAP_TYPE_ARRAY
,
3066 .map_name
= "struct_type_check_btf",
3067 .key_size
= sizeof(int),
3068 .value_size
= sizeof(int),
3075 .descr
= "valid struct, kind_flag, int member, bitfield_size != 0",
3077 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3078 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4), /* [2] */
3079 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(4, 0)),
3080 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(4, 4)),
3083 BTF_STR_SEC("\0A\0B"),
3084 .map_type
= BPF_MAP_TYPE_ARRAY
,
3085 .map_name
= "struct_type_check_btf",
3086 .key_size
= sizeof(int),
3087 .value_size
= sizeof(int),
3094 .descr
= "valid union, kind_flag, int member, bitfield_size != 0",
3096 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3097 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 1, 2), 4), /* [2] */
3098 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(4, 0)),
3099 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(4, 0)),
3102 BTF_STR_SEC("\0A\0B"),
3103 .map_type
= BPF_MAP_TYPE_ARRAY
,
3104 .map_name
= "union_type_check_btf",
3105 .key_size
= sizeof(int),
3106 .value_size
= sizeof(int),
3113 .descr
= "valid struct, kind_flag, enum member, bitfield_size != 0",
3115 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3116 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4), /* [2] */
3117 BTF_ENUM_ENC(NAME_TBD
, 0),
3118 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4),/* [3] */
3119 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(4, 0)),
3120 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(4, 4)),
3123 BTF_STR_SEC("\0A\0B\0C"),
3124 .map_type
= BPF_MAP_TYPE_ARRAY
,
3125 .map_name
= "struct_type_check_btf",
3126 .key_size
= sizeof(int),
3127 .value_size
= sizeof(int),
3134 .descr
= "valid union, kind_flag, enum member, bitfield_size != 0",
3136 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3137 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4), /* [2] */
3138 BTF_ENUM_ENC(NAME_TBD
, 0),
3139 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 1, 2), 4), /* [3] */
3140 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(4, 0)),
3141 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(4, 0)),
3144 BTF_STR_SEC("\0A\0B\0C"),
3145 .map_type
= BPF_MAP_TYPE_ARRAY
,
3146 .map_name
= "union_type_check_btf",
3147 .key_size
= sizeof(int),
3148 .value_size
= sizeof(int),
3155 .descr
= "valid struct, 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_STRUCT
, 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, 4)),
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
= "struct_type_check_btf",
3170 .key_size
= sizeof(int),
3171 .value_size
= sizeof(int),
3178 .descr
= "valid union, kind_flag, typedef member, bitfield_size != 0",
3180 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3181 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4), /* [2] */
3182 BTF_ENUM_ENC(NAME_TBD
, 0),
3183 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 1, 2), 4), /* [3] */
3184 BTF_MEMBER_ENC(NAME_TBD
, 4, BTF_MEMBER_OFFSET(4, 0)),
3185 BTF_MEMBER_ENC(NAME_TBD
, 5, BTF_MEMBER_OFFSET(4, 0)),
3186 BTF_TYPEDEF_ENC(NAME_TBD
, 1), /* [4] */
3187 BTF_TYPEDEF_ENC(NAME_TBD
, 2), /* [5] */
3190 BTF_STR_SEC("\0A\0B\0C\0D\0E"),
3191 .map_type
= BPF_MAP_TYPE_ARRAY
,
3192 .map_name
= "union_type_check_btf",
3193 .key_size
= sizeof(int),
3194 .value_size
= sizeof(int),
3201 .descr
= "invalid struct, kind_flag, bitfield_size greater than struct size",
3203 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3204 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4), /* [2] */
3205 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(20, 0)),
3206 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(20, 20)),
3209 BTF_STR_SEC("\0A\0B"),
3210 .map_type
= BPF_MAP_TYPE_ARRAY
,
3211 .map_name
= "struct_type_check_btf",
3212 .key_size
= sizeof(int),
3213 .value_size
= sizeof(int),
3217 .btf_load_err
= true,
3218 .err_str
= "Member exceeds struct_size",
3222 .descr
= "invalid struct, kind_flag, bitfield base_type int not regular",
3224 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3225 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 20, 4), /* [2] */
3226 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4), /* [3] */
3227 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(20, 0)),
3228 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(20, 20)),
3231 BTF_STR_SEC("\0A\0B"),
3232 .map_type
= BPF_MAP_TYPE_ARRAY
,
3233 .map_name
= "struct_type_check_btf",
3234 .key_size
= sizeof(int),
3235 .value_size
= sizeof(int),
3239 .btf_load_err
= true,
3240 .err_str
= "Invalid member base type",
3244 .descr
= "invalid struct, kind_flag, base_type int not regular",
3246 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3247 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 12, 4), /* [2] */
3248 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 4), /* [3] */
3249 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(8, 0)),
3250 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(8, 8)),
3253 BTF_STR_SEC("\0A\0B"),
3254 .map_type
= BPF_MAP_TYPE_ARRAY
,
3255 .map_name
= "struct_type_check_btf",
3256 .key_size
= sizeof(int),
3257 .value_size
= sizeof(int),
3261 .btf_load_err
= true,
3262 .err_str
= "Invalid member base type",
3266 .descr
= "invalid union, kind_flag, bitfield_size greater than struct size",
3268 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3269 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 1, 2), 2), /* [2] */
3270 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(8, 0)),
3271 BTF_MEMBER_ENC(NAME_TBD
, 1, BTF_MEMBER_OFFSET(20, 0)),
3274 BTF_STR_SEC("\0A\0B"),
3275 .map_type
= BPF_MAP_TYPE_ARRAY
,
3276 .map_name
= "union_type_check_btf",
3277 .key_size
= sizeof(int),
3278 .value_size
= sizeof(int),
3282 .btf_load_err
= true,
3283 .err_str
= "Member exceeds struct_size",
3287 .descr
= "invalid struct, kind_flag, int member, bitfield_size = 0, wrong byte alignment",
3289 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3290 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [2] */
3291 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 12), /* [3] */
3292 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 0)),
3293 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 36)),
3296 BTF_STR_SEC("\0A\0B"),
3297 .map_type
= BPF_MAP_TYPE_ARRAY
,
3298 .map_name
= "struct_type_check_btf",
3299 .key_size
= sizeof(int),
3300 .value_size
= sizeof(int),
3304 .btf_load_err
= true,
3305 .err_str
= "Invalid member offset",
3309 .descr
= "invalid struct, kind_flag, enum member, bitfield_size = 0, wrong byte alignment",
3311 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3312 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [2] */
3313 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4), /* [2] */
3314 BTF_ENUM_ENC(NAME_TBD
, 0),
3315 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 2), 12), /* [3] */
3316 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 0)),
3317 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 36)),
3320 BTF_STR_SEC("\0A\0B\0C"),
3321 .map_type
= BPF_MAP_TYPE_ARRAY
,
3322 .map_name
= "struct_type_check_btf",
3323 .key_size
= sizeof(int),
3324 .value_size
= sizeof(int),
3328 .btf_load_err
= true,
3329 .err_str
= "Invalid member offset",
3333 .descr
= "128-bit int",
3335 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3336 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 128, 16), /* [2] */
3340 .map_type
= BPF_MAP_TYPE_ARRAY
,
3341 .map_name
= "int_type_check_btf",
3342 .key_size
= sizeof(int),
3343 .value_size
= sizeof(int),
3350 .descr
= "struct, 128-bit int member",
3352 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3353 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 128, 16), /* [2] */
3354 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 16), /* [3] */
3355 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3359 .map_type
= BPF_MAP_TYPE_ARRAY
,
3360 .map_name
= "struct_type_check_btf",
3361 .key_size
= sizeof(int),
3362 .value_size
= sizeof(int),
3369 .descr
= "struct, 120-bit int member bitfield",
3371 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3372 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 120, 16), /* [2] */
3373 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 1), 16), /* [3] */
3374 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3378 .map_type
= BPF_MAP_TYPE_ARRAY
,
3379 .map_name
= "struct_type_check_btf",
3380 .key_size
= sizeof(int),
3381 .value_size
= sizeof(int),
3388 .descr
= "struct, kind_flag, 128-bit int member",
3390 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3391 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 128, 16), /* [2] */
3392 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 1), 16), /* [3] */
3393 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 0)),
3397 .map_type
= BPF_MAP_TYPE_ARRAY
,
3398 .map_name
= "struct_type_check_btf",
3399 .key_size
= sizeof(int),
3400 .value_size
= sizeof(int),
3407 .descr
= "struct, kind_flag, 120-bit int member bitfield",
3409 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
3410 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 128, 16), /* [2] */
3411 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 1), 16), /* [3] */
3412 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(120, 0)),
3416 .map_type
= BPF_MAP_TYPE_ARRAY
,
3417 .map_name
= "struct_type_check_btf",
3418 .key_size
= sizeof(int),
3419 .value_size
= sizeof(int),
3425 * typedef int arr_t[16];
3431 .descr
= "struct->ptr->typedef->array->int size resolution",
3433 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [1] */
3434 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3435 BTF_PTR_ENC(3), /* [2] */
3436 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
3437 BTF_TYPE_ARRAY_ENC(5, 5, 16), /* [4] */
3438 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [5] */
3441 BTF_STR_SEC("\0s\0a\0arr_t"),
3442 .map_type
= BPF_MAP_TYPE_ARRAY
,
3443 .map_name
= "ptr_mod_chain_size_resolve_map",
3444 .key_size
= sizeof(int),
3445 .value_size
= sizeof(int) * 16,
3446 .key_type_id
= 5 /* int */,
3447 .value_type_id
= 3 /* arr_t */,
3451 * typedef int arr_t[16][8][4];
3457 .descr
= "struct->ptr->typedef->multi-array->int size resolution",
3459 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [1] */
3460 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3461 BTF_PTR_ENC(3), /* [2] */
3462 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
3463 BTF_TYPE_ARRAY_ENC(5, 7, 16), /* [4] */
3464 BTF_TYPE_ARRAY_ENC(6, 7, 8), /* [5] */
3465 BTF_TYPE_ARRAY_ENC(7, 7, 4), /* [6] */
3466 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [7] */
3469 BTF_STR_SEC("\0s\0a\0arr_t"),
3470 .map_type
= BPF_MAP_TYPE_ARRAY
,
3471 .map_name
= "multi_arr_size_resolve_map",
3472 .key_size
= sizeof(int),
3473 .value_size
= sizeof(int) * 16 * 8 * 4,
3474 .key_type_id
= 7 /* int */,
3475 .value_type_id
= 3 /* arr_t */,
3479 * typedef int int_t;
3480 * typedef int_t arr3_t[4];
3481 * typedef arr3_t arr2_t[8];
3482 * typedef arr2_t arr1_t[16];
3488 .descr
= "typedef/multi-arr mix size resolution",
3490 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [1] */
3491 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
3492 BTF_PTR_ENC(3), /* [2] */
3493 BTF_TYPEDEF_ENC(NAME_TBD
, 4), /* [3] */
3494 BTF_TYPE_ARRAY_ENC(5, 10, 16), /* [4] */
3495 BTF_TYPEDEF_ENC(NAME_TBD
, 6), /* [5] */
3496 BTF_TYPE_ARRAY_ENC(7, 10, 8), /* [6] */
3497 BTF_TYPEDEF_ENC(NAME_TBD
, 8), /* [7] */
3498 BTF_TYPE_ARRAY_ENC(9, 10, 4), /* [8] */
3499 BTF_TYPEDEF_ENC(NAME_TBD
, 10), /* [9] */
3500 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [10] */
3503 BTF_STR_SEC("\0s\0a\0arr1_t\0arr2_t\0arr3_t\0int_t"),
3504 .map_type
= BPF_MAP_TYPE_ARRAY
,
3505 .map_name
= "typedef_arra_mix_size_resolve_map",
3506 .key_size
= sizeof(int),
3507 .value_size
= sizeof(int) * 16 * 8 * 4,
3508 .key_type_id
= 10 /* int */,
3509 .value_type_id
= 3 /* arr_t */,
3513 }; /* struct btf_raw_test raw_tests[] */
3515 static const char *get_next_str(const char *start
, const char *end
)
3517 return start
< end
- 1 ? start
+ 1 : NULL
;
3520 static int get_raw_sec_size(const __u32
*raw_types
)
3524 for (i
= MAX_NR_RAW_U32
- 1;
3525 i
>= 0 && raw_types
[i
] != BTF_END_RAW
;
3529 return i
< 0 ? i
: i
* sizeof(raw_types
[0]);
3532 static void *btf_raw_create(const struct btf_header
*hdr
,
3533 const __u32
*raw_types
,
3535 unsigned int str_sec_size
,
3536 unsigned int *btf_size
,
3537 const char **ret_next_str
)
3539 const char *next_str
= str
, *end_str
= str
+ str_sec_size
;
3540 const char **strs_idx
= NULL
, **tmp_strs_idx
;
3541 int strs_cap
= 0, strs_cnt
= 0, next_str_idx
= 0;
3542 unsigned int size_needed
, offset
;
3543 struct btf_header
*ret_hdr
;
3544 int i
, type_sec_size
, err
= 0;
3545 uint32_t *ret_types
;
3546 void *raw_btf
= NULL
;
3548 type_sec_size
= get_raw_sec_size(raw_types
);
3549 if (CHECK(type_sec_size
< 0, "Cannot get nr_raw_types"))
3552 size_needed
= sizeof(*hdr
) + type_sec_size
+ str_sec_size
;
3553 raw_btf
= malloc(size_needed
);
3554 if (CHECK(!raw_btf
, "Cannot allocate memory for raw_btf"))
3558 memcpy(raw_btf
, hdr
, sizeof(*hdr
));
3559 offset
= sizeof(*hdr
);
3562 while ((next_str
= get_next_str(next_str
, end_str
))) {
3563 if (strs_cnt
== strs_cap
) {
3564 strs_cap
+= max(16, strs_cap
/ 2);
3565 tmp_strs_idx
= realloc(strs_idx
,
3566 sizeof(*strs_idx
) * strs_cap
);
3567 if (CHECK(!tmp_strs_idx
,
3568 "Cannot allocate memory for strs_idx")) {
3572 strs_idx
= tmp_strs_idx
;
3574 strs_idx
[strs_cnt
++] = next_str
;
3575 next_str
+= strlen(next_str
);
3578 /* Copy type section */
3579 ret_types
= raw_btf
+ offset
;
3580 for (i
= 0; i
< type_sec_size
/ sizeof(raw_types
[0]); i
++) {
3581 if (raw_types
[i
] == NAME_TBD
) {
3582 if (CHECK(next_str_idx
== strs_cnt
,
3583 "Error in getting next_str #%d",
3588 ret_types
[i
] = strs_idx
[next_str_idx
++] - str
;
3589 } else if (IS_NAME_NTH(raw_types
[i
])) {
3590 int idx
= GET_NAME_NTH_IDX(raw_types
[i
]);
3592 if (CHECK(idx
<= 0 || idx
> strs_cnt
,
3593 "Error getting string #%d, strs_cnt:%d",
3598 ret_types
[i
] = strs_idx
[idx
-1] - str
;
3600 ret_types
[i
] = raw_types
[i
];
3603 offset
+= type_sec_size
;
3605 /* Copy string section */
3606 memcpy(raw_btf
+ offset
, str
, str_sec_size
);
3608 ret_hdr
= (struct btf_header
*)raw_btf
;
3609 ret_hdr
->type_len
= type_sec_size
;
3610 ret_hdr
->str_off
= type_sec_size
;
3611 ret_hdr
->str_len
= str_sec_size
;
3613 *btf_size
= size_needed
;
3616 next_str_idx
< strs_cnt
? strs_idx
[next_str_idx
] : NULL
;
3629 static void do_test_raw(unsigned int test_num
)
3631 struct btf_raw_test
*test
= &raw_tests
[test_num
- 1];
3632 struct bpf_create_map_attr create_attr
= {};
3633 int map_fd
= -1, btf_fd
= -1;
3634 unsigned int raw_btf_size
;
3635 struct btf_header
*hdr
;
3639 if (!test__start_subtest(test
->descr
))
3642 raw_btf
= btf_raw_create(&hdr_tmpl
,
3646 &raw_btf_size
, NULL
);
3652 hdr
->hdr_len
= (int)hdr
->hdr_len
+ test
->hdr_len_delta
;
3653 hdr
->type_off
= (int)hdr
->type_off
+ test
->type_off_delta
;
3654 hdr
->str_off
= (int)hdr
->str_off
+ test
->str_off_delta
;
3655 hdr
->str_len
= (int)hdr
->str_len
+ test
->str_len_delta
;
3657 *btf_log_buf
= '\0';
3658 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
3659 btf_log_buf
, BTF_LOG_BUF_SIZE
,
3663 err
= ((btf_fd
== -1) != test
->btf_load_err
);
3664 if (CHECK(err
, "btf_fd:%d test->btf_load_err:%u",
3665 btf_fd
, test
->btf_load_err
) ||
3666 CHECK(test
->err_str
&& !strstr(btf_log_buf
, test
->err_str
),
3667 "expected err_str:%s", test
->err_str
)) {
3672 if (err
|| btf_fd
== -1)
3675 create_attr
.name
= test
->map_name
;
3676 create_attr
.map_type
= test
->map_type
;
3677 create_attr
.key_size
= test
->key_size
;
3678 create_attr
.value_size
= test
->value_size
;
3679 create_attr
.max_entries
= test
->max_entries
;
3680 create_attr
.btf_fd
= btf_fd
;
3681 create_attr
.btf_key_type_id
= test
->key_type_id
;
3682 create_attr
.btf_value_type_id
= test
->value_type_id
;
3684 map_fd
= bpf_create_map_xattr(&create_attr
);
3686 err
= ((map_fd
== -1) != test
->map_create_err
);
3687 CHECK(err
, "map_fd:%d test->map_create_err:%u",
3688 map_fd
, test
->map_create_err
);
3691 if (*btf_log_buf
&& (err
|| always_log
))
3692 fprintf(stderr
, "\n%s", btf_log_buf
);
3699 struct btf_get_info_test
{
3701 const char *str_sec
;
3702 __u32 raw_types
[MAX_NR_RAW_U32
];
3705 int (*special_test
)(unsigned int test_num
);
3708 static int test_big_btf_info(unsigned int test_num
);
3709 static int test_btf_id(unsigned int test_num
);
3711 const struct btf_get_info_test get_info_tests
[] = {
3713 .descr
= "== raw_btf_size+1",
3716 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
3720 .str_sec_size
= sizeof(""),
3721 .btf_size_delta
= 1,
3724 .descr
= "== raw_btf_size-3",
3727 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
3731 .str_sec_size
= sizeof(""),
3732 .btf_size_delta
= -3,
3735 .descr
= "Large bpf_btf_info",
3738 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
3742 .str_sec_size
= sizeof(""),
3743 .special_test
= test_big_btf_info
,
3749 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4),
3750 /* unsigned int */ /* [2] */
3751 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4),
3755 .str_sec_size
= sizeof(""),
3756 .special_test
= test_btf_id
,
3760 static int test_big_btf_info(unsigned int test_num
)
3762 const struct btf_get_info_test
*test
= &get_info_tests
[test_num
- 1];
3763 uint8_t *raw_btf
= NULL
, *user_btf
= NULL
;
3764 unsigned int raw_btf_size
;
3766 struct bpf_btf_info info
;
3769 struct bpf_btf_info
*info
;
3770 int btf_fd
= -1, err
;
3773 raw_btf
= btf_raw_create(&hdr_tmpl
,
3777 &raw_btf_size
, NULL
);
3782 *btf_log_buf
= '\0';
3784 user_btf
= malloc(raw_btf_size
);
3785 if (CHECK(!user_btf
, "!user_btf")) {
3790 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
3791 btf_log_buf
, BTF_LOG_BUF_SIZE
,
3793 if (CHECK(btf_fd
== -1, "errno:%d", errno
)) {
3799 * GET_INFO should error out if the userspace info
3800 * has non zero tailing bytes.
3802 info
= &info_garbage
.info
;
3803 memset(info
, 0, sizeof(*info
));
3804 info_garbage
.garbage
= 0xdeadbeef;
3805 info_len
= sizeof(info_garbage
);
3806 info
->btf
= ptr_to_u64(user_btf
);
3807 info
->btf_size
= raw_btf_size
;
3809 err
= bpf_obj_get_info_by_fd(btf_fd
, info
, &info_len
);
3810 if (CHECK(!err
, "!err")) {
3816 * GET_INFO should succeed even info_len is larger than
3817 * the kernel supported as long as tailing bytes are zero.
3818 * The kernel supported info len should also be returned
3821 info_garbage
.garbage
= 0;
3822 err
= bpf_obj_get_info_by_fd(btf_fd
, info
, &info_len
);
3823 if (CHECK(err
|| info_len
!= sizeof(*info
),
3824 "err:%d errno:%d info_len:%u sizeof(*info):%zu",
3825 err
, errno
, info_len
, sizeof(*info
))) {
3830 fprintf(stderr
, "OK");
3833 if (*btf_log_buf
&& (err
|| always_log
))
3834 fprintf(stderr
, "\n%s", btf_log_buf
);
3845 static int test_btf_id(unsigned int test_num
)
3847 const struct btf_get_info_test
*test
= &get_info_tests
[test_num
- 1];
3848 struct bpf_create_map_attr create_attr
= {};
3849 uint8_t *raw_btf
= NULL
, *user_btf
[2] = {};
3850 int btf_fd
[2] = {-1, -1}, map_fd
= -1;
3851 struct bpf_map_info map_info
= {};
3852 struct bpf_btf_info info
[2] = {};
3853 unsigned int raw_btf_size
;
3857 raw_btf
= btf_raw_create(&hdr_tmpl
,
3861 &raw_btf_size
, NULL
);
3866 *btf_log_buf
= '\0';
3868 for (i
= 0; i
< 2; i
++) {
3869 user_btf
[i
] = malloc(raw_btf_size
);
3870 if (CHECK(!user_btf
[i
], "!user_btf[%d]", i
)) {
3874 info
[i
].btf
= ptr_to_u64(user_btf
[i
]);
3875 info
[i
].btf_size
= raw_btf_size
;
3878 btf_fd
[0] = bpf_load_btf(raw_btf
, raw_btf_size
,
3879 btf_log_buf
, BTF_LOG_BUF_SIZE
,
3881 if (CHECK(btf_fd
[0] == -1, "errno:%d", errno
)) {
3886 /* Test BPF_OBJ_GET_INFO_BY_ID on btf_id */
3887 info_len
= sizeof(info
[0]);
3888 err
= bpf_obj_get_info_by_fd(btf_fd
[0], &info
[0], &info_len
);
3889 if (CHECK(err
, "errno:%d", errno
)) {
3894 btf_fd
[1] = bpf_btf_get_fd_by_id(info
[0].id
);
3895 if (CHECK(btf_fd
[1] == -1, "errno:%d", errno
)) {
3901 err
= bpf_obj_get_info_by_fd(btf_fd
[1], &info
[1], &info_len
);
3902 if (CHECK(err
|| info
[0].id
!= info
[1].id
||
3903 info
[0].btf_size
!= info
[1].btf_size
||
3904 (ret
= memcmp(user_btf
[0], user_btf
[1], info
[0].btf_size
)),
3905 "err:%d errno:%d id0:%u id1:%u btf_size0:%u btf_size1:%u memcmp:%d",
3906 err
, errno
, info
[0].id
, info
[1].id
,
3907 info
[0].btf_size
, info
[1].btf_size
, ret
)) {
3912 /* Test btf members in struct bpf_map_info */
3913 create_attr
.name
= "test_btf_id";
3914 create_attr
.map_type
= BPF_MAP_TYPE_ARRAY
;
3915 create_attr
.key_size
= sizeof(int);
3916 create_attr
.value_size
= sizeof(unsigned int);
3917 create_attr
.max_entries
= 4;
3918 create_attr
.btf_fd
= btf_fd
[0];
3919 create_attr
.btf_key_type_id
= 1;
3920 create_attr
.btf_value_type_id
= 2;
3922 map_fd
= bpf_create_map_xattr(&create_attr
);
3923 if (CHECK(map_fd
== -1, "errno:%d", errno
)) {
3928 info_len
= sizeof(map_info
);
3929 err
= bpf_obj_get_info_by_fd(map_fd
, &map_info
, &info_len
);
3930 if (CHECK(err
|| map_info
.btf_id
!= info
[0].id
||
3931 map_info
.btf_key_type_id
!= 1 || map_info
.btf_value_type_id
!= 2,
3932 "err:%d errno:%d info.id:%u btf_id:%u btf_key_type_id:%u btf_value_type_id:%u",
3933 err
, errno
, info
[0].id
, map_info
.btf_id
, map_info
.btf_key_type_id
,
3934 map_info
.btf_value_type_id
)) {
3939 for (i
= 0; i
< 2; i
++) {
3944 /* Test BTF ID is removed from the kernel */
3945 btf_fd
[0] = bpf_btf_get_fd_by_id(map_info
.btf_id
);
3946 if (CHECK(btf_fd
[0] == -1, "errno:%d", errno
)) {
3953 /* The map holds the last ref to BTF and its btf_id */
3956 btf_fd
[0] = bpf_btf_get_fd_by_id(map_info
.btf_id
);
3957 if (CHECK(btf_fd
[0] != -1, "BTF lingers")) {
3962 fprintf(stderr
, "OK");
3965 if (*btf_log_buf
&& (err
|| always_log
))
3966 fprintf(stderr
, "\n%s", btf_log_buf
);
3971 for (i
= 0; i
< 2; i
++) {
3973 if (btf_fd
[i
] != -1)
3980 static void do_test_get_info(unsigned int test_num
)
3982 const struct btf_get_info_test
*test
= &get_info_tests
[test_num
- 1];
3983 unsigned int raw_btf_size
, user_btf_size
, expected_nbytes
;
3984 uint8_t *raw_btf
= NULL
, *user_btf
= NULL
;
3985 struct bpf_btf_info info
= {};
3986 int btf_fd
= -1, err
, ret
;
3989 if (!test__start_subtest(test
->descr
))
3992 if (test
->special_test
) {
3993 err
= test
->special_test(test_num
);
3994 if (CHECK(err
, "failed: %d\n", err
))
3998 raw_btf
= btf_raw_create(&hdr_tmpl
,
4002 &raw_btf_size
, NULL
);
4007 *btf_log_buf
= '\0';
4009 user_btf
= malloc(raw_btf_size
);
4010 if (CHECK(!user_btf
, "!user_btf")) {
4015 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
4016 btf_log_buf
, BTF_LOG_BUF_SIZE
,
4018 if (CHECK(btf_fd
== -1, "errno:%d", errno
)) {
4023 user_btf_size
= (int)raw_btf_size
+ test
->btf_size_delta
;
4024 expected_nbytes
= min(raw_btf_size
, user_btf_size
);
4025 if (raw_btf_size
> expected_nbytes
)
4026 memset(user_btf
+ expected_nbytes
, 0xff,
4027 raw_btf_size
- expected_nbytes
);
4029 info_len
= sizeof(info
);
4030 info
.btf
= ptr_to_u64(user_btf
);
4031 info
.btf_size
= user_btf_size
;
4034 err
= bpf_obj_get_info_by_fd(btf_fd
, &info
, &info_len
);
4035 if (CHECK(err
|| !info
.id
|| info_len
!= sizeof(info
) ||
4036 info
.btf_size
!= raw_btf_size
||
4037 (ret
= memcmp(raw_btf
, user_btf
, expected_nbytes
)),
4038 "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",
4039 err
, errno
, info
.id
, info_len
, sizeof(info
),
4040 raw_btf_size
, info
.btf_size
, expected_nbytes
, ret
)) {
4045 while (expected_nbytes
< raw_btf_size
) {
4046 fprintf(stderr
, "%u...", expected_nbytes
);
4047 if (CHECK(user_btf
[expected_nbytes
++] != 0xff,
4048 "user_btf[%u]:%x != 0xff", expected_nbytes
- 1,
4049 user_btf
[expected_nbytes
- 1])) {
4055 fprintf(stderr
, "OK");
4058 if (*btf_log_buf
&& (err
|| always_log
))
4059 fprintf(stderr
, "\n%s", btf_log_buf
);
4068 struct btf_file_test
{
4070 bool btf_kv_notfound
;
4073 static struct btf_file_test file_tests
[] = {
4074 { .file
= "test_btf_haskv.o", },
4075 { .file
= "test_btf_newkv.o", },
4076 { .file
= "test_btf_nokv.o", .btf_kv_notfound
= true, },
4079 static void do_test_file(unsigned int test_num
)
4081 const struct btf_file_test
*test
= &file_tests
[test_num
- 1];
4082 const char *expected_fnames
[] = {"_dummy_tracepoint",
4083 "test_long_fname_1",
4084 "test_long_fname_2"};
4085 struct btf_ext
*btf_ext
= NULL
;
4086 struct bpf_prog_info info
= {};
4087 struct bpf_object
*obj
= NULL
;
4088 struct bpf_func_info
*finfo
;
4089 struct bpf_program
*prog
;
4090 __u32 info_len
, rec_size
;
4091 bool has_btf_ext
= false;
4092 struct btf
*btf
= NULL
;
4093 void *func_info
= NULL
;
4094 struct bpf_map
*map
;
4095 int i
, err
, prog_fd
;
4097 if (!test__start_subtest(test
->file
))
4100 btf
= btf__parse_elf(test
->file
, &btf_ext
);
4102 if (PTR_ERR(btf
) == -ENOENT
) {
4103 printf("%s:SKIP: No ELF %s found", __func__
, BTF_ELF_SEC
);
4111 has_btf_ext
= btf_ext
!= NULL
;
4112 btf_ext__free(btf_ext
);
4114 obj
= bpf_object__open(test
->file
);
4115 if (CHECK(IS_ERR(obj
), "obj: %ld", PTR_ERR(obj
)))
4118 prog
= bpf_program__next(NULL
, obj
);
4119 if (CHECK(!prog
, "Cannot find bpf_prog")) {
4124 bpf_program__set_type(prog
, BPF_PROG_TYPE_TRACEPOINT
);
4125 err
= bpf_object__load(obj
);
4126 if (CHECK(err
< 0, "bpf_object__load: %d", err
))
4128 prog_fd
= bpf_program__fd(prog
);
4130 map
= bpf_object__find_map_by_name(obj
, "btf_map");
4131 if (CHECK(!map
, "btf_map not found")) {
4136 err
= (bpf_map__btf_key_type_id(map
) == 0 || bpf_map__btf_value_type_id(map
) == 0)
4137 != test
->btf_kv_notfound
;
4138 if (CHECK(err
, "btf_key_type_id:%u btf_value_type_id:%u test->btf_kv_notfound:%u",
4139 bpf_map__btf_key_type_id(map
), bpf_map__btf_value_type_id(map
),
4140 test
->btf_kv_notfound
))
4146 /* get necessary program info */
4147 info_len
= sizeof(struct bpf_prog_info
);
4148 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
4150 if (CHECK(err
== -1, "invalid get info (1st) errno:%d", errno
)) {
4151 fprintf(stderr
, "%s\n", btf_log_buf
);
4155 if (CHECK(info
.nr_func_info
!= 3,
4156 "incorrect info.nr_func_info (1st) %d",
4157 info
.nr_func_info
)) {
4161 rec_size
= info
.func_info_rec_size
;
4162 if (CHECK(rec_size
!= sizeof(struct bpf_func_info
),
4163 "incorrect info.func_info_rec_size (1st) %d\n", rec_size
)) {
4168 func_info
= malloc(info
.nr_func_info
* rec_size
);
4169 if (CHECK(!func_info
, "out of memory")) {
4174 /* reset info to only retrieve func_info related data */
4175 memset(&info
, 0, sizeof(info
));
4176 info
.nr_func_info
= 3;
4177 info
.func_info_rec_size
= rec_size
;
4178 info
.func_info
= ptr_to_u64(func_info
);
4180 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
4182 if (CHECK(err
== -1, "invalid get info (2nd) errno:%d", errno
)) {
4183 fprintf(stderr
, "%s\n", btf_log_buf
);
4187 if (CHECK(info
.nr_func_info
!= 3,
4188 "incorrect info.nr_func_info (2nd) %d",
4189 info
.nr_func_info
)) {
4193 if (CHECK(info
.func_info_rec_size
!= rec_size
,
4194 "incorrect info.func_info_rec_size (2nd) %d",
4195 info
.func_info_rec_size
)) {
4200 err
= btf__get_from_id(info
.btf_id
, &btf
);
4201 if (CHECK(err
, "cannot get btf from kernel, err: %d", err
))
4204 /* check three functions */
4206 for (i
= 0; i
< 3; i
++) {
4207 const struct btf_type
*t
;
4210 t
= btf__type_by_id(btf
, finfo
->type_id
);
4211 if (CHECK(!t
, "btf__type_by_id failure: id %u",
4217 fname
= btf__name_by_offset(btf
, t
->name_off
);
4218 err
= strcmp(fname
, expected_fnames
[i
]);
4219 /* for the second and third functions in .text section,
4220 * the compiler may order them either way.
4223 err
= strcmp(fname
, expected_fnames
[3 - i
]);
4224 if (CHECK(err
, "incorrect fname %s", fname
? : "")) {
4229 finfo
= (void *)finfo
+ rec_size
;
4233 fprintf(stderr
, "OK");
4237 bpf_object__close(obj
);
4240 const char *pprint_enum_str
[] = {
4247 struct pprint_mapv
{
4252 uint32_t unused_bits2a
:2,
4267 uint8_t si8_4
[2][2];
4270 #ifdef __SIZEOF_INT128__
4271 struct pprint_mapv_int128
{
4274 unsigned __int128 bits3
:3;
4275 unsigned __int128 bits80
:80;
4276 unsigned __int128 ui128
;
4280 static struct btf_raw_test pprint_test_template
[] = {
4283 /* unsighed char */ /* [1] */
4284 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 8, 1),
4285 /* unsigned short */ /* [2] */
4286 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 16, 2),
4287 /* unsigned int */ /* [3] */
4288 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4),
4290 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
4291 /* unsigned long long */ /* [5] */
4292 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 64, 8),
4293 /* 2 bits */ /* [6] */
4294 BTF_TYPE_INT_ENC(0, 0, 0, 2, 2),
4295 /* 28 bits */ /* [7] */
4296 BTF_TYPE_INT_ENC(0, 0, 0, 28, 4),
4297 /* uint8_t[8] */ /* [8] */
4298 BTF_TYPE_ARRAY_ENC(9, 1, 8),
4299 /* typedef unsigned char uint8_t */ /* [9] */
4300 BTF_TYPEDEF_ENC(NAME_TBD
, 1),
4301 /* typedef unsigned short uint16_t */ /* [10] */
4302 BTF_TYPEDEF_ENC(NAME_TBD
, 2),
4303 /* typedef unsigned int uint32_t */ /* [11] */
4304 BTF_TYPEDEF_ENC(NAME_TBD
, 3),
4305 /* typedef int int32_t */ /* [12] */
4306 BTF_TYPEDEF_ENC(NAME_TBD
, 4),
4307 /* typedef unsigned long long uint64_t *//* [13] */
4308 BTF_TYPEDEF_ENC(NAME_TBD
, 5),
4309 /* union (anon) */ /* [14] */
4310 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 0, 2), 8),
4311 BTF_MEMBER_ENC(NAME_TBD
, 13, 0),/* uint64_t ui64; */
4312 BTF_MEMBER_ENC(NAME_TBD
, 8, 0), /* uint8_t ui8a[8]; */
4313 /* enum (anon) */ /* [15] */
4314 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 4), 4),
4315 BTF_ENUM_ENC(NAME_TBD
, 0),
4316 BTF_ENUM_ENC(NAME_TBD
, 1),
4317 BTF_ENUM_ENC(NAME_TBD
, 2),
4318 BTF_ENUM_ENC(NAME_TBD
, 3),
4319 /* struct pprint_mapv */ /* [16] */
4320 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 0, 11), 40),
4321 BTF_MEMBER_ENC(NAME_TBD
, 11, 0), /* uint32_t ui32 */
4322 BTF_MEMBER_ENC(NAME_TBD
, 10, 32), /* uint16_t ui16 */
4323 BTF_MEMBER_ENC(NAME_TBD
, 12, 64), /* int32_t si32 */
4324 BTF_MEMBER_ENC(NAME_TBD
, 6, 96), /* unused_bits2a */
4325 BTF_MEMBER_ENC(NAME_TBD
, 7, 98), /* bits28 */
4326 BTF_MEMBER_ENC(NAME_TBD
, 6, 126), /* unused_bits2b */
4327 BTF_MEMBER_ENC(0, 14, 128), /* union (anon) */
4328 BTF_MEMBER_ENC(NAME_TBD
, 15, 192), /* aenum */
4329 BTF_MEMBER_ENC(NAME_TBD
, 11, 224), /* uint32_t ui32b */
4330 BTF_MEMBER_ENC(NAME_TBD
, 6, 256), /* bits2c */
4331 BTF_MEMBER_ENC(NAME_TBD
, 17, 264), /* si8_4 */
4332 BTF_TYPE_ARRAY_ENC(18, 1, 2), /* [17] */
4333 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [18] */
4336 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"),
4337 .key_size
= sizeof(unsigned int),
4338 .value_size
= sizeof(struct pprint_mapv
),
4339 .key_type_id
= 3, /* unsigned int */
4340 .value_type_id
= 16, /* struct pprint_mapv */
4345 /* this type will have the same type as the
4346 * first .raw_types definition, but struct type will
4347 * be encoded with kind_flag set.
4350 /* unsighed char */ /* [1] */
4351 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 8, 1),
4352 /* unsigned short */ /* [2] */
4353 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 16, 2),
4354 /* unsigned int */ /* [3] */
4355 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4),
4357 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
4358 /* unsigned long long */ /* [5] */
4359 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 64, 8),
4360 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [6] */
4361 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [7] */
4362 /* uint8_t[8] */ /* [8] */
4363 BTF_TYPE_ARRAY_ENC(9, 1, 8),
4364 /* typedef unsigned char uint8_t */ /* [9] */
4365 BTF_TYPEDEF_ENC(NAME_TBD
, 1),
4366 /* typedef unsigned short uint16_t */ /* [10] */
4367 BTF_TYPEDEF_ENC(NAME_TBD
, 2),
4368 /* typedef unsigned int uint32_t */ /* [11] */
4369 BTF_TYPEDEF_ENC(NAME_TBD
, 3),
4370 /* typedef int int32_t */ /* [12] */
4371 BTF_TYPEDEF_ENC(NAME_TBD
, 4),
4372 /* typedef unsigned long long uint64_t *//* [13] */
4373 BTF_TYPEDEF_ENC(NAME_TBD
, 5),
4374 /* union (anon) */ /* [14] */
4375 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 0, 2), 8),
4376 BTF_MEMBER_ENC(NAME_TBD
, 13, 0),/* uint64_t ui64; */
4377 BTF_MEMBER_ENC(NAME_TBD
, 8, 0), /* uint8_t ui8a[8]; */
4378 /* enum (anon) */ /* [15] */
4379 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 4), 4),
4380 BTF_ENUM_ENC(NAME_TBD
, 0),
4381 BTF_ENUM_ENC(NAME_TBD
, 1),
4382 BTF_ENUM_ENC(NAME_TBD
, 2),
4383 BTF_ENUM_ENC(NAME_TBD
, 3),
4384 /* struct pprint_mapv */ /* [16] */
4385 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 11), 40),
4386 BTF_MEMBER_ENC(NAME_TBD
, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
4387 BTF_MEMBER_ENC(NAME_TBD
, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
4388 BTF_MEMBER_ENC(NAME_TBD
, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
4389 BTF_MEMBER_ENC(NAME_TBD
, 6, BTF_MEMBER_OFFSET(2, 96)), /* unused_bits2a */
4390 BTF_MEMBER_ENC(NAME_TBD
, 7, BTF_MEMBER_OFFSET(28, 98)), /* bits28 */
4391 BTF_MEMBER_ENC(NAME_TBD
, 6, BTF_MEMBER_OFFSET(2, 126)), /* unused_bits2b */
4392 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
4393 BTF_MEMBER_ENC(NAME_TBD
, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
4394 BTF_MEMBER_ENC(NAME_TBD
, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
4395 BTF_MEMBER_ENC(NAME_TBD
, 6, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
4396 BTF_MEMBER_ENC(NAME_TBD
, 17, 264), /* si8_4 */
4397 BTF_TYPE_ARRAY_ENC(18, 1, 2), /* [17] */
4398 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [18] */
4401 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"),
4402 .key_size
= sizeof(unsigned int),
4403 .value_size
= sizeof(struct pprint_mapv
),
4404 .key_type_id
= 3, /* unsigned int */
4405 .value_type_id
= 16, /* struct pprint_mapv */
4410 /* this type will have the same layout as the
4411 * first .raw_types definition. The struct type will
4412 * be encoded with kind_flag set, bitfield members
4413 * are added typedef/const/volatile, and bitfield members
4414 * will have both int and enum types.
4417 /* unsighed char */ /* [1] */
4418 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 8, 1),
4419 /* unsigned short */ /* [2] */
4420 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 16, 2),
4421 /* unsigned int */ /* [3] */
4422 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4),
4424 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4),
4425 /* unsigned long long */ /* [5] */
4426 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 64, 8),
4427 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [6] */
4428 BTF_TYPE_INT_ENC(0, 0, 0, 32, 4), /* [7] */
4429 /* uint8_t[8] */ /* [8] */
4430 BTF_TYPE_ARRAY_ENC(9, 1, 8),
4431 /* typedef unsigned char uint8_t */ /* [9] */
4432 BTF_TYPEDEF_ENC(NAME_TBD
, 1),
4433 /* typedef unsigned short uint16_t */ /* [10] */
4434 BTF_TYPEDEF_ENC(NAME_TBD
, 2),
4435 /* typedef unsigned int uint32_t */ /* [11] */
4436 BTF_TYPEDEF_ENC(NAME_TBD
, 3),
4437 /* typedef int int32_t */ /* [12] */
4438 BTF_TYPEDEF_ENC(NAME_TBD
, 4),
4439 /* typedef unsigned long long uint64_t *//* [13] */
4440 BTF_TYPEDEF_ENC(NAME_TBD
, 5),
4441 /* union (anon) */ /* [14] */
4442 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_UNION
, 0, 2), 8),
4443 BTF_MEMBER_ENC(NAME_TBD
, 13, 0),/* uint64_t ui64; */
4444 BTF_MEMBER_ENC(NAME_TBD
, 8, 0), /* uint8_t ui8a[8]; */
4445 /* enum (anon) */ /* [15] */
4446 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 4), 4),
4447 BTF_ENUM_ENC(NAME_TBD
, 0),
4448 BTF_ENUM_ENC(NAME_TBD
, 1),
4449 BTF_ENUM_ENC(NAME_TBD
, 2),
4450 BTF_ENUM_ENC(NAME_TBD
, 3),
4451 /* struct pprint_mapv */ /* [16] */
4452 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 11), 40),
4453 BTF_MEMBER_ENC(NAME_TBD
, 11, BTF_MEMBER_OFFSET(0, 0)), /* uint32_t ui32 */
4454 BTF_MEMBER_ENC(NAME_TBD
, 10, BTF_MEMBER_OFFSET(0, 32)), /* uint16_t ui16 */
4455 BTF_MEMBER_ENC(NAME_TBD
, 12, BTF_MEMBER_OFFSET(0, 64)), /* int32_t si32 */
4456 BTF_MEMBER_ENC(NAME_TBD
, 17, BTF_MEMBER_OFFSET(2, 96)), /* unused_bits2a */
4457 BTF_MEMBER_ENC(NAME_TBD
, 7, BTF_MEMBER_OFFSET(28, 98)), /* bits28 */
4458 BTF_MEMBER_ENC(NAME_TBD
, 19, BTF_MEMBER_OFFSET(2, 126)),/* unused_bits2b */
4459 BTF_MEMBER_ENC(0, 14, BTF_MEMBER_OFFSET(0, 128)), /* union (anon) */
4460 BTF_MEMBER_ENC(NAME_TBD
, 15, BTF_MEMBER_OFFSET(0, 192)), /* aenum */
4461 BTF_MEMBER_ENC(NAME_TBD
, 11, BTF_MEMBER_OFFSET(0, 224)), /* uint32_t ui32b */
4462 BTF_MEMBER_ENC(NAME_TBD
, 17, BTF_MEMBER_OFFSET(2, 256)), /* bits2c */
4463 BTF_MEMBER_ENC(NAME_TBD
, 20, BTF_MEMBER_OFFSET(0, 264)), /* si8_4 */
4464 /* typedef unsigned int ___int */ /* [17] */
4465 BTF_TYPEDEF_ENC(NAME_TBD
, 18),
4466 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE
, 0, 0), 6), /* [18] */
4467 BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST
, 0, 0), 15), /* [19] */
4468 BTF_TYPE_ARRAY_ENC(21, 1, 2), /* [20] */
4469 BTF_TYPE_ARRAY_ENC(1, 1, 2), /* [21] */
4472 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"),
4473 .key_size
= sizeof(unsigned int),
4474 .value_size
= sizeof(struct pprint_mapv
),
4475 .key_type_id
= 3, /* unsigned int */
4476 .value_type_id
= 16, /* struct pprint_mapv */
4480 #ifdef __SIZEOF_INT128__
4484 /* unsigned int */ /* [1] */
4485 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4),
4486 /* __int128 */ /* [2] */
4487 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 128, 16),
4488 /* unsigned __int128 */ /* [3] */
4489 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 128, 16),
4490 /* struct pprint_mapv_int128 */ /* [4] */
4491 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_STRUCT
, 1, 5), 64),
4492 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 0)), /* si128a */
4493 BTF_MEMBER_ENC(NAME_TBD
, 2, BTF_MEMBER_OFFSET(0, 128)), /* si128b */
4494 BTF_MEMBER_ENC(NAME_TBD
, 3, BTF_MEMBER_OFFSET(3, 256)), /* bits3 */
4495 BTF_MEMBER_ENC(NAME_TBD
, 3, BTF_MEMBER_OFFSET(80, 259)), /* bits80 */
4496 BTF_MEMBER_ENC(NAME_TBD
, 3, BTF_MEMBER_OFFSET(0, 384)), /* ui128 */
4499 BTF_STR_SEC("\0unsigned int\0__int128\0unsigned __int128\0pprint_mapv_int128\0si128a\0si128b\0bits3\0bits80\0ui128"),
4500 .key_size
= sizeof(unsigned int),
4501 .value_size
= sizeof(struct pprint_mapv_int128
),
4505 .mapv_kind
= PPRINT_MAPV_KIND_INT128
,
4511 static struct btf_pprint_test_meta
{
4513 enum bpf_map_type map_type
;
4514 const char *map_name
;
4518 } pprint_tests_meta
[] = {
4520 .descr
= "BTF pretty print array",
4521 .map_type
= BPF_MAP_TYPE_ARRAY
,
4522 .map_name
= "pprint_test_array",
4523 .ordered_map
= true,
4524 .lossless_map
= true,
4525 .percpu_map
= false,
4529 .descr
= "BTF pretty print hash",
4530 .map_type
= BPF_MAP_TYPE_HASH
,
4531 .map_name
= "pprint_test_hash",
4532 .ordered_map
= false,
4533 .lossless_map
= true,
4534 .percpu_map
= false,
4538 .descr
= "BTF pretty print lru hash",
4539 .map_type
= BPF_MAP_TYPE_LRU_HASH
,
4540 .map_name
= "pprint_test_lru_hash",
4541 .ordered_map
= false,
4542 .lossless_map
= false,
4543 .percpu_map
= false,
4547 .descr
= "BTF pretty print percpu array",
4548 .map_type
= BPF_MAP_TYPE_PERCPU_ARRAY
,
4549 .map_name
= "pprint_test_percpu_array",
4550 .ordered_map
= true,
4551 .lossless_map
= true,
4556 .descr
= "BTF pretty print percpu hash",
4557 .map_type
= BPF_MAP_TYPE_PERCPU_HASH
,
4558 .map_name
= "pprint_test_percpu_hash",
4559 .ordered_map
= false,
4560 .lossless_map
= true,
4565 .descr
= "BTF pretty print lru percpu hash",
4566 .map_type
= BPF_MAP_TYPE_LRU_PERCPU_HASH
,
4567 .map_name
= "pprint_test_lru_percpu_hash",
4568 .ordered_map
= false,
4569 .lossless_map
= false,
4575 static size_t get_pprint_mapv_size(enum pprint_mapv_kind_t mapv_kind
)
4577 if (mapv_kind
== PPRINT_MAPV_KIND_BASIC
)
4578 return sizeof(struct pprint_mapv
);
4580 #ifdef __SIZEOF_INT128__
4581 if (mapv_kind
== PPRINT_MAPV_KIND_INT128
)
4582 return sizeof(struct pprint_mapv_int128
);
4588 static void set_pprint_mapv(enum pprint_mapv_kind_t mapv_kind
,
4589 void *mapv
, uint32_t i
,
4590 int num_cpus
, int rounded_value_size
)
4594 if (mapv_kind
== PPRINT_MAPV_KIND_BASIC
) {
4595 struct pprint_mapv
*v
= mapv
;
4597 for (cpu
= 0; cpu
< num_cpus
; cpu
++) {
4600 v
->unused_bits2a
= 3;
4602 v
->unused_bits2b
= 3;
4604 v
->aenum
= i
& 0x03;
4607 v
->si8_4
[0][0] = (cpu
+ i
) & 0xff;
4608 v
->si8_4
[0][1] = (cpu
+ i
+ 1) & 0xff;
4609 v
->si8_4
[1][0] = (cpu
+ i
+ 2) & 0xff;
4610 v
->si8_4
[1][1] = (cpu
+ i
+ 3) & 0xff;
4611 v
= (void *)v
+ rounded_value_size
;
4615 #ifdef __SIZEOF_INT128__
4616 if (mapv_kind
== PPRINT_MAPV_KIND_INT128
) {
4617 struct pprint_mapv_int128
*v
= mapv
;
4619 for (cpu
= 0; cpu
< num_cpus
; cpu
++) {
4622 v
->bits3
= i
& 0x07;
4623 v
->bits80
= (((unsigned __int128
)1) << 64) + i
;
4624 v
->ui128
= (((unsigned __int128
)2) << 64) + i
;
4625 v
= (void *)v
+ rounded_value_size
;
4631 ssize_t
get_pprint_expected_line(enum pprint_mapv_kind_t mapv_kind
,
4632 char *expected_line
, ssize_t line_size
,
4633 bool percpu_map
, unsigned int next_key
,
4634 int cpu
, void *mapv
)
4636 ssize_t nexpected_line
= -1;
4638 if (mapv_kind
== PPRINT_MAPV_KIND_BASIC
) {
4639 struct pprint_mapv
*v
= mapv
;
4641 nexpected_line
= snprintf(expected_line
, line_size
,
4642 "%s%u: {%u,0,%d,0x%x,0x%x,0x%x,"
4643 "{%llu|[%u,%u,%u,%u,%u,%u,%u,%u]},%s,"
4644 "%u,0x%x,[[%d,%d],[%d,%d]]}\n",
4645 percpu_map
? "\tcpu" : "",
4646 percpu_map
? cpu
: next_key
,
4652 v
->ui8a
[0], v
->ui8a
[1],
4653 v
->ui8a
[2], v
->ui8a
[3],
4654 v
->ui8a
[4], v
->ui8a
[5],
4655 v
->ui8a
[6], v
->ui8a
[7],
4656 pprint_enum_str
[v
->aenum
],
4659 v
->si8_4
[0][0], v
->si8_4
[0][1],
4660 v
->si8_4
[1][0], v
->si8_4
[1][1]);
4663 #ifdef __SIZEOF_INT128__
4664 if (mapv_kind
== PPRINT_MAPV_KIND_INT128
) {
4665 struct pprint_mapv_int128
*v
= mapv
;
4667 nexpected_line
= snprintf(expected_line
, line_size
,
4668 "%s%u: {0x%lx,0x%lx,0x%lx,"
4669 "0x%lx%016lx,0x%lx%016lx}\n",
4670 percpu_map
? "\tcpu" : "",
4671 percpu_map
? cpu
: next_key
,
4672 (uint64_t)v
->si128a
,
4673 (uint64_t)v
->si128b
,
4675 (uint64_t)(v
->bits80
>> 64),
4676 (uint64_t)v
->bits80
,
4677 (uint64_t)(v
->ui128
>> 64),
4678 (uint64_t)v
->ui128
);
4682 return nexpected_line
;
4685 static int check_line(const char *expected_line
, int nexpected_line
,
4686 int expected_line_len
, const char *line
)
4688 if (CHECK(nexpected_line
== expected_line_len
,
4689 "expected_line is too long"))
4692 if (strcmp(expected_line
, line
)) {
4693 fprintf(stderr
, "unexpected pprint output\n");
4694 fprintf(stderr
, "expected: %s", expected_line
);
4695 fprintf(stderr
, " read: %s", line
);
4703 static void do_test_pprint(int test_num
)
4705 const struct btf_raw_test
*test
= &pprint_test_template
[test_num
];
4706 enum pprint_mapv_kind_t mapv_kind
= test
->mapv_kind
;
4707 struct bpf_create_map_attr create_attr
= {};
4708 bool ordered_map
, lossless_map
, percpu_map
;
4709 int err
, ret
, num_cpus
, rounded_value_size
;
4710 unsigned int key
, nr_read_elems
;
4711 int map_fd
= -1, btf_fd
= -1;
4712 unsigned int raw_btf_size
;
4713 char expected_line
[255];
4714 FILE *pin_file
= NULL
;
4716 size_t line_len
= 0;
4722 if (!test__start_subtest(test
->descr
))
4725 raw_btf
= btf_raw_create(&hdr_tmpl
, test
->raw_types
,
4726 test
->str_sec
, test
->str_sec_size
,
4727 &raw_btf_size
, NULL
);
4732 *btf_log_buf
= '\0';
4733 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
4734 btf_log_buf
, BTF_LOG_BUF_SIZE
,
4738 if (CHECK(btf_fd
== -1, "errno:%d", errno
)) {
4743 create_attr
.name
= test
->map_name
;
4744 create_attr
.map_type
= test
->map_type
;
4745 create_attr
.key_size
= test
->key_size
;
4746 create_attr
.value_size
= test
->value_size
;
4747 create_attr
.max_entries
= test
->max_entries
;
4748 create_attr
.btf_fd
= btf_fd
;
4749 create_attr
.btf_key_type_id
= test
->key_type_id
;
4750 create_attr
.btf_value_type_id
= test
->value_type_id
;
4752 map_fd
= bpf_create_map_xattr(&create_attr
);
4753 if (CHECK(map_fd
== -1, "errno:%d", errno
)) {
4758 ret
= snprintf(pin_path
, sizeof(pin_path
), "%s/%s",
4759 "/sys/fs/bpf", test
->map_name
);
4761 if (CHECK(ret
== sizeof(pin_path
), "pin_path %s/%s is too long",
4762 "/sys/fs/bpf", test
->map_name
)) {
4767 err
= bpf_obj_pin(map_fd
, pin_path
);
4768 if (CHECK(err
, "bpf_obj_pin(%s): errno:%d.", pin_path
, errno
))
4771 percpu_map
= test
->percpu_map
;
4772 num_cpus
= percpu_map
? bpf_num_possible_cpus() : 1;
4773 rounded_value_size
= round_up(get_pprint_mapv_size(mapv_kind
), 8);
4774 mapv
= calloc(num_cpus
, rounded_value_size
);
4775 if (CHECK(!mapv
, "mapv allocation failure")) {
4780 for (key
= 0; key
< test
->max_entries
; key
++) {
4781 set_pprint_mapv(mapv_kind
, mapv
, key
, num_cpus
, rounded_value_size
);
4782 bpf_map_update_elem(map_fd
, &key
, mapv
, 0);
4785 pin_file
= fopen(pin_path
, "r");
4786 if (CHECK(!pin_file
, "fopen(%s): errno:%d", pin_path
, errno
)) {
4791 /* Skip lines start with '#' */
4792 while ((nread
= getline(&line
, &line_len
, pin_file
)) > 0 &&
4796 if (CHECK(nread
<= 0, "Unexpected EOF")) {
4802 ordered_map
= test
->ordered_map
;
4803 lossless_map
= test
->lossless_map
;
4805 ssize_t nexpected_line
;
4806 unsigned int next_key
;
4810 next_key
= ordered_map
? nr_read_elems
: atoi(line
);
4811 set_pprint_mapv(mapv_kind
, mapv
, next_key
, num_cpus
, rounded_value_size
);
4814 for (cpu
= 0; cpu
< num_cpus
; cpu
++) {
4816 /* for percpu map, the format looks like:
4818 * cpu0: <value_on_cpu0>
4819 * cpu1: <value_on_cpu1>
4821 * cpun: <value_on_cpun>
4824 * let us verify the line containing the key here.
4827 nexpected_line
= snprintf(expected_line
,
4828 sizeof(expected_line
),
4832 err
= check_line(expected_line
, nexpected_line
,
4833 sizeof(expected_line
), line
);
4838 /* read value@cpu */
4839 nread
= getline(&line
, &line_len
, pin_file
);
4844 nexpected_line
= get_pprint_expected_line(mapv_kind
, expected_line
,
4845 sizeof(expected_line
),
4846 percpu_map
, next_key
,
4848 err
= check_line(expected_line
, nexpected_line
,
4849 sizeof(expected_line
), line
);
4853 cmapv
= cmapv
+ rounded_value_size
;
4857 /* skip the last bracket for the percpu map */
4858 nread
= getline(&line
, &line_len
, pin_file
);
4863 nread
= getline(&line
, &line_len
, pin_file
);
4864 } while (++nr_read_elems
< test
->max_entries
&& nread
> 0);
4867 CHECK(nr_read_elems
< test
->max_entries
,
4868 "Unexpected EOF. nr_read_elems:%u test->max_entries:%u",
4869 nr_read_elems
, test
->max_entries
)) {
4874 if (CHECK(nread
> 0, "Unexpected extra pprint output: %s", line
)) {
4885 fprintf(stderr
, "OK");
4886 if (*btf_log_buf
&& (err
|| always_log
))
4887 fprintf(stderr
, "\n%s", btf_log_buf
);
4898 static void test_pprint(void)
4902 /* test various maps with the first test template */
4903 for (i
= 0; i
< ARRAY_SIZE(pprint_tests_meta
); i
++) {
4904 pprint_test_template
[0].descr
= pprint_tests_meta
[i
].descr
;
4905 pprint_test_template
[0].map_type
= pprint_tests_meta
[i
].map_type
;
4906 pprint_test_template
[0].map_name
= pprint_tests_meta
[i
].map_name
;
4907 pprint_test_template
[0].ordered_map
= pprint_tests_meta
[i
].ordered_map
;
4908 pprint_test_template
[0].lossless_map
= pprint_tests_meta
[i
].lossless_map
;
4909 pprint_test_template
[0].percpu_map
= pprint_tests_meta
[i
].percpu_map
;
4914 /* test rest test templates with the first map */
4915 for (i
= 1; i
< ARRAY_SIZE(pprint_test_template
); i
++) {
4916 pprint_test_template
[i
].descr
= pprint_tests_meta
[0].descr
;
4917 pprint_test_template
[i
].map_type
= pprint_tests_meta
[0].map_type
;
4918 pprint_test_template
[i
].map_name
= pprint_tests_meta
[0].map_name
;
4919 pprint_test_template
[i
].ordered_map
= pprint_tests_meta
[0].ordered_map
;
4920 pprint_test_template
[i
].lossless_map
= pprint_tests_meta
[0].lossless_map
;
4921 pprint_test_template
[i
].percpu_map
= pprint_tests_meta
[0].percpu_map
;
4926 #define BPF_LINE_INFO_ENC(insn_off, file_off, line_off, line_num, line_col) \
4927 (insn_off), (file_off), (line_off), ((line_num) << 10 | ((line_col) & 0x3ff))
4929 static struct prog_info_raw_test
{
4931 const char *str_sec
;
4932 const char *err_str
;
4933 __u32 raw_types
[MAX_NR_RAW_U32
];
4935 struct bpf_insn insns
[MAX_INSNS
];
4937 __u32 func_info
[MAX_SUBPROGS
][2];
4938 __u32 func_info_rec_size
;
4939 __u32 func_info_cnt
;
4940 __u32 line_info
[MAX_NR_RAW_U32
];
4941 __u32 line_info_rec_size
;
4942 __u32 nr_jited_ksyms
;
4943 bool expected_prog_load_failure
;
4944 __u32 dead_code_cnt
;
4945 __u32 dead_code_mask
;
4946 __u32 dead_func_cnt
;
4947 __u32 dead_func_mask
;
4948 } info_raw_tests
[] = {
4950 .descr
= "func_type (main func + one sub)",
4952 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
4953 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4), /* [2] */
4954 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
4955 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
4956 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
4957 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
4958 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
4959 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
4960 BTF_FUNC_ENC(NAME_TBD
, 3), /* [5] */
4961 BTF_FUNC_ENC(NAME_TBD
, 4), /* [6] */
4964 .str_sec
= "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
4965 .str_sec_size
= sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
4967 BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 1, 0, 2),
4968 BPF_MOV64_IMM(BPF_REG_0
, 1),
4970 BPF_MOV64_IMM(BPF_REG_0
, 2),
4973 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
4974 .func_info
= { {0, 5}, {3, 6} },
4975 .func_info_rec_size
= 8,
4977 .line_info
= { BTF_END_RAW
},
4981 .descr
= "func_type (Incorrect func_info_rec_size)",
4983 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
4984 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4), /* [2] */
4985 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
4986 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
4987 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
4988 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
4989 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
4990 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
4991 BTF_FUNC_ENC(NAME_TBD
, 3), /* [5] */
4992 BTF_FUNC_ENC(NAME_TBD
, 4), /* [6] */
4995 .str_sec
= "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
4996 .str_sec_size
= sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
4998 BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 1, 0, 2),
4999 BPF_MOV64_IMM(BPF_REG_0
, 1),
5001 BPF_MOV64_IMM(BPF_REG_0
, 2),
5004 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5005 .func_info
= { {0, 5}, {3, 6} },
5006 .func_info_rec_size
= 4,
5008 .line_info
= { BTF_END_RAW
},
5009 .expected_prog_load_failure
= true,
5013 .descr
= "func_type (Incorrect func_info_cnt)",
5015 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5016 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4), /* [2] */
5017 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5018 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5019 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5020 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5021 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5022 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5023 BTF_FUNC_ENC(NAME_TBD
, 3), /* [5] */
5024 BTF_FUNC_ENC(NAME_TBD
, 4), /* [6] */
5027 .str_sec
= "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5028 .str_sec_size
= sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5030 BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 1, 0, 2),
5031 BPF_MOV64_IMM(BPF_REG_0
, 1),
5033 BPF_MOV64_IMM(BPF_REG_0
, 2),
5036 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5037 .func_info
= { {0, 5}, {3, 6} },
5038 .func_info_rec_size
= 8,
5040 .line_info
= { BTF_END_RAW
},
5041 .expected_prog_load_failure
= true,
5045 .descr
= "func_type (Incorrect bpf_func_info.insn_off)",
5047 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5048 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 32, 4), /* [2] */
5049 BTF_FUNC_PROTO_ENC(1, 2), /* [3] */
5050 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5051 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5052 BTF_FUNC_PROTO_ENC(1, 2), /* [4] */
5053 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 2),
5054 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5055 BTF_FUNC_ENC(NAME_TBD
, 3), /* [5] */
5056 BTF_FUNC_ENC(NAME_TBD
, 4), /* [6] */
5059 .str_sec
= "\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB",
5060 .str_sec_size
= sizeof("\0int\0unsigned int\0a\0b\0c\0d\0funcA\0funcB"),
5062 BPF_RAW_INSN(BPF_JMP
| BPF_CALL
, 0, 1, 0, 2),
5063 BPF_MOV64_IMM(BPF_REG_0
, 1),
5065 BPF_MOV64_IMM(BPF_REG_0
, 2),
5068 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5069 .func_info
= { {0, 5}, {2, 6} },
5070 .func_info_rec_size
= 8,
5072 .line_info
= { BTF_END_RAW
},
5073 .expected_prog_load_failure
= true,
5077 .descr
= "line_info (No subprog)",
5079 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5082 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5084 BPF_MOV64_IMM(BPF_REG_0
, 1),
5085 BPF_MOV64_IMM(BPF_REG_1
, 2),
5086 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5089 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5092 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5093 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9),
5094 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5095 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7),
5098 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5099 .nr_jited_ksyms
= 1,
5103 .descr
= "line_info (No subprog. insn_off >= prog->len)",
5105 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5108 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5110 BPF_MOV64_IMM(BPF_REG_0
, 1),
5111 BPF_MOV64_IMM(BPF_REG_1
, 2),
5112 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5115 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5118 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5119 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9),
5120 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5121 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7),
5122 BPF_LINE_INFO_ENC(4, 0, 0, 5, 6),
5125 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5126 .nr_jited_ksyms
= 1,
5127 .err_str
= "line_info[4].insn_off",
5128 .expected_prog_load_failure
= true,
5132 .descr
= "line_info (Zero bpf insn code)",
5134 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5135 BTF_TYPE_INT_ENC(NAME_TBD
, 0, 0, 64, 8), /* [2] */
5136 BTF_TYPEDEF_ENC(NAME_TBD
, 2), /* [3] */
5139 BTF_STR_SEC("\0int\0unsigned long\0u64\0u64 a=1;\0return a;"),
5141 BPF_LD_IMM64(BPF_REG_0
, 1),
5144 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5147 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5148 BPF_LINE_INFO_ENC(1, 0, 0, 2, 9),
5149 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5152 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5153 .nr_jited_ksyms
= 1,
5154 .err_str
= "Invalid insn code at line_info[1]",
5155 .expected_prog_load_failure
= true,
5159 .descr
= "line_info (No subprog. zero tailing line_info",
5161 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5164 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5166 BPF_MOV64_IMM(BPF_REG_0
, 1),
5167 BPF_MOV64_IMM(BPF_REG_1
, 2),
5168 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5171 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5174 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10), 0,
5175 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9), 0,
5176 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8), 0,
5177 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7), 0,
5180 .line_info_rec_size
= sizeof(struct bpf_line_info
) + sizeof(__u32
),
5181 .nr_jited_ksyms
= 1,
5185 .descr
= "line_info (No subprog. nonzero tailing line_info)",
5187 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5190 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5192 BPF_MOV64_IMM(BPF_REG_0
, 1),
5193 BPF_MOV64_IMM(BPF_REG_1
, 2),
5194 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5197 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5200 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10), 0,
5201 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9), 0,
5202 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8), 0,
5203 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7), 1,
5206 .line_info_rec_size
= sizeof(struct bpf_line_info
) + sizeof(__u32
),
5207 .nr_jited_ksyms
= 1,
5208 .err_str
= "nonzero tailing record in line_info",
5209 .expected_prog_load_failure
= true,
5213 .descr
= "line_info (subprog)",
5215 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5218 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5220 BPF_MOV64_IMM(BPF_REG_2
, 1),
5221 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5222 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5225 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5226 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5229 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5232 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5233 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 2, 9),
5234 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 3, 8),
5235 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5238 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5239 .nr_jited_ksyms
= 2,
5243 .descr
= "line_info (subprog + func_info)",
5245 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5246 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5247 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5248 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5249 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5252 BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5254 BPF_MOV64_IMM(BPF_REG_2
, 1),
5255 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5256 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5259 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5260 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5263 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5265 .func_info_rec_size
= 8,
5266 .func_info
= { {0, 4}, {5, 3} },
5268 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5269 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 2, 9),
5270 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 3, 8),
5271 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5274 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5275 .nr_jited_ksyms
= 2,
5279 .descr
= "line_info (subprog. missing 1st func line info)",
5281 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5284 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5286 BPF_MOV64_IMM(BPF_REG_2
, 1),
5287 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5288 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5291 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5292 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5295 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5298 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 1, 10),
5299 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 2, 9),
5300 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 3, 8),
5301 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5304 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5305 .nr_jited_ksyms
= 2,
5306 .err_str
= "missing bpf_line_info for func#0",
5307 .expected_prog_load_failure
= true,
5311 .descr
= "line_info (subprog. missing 2nd func line info)",
5313 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5316 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5318 BPF_MOV64_IMM(BPF_REG_2
, 1),
5319 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5320 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5323 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5324 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5327 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5330 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5331 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 2, 9),
5332 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 3, 8),
5333 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5336 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5337 .nr_jited_ksyms
= 2,
5338 .err_str
= "missing bpf_line_info for func#1",
5339 .expected_prog_load_failure
= true,
5343 .descr
= "line_info (subprog. unordered insn offset)",
5345 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5348 BTF_STR_SEC("\0int\0int a=1+1;\0return func(a);\0b+=1;\0return b;"),
5350 BPF_MOV64_IMM(BPF_REG_2
, 1),
5351 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5352 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5355 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5356 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5359 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5362 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5363 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 2, 9),
5364 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5365 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 4, 7),
5368 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5369 .nr_jited_ksyms
= 2,
5370 .err_str
= "Invalid line_info[2].insn_off",
5371 .expected_prog_load_failure
= true,
5375 .descr
= "line_info (dead start)",
5377 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5380 BTF_STR_SEC("\0int\0/* dead jmp */\0int a=1;\0int b=2;\0return a + b;\0return a + b;"),
5382 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5383 BPF_MOV64_IMM(BPF_REG_0
, 1),
5384 BPF_MOV64_IMM(BPF_REG_1
, 2),
5385 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5388 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5391 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5392 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 9),
5393 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 8),
5394 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 7),
5395 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 5, 6),
5398 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5399 .nr_jited_ksyms
= 1,
5401 .dead_code_mask
= 0x01,
5405 .descr
= "line_info (dead end)",
5407 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5410 BTF_STR_SEC("\0int\0int a=1;\0int b=2;\0return a + b;\0/* dead jmp */\0return a + b;\0/* dead exit */"),
5412 BPF_MOV64_IMM(BPF_REG_0
, 1),
5413 BPF_MOV64_IMM(BPF_REG_1
, 2),
5414 BPF_ALU64_REG(BPF_ADD
, BPF_REG_0
, BPF_REG_1
),
5415 BPF_JMP_IMM(BPF_JGE
, BPF_REG_0
, 10, 1),
5419 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5422 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 12),
5423 BPF_LINE_INFO_ENC(1, 0, NAME_TBD
, 2, 11),
5424 BPF_LINE_INFO_ENC(2, 0, NAME_TBD
, 3, 10),
5425 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 4, 9),
5426 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 5, 8),
5427 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 6, 7),
5430 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5431 .nr_jited_ksyms
= 1,
5433 .dead_code_mask
= 0x28,
5437 .descr
= "line_info (dead code + subprog + func_info)",
5439 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5440 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5441 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5442 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5443 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5446 BTF_STR_SEC("\0int\0x\0sub\0main\0int a=1+1;\0/* dead jmp */"
5447 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
5448 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
5449 "\0return func(a);\0b+=1;\0return b;"),
5451 BPF_MOV64_IMM(BPF_REG_2
, 1),
5452 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_2
, 1),
5453 BPF_MOV64_REG(BPF_REG_1
, BPF_REG_2
),
5454 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 8),
5455 BPF_MOV64_IMM(BPF_REG_2
, 1),
5456 BPF_MOV64_IMM(BPF_REG_2
, 1),
5457 BPF_MOV64_IMM(BPF_REG_2
, 1),
5458 BPF_MOV64_IMM(BPF_REG_2
, 1),
5459 BPF_MOV64_IMM(BPF_REG_2
, 1),
5460 BPF_MOV64_IMM(BPF_REG_2
, 1),
5461 BPF_MOV64_IMM(BPF_REG_2
, 1),
5462 BPF_MOV64_IMM(BPF_REG_2
, 1),
5465 BPF_MOV64_REG(BPF_REG_0
, BPF_REG_1
),
5466 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5469 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5471 .func_info_rec_size
= 8,
5472 .func_info
= { {0, 4}, {14, 3} },
5474 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5475 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5476 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5477 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5478 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5479 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 1, 10),
5480 BPF_LINE_INFO_ENC(8, 0, NAME_TBD
, 1, 10),
5481 BPF_LINE_INFO_ENC(9, 0, NAME_TBD
, 1, 10),
5482 BPF_LINE_INFO_ENC(10, 0, NAME_TBD
, 1, 10),
5483 BPF_LINE_INFO_ENC(11, 0, NAME_TBD
, 2, 9),
5484 BPF_LINE_INFO_ENC(12, 0, NAME_TBD
, 2, 9),
5485 BPF_LINE_INFO_ENC(14, 0, NAME_TBD
, 3, 8),
5486 BPF_LINE_INFO_ENC(16, 0, NAME_TBD
, 4, 7),
5489 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5490 .nr_jited_ksyms
= 2,
5492 .dead_code_mask
= 0x3fe,
5496 .descr
= "line_info (dead subprog)",
5498 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5499 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5500 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5501 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5502 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5503 BTF_FUNC_ENC(NAME_TBD
, 2), /* [5] */
5506 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
5507 "\0return 0;\0return 0;\0/* dead */\0/* dead */"
5508 "\0/* dead */\0return bla + 1;\0return bla + 1;"
5509 "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
5511 BPF_MOV64_IMM(BPF_REG_2
, 1),
5512 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 1),
5515 BPF_MOV64_IMM(BPF_REG_0
, 0),
5517 BPF_MOV64_IMM(BPF_REG_0
, 0),
5520 BPF_MOV64_REG(BPF_REG_0
, 2),
5521 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5524 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5526 .func_info_rec_size
= 8,
5527 .func_info
= { {0, 4}, {6, 3}, {9, 5} },
5529 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5530 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5531 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5532 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5533 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5534 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 1, 10),
5535 BPF_LINE_INFO_ENC(8, 0, NAME_TBD
, 1, 10),
5536 BPF_LINE_INFO_ENC(9, 0, NAME_TBD
, 1, 10),
5537 BPF_LINE_INFO_ENC(10, 0, NAME_TBD
, 1, 10),
5538 BPF_LINE_INFO_ENC(11, 0, NAME_TBD
, 2, 9),
5541 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5542 .nr_jited_ksyms
= 2,
5544 .dead_code_mask
= 0x70,
5546 .dead_func_mask
= 0x2,
5550 .descr
= "line_info (dead last subprog)",
5552 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5553 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5554 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5555 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5556 BTF_FUNC_ENC(NAME_TBD
, 2), /* [5] */
5559 BTF_STR_SEC("\0int\0x\0dead\0main\0int a=1+1;\0/* live call */"
5560 "\0return 0;\0/* dead */\0/* dead */"),
5562 BPF_MOV64_IMM(BPF_REG_2
, 1),
5563 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 1),
5565 BPF_MOV64_IMM(BPF_REG_0
, 0),
5567 BPF_MOV64_IMM(BPF_REG_0
, 0),
5570 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5572 .func_info_rec_size
= 8,
5573 .func_info
= { {0, 4}, {5, 3} },
5575 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5576 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5577 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5578 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5579 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5582 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5583 .nr_jited_ksyms
= 1,
5585 .dead_code_mask
= 0x18,
5587 .dead_func_mask
= 0x2,
5591 .descr
= "line_info (dead subprog + dead start)",
5593 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5594 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5595 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5596 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5597 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5598 BTF_FUNC_ENC(NAME_TBD
, 2), /* [5] */
5601 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* dead */"
5602 "\0return 0;\0return 0;\0return 0;"
5603 "\0/* dead */\0/* dead */\0/* dead */\0/* dead */"
5604 "\0return b + 1;\0return b + 1;\0return b + 1;"),
5606 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5607 BPF_MOV64_IMM(BPF_REG_2
, 1),
5608 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 1),
5611 BPF_MOV64_IMM(BPF_REG_0
, 0),
5613 BPF_MOV64_IMM(BPF_REG_0
, 0),
5616 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5617 BPF_MOV64_REG(BPF_REG_0
, 2),
5618 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5621 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5623 .func_info_rec_size
= 8,
5624 .func_info
= { {0, 4}, {7, 3}, {10, 5} },
5626 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5627 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5628 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5629 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5630 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5631 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 1, 10),
5632 BPF_LINE_INFO_ENC(8, 0, NAME_TBD
, 1, 10),
5633 BPF_LINE_INFO_ENC(9, 0, NAME_TBD
, 1, 10),
5634 BPF_LINE_INFO_ENC(10, 0, NAME_TBD
, 1, 10),
5635 BPF_LINE_INFO_ENC(11, 0, NAME_TBD
, 2, 9),
5636 BPF_LINE_INFO_ENC(12, 0, NAME_TBD
, 2, 9),
5637 BPF_LINE_INFO_ENC(13, 0, NAME_TBD
, 2, 9),
5640 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5641 .nr_jited_ksyms
= 2,
5643 .dead_code_mask
= 0x1e2,
5645 .dead_func_mask
= 0x2,
5649 .descr
= "line_info (dead subprog + dead start w/ move)",
5651 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5652 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5653 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5654 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5655 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5656 BTF_FUNC_ENC(NAME_TBD
, 2), /* [5] */
5659 BTF_STR_SEC("\0int\0x\0dead\0main\0func\0int a=1+1;\0/* live call */"
5660 "\0return 0;\0return 0;\0/* dead */\0/* dead */"
5661 "\0/* dead */\0return bla + 1;\0return bla + 1;"
5662 "\0return bla + 1;\0return func(a);\0b+=1;\0return b;"),
5664 BPF_MOV64_IMM(BPF_REG_2
, 1),
5665 BPF_JMP_IMM(BPF_JGE
, BPF_REG_2
, 0, 1),
5668 BPF_MOV64_IMM(BPF_REG_0
, 0),
5670 BPF_MOV64_IMM(BPF_REG_0
, 0),
5673 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5674 BPF_MOV64_REG(BPF_REG_0
, 2),
5675 BPF_ALU64_IMM(BPF_ADD
, BPF_REG_0
, 1),
5678 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5680 .func_info_rec_size
= 8,
5681 .func_info
= { {0, 4}, {6, 3}, {9, 5} },
5683 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5684 BPF_LINE_INFO_ENC(3, 0, NAME_TBD
, 1, 10),
5685 BPF_LINE_INFO_ENC(4, 0, NAME_TBD
, 1, 10),
5686 BPF_LINE_INFO_ENC(5, 0, NAME_TBD
, 1, 10),
5687 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5688 BPF_LINE_INFO_ENC(7, 0, NAME_TBD
, 1, 10),
5689 BPF_LINE_INFO_ENC(8, 0, NAME_TBD
, 1, 10),
5690 BPF_LINE_INFO_ENC(9, 0, NAME_TBD
, 1, 10),
5691 BPF_LINE_INFO_ENC(11, 0, NAME_TBD
, 1, 10),
5692 BPF_LINE_INFO_ENC(12, 0, NAME_TBD
, 2, 9),
5695 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5696 .nr_jited_ksyms
= 2,
5698 .dead_code_mask
= 0x70,
5700 .dead_func_mask
= 0x2,
5704 .descr
= "line_info (dead end + subprog start w/ no linfo)",
5706 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
5707 BTF_FUNC_PROTO_ENC(1, 1), /* [2] */
5708 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
5709 BTF_FUNC_ENC(NAME_TBD
, 2), /* [3] */
5710 BTF_FUNC_ENC(NAME_TBD
, 2), /* [4] */
5713 BTF_STR_SEC("\0int\0x\0main\0func\0/* main linfo */\0/* func linfo */"),
5715 BPF_MOV64_IMM(BPF_REG_0
, 0),
5716 BPF_JMP_IMM(BPF_JGE
, BPF_REG_0
, 1, 3),
5718 BPF_MOV64_IMM(BPF_REG_0
, 0),
5721 BPF_JMP_IMM(BPF_JA
, 0, 0, 0),
5724 .prog_type
= BPF_PROG_TYPE_TRACEPOINT
,
5726 .func_info_rec_size
= 8,
5727 .func_info
= { {0, 3}, {6, 4}, },
5729 BPF_LINE_INFO_ENC(0, 0, NAME_TBD
, 1, 10),
5730 BPF_LINE_INFO_ENC(6, 0, NAME_TBD
, 1, 10),
5733 .line_info_rec_size
= sizeof(struct bpf_line_info
),
5734 .nr_jited_ksyms
= 2,
5739 static size_t probe_prog_length(const struct bpf_insn
*fp
)
5743 for (len
= MAX_INSNS
- 1; len
> 0; --len
)
5744 if (fp
[len
].code
!= 0 || fp
[len
].imm
!= 0)
5749 static __u32
*patch_name_tbd(const __u32
*raw_u32
,
5750 const char *str
, __u32 str_off
,
5751 unsigned int str_sec_size
,
5752 unsigned int *ret_size
)
5754 int i
, raw_u32_size
= get_raw_sec_size(raw_u32
);
5755 const char *end_str
= str
+ str_sec_size
;
5756 const char *next_str
= str
+ str_off
;
5757 __u32
*new_u32
= NULL
;
5759 if (raw_u32_size
== -1)
5760 return ERR_PTR(-EINVAL
);
5762 if (!raw_u32_size
) {
5767 new_u32
= malloc(raw_u32_size
);
5769 return ERR_PTR(-ENOMEM
);
5771 for (i
= 0; i
< raw_u32_size
/ sizeof(raw_u32
[0]); i
++) {
5772 if (raw_u32
[i
] == NAME_TBD
) {
5773 next_str
= get_next_str(next_str
, end_str
);
5774 if (CHECK(!next_str
, "Error in getting next_str\n")) {
5776 return ERR_PTR(-EINVAL
);
5778 new_u32
[i
] = next_str
- str
;
5779 next_str
+= strlen(next_str
);
5781 new_u32
[i
] = raw_u32
[i
];
5785 *ret_size
= raw_u32_size
;
5789 static int test_get_finfo(const struct prog_info_raw_test
*test
,
5792 struct bpf_prog_info info
= {};
5793 struct bpf_func_info
*finfo
;
5794 __u32 info_len
, rec_size
, i
;
5795 void *func_info
= NULL
;
5799 /* get necessary lens */
5800 info_len
= sizeof(struct bpf_prog_info
);
5801 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
5802 if (CHECK(err
== -1, "invalid get info (1st) errno:%d", errno
)) {
5803 fprintf(stderr
, "%s\n", btf_log_buf
);
5806 nr_func_info
= test
->func_info_cnt
- test
->dead_func_cnt
;
5807 if (CHECK(info
.nr_func_info
!= nr_func_info
,
5808 "incorrect info.nr_func_info (1st) %d",
5809 info
.nr_func_info
)) {
5813 rec_size
= info
.func_info_rec_size
;
5814 if (CHECK(rec_size
!= sizeof(struct bpf_func_info
),
5815 "incorrect info.func_info_rec_size (1st) %d", rec_size
)) {
5819 if (!info
.nr_func_info
)
5822 func_info
= malloc(info
.nr_func_info
* rec_size
);
5823 if (CHECK(!func_info
, "out of memory"))
5826 /* reset info to only retrieve func_info related data */
5827 memset(&info
, 0, sizeof(info
));
5828 info
.nr_func_info
= nr_func_info
;
5829 info
.func_info_rec_size
= rec_size
;
5830 info
.func_info
= ptr_to_u64(func_info
);
5831 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
5832 if (CHECK(err
== -1, "invalid get info (2nd) errno:%d", errno
)) {
5833 fprintf(stderr
, "%s\n", btf_log_buf
);
5837 if (CHECK(info
.nr_func_info
!= nr_func_info
,
5838 "incorrect info.nr_func_info (2nd) %d",
5839 info
.nr_func_info
)) {
5843 if (CHECK(info
.func_info_rec_size
!= rec_size
,
5844 "incorrect info.func_info_rec_size (2nd) %d",
5845 info
.func_info_rec_size
)) {
5851 for (i
= 0; i
< nr_func_info
; i
++) {
5852 if (test
->dead_func_mask
& (1 << i
))
5854 if (CHECK(finfo
->type_id
!= test
->func_info
[i
][1],
5855 "incorrect func_type %u expected %u",
5856 finfo
->type_id
, test
->func_info
[i
][1])) {
5860 finfo
= (void *)finfo
+ rec_size
;
5870 static int test_get_linfo(const struct prog_info_raw_test
*test
,
5871 const void *patched_linfo
,
5872 __u32 cnt
, int prog_fd
)
5874 __u32 i
, info_len
, nr_jited_ksyms
, nr_jited_func_lens
;
5875 __u64
*jited_linfo
= NULL
, *jited_ksyms
= NULL
;
5876 __u32 rec_size
, jited_rec_size
, jited_cnt
;
5877 struct bpf_line_info
*linfo
= NULL
;
5878 __u32 cur_func_len
, ksyms_found
;
5879 struct bpf_prog_info info
= {};
5880 __u32
*jited_func_lens
= NULL
;
5881 __u64 cur_func_ksyms
;
5886 rec_size
= sizeof(*linfo
);
5887 jited_rec_size
= sizeof(*jited_linfo
);
5888 if (test
->nr_jited_ksyms
)
5889 nr_jited_ksyms
= test
->nr_jited_ksyms
;
5891 nr_jited_ksyms
= test
->func_info_cnt
- test
->dead_func_cnt
;
5892 nr_jited_func_lens
= nr_jited_ksyms
;
5894 info_len
= sizeof(struct bpf_prog_info
);
5895 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
5896 if (CHECK(err
== -1, "err:%d errno:%d", err
, errno
)) {
5901 if (!info
.jited_prog_len
) {
5902 /* prog is not jited */
5905 nr_jited_func_lens
= 1;
5908 if (CHECK(info
.nr_line_info
!= cnt
||
5909 info
.nr_jited_line_info
!= jited_cnt
||
5910 info
.nr_jited_ksyms
!= nr_jited_ksyms
||
5911 info
.nr_jited_func_lens
!= nr_jited_func_lens
||
5912 (!info
.nr_line_info
&& info
.nr_jited_line_info
),
5913 "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)",
5914 info
.nr_line_info
, cnt
,
5915 info
.nr_jited_line_info
, jited_cnt
,
5916 info
.nr_jited_ksyms
, nr_jited_ksyms
,
5917 info
.nr_jited_func_lens
, nr_jited_func_lens
)) {
5922 if (CHECK(info
.line_info_rec_size
!= sizeof(struct bpf_line_info
) ||
5923 info
.jited_line_info_rec_size
!= sizeof(__u64
),
5924 "info: line_info_rec_size:%u(userspace expected:%u) jited_line_info_rec_size:%u(userspace expected:%u)",
5925 info
.line_info_rec_size
, rec_size
,
5926 info
.jited_line_info_rec_size
, jited_rec_size
)) {
5934 rec_size
= info
.line_info_rec_size
;
5935 jited_rec_size
= info
.jited_line_info_rec_size
;
5937 memset(&info
, 0, sizeof(info
));
5939 linfo
= calloc(cnt
, rec_size
);
5940 if (CHECK(!linfo
, "!linfo")) {
5944 info
.nr_line_info
= cnt
;
5945 info
.line_info_rec_size
= rec_size
;
5946 info
.line_info
= ptr_to_u64(linfo
);
5949 jited_linfo
= calloc(jited_cnt
, jited_rec_size
);
5950 jited_ksyms
= calloc(nr_jited_ksyms
, sizeof(*jited_ksyms
));
5951 jited_func_lens
= calloc(nr_jited_func_lens
,
5952 sizeof(*jited_func_lens
));
5953 if (CHECK(!jited_linfo
|| !jited_ksyms
|| !jited_func_lens
,
5954 "jited_linfo:%p jited_ksyms:%p jited_func_lens:%p",
5955 jited_linfo
, jited_ksyms
, jited_func_lens
)) {
5960 info
.nr_jited_line_info
= jited_cnt
;
5961 info
.jited_line_info_rec_size
= jited_rec_size
;
5962 info
.jited_line_info
= ptr_to_u64(jited_linfo
);
5963 info
.nr_jited_ksyms
= nr_jited_ksyms
;
5964 info
.jited_ksyms
= ptr_to_u64(jited_ksyms
);
5965 info
.nr_jited_func_lens
= nr_jited_func_lens
;
5966 info
.jited_func_lens
= ptr_to_u64(jited_func_lens
);
5969 err
= bpf_obj_get_info_by_fd(prog_fd
, &info
, &info_len
);
5972 * Only recheck the info.*line_info* fields.
5973 * Other fields are not the concern of this test.
5975 if (CHECK(err
== -1 ||
5976 info
.nr_line_info
!= cnt
||
5977 (jited_cnt
&& !info
.jited_line_info
) ||
5978 info
.nr_jited_line_info
!= jited_cnt
||
5979 info
.line_info_rec_size
!= rec_size
||
5980 info
.jited_line_info_rec_size
!= jited_rec_size
,
5981 "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",
5983 info
.nr_line_info
, cnt
,
5984 info
.nr_jited_line_info
, jited_cnt
,
5985 info
.line_info_rec_size
, rec_size
,
5986 info
.jited_line_info_rec_size
, jited_rec_size
,
5987 (void *)(long)info
.line_info
,
5988 (void *)(long)info
.jited_line_info
)) {
5994 while (test
->dead_code_mask
& (1 << dead_insns
))
5997 CHECK(linfo
[0].insn_off
, "linfo[0].insn_off:%u",
5999 for (i
= 1; i
< cnt
; i
++) {
6000 const struct bpf_line_info
*expected_linfo
;
6002 while (test
->dead_code_mask
& (1 << (i
+ dead_insns
)))
6005 expected_linfo
= patched_linfo
+
6006 ((i
+ dead_insns
) * test
->line_info_rec_size
);
6007 if (CHECK(linfo
[i
].insn_off
<= linfo
[i
- 1].insn_off
,
6008 "linfo[%u].insn_off:%u <= linfo[%u].insn_off:%u",
6009 i
, linfo
[i
].insn_off
,
6010 i
- 1, linfo
[i
- 1].insn_off
)) {
6014 if (CHECK(linfo
[i
].file_name_off
!= expected_linfo
->file_name_off
||
6015 linfo
[i
].line_off
!= expected_linfo
->line_off
||
6016 linfo
[i
].line_col
!= expected_linfo
->line_col
,
6017 "linfo[%u] (%u, %u, %u) != (%u, %u, %u)", i
,
6018 linfo
[i
].file_name_off
,
6021 expected_linfo
->file_name_off
,
6022 expected_linfo
->line_off
,
6023 expected_linfo
->line_col
)) {
6030 fprintf(stderr
, "not jited. skipping jited_line_info check. ");
6035 if (CHECK(jited_linfo
[0] != jited_ksyms
[0],
6036 "jited_linfo[0]:%lx != jited_ksyms[0]:%lx",
6037 (long)(jited_linfo
[0]), (long)(jited_ksyms
[0]))) {
6043 cur_func_len
= jited_func_lens
[0];
6044 cur_func_ksyms
= jited_ksyms
[0];
6045 for (i
= 1; i
< jited_cnt
; i
++) {
6046 if (ksyms_found
< nr_jited_ksyms
&&
6047 jited_linfo
[i
] == jited_ksyms
[ksyms_found
]) {
6048 cur_func_ksyms
= jited_ksyms
[ksyms_found
];
6049 cur_func_len
= jited_ksyms
[ksyms_found
];
6054 if (CHECK(jited_linfo
[i
] <= jited_linfo
[i
- 1],
6055 "jited_linfo[%u]:%lx <= jited_linfo[%u]:%lx",
6056 i
, (long)jited_linfo
[i
],
6057 i
- 1, (long)(jited_linfo
[i
- 1]))) {
6062 if (CHECK(jited_linfo
[i
] - cur_func_ksyms
> cur_func_len
,
6063 "jited_linfo[%u]:%lx - %lx > %u",
6064 i
, (long)jited_linfo
[i
], (long)cur_func_ksyms
,
6071 if (CHECK(ksyms_found
!= nr_jited_ksyms
,
6072 "ksyms_found:%u != nr_jited_ksyms:%u",
6073 ksyms_found
, nr_jited_ksyms
)) {
6084 free(jited_func_lens
);
6088 static void do_test_info_raw(unsigned int test_num
)
6090 const struct prog_info_raw_test
*test
= &info_raw_tests
[test_num
- 1];
6091 unsigned int raw_btf_size
, linfo_str_off
, linfo_size
;
6092 int btf_fd
= -1, prog_fd
= -1, err
= 0;
6093 void *raw_btf
, *patched_linfo
= NULL
;
6094 const char *ret_next_str
;
6095 union bpf_attr attr
= {};
6097 if (!test__start_subtest(test
->descr
))
6100 raw_btf
= btf_raw_create(&hdr_tmpl
, test
->raw_types
,
6101 test
->str_sec
, test
->str_sec_size
,
6102 &raw_btf_size
, &ret_next_str
);
6106 *btf_log_buf
= '\0';
6107 btf_fd
= bpf_load_btf(raw_btf
, raw_btf_size
,
6108 btf_log_buf
, BTF_LOG_BUF_SIZE
,
6112 if (CHECK(btf_fd
== -1, "invalid btf_fd errno:%d", errno
)) {
6117 if (*btf_log_buf
&& always_log
)
6118 fprintf(stderr
, "\n%s", btf_log_buf
);
6119 *btf_log_buf
= '\0';
6121 linfo_str_off
= ret_next_str
- test
->str_sec
;
6122 patched_linfo
= patch_name_tbd(test
->line_info
,
6123 test
->str_sec
, linfo_str_off
,
6124 test
->str_sec_size
, &linfo_size
);
6125 if (IS_ERR(patched_linfo
)) {
6126 fprintf(stderr
, "error in creating raw bpf_line_info");
6131 attr
.prog_type
= test
->prog_type
;
6132 attr
.insns
= ptr_to_u64(test
->insns
);
6133 attr
.insn_cnt
= probe_prog_length(test
->insns
);
6134 attr
.license
= ptr_to_u64("GPL");
6135 attr
.prog_btf_fd
= btf_fd
;
6136 attr
.func_info_rec_size
= test
->func_info_rec_size
;
6137 attr
.func_info_cnt
= test
->func_info_cnt
;
6138 attr
.func_info
= ptr_to_u64(test
->func_info
);
6139 attr
.log_buf
= ptr_to_u64(btf_log_buf
);
6140 attr
.log_size
= BTF_LOG_BUF_SIZE
;
6143 attr
.line_info_rec_size
= test
->line_info_rec_size
;
6144 attr
.line_info
= ptr_to_u64(patched_linfo
);
6145 attr
.line_info_cnt
= linfo_size
/ attr
.line_info_rec_size
;
6148 prog_fd
= syscall(__NR_bpf
, BPF_PROG_LOAD
, &attr
, sizeof(attr
));
6149 err
= ((prog_fd
== -1) != test
->expected_prog_load_failure
);
6150 if (CHECK(err
, "prog_fd:%d expected_prog_load_failure:%u errno:%d",
6151 prog_fd
, test
->expected_prog_load_failure
, errno
) ||
6152 CHECK(test
->err_str
&& !strstr(btf_log_buf
, test
->err_str
),
6153 "expected err_str:%s", test
->err_str
)) {
6161 err
= test_get_finfo(test
, prog_fd
);
6165 err
= test_get_linfo(test
, patched_linfo
,
6166 attr
.line_info_cnt
- test
->dead_code_cnt
,
6172 if (*btf_log_buf
&& (err
|| always_log
))
6173 fprintf(stderr
, "\n%s", btf_log_buf
);
6180 if (!IS_ERR(patched_linfo
))
6181 free(patched_linfo
);
6184 struct btf_raw_data
{
6185 __u32 raw_types
[MAX_NR_RAW_U32
];
6186 const char *str_sec
;
6190 struct btf_dedup_test
{
6192 struct btf_raw_data input
;
6193 struct btf_raw_data expect
;
6194 struct btf_dedup_opts opts
;
6197 const struct btf_dedup_test dedup_tests
[] = {
6200 .descr
= "dedup: unused strings filtering",
6203 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 32, 4),
6204 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED
, 0, 64, 8),
6207 BTF_STR_SEC("\0unused\0int\0foo\0bar\0long"),
6211 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6212 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 64, 8),
6215 BTF_STR_SEC("\0int\0long"),
6218 .dont_resolve_fwds
= false,
6222 .descr
= "dedup: strings deduplication",
6225 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6226 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 64, 8),
6227 BTF_TYPE_INT_ENC(NAME_NTH(3), BTF_INT_SIGNED
, 0, 32, 4),
6228 BTF_TYPE_INT_ENC(NAME_NTH(4), BTF_INT_SIGNED
, 0, 64, 8),
6229 BTF_TYPE_INT_ENC(NAME_NTH(5), BTF_INT_SIGNED
, 0, 32, 4),
6232 BTF_STR_SEC("\0int\0long int\0int\0long int\0int"),
6236 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6237 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 64, 8),
6240 BTF_STR_SEC("\0int\0long int"),
6243 .dont_resolve_fwds
= false,
6247 .descr
= "dedup: struct example #1",
6259 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
6261 BTF_TYPE_ARRAY_ENC(1, 1, 16), /* [2] */
6263 BTF_STRUCT_ENC(NAME_NTH(2), 4, 84), /* [3] */
6264 BTF_MEMBER_ENC(NAME_NTH(3), 4, 0), /* struct s *next; */
6265 BTF_MEMBER_ENC(NAME_NTH(4), 5, 64), /* const int *a; */
6266 BTF_MEMBER_ENC(NAME_NTH(5), 2, 128), /* int b[16]; */
6267 BTF_MEMBER_ENC(NAME_NTH(6), 1, 640), /* int c; */
6268 /* ptr -> [3] struct s */
6269 BTF_PTR_ENC(3), /* [4] */
6270 /* ptr -> [6] const int */
6271 BTF_PTR_ENC(6), /* [5] */
6272 /* const -> [1] int */
6273 BTF_CONST_ENC(1), /* [6] */
6275 /* full copy of the above */
6276 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4), /* [7] */
6277 BTF_TYPE_ARRAY_ENC(7, 7, 16), /* [8] */
6278 BTF_STRUCT_ENC(NAME_NTH(2), 4, 84), /* [9] */
6279 BTF_MEMBER_ENC(NAME_NTH(3), 10, 0),
6280 BTF_MEMBER_ENC(NAME_NTH(4), 11, 64),
6281 BTF_MEMBER_ENC(NAME_NTH(5), 8, 128),
6282 BTF_MEMBER_ENC(NAME_NTH(6), 7, 640),
6283 BTF_PTR_ENC(9), /* [10] */
6284 BTF_PTR_ENC(12), /* [11] */
6285 BTF_CONST_ENC(7), /* [12] */
6288 BTF_STR_SEC("\0int\0s\0next\0a\0b\0c\0"),
6293 BTF_TYPE_INT_ENC(NAME_NTH(4), BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
6295 BTF_TYPE_ARRAY_ENC(1, 1, 16), /* [2] */
6297 BTF_STRUCT_ENC(NAME_NTH(6), 4, 84), /* [3] */
6298 BTF_MEMBER_ENC(NAME_NTH(5), 4, 0), /* struct s *next; */
6299 BTF_MEMBER_ENC(NAME_NTH(1), 5, 64), /* const int *a; */
6300 BTF_MEMBER_ENC(NAME_NTH(2), 2, 128), /* int b[16]; */
6301 BTF_MEMBER_ENC(NAME_NTH(3), 1, 640), /* int c; */
6302 /* ptr -> [3] struct s */
6303 BTF_PTR_ENC(3), /* [4] */
6304 /* ptr -> [6] const int */
6305 BTF_PTR_ENC(6), /* [5] */
6306 /* const -> [1] int */
6307 BTF_CONST_ENC(1), /* [6] */
6310 BTF_STR_SEC("\0a\0b\0c\0int\0next\0s"),
6313 .dont_resolve_fwds
= false,
6317 .descr
= "dedup: struct <-> fwd resolution w/ hash collision",
6333 BTF_FWD_ENC(NAME_TBD
, 0 /* struct fwd */), /* [1] fwd x */
6334 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
6335 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [3] struct s */
6336 BTF_MEMBER_ENC(NAME_TBD
, 2, 0),
6338 BTF_STRUCT_ENC(NAME_TBD
, 0, 0), /* [4] struct x */
6339 BTF_PTR_ENC(4), /* [5] ptr -> [4] */
6340 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [6] struct s */
6341 BTF_MEMBER_ENC(NAME_TBD
, 5, 0),
6344 BTF_STR_SEC("\0x\0s\0x\0x\0s\0x\0"),
6348 BTF_PTR_ENC(3), /* [1] ptr -> [3] */
6349 BTF_STRUCT_ENC(NAME_TBD
, 1, 8), /* [2] struct s */
6350 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6351 BTF_STRUCT_ENC(NAME_NTH(2), 0, 0), /* [3] struct x */
6354 BTF_STR_SEC("\0s\0x"),
6357 .dont_resolve_fwds
= false,
6358 .dedup_table_size
= 1, /* force hash collisions */
6362 .descr
= "dedup: void equiv check",
6376 BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
6377 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
6378 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
6379 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
6381 BTF_PTR_ENC(0), /* [4] ptr -> void */
6382 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
6383 BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
6386 BTF_STR_SEC("\0s\0x"),
6391 BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
6392 BTF_PTR_ENC(1), /* [2] ptr -> [1] */
6393 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
6394 BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
6396 BTF_PTR_ENC(0), /* [4] ptr -> void */
6397 BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
6398 BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
6401 BTF_STR_SEC("\0s\0x"),
6404 .dont_resolve_fwds
= false,
6405 .dedup_table_size
= 1, /* force hash collisions */
6409 .descr
= "dedup: all possible kinds (no duplicates)",
6412 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 8), /* [1] int */
6413 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), 4), /* [2] enum */
6414 BTF_ENUM_ENC(NAME_TBD
, 0),
6415 BTF_ENUM_ENC(NAME_TBD
, 1),
6416 BTF_FWD_ENC(NAME_TBD
, 1 /* union kind_flag */), /* [3] fwd */
6417 BTF_TYPE_ARRAY_ENC(2, 1, 7), /* [4] array */
6418 BTF_STRUCT_ENC(NAME_TBD
, 1, 4), /* [5] struct */
6419 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6420 BTF_UNION_ENC(NAME_TBD
, 1, 4), /* [6] union */
6421 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6422 BTF_TYPEDEF_ENC(NAME_TBD
, 1), /* [7] typedef */
6423 BTF_PTR_ENC(0), /* [8] ptr */
6424 BTF_CONST_ENC(8), /* [9] const */
6425 BTF_VOLATILE_ENC(8), /* [10] volatile */
6426 BTF_RESTRICT_ENC(8), /* [11] restrict */
6427 BTF_FUNC_PROTO_ENC(1, 2), /* [12] func_proto */
6428 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
6429 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 8),
6430 BTF_FUNC_ENC(NAME_TBD
, 12), /* [13] func */
6433 BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M"),
6437 BTF_TYPE_INT_ENC(NAME_TBD
, BTF_INT_SIGNED
, 0, 32, 8), /* [1] int */
6438 BTF_TYPE_ENC(NAME_TBD
, BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 2), 4), /* [2] enum */
6439 BTF_ENUM_ENC(NAME_TBD
, 0),
6440 BTF_ENUM_ENC(NAME_TBD
, 1),
6441 BTF_FWD_ENC(NAME_TBD
, 1 /* union kind_flag */), /* [3] fwd */
6442 BTF_TYPE_ARRAY_ENC(2, 1, 7), /* [4] array */
6443 BTF_STRUCT_ENC(NAME_TBD
, 1, 4), /* [5] struct */
6444 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6445 BTF_UNION_ENC(NAME_TBD
, 1, 4), /* [6] union */
6446 BTF_MEMBER_ENC(NAME_TBD
, 1, 0),
6447 BTF_TYPEDEF_ENC(NAME_TBD
, 1), /* [7] typedef */
6448 BTF_PTR_ENC(0), /* [8] ptr */
6449 BTF_CONST_ENC(8), /* [9] const */
6450 BTF_VOLATILE_ENC(8), /* [10] volatile */
6451 BTF_RESTRICT_ENC(8), /* [11] restrict */
6452 BTF_FUNC_PROTO_ENC(1, 2), /* [12] func_proto */
6453 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 1),
6454 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD
, 8),
6455 BTF_FUNC_ENC(NAME_TBD
, 12), /* [13] func */
6458 BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M"),
6461 .dont_resolve_fwds
= false,
6465 .descr
= "dedup: no int duplicates",
6468 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 8),
6469 /* different name */
6470 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 32, 8),
6471 /* different encoding */
6472 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR
, 0, 32, 8),
6473 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL
, 0, 32, 8),
6474 /* different bit offset */
6475 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 8, 32, 8),
6476 /* different bit size */
6477 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 27, 8),
6478 /* different byte size */
6479 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6482 BTF_STR_SEC("\0int\0some other int"),
6486 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 8),
6487 /* different name */
6488 BTF_TYPE_INT_ENC(NAME_NTH(2), BTF_INT_SIGNED
, 0, 32, 8),
6489 /* different encoding */
6490 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_CHAR
, 0, 32, 8),
6491 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_BOOL
, 0, 32, 8),
6492 /* different bit offset */
6493 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 8, 32, 8),
6494 /* different bit size */
6495 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 27, 8),
6496 /* different byte size */
6497 BTF_TYPE_INT_ENC(NAME_NTH(1), BTF_INT_SIGNED
, 0, 32, 4),
6500 BTF_STR_SEC("\0int\0some other int"),
6503 .dont_resolve_fwds
= false,
6507 .descr
= "dedup: enum fwd resolution",
6510 /* [1] fwd enum 'e1' before full enum */
6511 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 0), 4),
6512 /* [2] full enum 'e1' after fwd */
6513 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6514 BTF_ENUM_ENC(NAME_NTH(2), 123),
6515 /* [3] full enum 'e2' before fwd */
6516 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6517 BTF_ENUM_ENC(NAME_NTH(4), 456),
6518 /* [4] fwd enum 'e2' after full enum */
6519 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 0), 4),
6520 /* [5] incompatible fwd enum with different size */
6521 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 0), 1),
6522 /* [6] incompatible full enum with different value */
6523 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6524 BTF_ENUM_ENC(NAME_NTH(2), 321),
6527 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
6531 /* [1] full enum 'e1' */
6532 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6533 BTF_ENUM_ENC(NAME_NTH(2), 123),
6534 /* [2] full enum 'e2' */
6535 BTF_TYPE_ENC(NAME_NTH(3), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6536 BTF_ENUM_ENC(NAME_NTH(4), 456),
6537 /* [3] incompatible fwd enum with different size */
6538 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 0), 1),
6539 /* [4] incompatible full enum with different value */
6540 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_ENUM
, 0, 1), 4),
6541 BTF_ENUM_ENC(NAME_NTH(2), 321),
6544 BTF_STR_SEC("\0e1\0e1_val\0e2\0e2_val"),
6547 .dont_resolve_fwds
= false,
6551 .descr
= "dedup: datasec and vars pass-through",
6555 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
6557 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [2] */
6558 /* .bss section */ /* [3] */
6559 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
6560 BTF_VAR_SECINFO_ENC(2, 0, 4),
6561 /* int, referenced from [5] */
6562 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [4] */
6563 /* another static int t */
6564 BTF_VAR_ENC(NAME_NTH(2), 4, 0), /* [5] */
6565 /* another .bss section */ /* [6] */
6566 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
6567 BTF_VAR_SECINFO_ENC(5, 0, 4),
6570 BTF_STR_SEC("\0.bss\0t"),
6575 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED
, 0, 32, 4), /* [1] */
6577 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [2] */
6578 /* .bss section */ /* [3] */
6579 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
6580 BTF_VAR_SECINFO_ENC(2, 0, 4),
6581 /* another static int t */
6582 BTF_VAR_ENC(NAME_NTH(2), 1, 0), /* [4] */
6583 /* another .bss section */ /* [5] */
6584 BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC
, 0, 1), 4),
6585 BTF_VAR_SECINFO_ENC(4, 0, 4),
6588 BTF_STR_SEC("\0.bss\0t"),
6591 .dont_resolve_fwds
= false,
6592 .dedup_table_size
= 1
6598 static int btf_type_size(const struct btf_type
*t
)
6600 int base_size
= sizeof(struct btf_type
);
6601 __u16 vlen
= BTF_INFO_VLEN(t
->info
);
6602 __u16 kind
= BTF_INFO_KIND(t
->info
);
6606 case BTF_KIND_CONST
:
6607 case BTF_KIND_VOLATILE
:
6608 case BTF_KIND_RESTRICT
:
6610 case BTF_KIND_TYPEDEF
:
6614 return base_size
+ sizeof(__u32
);
6616 return base_size
+ vlen
* sizeof(struct btf_enum
);
6617 case BTF_KIND_ARRAY
:
6618 return base_size
+ sizeof(struct btf_array
);
6619 case BTF_KIND_STRUCT
:
6620 case BTF_KIND_UNION
:
6621 return base_size
+ vlen
* sizeof(struct btf_member
);
6622 case BTF_KIND_FUNC_PROTO
:
6623 return base_size
+ vlen
* sizeof(struct btf_param
);
6625 return base_size
+ sizeof(struct btf_var
);
6626 case BTF_KIND_DATASEC
:
6627 return base_size
+ vlen
* sizeof(struct btf_var_secinfo
);
6629 fprintf(stderr
, "Unsupported BTF_KIND:%u\n", kind
);
6634 static void dump_btf_strings(const char *strs
, __u32 len
)
6636 const char *cur
= strs
;
6639 while (cur
< strs
+ len
) {
6640 fprintf(stderr
, "string #%d: '%s'\n", i
, cur
);
6641 cur
+= strlen(cur
) + 1;
6646 static void do_test_dedup(unsigned int test_num
)
6648 const struct btf_dedup_test
*test
= &dedup_tests
[test_num
- 1];
6649 __u32 test_nr_types
, expect_nr_types
, test_btf_size
, expect_btf_size
;
6650 const struct btf_header
*test_hdr
, *expect_hdr
;
6651 struct btf
*test_btf
= NULL
, *expect_btf
= NULL
;
6652 const void *test_btf_data
, *expect_btf_data
;
6653 const char *ret_test_next_str
, *ret_expect_next_str
;
6654 const char *test_strs
, *expect_strs
;
6655 const char *test_str_cur
;
6656 const char *expect_str_cur
, *expect_str_end
;
6657 unsigned int raw_btf_size
;
6661 if (!test__start_subtest(test
->descr
))
6664 raw_btf
= btf_raw_create(&hdr_tmpl
, test
->input
.raw_types
,
6665 test
->input
.str_sec
, test
->input
.str_sec_size
,
6666 &raw_btf_size
, &ret_test_next_str
);
6670 test_btf
= btf__new((__u8
*)raw_btf
, raw_btf_size
);
6672 if (CHECK(IS_ERR(test_btf
), "invalid test_btf errno:%ld",
6673 PTR_ERR(test_btf
))) {
6678 raw_btf
= btf_raw_create(&hdr_tmpl
, test
->expect
.raw_types
,
6679 test
->expect
.str_sec
,
6680 test
->expect
.str_sec_size
,
6681 &raw_btf_size
, &ret_expect_next_str
);
6684 expect_btf
= btf__new((__u8
*)raw_btf
, raw_btf_size
);
6686 if (CHECK(IS_ERR(expect_btf
), "invalid expect_btf errno:%ld",
6687 PTR_ERR(expect_btf
))) {
6692 err
= btf__dedup(test_btf
, NULL
, &test
->opts
);
6693 if (CHECK(err
, "btf_dedup failed errno:%d", err
)) {
6698 test_btf_data
= btf__get_raw_data(test_btf
, &test_btf_size
);
6699 expect_btf_data
= btf__get_raw_data(expect_btf
, &expect_btf_size
);
6700 if (CHECK(test_btf_size
!= expect_btf_size
,
6701 "test_btf_size:%u != expect_btf_size:%u",
6702 test_btf_size
, expect_btf_size
)) {
6707 test_hdr
= test_btf_data
;
6708 test_strs
= test_btf_data
+ sizeof(*test_hdr
) + test_hdr
->str_off
;
6709 expect_hdr
= expect_btf_data
;
6710 expect_strs
= expect_btf_data
+ sizeof(*test_hdr
) + expect_hdr
->str_off
;
6711 if (CHECK(test_hdr
->str_len
!= expect_hdr
->str_len
,
6712 "test_hdr->str_len:%u != expect_hdr->str_len:%u",
6713 test_hdr
->str_len
, expect_hdr
->str_len
)) {
6714 fprintf(stderr
, "\ntest strings:\n");
6715 dump_btf_strings(test_strs
, test_hdr
->str_len
);
6716 fprintf(stderr
, "\nexpected strings:\n");
6717 dump_btf_strings(expect_strs
, expect_hdr
->str_len
);
6722 expect_str_cur
= expect_strs
;
6723 expect_str_end
= expect_strs
+ expect_hdr
->str_len
;
6724 while (expect_str_cur
< expect_str_end
) {
6725 size_t test_len
, expect_len
;
6728 off
= btf__find_str(test_btf
, expect_str_cur
);
6729 if (CHECK(off
< 0, "exp str '%s' not found: %d\n", expect_str_cur
, off
)) {
6733 test_str_cur
= btf__str_by_offset(test_btf
, off
);
6735 test_len
= strlen(test_str_cur
);
6736 expect_len
= strlen(expect_str_cur
);
6737 if (CHECK(test_len
!= expect_len
,
6738 "test_len:%zu != expect_len:%zu "
6739 "(test_str:%s, expect_str:%s)",
6740 test_len
, expect_len
, test_str_cur
, expect_str_cur
)) {
6744 if (CHECK(strcmp(test_str_cur
, expect_str_cur
),
6745 "test_str:%s != expect_str:%s",
6746 test_str_cur
, expect_str_cur
)) {
6750 expect_str_cur
+= expect_len
+ 1;
6753 test_nr_types
= btf__get_nr_types(test_btf
);
6754 expect_nr_types
= btf__get_nr_types(expect_btf
);
6755 if (CHECK(test_nr_types
!= expect_nr_types
,
6756 "test_nr_types:%u != expect_nr_types:%u",
6757 test_nr_types
, expect_nr_types
)) {
6762 for (i
= 1; i
<= test_nr_types
; i
++) {
6763 const struct btf_type
*test_type
, *expect_type
;
6764 int test_size
, expect_size
;
6766 test_type
= btf__type_by_id(test_btf
, i
);
6767 expect_type
= btf__type_by_id(expect_btf
, i
);
6768 test_size
= btf_type_size(test_type
);
6769 expect_size
= btf_type_size(expect_type
);
6771 if (CHECK(test_size
!= expect_size
,
6772 "type #%d: test_size:%d != expect_size:%u",
6773 i
, test_size
, expect_size
)) {
6777 if (CHECK(btf_kind(test_type
) != btf_kind(expect_type
),
6778 "type %d kind: exp %d != got %u\n",
6779 i
, btf_kind(expect_type
), btf_kind(test_type
))) {
6783 if (CHECK(test_type
->info
!= expect_type
->info
,
6784 "type %d info: exp %d != got %u\n",
6785 i
, expect_type
->info
, test_type
->info
)) {
6789 if (CHECK(test_type
->size
!= expect_type
->size
,
6790 "type %d size/type: exp %d != got %u\n",
6791 i
, expect_type
->size
, test_type
->size
)) {
6798 if (!IS_ERR(test_btf
))
6799 btf__free(test_btf
);
6800 if (!IS_ERR(expect_btf
))
6801 btf__free(expect_btf
);
6808 always_log
= env
.verbosity
> VERBOSE_NONE
;
6810 for (i
= 1; i
<= ARRAY_SIZE(raw_tests
); i
++)
6812 for (i
= 1; i
<= ARRAY_SIZE(get_info_tests
); i
++)
6813 do_test_get_info(i
);
6814 for (i
= 1; i
<= ARRAY_SIZE(file_tests
); i
++)
6816 for (i
= 1; i
<= ARRAY_SIZE(info_raw_tests
); i
++)
6817 do_test_info_raw(i
);
6818 for (i
= 1; i
<= ARRAY_SIZE(dedup_tests
); i
++)