* [PATCH] libbpf: fix warnings "'pad_type' 'pad_bits' 'new_off' may be used uninitialized"
@ 2023-07-27 8:25 Xiangyu Chen
2023-07-27 11:01 ` Jiri Olsa
0 siblings, 1 reply; 5+ messages in thread
From: Xiangyu Chen @ 2023-07-27 8:25 UTC (permalink / raw)
To: bpf; +Cc: linux-kernel
From: Xiangyu Chen <xiangyu.chen@windriver.com>
When turn on the yocto DEBUG_BUILD flag, the build options for gcc would enable maybe-uninitialized,
and following warnings would be reported as below:
| btf_dump.c: In function 'btf_dump_emit_bit_padding':
| btf_dump.c:916:4: error: 'pad_type' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| 916 | btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type,
| | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 917 | in_bitfield ? new_off - cur_off : 0);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| btf_dump.c:929:6: error: 'pad_bits' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| 929 | if (bits == pad_bits) {
| | ^
| btf_dump.c:913:28: error: 'new_off' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| 913 | (new_off == next_off && roundup(cur_off, next_align * 8) != new_off) ||
| | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| HOSTLD scripts/mod/modpost
Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
---
tools/lib/bpf/btf_dump.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 4d9f30bf7f01..79923c3b8777 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -867,8 +867,8 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d,
} pads[] = {
{"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8}
};
- int new_off, pad_bits, bits, i;
- const char *pad_type;
+ int new_off = 0, pad_bits = 0, bits, i;
+ const char *pad_type = NULL;
if (cur_off >= next_off)
return; /* no gap */
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] libbpf: fix warnings "'pad_type' 'pad_bits' 'new_off' may be used uninitialized" 2023-07-27 8:25 [PATCH] libbpf: fix warnings "'pad_type' 'pad_bits' 'new_off' may be used uninitialized" Xiangyu Chen @ 2023-07-27 11:01 ` Jiri Olsa 2023-07-27 18:23 ` Yonghong Song 2023-07-28 5:39 ` Xiangyu Chen 0 siblings, 2 replies; 5+ messages in thread From: Jiri Olsa @ 2023-07-27 11:01 UTC (permalink / raw) To: Xiangyu Chen; +Cc: bpf, linux-kernel On Thu, Jul 27, 2023 at 04:25:36PM +0800, Xiangyu Chen wrote: > From: Xiangyu Chen <xiangyu.chen@windriver.com> > > When turn on the yocto DEBUG_BUILD flag, the build options for gcc would enable maybe-uninitialized, > and following warnings would be reported as below: curious, what's the gcc version? I can't reproduce that, and we already have all warnings enabled: CFLAGS += -Werror -Wall they seem like false warnings also, because ARRAY_SIZE(pads) will be always > 0 jirka > > | btf_dump.c: In function 'btf_dump_emit_bit_padding': > | btf_dump.c:916:4: error: 'pad_type' may be used uninitialized in this function [-Werror=maybe-uninitialized] > | 916 | btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, > | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > | 917 | in_bitfield ? new_off - cur_off : 0); > | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > | btf_dump.c:929:6: error: 'pad_bits' may be used uninitialized in this function [-Werror=maybe-uninitialized] > | 929 | if (bits == pad_bits) { > | | ^ > | btf_dump.c:913:28: error: 'new_off' may be used uninitialized in this function [-Werror=maybe-uninitialized] > | 913 | (new_off == next_off && roundup(cur_off, next_align * 8) != new_off) || > | | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > | HOSTLD scripts/mod/modpost > > Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com> > --- > tools/lib/bpf/btf_dump.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c > index 4d9f30bf7f01..79923c3b8777 100644 > --- a/tools/lib/bpf/btf_dump.c > +++ b/tools/lib/bpf/btf_dump.c > @@ -867,8 +867,8 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d, > } pads[] = { > {"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8} > }; > - int new_off, pad_bits, bits, i; > - const char *pad_type; > + int new_off = 0, pad_bits = 0, bits, i; > + const char *pad_type = NULL; > > if (cur_off >= next_off) > return; /* no gap */ > -- > 2.34.1 > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libbpf: fix warnings "'pad_type' 'pad_bits' 'new_off' may be used uninitialized" 2023-07-27 11:01 ` Jiri Olsa @ 2023-07-27 18:23 ` Yonghong Song 2023-07-28 8:10 ` Jiri Olsa 2023-07-28 5:39 ` Xiangyu Chen 1 sibling, 1 reply; 5+ messages in thread From: Yonghong Song @ 2023-07-27 18:23 UTC (permalink / raw) To: Jiri Olsa, Xiangyu Chen; +Cc: bpf, linux-kernel On 7/27/23 4:01 AM, Jiri Olsa wrote: > On Thu, Jul 27, 2023 at 04:25:36PM +0800, Xiangyu Chen wrote: >> From: Xiangyu Chen <xiangyu.chen@windriver.com> >> >> When turn on the yocto DEBUG_BUILD flag, the build options for gcc would enable maybe-uninitialized, >> and following warnings would be reported as below: > > curious, what's the gcc version? I can't reproduce that, > and we already have all warnings enabled: > > CFLAGS += -Werror -Wall > > they seem like false warnings also, because ARRAY_SIZE(pads) > will be always > 0 Agree. This definitely a false positive. In kernel top Makefile, we have # Enabled with W=2, disabled by default as noisy ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += -Wno-maybe-uninitialized endif That means gcc -maybe-uninitialized is very noisy. > > jirka > >> >> | btf_dump.c: In function 'btf_dump_emit_bit_padding': >> | btf_dump.c:916:4: error: 'pad_type' may be used uninitialized in this function [-Werror=maybe-uninitialized] >> | 916 | btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, >> | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> | 917 | in_bitfield ? new_off - cur_off : 0); >> | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> | btf_dump.c:929:6: error: 'pad_bits' may be used uninitialized in this function [-Werror=maybe-uninitialized] >> | 929 | if (bits == pad_bits) { >> | | ^ >> | btf_dump.c:913:28: error: 'new_off' may be used uninitialized in this function [-Werror=maybe-uninitialized] >> | 913 | (new_off == next_off && roundup(cur_off, next_align * 8) != new_off) || >> | | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> | HOSTLD scripts/mod/modpost >> >> Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com> >> --- >> tools/lib/bpf/btf_dump.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c >> index 4d9f30bf7f01..79923c3b8777 100644 >> --- a/tools/lib/bpf/btf_dump.c >> +++ b/tools/lib/bpf/btf_dump.c >> @@ -867,8 +867,8 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d, >> } pads[] = { >> {"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8} >> }; >> - int new_off, pad_bits, bits, i; >> - const char *pad_type; >> + int new_off = 0, pad_bits = 0, bits, i; >> + const char *pad_type = NULL; >> >> if (cur_off >= next_off) >> return; /* no gap */ >> -- >> 2.34.1 >> >> > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libbpf: fix warnings "'pad_type' 'pad_bits' 'new_off' may be used uninitialized" 2023-07-27 18:23 ` Yonghong Song @ 2023-07-28 8:10 ` Jiri Olsa 0 siblings, 0 replies; 5+ messages in thread From: Jiri Olsa @ 2023-07-28 8:10 UTC (permalink / raw) To: Yonghong Song; +Cc: Jiri Olsa, Xiangyu Chen, bpf, linux-kernel On Thu, Jul 27, 2023 at 11:23:21AM -0700, Yonghong Song wrote: > > > On 7/27/23 4:01 AM, Jiri Olsa wrote: > > On Thu, Jul 27, 2023 at 04:25:36PM +0800, Xiangyu Chen wrote: > > > From: Xiangyu Chen <xiangyu.chen@windriver.com> > > > > > > When turn on the yocto DEBUG_BUILD flag, the build options for gcc would enable maybe-uninitialized, > > > and following warnings would be reported as below: > > > > curious, what's the gcc version? I can't reproduce that, > > and we already have all warnings enabled: > > > > CFLAGS += -Werror -Wall > > > > they seem like false warnings also, because ARRAY_SIZE(pads) > > will be always > 0 > > Agree. This definitely a false positive. > In kernel top Makefile, we have > > # Enabled with W=2, disabled by default as noisy > ifdef CONFIG_CC_IS_GCC > KBUILD_CFLAGS += -Wno-maybe-uninitialized > endif > > That means gcc -maybe-uninitialized is very noisy. nice, I think we should do the same then ;-) bt not sure how to do the gcc check though jirka > > > > > jirka > > > > > > > > | btf_dump.c: In function 'btf_dump_emit_bit_padding': > > > | btf_dump.c:916:4: error: 'pad_type' may be used uninitialized in this function [-Werror=maybe-uninitialized] > > > | 916 | btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, > > > | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > | 917 | in_bitfield ? new_off - cur_off : 0); > > > | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > | btf_dump.c:929:6: error: 'pad_bits' may be used uninitialized in this function [-Werror=maybe-uninitialized] > > > | 929 | if (bits == pad_bits) { > > > | | ^ > > > | btf_dump.c:913:28: error: 'new_off' may be used uninitialized in this function [-Werror=maybe-uninitialized] > > > | 913 | (new_off == next_off && roundup(cur_off, next_align * 8) != new_off) || > > > | | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > | HOSTLD scripts/mod/modpost > > > > > > Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com> > > > --- > > > tools/lib/bpf/btf_dump.c | 4 ++-- > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c > > > index 4d9f30bf7f01..79923c3b8777 100644 > > > --- a/tools/lib/bpf/btf_dump.c > > > +++ b/tools/lib/bpf/btf_dump.c > > > @@ -867,8 +867,8 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d, > > > } pads[] = { > > > {"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8} > > > }; > > > - int new_off, pad_bits, bits, i; > > > - const char *pad_type; > > > + int new_off = 0, pad_bits = 0, bits, i; > > > + const char *pad_type = NULL; > > > if (cur_off >= next_off) > > > return; /* no gap */ > > > -- > > > 2.34.1 > > > > > > > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libbpf: fix warnings "'pad_type' 'pad_bits' 'new_off' may be used uninitialized" 2023-07-27 11:01 ` Jiri Olsa 2023-07-27 18:23 ` Yonghong Song @ 2023-07-28 5:39 ` Xiangyu Chen 1 sibling, 0 replies; 5+ messages in thread From: Xiangyu Chen @ 2023-07-28 5:39 UTC (permalink / raw) To: Jiri Olsa; +Cc: bpf, linux-kernel On 7/27/23 19:01, Jiri Olsa wrote: > CAUTION: This email comes from a non Wind River email account! > Do not click links or open attachments unless you recognize the sender and know the content is safe. > > On Thu, Jul 27, 2023 at 04:25:36PM +0800, Xiangyu Chen wrote: >> From: Xiangyu Chen <xiangyu.chen@windriver.com> >> >> When turn on the yocto DEBUG_BUILD flag, the build options for gcc would enable maybe-uninitialized, >> and following warnings would be reported as below: > curious, what's the gcc version? I can't reproduce that, Indeed, it's also strange to me, the compiler using gcc-11.3.0 which is generated by yocto 4.2.2(mickledore branch). The warning happens on turn on DEBUG_BUILD flag in yocto configuration, but when disable the DEBUG_BUILD flag, this warning disappeared. I have compared w/wo the DEBUG_BUILD's kernel build parameters this morning, when enabled the flag, the kernel build parameters as normal, the warning won't happen. When I enabled the DEBUG_BUILD, the cflags with -Og -g -feliminate-unused-debug-types seems the debug cflags caused the false warning behavior. > and we already have all warnings enabled: > > CFLAGS += -Werror -Wall > > they seem like false warnings also, because ARRAY_SIZE(pads) > will be always > 0 > > jirka > >> | btf_dump.c: In function 'btf_dump_emit_bit_padding': >> | btf_dump.c:916:4: error: 'pad_type' may be used uninitialized in this function [-Werror=maybe-uninitialized] >> | 916 | btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, >> | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> | 917 | in_bitfield ? new_off - cur_off : 0); >> | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> | btf_dump.c:929:6: error: 'pad_bits' may be used uninitialized in this function [-Werror=maybe-uninitialized] >> | 929 | if (bits == pad_bits) { >> | | ^ >> | btf_dump.c:913:28: error: 'new_off' may be used uninitialized in this function [-Werror=maybe-uninitialized] >> | 913 | (new_off == next_off && roundup(cur_off, next_align * 8) != new_off) || >> | | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> | HOSTLD scripts/mod/modpost >> >> Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com> >> --- >> tools/lib/bpf/btf_dump.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c >> index 4d9f30bf7f01..79923c3b8777 100644 >> --- a/tools/lib/bpf/btf_dump.c >> +++ b/tools/lib/bpf/btf_dump.c >> @@ -867,8 +867,8 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d, >> } pads[] = { >> {"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8} >> }; >> - int new_off, pad_bits, bits, i; >> - const char *pad_type; >> + int new_off = 0, pad_bits = 0, bits, i; >> + const char *pad_type = NULL; >> >> if (cur_off >= next_off) >> return; /* no gap */ >> -- >> 2.34.1 >> >> ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-28 8:10 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-07-27 8:25 [PATCH] libbpf: fix warnings "'pad_type' 'pad_bits' 'new_off' may be used uninitialized" Xiangyu Chen 2023-07-27 11:01 ` Jiri Olsa 2023-07-27 18:23 ` Yonghong Song 2023-07-28 8:10 ` Jiri Olsa 2023-07-28 5:39 ` Xiangyu Chen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox