Skip to contentSkip to conversation

libbpf: fix non-C89 loop variable declaration in gen_loader.c

PATCH In review Andrii Nakryiko 4 participants 9 messages Nov 5, 2021 – Nov 6, 2021

Subsystems (2)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 libbpf: fix non-C89 loop variable declaration in gen_loader.c

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")
---
 tools/lib/bpf/gen_loader.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/bpf/gen_loader.c +2 -1
index 502dea53a742..2e10776b6d85 100644
@@ -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];
Signature · 1 line
2.30.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Andrii Nakryiko

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")

Thanks for the fix, and sorry about that.

Quoted 1 line

[...]

--
Kartikeya

#2 lore raw
Quoted 5 lines · Kumar Kartikeya Dwivedi
Quoted 3 lines · Andrii Nakryiko

Fix the int i declaration inside the for statement. This is non-C89 compliant. See [0] for user report breaking BCC build.

Quoted 9 lines
Quoted 4 lines

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

Fixes 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")

Thanks for the fix, and sorry about that.

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).

Quoted 4 lines
Quoted 1 line

[...]

--
Kartikeya

#3 lore raw
Quoted 16 lines · Andrii Nakryiko
Quoted 5 lines · Kumar Kartikeya Dwivedi
Quoted 3 lines · Andrii Nakryiko

Fix the int i declaration inside the for statement. This is non-C89 compliant. See [0] for user report breaking BCC build.

Quoted 9 lines
Quoted 4 lines

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

Fixes 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")

Thanks for the fix, and sorry about that.

Quoted 9 lines

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.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

[...]

--
Kartikeya

--
Kartikeya

#4 lore raw
Quoted 23 lines · Kumar Kartikeya Dwivedi
Quoted 21 lines · Andrii Nakryiko
Quoted 5 lines · Kumar Kartikeya Dwivedi
Quoted 3 lines · Andrii Nakryiko

Fix the int i declaration inside the for statement. This is non-C89 compliant. See [0] for user report breaking BCC build.

Quoted 9 lines
Quoted 4 lines

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

Fixes 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")

Thanks for the fix, and sorry about that.

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.

Quoted 7 lines
Quoted 4 lines

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?

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

[...]

--
Kartikeya

--
Kartikeya

#5 lore raw
Quoted 29 lines · Andrii Nakryiko
Quoted 28 lines · Kumar Kartikeya Dwivedi
Quoted 25 lines · Andrii Nakryiko
Quoted 5 lines · Kumar Kartikeya Dwivedi
Quoted 3 lines · Andrii Nakryiko

Fix the int i declaration inside the for statement. This is non-C89 compliant. See [0] for user report breaking BCC build.

Quoted 9 lines
Quoted 4 lines

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

Fixes 18f4fccbf314 ("libbpf: Update gen_loader to emit BTF_KIND_FUNC relocations")

Thanks for the fix, and sorry about that.

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).

Quoted 7 lines
Quoted 2 lines

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

#7 lore raw
Quoted 10 lines · Alexei Starovoitov
Quoted 5 lines · Andrii Nakryiko

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.

#8 lore raw
Quoted 9 lines · Andrii Nakryiko
Quoted 6 lines · Alexei Starovoitov
Quoted 4 lines · Andrii Nakryiko

Fix the int i declaration inside the for statement. This is non-C89 compliant. See [0] for user report breaking BCC build.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

[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.