btf_loader: handle union forward declaration properly
Differentiate between struct and union forwards in BTF. BTF type
representing forward declaration (BTF_KIND_FWD) encodes whether the
forward declaration is for struct or union type by using kflag. So use
that kflag to create a proper internal representation of forward
declaration.
Tested with btfdiff on vmlinux:
$ PAHOLE=build/pahole ./btfdiff ~/linux-build/default/vmlinux | wc -l
0
$
Also tested manually:
$ cat test.c
struct struct_fwd;
union union_fwd;
struct s {
struct struct_fwd *f1;
union union_fwd *f2;
};
int func(struct s *s) {
return !!s->f1 + !!s->f2;
}
$ clang -g -target bpf -c test.c -o test.o
$ bpftool btf dump file test.o | grep fwd_kind
[6] FWD 'struct_fwd' fwd_kind=struct
[8] FWD 'union_fwd' fwd_kind=union
$ build/pahole -F btf test.o
struct s {
struct struct_fwd * f1; /* 0 8 */
union union_fwd * f2; /* 8 8 */
/* size: 16, cachelines: 1, members: 2 */
/* last cacheline: 16 bytes */
};
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 file changed