diff mbox series

[bpf-next] libbpf: fix non-C89 loop variable declaration in gen_loader.c

Message ID 20211105191055.3324874-1-andrii@kernel.org (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series [bpf-next] libbpf: fix non-C89 loop variable declaration in gen_loader.c | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 6 maintainers not CCed: yhs@fb.com songliubraving@fb.com kafai@fb.com netdev@vger.kernel.org john.fastabend@gmail.com kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary

Commit Message

Andrii Nakryiko Nov. 5, 2021, 7:10 p.m. UTC
Fix the `int i` declaration inside the for statement. This is non-C89
compliant. See [0] for user report breaking BCC build.

  [0] https://github.com/libbpf/libbpf/issues/403

Fixes: 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/gen_loader.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Kumar Kartikeya Dwivedi Nov. 5, 2021, 8:40 p.m. UTC | #1
On Sat, Nov 06, 2021 at 12:40:55AM IST, Andrii Nakryiko wrote:
> Fix the `int i` declaration inside the for statement. This is non-C89
> compliant. See [0] for user report breaking BCC build.
>
>   [0] https://github.com/libbpf/libbpf/issues/403
>
> Fixes: 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

Thanks for the fix, and sorry about that.

Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

> [...]

--
Kartikeya
Andrii Nakryiko Nov. 5, 2021, 9:49 p.m. UTC | #2
On Fri, Nov 5, 2021 at 1:40 PM Kumar Kartikeya Dwivedi <memxor@gmail.com> wrote:
>
> On Sat, Nov 06, 2021 at 12:40:55AM IST, Andrii Nakryiko wrote:
> > Fix the `int i` declaration inside the for statement. This is non-C89
> > compliant. See [0] for user report breaking BCC build.
> >
> >   [0] https://github.com/libbpf/libbpf/issues/403
> >
> > Fixes: 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")
> > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
>
> Thanks for the fix, and sorry about that.
>
> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
>

No worries, we just need to figure out which compiler flags we need to
catch this. I'm surprised BCC build caught this and neither libbpf's
Makefile nor selftest did. Selftests are definitely too permissive
w.r.t. stuff like this.

If you could take a look and see what we'll need to lock it down a
bit, that would be great. I've also requested help from the original
reporter of this issue (see issue on Github).


> > [...]
>
> --
> Kartikeya
Kumar Kartikeya Dwivedi Nov. 5, 2021, 10:04 p.m. UTC | #3
On Sat, Nov 06, 2021 at 03:19:38AM IST, Andrii Nakryiko wrote:
> On Fri, Nov 5, 2021 at 1:40 PM Kumar Kartikeya Dwivedi <memxor@gmail.com> wrote:
> >
> > On Sat, Nov 06, 2021 at 12:40:55AM IST, Andrii Nakryiko wrote:
> > > Fix the `int i` declaration inside the for statement. This is non-C89
> > > compliant. See [0] for user report breaking BCC build.
> > >
> > >   [0] https://github.com/libbpf/libbpf/issues/403
> > >
> > > Fixes: 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")
> > > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> >
> > Thanks for the fix, and sorry about that.
> >
> > Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> >
>
> No worries, we just need to figure out which compiler flags we need to
> catch this. I'm surprised BCC build caught this and neither libbpf's
> Makefile nor selftest did. Selftests are definitely too permissive
> w.r.t. stuff like this.
>
> If you could take a look and see what we'll need to lock it down a
> bit, that would be great. I've also requested help from the original
> reporter of this issue (see issue on Github).
>

I think you want -std=gnu89 (i.e. C89 with GNU extensions). I get the same error
as the reporter when building with that.

>
> > > [...]
> >
> > --
> > Kartikeya

--
Kartikeya
Andrii Nakryiko Nov. 5, 2021, 10:20 p.m. UTC | #4
On Fri, Nov 5, 2021 at 3:04 PM Kumar Kartikeya Dwivedi <memxor@gmail.com> wrote:
>
> On Sat, Nov 06, 2021 at 03:19:38AM IST, Andrii Nakryiko wrote:
> > On Fri, Nov 5, 2021 at 1:40 PM Kumar Kartikeya Dwivedi <memxor@gmail.com> wrote:
> > >
> > > On Sat, Nov 06, 2021 at 12:40:55AM IST, Andrii Nakryiko wrote:
> > > > Fix the `int i` declaration inside the for statement. This is non-C89
> > > > compliant. See [0] for user report breaking BCC build.
> > > >
> > > >   [0] https://github.com/libbpf/libbpf/issues/403
> > > >
> > > > Fixes: 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")
> > > > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> > >
> > > Thanks for the fix, and sorry about that.
> > >
> > > Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> > >
> >
> > No worries, we just need to figure out which compiler flags we need to
> > catch this. I'm surprised BCC build caught this and neither libbpf's
> > Makefile nor selftest did. Selftests are definitely too permissive
> > w.r.t. stuff like this.
> >
> > If you could take a look and see what we'll need to lock it down a
> > bit, that would be great. I've also requested help from the original
> > reporter of this issue (see issue on Github).
> >
>
> I think you want -std=gnu89 (i.e. C89 with GNU extensions). I get the same error
> as the reporter when building with that.

Oh, I think I tried -std=c89 and it didn't compile due to use of those
extensions. Didn't realize gnu89 exists. Do you mind adding it to
bpftool, libbpf, and selftests Makefiles and sending a patch?

>
> >
> > > > [...]
> > >
> > > --
> > > Kartikeya
>
> --
> Kartikeya
Kumar Kartikeya Dwivedi Nov. 5, 2021, 10:26 p.m. UTC | #5
On Sat, Nov 06, 2021 at 03:50:47AM IST, Andrii Nakryiko wrote:
> On Fri, Nov 5, 2021 at 3:04 PM Kumar Kartikeya Dwivedi <memxor@gmail.com> wrote:
> >
> > On Sat, Nov 06, 2021 at 03:19:38AM IST, Andrii Nakryiko wrote:
> > > On Fri, Nov 5, 2021 at 1:40 PM Kumar Kartikeya Dwivedi <memxor@gmail.com> wrote:
> > > >
> > > > On Sat, Nov 06, 2021 at 12:40:55AM IST, Andrii Nakryiko wrote:
> > > > > Fix the `int i` declaration inside the for statement. This is non-C89
> > > > > compliant. See [0] for user report breaking BCC build.
> > > > >
> > > > >   [0] https://github.com/libbpf/libbpf/issues/403
> > > > >
> > > > > Fixes: 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")
> > > > > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> > > >
> > > > Thanks for the fix, and sorry about that.
> > > >
> > > > Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> > > >
> > >
> > > No worries, we just need to figure out which compiler flags we need to
> > > catch this. I'm surprised BCC build caught this and neither libbpf's
> > > Makefile nor selftest did. Selftests are definitely too permissive
> > > w.r.t. stuff like this.
> > >
> > > If you could take a look and see what we'll need to lock it down a
> > > bit, that would be great. I've also requested help from the original
> > > reporter of this issue (see issue on Github).
> > >
> >
> > I think you want -std=gnu89 (i.e. C89 with GNU extensions). I get the same error
> > as the reporter when building with that.
>
> Oh, I think I tried -std=c89 and it didn't compile due to use of those
> extensions. Didn't realize gnu89 exists. Do you mind adding it to
> bpftool, libbpf, and selftests Makefiles and sending a patch?
>

Sure, will do!

--
Kartikeya
Alexei Starovoitov Nov. 6, 2021, 4:37 p.m. UTC | #6
On Fri, Nov 5, 2021 at 12:11 PM Andrii Nakryiko <andrii@kernel.org> wrote:
>
> Fix the `int i` declaration inside the for statement. This is non-C89
> compliant. See [0] for user report breaking BCC build.
>
>   [0] https://github.com/libbpf/libbpf/issues/403

I'd prefer to fix bcc and/or its derivatives instead.
It's year 2021.
Andrii Nakryiko Nov. 6, 2021, 7:56 p.m. UTC | #7
On Sat, Nov 6, 2021 at 9:38 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Fri, Nov 5, 2021 at 12:11 PM Andrii Nakryiko <andrii@kernel.org> wrote:
> >
> > Fix the `int i` declaration inside the for statement. This is non-C89
> > compliant. See [0] for user report breaking BCC build.
> >
> >   [0] https://github.com/libbpf/libbpf/issues/403
>
> I'd prefer to fix bcc and/or its derivatives instead.
> It's year 2021.

Fixing BCC and derivatives is a separate topic. This is the only
instance of non-C89 compliant for() loop in libbpf and I'd prefer to
fix it at the very least for style consistency.
Alexei Starovoitov Nov. 6, 2021, 11:18 p.m. UTC | #8
On Sat, Nov 6, 2021 at 12:56 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Sat, Nov 6, 2021 at 9:38 AM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> >
> > On Fri, Nov 5, 2021 at 12:11 PM Andrii Nakryiko <andrii@kernel.org> wrote:
> > >
> > > Fix the `int i` declaration inside the for statement. This is non-C89
> > > compliant. See [0] for user report breaking BCC build.
> > >
> > >   [0] https://github.com/libbpf/libbpf/issues/403
> >
> > I'd prefer to fix bcc and/or its derivatives instead.
> > It's year 2021.
>
> Fixing BCC and derivatives is a separate topic. This is the only
> instance of non-C89 compliant for() loop in libbpf and I'd prefer to
> fix it at the very least for style consistency.

Fair enough. Applied.
diff mbox series

Patch

diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c
index 502dea53a742..2e10776b6d85 100644
--- a/tools/lib/bpf/gen_loader.c
+++ b/tools/lib/bpf/gen_loader.c
@@ -584,8 +584,9 @@  void bpf_gen__record_extern(struct bpf_gen *gen, const char *name, bool is_weak,
 static struct ksym_desc *get_ksym_desc(struct bpf_gen *gen, struct ksym_relo_desc *relo)
 {
 	struct ksym_desc *kdesc;
+	int i;
 
-	for (int i = 0; i < gen->nr_ksyms; i++) {
+	for (i = 0; i < gen->nr_ksyms; i++) {
 		if (!strcmp(gen->ksyms[i].name, relo->name)) {
 			gen->ksyms[i].ref++;
 			return &gen->ksyms[i];