]> www.infradead.org Git - users/jedix/linux-maple.git/commit
bpftool: Introduce btf c dump sorting
authorMykyta Yatsenko <yatsenko@meta.com>
Tue, 14 May 2024 13:12:21 +0000 (14:12 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 18 May 2024 17:46:16 +0000 (10:46 -0700)
commit94133cf24bb33889aac267a7f0e3e6a08b8a8e5a
treee216440a607c5efdce134e920c36aa633e941fc8
parent4b377b4868ef17b040065bd468668c707d2477a5
bpftool: Introduce btf c dump sorting

Sort bpftool c dump output; aiming to simplify vmlinux.h diffing and
forcing more natural type definitions ordering.

Definitions are sorted first by their BTF kind ranks, then by their base
type name and by their own name.

Type ranks

Assign ranks to btf kinds (defined in function btf_type_rank) to set
next order:
1. Anonymous enums/enums64
2. Named enums/enums64
3. Trivial types typedefs (ints, then floats)
4. Structs/Unions
5. Function prototypes
6. Forward declarations

Type rank is set to maximum for unnamed reference types, structs and
unions to avoid emitting those types early. They will be emitted as
part of the type chain starting with named type.

Lexicographical ordering

Each type is assigned a sort_name and own_name.
sort_name is the resolved name of the final base type for reference
types (typedef, pointer, array etc). Sorting by sort_name allows to
group typedefs of the same base type. sort_name for non-reference type
is the same as own_name. own_name is a direct name of particular type,
is used as final sorting step.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240514131221.20585-1-yatsenko@meta.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/bpf/bpftool/Documentation/bpftool-btf.rst
tools/bpf/bpftool/bash-completion/bpftool
tools/bpf/bpftool/btf.c