Skip to contentSkip to conversation

5.15.221 & 6.1.188: bpftool: redefinition of 'free_btf_vmlinux'

REGRESSION New Suraj Jitindar Singh 2 participants 4 messages Sep 15 – Sep 16

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Greg, all,

Building bpftool from the v6.1.188 and v5.15.221 stable tags fails with a duplicate function definition:

tools/bpf/bpftool/map.c: error: redefinition of 'free_btf_vmlinux'
note: previous definition of 'free_btf_vmlinux' was here

This is a stable-only regression caused by a bad backport (the fix is correct in mainline). It affects only the current head of each series:

  Tree     Broken      Last good
  5.15.y   v5.15.221   v5.15.220
  6.1.y    v6.1.188    v6.1.187

6.6.y, 6.12.y, 6.18.y and 7.2.y are NOT affected -- those trees already carried free_btf_vmlinux() in its current (btf_vmlinux = NULL) form before this cycle, so the backport deduplicated cleanly there.

Root cause
----------
In 6.1.y the backport of

660a19e46942 ("tools/bpf/bpftool: Reset vmlinux BTF after map commands") [mainline 66d7e39e49b0]

*adds* a free_btf_vmlinux() definition. But 6.1.y still carried the older definition that mainline had already removed, so the result is two identical-signature static definitions in map.c and the build breaks.

The same happens in 5.15.221, where two commits applied in the same release collide:

a9e2496111aa ("tools/bpf/bpftool: Reset vmlinux BTF after map commands") 44f58f0c5202 ("bpftool: Use libbpf_get_error() to check error")

the latter keeping the old guarded form (if (!libbpf_get_error(...))) while the former adds the new form.

Reproducer (no kernel build / .config needed)
---------------------------------------------
git checkout v6.1.188 # or v5.15.221

  gcc -fsyntax-only tools/bpf/bpftool/map.c \
      -Itools/bpf/bpftool -Itools/include -Itools/include/uapi \
      -Itools/lib -Itools/bpf/bpftool/../../include

=> map.c: error: redefinition of 'free_btf_vmlinux'

Suggested fix
-------------
Drop the stale pre-existing definition and keep the one introduced by the backport (which also resets btf_vmlinux = NULL, matching mainline 66d7e39e49b0). For 6.1.y:

  --- a/tools/bpf/bpftool/map.c
  +++ b/tools/bpf/bpftool/map.c
  @@ -817,11 +817,6 @@ static void free_map_kv_btf(struct btf *btf)
   		btf__free(btf);
   }

  -static void free_btf_vmlinux(void)
  -{
  -	btf__free(btf_vmlinux);
  -}
  -
   static int
   map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,

For 5.15.y the same fix applies -- remove the older libbpf_get_error()-guarded free_btf_vmlinux() definition, keeping the one that resets btf_vmlinux = NULL.

Happy to send this as a formal patch per-tree if you prefer.

#regzbot introduced: 660a19e46942

Thanks,
Suraj

#1 lore raw

PATCH 1/1 bpftool: remove duplicate free_btf_vmlinux() definition

v6.1.188 backported

660a19e46942 ("tools/bpf/bpftool: Reset vmlinux BTF after map commands") [ upstream commit 66d7e39e49b0 ]

which re-adds free_btf_vmlinux(). However, the prerequisite cleanup

52df1a8aabad ("bpftool: remove function free_btf_vmlinux()")

was never backported to 6.1.y, so the tree still carried the original free_btf_vmlinux() definition. The backport therefore produced two identical-signature static definitions in tools/bpf/bpftool/map.c and the build fails:

map.c: error: redefinition of 'free_btf_vmlinux'

Remove the stale pre-existing definition, keeping the one reintroduced by 660a19e46942 (which also resets btf_vmlinux = NULL). This matches the current mainline end state.

Fixes 660a19e46942 ("tools/bpf/bpftool: Reset vmlinux BTF after map commands")

---
This is a stable-only fix. Mainline is not affected: 52df1a8aabad ("bpftool: remove function free_btf_vmlinux()") removed the original definition, and 66d7e39e49b0 later re-added a single one. The duplicate exists only in the 5.15.y and 6.1.y trees, which received the backport of 66d7e39e49b0 without the prerequisite 52df1a8aabad. There is therefore no single upstream commit to cite; the fix restores the mainline end state.

 tools/bpf/bpftool/map.c | 5 -----
 1 file changed, 5 deletions(-)
tools/bpf/bpftool/map.c +0 -5
index a77bf45d6f83..748b3def6b2c 100644
@@ -817,11 +817,6 @@ static void free_map_kv_btf(struct btf *btf)
 		btf__free(btf);
 }
 
-static void free_btf_vmlinux(void)
-{
-	btf__free(btf_vmlinux);
-}
-
 static int
 map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
 	 bool show_header)
Signature · 1 line
2.47.3
#2 lore raw

PATCH 1/1 bpftool: remove duplicate free_btf_vmlinux() definition

In reply to Suraj Jitindar Singh

v5.15.221 backported

a9e2496111aa ("tools/bpf/bpftool: Reset vmlinux BTF after map commands") [ upstream commit 66d7e39e49b0 ]

which re-adds free_btf_vmlinux(). However, the prerequisite cleanup

52df1a8aabad ("bpftool: remove function free_btf_vmlinux()")

was never backported to 5.15.y, so the tree still carried the original free_btf_vmlinux() definition. The backport therefore produced two identical-signature static definitions in tools/bpf/bpftool/map.c and the build fails:

map.c: error: redefinition of 'free_btf_vmlinux'

Remove the stale pre-existing definition, keeping the one reintroduced by a9e2496111aa (which also resets btf_vmlinux = NULL). This matches the current mainline end state.

Fixes a9e2496111aa ("tools/bpf/bpftool: Reset vmlinux BTF after map commands")

---
This is a stable-only fix. Mainline is not affected: 52df1a8aabad ("bpftool: remove function free_btf_vmlinux()") removed the original definition, and 66d7e39e49b0 later re-added a single one. The duplicate exists only in the 5.15.y and 6.1.y trees, which received the backport of 66d7e39e49b0 without the prerequisite 52df1a8aabad. There is therefore no single upstream commit to cite; the fix restores the mainline end state.

 tools/bpf/bpftool/map.c | 6 ------
 1 file changed, 6 deletions(-)
tools/bpf/bpftool/map.c +0 -6
index cf257da20195..54d855ac5408 100644
@@ -828,12 +828,6 @@ static void free_map_kv_btf(struct btf *btf)
 		btf__free(btf);
 }
 
-static void free_btf_vmlinux(void)
-{
-	if (!libbpf_get_error(btf_vmlinux))
-		btf__free(btf_vmlinux);
-}
-
 static int
 map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
 	 bool show_header)
Signature · 1 line
2.47.3
maintainer Applied
#3 lore raw
In reply to Suraj Jitindar Singh
Quoted 5 lines

Building bpftool from the v6.1.188 and v5.15.221 stable tags fails with a duplicate function definition:

tools/bpf/bpftool/map.c: error: redefinition of 'free_btf_vmlinux'
note: previous definition of 'free_btf_vmlinux' was here

Queued for 6.1 and 5.15, thanks.

Signature · 2 lines
Thanks,
Sasha