Commit de048b6
libbpf: Resolve enum fwd as full enum64 and vice versa
Changes de-duplication logic for enums in the following way:
- update btf_hash_enum to ignore size and kind fields to get
ENUM and ENUM64 types in a same hash bucket;
- update btf_compat_enum to consider enum fwd to be compatible with
full enum64 (and vice versa);
This allows BTF de-duplication in the following case:
// CU #1
enum foo;
struct s {
enum foo *a;
} *x;
// CU #2
enum foo {
x = 0xfffffffff // big enough to force enum64
};
struct s {
enum foo *a;
} *y;
De-duplicated BTF prior to this commit:
[1] ENUM64 'foo' encoding=UNSIGNED size=8 vlen=1
'x' val=68719476735ULL
[2] INT 'long unsigned int' size=8 bits_offset=0 nr_bits=64
encoding=(none)
[3] STRUCT 's' size=8 vlen=1
'a' type_id=4 bits_offset=0
[4] PTR '(anon)' type_id=1
[5] PTR '(anon)' type_id=3
[6] STRUCT 's' size=8 vlen=1
'a' type_id=8 bits_offset=0
[7] ENUM 'foo' encoding=UNSIGNED size=4 vlen=0
[8] PTR '(anon)' type_id=7
[9] PTR '(anon)' type_id=6
De-duplicated BTF after this commit:
[1] ENUM64 'foo' encoding=UNSIGNED size=8 vlen=1
'x' val=68719476735ULL
[2] INT 'long unsigned int' size=8 bits_offset=0 nr_bits=64
encoding=(none)
[3] STRUCT 's' size=8 vlen=1
'a' type_id=4 bits_offset=0
[4] PTR '(anon)' type_id=1
[5] PTR '(anon)' type_id=3
Enum forward declarations in C do not provide information about
enumeration values range. Thus the `btf_type->size` field is
meaningless for forward enum declarations. In fact, GCC does not
encode size in DWARF for forward enum declarations
(but dwarves sets enumeration size to a default value of `sizeof(int) * 8`
when size is not specified see dwarf_loader.c:die__create_new_enumeration).
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221101235413.1824260-1-eddyz87@gmail.com1 parent 07d90c7 commit de048b6
1 file changed
Lines changed: 25 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3404 | 3404 | | |
3405 | 3405 | | |
3406 | 3406 | | |
3407 | | - | |
| 3407 | + | |
3408 | 3408 | | |
3409 | | - | |
3410 | | - | |
3411 | 3409 | | |
3412 | 3410 | | |
3413 | 3411 | | |
3414 | | - | |
3415 | | - | |
| 3412 | + | |
3416 | 3413 | | |
3417 | 3414 | | |
3418 | 3415 | | |
3419 | 3416 | | |
3420 | 3417 | | |
3421 | | - | |
3422 | | - | |
3423 | | - | |
3424 | 3418 | | |
3425 | 3419 | | |
3426 | 3420 | | |
| |||
3433 | 3427 | | |
3434 | 3428 | | |
3435 | 3429 | | |
3436 | | - | |
| 3430 | + | |
3437 | 3431 | | |
3438 | 3432 | | |
3439 | 3433 | | |
3440 | 3434 | | |
3441 | 3435 | | |
3442 | | - | |
3443 | | - | |
3444 | | - | |
3445 | 3436 | | |
3446 | 3437 | | |
3447 | 3438 | | |
| |||
3455 | 3446 | | |
3456 | 3447 | | |
3457 | 3448 | | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
3458 | 3462 | | |
3459 | 3463 | | |
3460 | 3464 | | |
| |||
3464 | 3468 | | |
3465 | 3469 | | |
3466 | 3470 | | |
3467 | | - | |
3468 | | - | |
3469 | | - | |
3470 | | - | |
3471 | | - | |
3472 | | - | |
3473 | | - | |
3474 | | - | |
3475 | | - | |
3476 | | - | |
3477 | | - | |
3478 | | - | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
3479 | 3477 | | |
3480 | | - | |
3481 | | - | |
| 3478 | + | |
3482 | 3479 | | |
3483 | 3480 | | |
3484 | 3481 | | |
| |||
3763 | 3760 | | |
3764 | 3761 | | |
3765 | 3762 | | |
| 3763 | + | |
3766 | 3764 | | |
3767 | 3765 | | |
3768 | 3766 | | |
| |||
3783 | 3781 | | |
3784 | 3782 | | |
3785 | 3783 | | |
3786 | | - | |
3787 | | - | |
3788 | | - | |
3789 | | - | |
3790 | | - | |
3791 | | - | |
3792 | | - | |
3793 | | - | |
3794 | | - | |
3795 | | - | |
3796 | | - | |
3797 | | - | |
3798 | | - | |
3799 | | - | |
3800 | | - | |
3801 | | - | |
3802 | | - | |
3803 | | - | |
3804 | | - | |
3805 | | - | |
3806 | | - | |
3807 | 3784 | | |
3808 | 3785 | | |
3809 | 3786 | | |
| |||
4099 | 4076 | | |
4100 | 4077 | | |
4101 | 4078 | | |
4102 | | - | |
4103 | | - | |
4104 | 4079 | | |
4105 | | - | |
| 4080 | + | |
4106 | 4081 | | |
4107 | 4082 | | |
4108 | 4083 | | |
| |||
0 commit comments