libbpf: fix build by renaming variables
Subsystems (4)
PATCH 1/1 libbpf: fix build by renaming variables
In btf__align_of() variable name 't' is shadowed by inner block declaration of another variable with same name. Patch renames variables in order to fix it.
CC sharedobjs/btf.obtf.c: In function ‘btf__align_of’:
btf.c:303:21: error: declaration of ‘t’ shadows a previous local [-Werror=shadow]
303 | int i, align = 1, t;
| ^
btf.c:283:25: note: shadowed declaration is here
283 | const struct btf_type *t = btf__type_by_id(btf, id);
|--- tools/lib/bpf/btf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/lib/bpf/btf.c +6 -6
@@ -300,16 +300,16 @@ int btf__align_of(const struct btf *btf, __u32 id)case BTF_KIND_UNION : {const struct btf_member *m =btf_members (t);__u16 vlen =btf_vlen (t); -int i, align =1 , t; +int i, max_align =1 , align;for (i =0 ; i < vlen; i++, m++) { - t =btf__align_of (btf, m->type); -if (t <=0 ) -return t; - align =max (align, t); + align =btf__align_of (btf, m->type); +if (align <=0 ) +return align; + max_align =max (max_align, align); } -return align; +return max_align; }default :pr_warn ("unsupported BTF_KIND:%u\n" ,btf_kind (t));
Signature · 1 line
2.21.0
Quoted 10 lines · Prashant Bhole
In
btf__align_of()variable name 't' is shadowed by inner block declaration of another variable with same name. Patch renames variables in order to fix it.CC
sharedobjs/btf.obtf.c: In function ‘btf__align_of’:
btf.c:303:21: error: declaration of ‘t’ shadows a previous local [-Werror=shadow]
303 | int i, align = 1, t;
| ^
btf.c:283:25: note: shadowed declaration is here
Quoted 5 lines
283 | const struct btf_type *t = btf__type_by_id(btf, id); |Fixes 3d208f4ca111 ("libbpf: Expose btf__align_of() API")Signed-off-by Prashant Bhole <[email protected]>
Seems there are quite a few build errors in bpf today; this at least fixes libbpf. Thank you!
Quoted 10 lines · Prashant Bhole
In
btf__align_of()variable name 't' is shadowed by inner block declaration of another variable with same name. Patch renames variables in order to fix it.CC
sharedobjs/btf.obtf.c: In function ‘btf__align_of’:
btf.c:303:21: error: declaration of ‘t’ shadows a previous local [-Werror=shadow]
303 | int i, align = 1, t;
| ^
btf.c:283:25: note: shadowed declaration is here
Quoted 5 lines
283 | const struct btf_type *t = btf__type_by_id(btf, id); |Fixes 3d208f4ca111 ("libbpf: Expose btf__align_of() API")Signed-off-by Prashant Bhole <[email protected]>
Applied, thanks!
Quoted 15 lines · Daniel Borkmann
Quoted 13 lines · Prashant Bhole
In
btf__align_of()variable name 't' is shadowed by inner block declaration of another variable with same name. Patch renames variables in order to fix it.CC
sharedobjs/btf.obtf.c: In function ‘btf__align_of’:
btf.c:303:21: error: declaration of ‘t’ shadows a previous local [-Werror=shadow]
303 | int i, align = 1, t;
| ^
btf.c:283:25: note: shadowed declaration is here283 | const struct btf_type *t = btf__type_by_id(btf, id); |
Quoted 4 lines
Quoted 2 lines
Fixes 3d208f4ca111 ("libbpf: Expose btf__align_of() API")Signed-off-by Prashant Bhole <[email protected]>Applied, thanks!
Prashant,
Thanks for the fixes.
Which compiler do use?
Sadly I didn't see any of those with my gcc 6.3.0
Going to upgrade it. Need to decide which one.
Daniel Borkmann
maintainerQuoted 18 lines · Alexei Starovoitov
Quoted 17 lines · Daniel Borkmann
Quoted 15 lines · Prashant Bhole
In
btf__align_of()variable name 't' is shadowed by inner block declaration of another variable with same name. Patch renames variables in order to fix it.CC
sharedobjs/btf.obtf.c: In function ‘btf__align_of’:
btf.c:303:21: error: declaration of ‘t’ shadows a previous local [-Werror=shadow]
303 | int i, align = 1, t;
| ^
btf.c:283:25: note: shadowed declaration is here283 | const struct btf_type *t = btf__type_by_id(btf, id); |Fixes 3d208f4ca111 ("libbpf: Expose btf__align_of() API")Signed-off-by Prashant Bhole <[email protected]>
Quoted 7 lines
Quoted 1 line
Applied, thanks!
Prashant,
Thanks for the fixes.
Which compiler do use?
Sadly I didn't see any of those with my gcc 6.3.0
Going to upgrade it. Need to decide which one.
I've seen it with:
$ gcc --version gcc (GCC) 9.0.1 20190312 (Red Hat 9.0.1-0.10)
Quoted 16 lines · Alexei Starovoitov
Quoted 15 lines · Daniel Borkmann
Quoted 13 lines · Prashant Bhole
In
btf__align_of()variable name 't' is shadowed by inner block declaration of another variable with same name. Patch renames variables in order to fix it.CC
sharedobjs/btf.obtf.c: In function ‘btf__align_of’:
btf.c:303:21: error: declaration of ‘t’ shadows a previous local [-Werror=shadow]
303 | int i, align = 1, t;
| ^
btf.c:283:25: note: shadowed declaration is here283 | const struct btf_type *t = btf__type_by_id(btf, id); |
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Fixes 3d208f4ca111 ("libbpf: Expose btf__align_of() API")Signed-off-by Prashant Bhole <[email protected]>Applied, thanks!
Prashant,
Thanks for the fixes.
Which compiler do use?
gcc (GCC) 9.1.1 20190503 (Red Hat 9.1.1-1)
Quoted 3 lines
Sadly I didn't see any of those with my gcc 6.3.0
Going to upgrade it. Need to decide which one.
Quoted 23 lines · Prashant Bhole
Quoted 19 lines · Alexei Starovoitov
Quoted 18 lines · Daniel Borkmann
Quoted 15 lines · Prashant Bhole
In
btf__align_of()variable name 't' is shadowed by inner block declaration of another variable with same name. Patch renames variables in order to fix it.CC
sharedobjs/btf.obtf.c: In function ‘btf__align_of’:
btf.c:303:21: error: declaration of ‘t’ shadows a previous local [-Werror=shadow]
303 | int i, align = 1, t;
| ^
btf.c:283:25: note: shadowed declaration is here283 | const struct btf_type *t = btf__type_by_id(btf, id); |Fixes 3d208f4ca111 ("libbpf: Expose btf__align_of() API")Signed-off-by Prashant Bhole <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Applied, thanks!
Prashant,
Thanks for the fixes.
Which compiler do use?gcc (GCC) 9.1.1 20190503 (Red Hat 9.1.1-1)
I've tried devtoolset-8 and devtoolset-9. Which is
gcc version 9.1.1 20190605 (Red Hat 9.1.1-2) (GCC)
make clean;make doesn't produce that warning.
make V=1 tells me:
gcc -O2 -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wstrict-prototypes -Wswitch-default -Wundef -Wwrite-strings -Wformat -Wstrict-aliasing=3 -fno-strict-aliasing -Wno-shadow
... -c -MMD -o gen.o gen.c
For some odd reason this check is failing for me
$ tools/scripts/Makefile.include ifneq ($(filter 3.%,$(MAKE_VERSION)),) # make-3 EXTRA_WARNINGS += -fno-strict-aliasing EXTRA_WARNINGS += -Wno-shadow else EXTRA_WARNINGS += -Wshadow endif
$ make -v GNU Make 3.82
Not sure how to fix this.