On Monday, January 6th, 2025 at 7:05 AM, Daniel Borkmann <daniel@xxxxxxxxxxxxx> wrote: > > On 1/4/25 1:17 AM, Ihor Solodrai wrote: > > > Various compilation errors happen when BPF programs in selftests/bpf > > are built with GCC BPF. For more details see the discussion at [1]. > > > Thanks for the patch! Hi Daniel, thanks for review. > > > The changes only affect test_progs-bpf_gcc, which is built only if > > BPF_GCC is set: > > * Pass -std=gnu17 when to avoid errors on bool > > types declarations in vmlinux.h > > * Pass -nostdinc for tests that trigger int64_t declaration > > collision due to a difference between gcc and clang stdint.h > > * Pass -Wno-error for tests that trigger uninitialized variable > > warning pm BPF_RAW_INSNS > > > > [1] https://lore.kernel.org/bpf/EYcXjcKDCJY7Yb0GGtAAb7nLKPEvrgWdvWpuNzXm2qi6rYMZDixKv5KwfVVMBq17V55xyC-A1wIjrqG3aw-Imqudo9q9X7D7nLU2gWgbN0w=@pm.me/ > > > > Signed-off-by: Ihor Solodrai ihor.solodrai@xxxxx > > > [ pls also add Jose to Cc (done here) ] > > > --- > > tools/testing/selftests/bpf/Makefile | 11 ++++++++++- > > 1 file changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile > > index 9e870e519c30..2e1fe53efa83 100644 > > --- a/tools/testing/selftests/bpf/Makefile > > +++ b/tools/testing/selftests/bpf/Makefile > > @@ -103,6 +103,15 @@ progs/btf_dump_test_case_packing.c-bpf_gcc-CFLAGS := -Wno-error > > progs/btf_dump_test_case_padding.c-bpf_gcc-CFLAGS := -Wno-error > > progs/btf_dump_test_case_syntax.c-bpf_gcc-CFLAGS := -Wno-error > > > > +# Uninitialized variable warning on BPF_RAW_INSN > > +progs/verifier_bpf_fastcall.c-CFLAGS := -Wno-error > > +progs/verifier_search_pruning.c-CFLAGS := -Wno-error > > > See previous feedback from Jose: > > Ignoring the warning doesn't cure the resulting undefined behavior. > These selftests seems to be violating strict aliasing rules, so it is > better to either change the testcase to work well with anti-aliasing > rules or to disable strict aliasing, like it is done for many other > tests already: > > progs/verifier_bpf_fastcall.c-CFLAGS := -fno-strict-aliasing > progs/verifier_search_pruning.c-CFLAGS := -fno-strict-aliasing Yeah, I haven't seen this message before sending the patch. > > > +# int64_t declaration collision > > +progs/test_cls_redirect.c-CFLAGS := -nostdinc > > +progs/test_cls_redirect_dynptr.c-CFLAGS := -nostdinc > > +progs/test_cls_redirect_subprogs.c-CFLAGS := -nostdinc > > > iiuc, this hunk is not needed given [1] got merged which addresses the > collision issue already? > > [0] https://lore.kernel.org/bpf/87pll3c8bt.fsf@xxxxxxxxxx/ > [1] https://gcc.gnu.org/pipermail/gcc-patches/2025-January/672508.html > I am going to test the GCC change, and will send v2 shortly after. Thanks! > > # The following tests do type-punning, via the __imm_insn macro, from > > # `struct bpf_insn' to long and then uses the value. This triggers an > > # "is used uninitialized" warning in GCC due to strict-aliasing > > @@ -507,7 +516,7 @@ endef > > # Build BPF object using GCC > > define GCC_BPF_BUILD_RULE > > $(call msg,GCC-BPF,$4,$2) > > - $(Q)$(BPF_GCC) $3 -DBPF_NO_PRESERVE_ACCESS_INDEX -Wno-attributes -O2 -c $1 -o $2 > > + $(Q)$(BPF_GCC) $3 -DBPF_NO_PRESERVE_ACCESS_INDEX -Wno-attributes -O2 -std=gnu17 -c $1 -o $2 > > endef > > > > SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c