Skip to content

Commit e12ab61

Browse files
Xu KuohaiNobody
Xu Kuohai
authored and
Nobody
committed
libbpf: Skip forward declaration when counting duplicated type names
Currently if a declaration appears in the BTF before the definition, the definition is dumped as a conflicting name, eg: $ bpftool btf dump file vmlinux format raw | grep "'unix_sock'" [81287] FWD 'unix_sock' fwd_kind=struct [89336] STRUCT 'unix_sock' size=1024 vlen=14 $ bpftool btf dump file vmlinux format c | grep "struct unix_sock" struct unix_sock; struct unix_sock___2 { <--- conflict, the "___2" is unexpected struct unix_sock___2 *unix_sk; This causes a compilation error if the dump output is used as a header file. Fix it by skipping declaration when counting duplicated type names. Fixes: 351131b ("libbpf: add btf_dump API for BTF-to-C conversion") Signed-off-by: Xu Kuohai <[email protected]> Acked-by: Song Liu <[email protected]>
1 parent ee20c17 commit e12ab61

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/lib/bpf/btf_dump.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,11 @@ static const char *btf_dump_resolve_name(struct btf_dump *d, __u32 id,
15051505
if (s->name_resolved)
15061506
return *cached_name ? *cached_name : orig_name;
15071507

1508+
if (btf_is_fwd(t) || (btf_is_enum(t) && btf_vlen(t) == 0)) {
1509+
s->name_resolved = 1;
1510+
return orig_name;
1511+
}
1512+
15081513
dup_cnt = btf_dump_name_dups(d, name_map, orig_name);
15091514
if (dup_cnt > 1) {
15101515
const size_t max_len = 256;

0 commit comments

Comments
 (0)