btf: resolve enum fwds in btf_dedup
authorAndrii Nakryiko <andriin@fb.com>
Mon, 11 Mar 2019 00:44:09 +0000 (17:44 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 14 Mar 2019 20:53:18 +0000 (13:53 -0700)
commit9768095ba97ce946838e8210f0b44f2fd36ec31d
tree991332fbd5ee7eacdf4beb46cda6c32110d8834e
parentf48a920504e516bded420255946f8e1cb8a0944a
btf: resolve enum fwds in btf_dedup

GCC and clang support enum forward declarations as an extension. Such
forward-declared enums will be represented as normal BTF_KIND_ENUM types with
vlen=0. This patch adds ability to resolve such enums to their corresponding
fully defined enums. This helps to avoid duplicated BTF type graphs which only
differ by some types referencing forward-declared enum vs full enum.

One such example in kernel is enum irqchip_irq_state, defined in
include/linux/interrupt.h and forward-declared in include/linux/irq.h. This
causes entire struct task_struct and all referenced types to be duplicated in
btf_dedup output. This patch eliminates such duplication cases.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/btf.c