1 From 74d0dcf7608b1bab116e297468ac51b57eb97ce0 Mon Sep 17 00:00:00 2001
2 From: Tony Ambardar <Tony.Ambardar@gmail.com>
3 Date: Thu, 20 Aug 2020 10:06:24 -0700
4 Subject: [PATCH] libbpf: fix build failure from uninitialized variable warning
6 While compiling libbpf, some GCC versions (at least 8.4.0) have difficulty
7 determining control flow and a emit warning for potentially uninitialized
8 usage of 'map', which results in a build error if using "-Werror":
10 In file included from libbpf.c:56:
11 libbpf.c: In function '__bpf_object__open':
12 libbpf_internal.h:59:2: warning: 'map' may be used uninitialized in this function [-Wmaybe-uninitialized]
13 libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \
15 libbpf.c:5032:18: note: 'map' was declared here
16 struct bpf_map *map, *targ_map;
19 The warning/error is false based on code inspection, so silence it with a
22 Fixes: 646f02ffdd49 ("libbpf: Add BTF-defined map-in-map support")
23 Ref: 063e68813391 ("libbpf: Fix false uninitialized variable warning")
25 Signed-off-by: Tony Ambardar <Tony.Ambardar@gmail.com>
27 tools/lib/bpf/libbpf.c | 2 +-
28 1 file changed, 1 insertion(+), 1 deletion(-)
30 diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
31 index 11e4725b8b1c..a72296797357 100644
32 --- a/tools/lib/bpf/libbpf.c
33 +++ b/tools/lib/bpf/libbpf.c
34 @@ -5028,8 +5028,8 @@ static int bpf_object__collect_map_relos(struct bpf_object *obj,
35 int i, j, nrels, new_sz, ptr_sz = sizeof(void *);
36 const struct btf_var_secinfo *vi = NULL;
37 const struct btf_type *sec, *var, *def;
38 + struct bpf_map *map = NULL, *targ_map;
39 const struct btf_member *member;
40 - struct bpf_map *map, *targ_map;
41 const char *name, *mname;