On Mon, Jan 6, 2025 at 10:59 AM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote: > > On Mon, 2025-01-06 at 18:54 +0000, 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]. > > > > The changes only affect test_progs-bpf_gcc, which is built only if > > BPF_GCC is set: > > * Pass -std=gnu17 to gcc in order to avoid errors on bool types > > declarations in vmlinux.h > > * Pass -fno-strict-aliasing for tests that trigger uninitialized > > variable warning on BPF_RAW_INSNS [2] > > > > [1] https://lore.kernel.org/bpf/EYcXjcKDCJY7Yb0GGtAAb7nLKPEvrgWdvWpuNzXm2qi6rYMZDixKv5KwfVVMBq17V55xyC-A1wIjrqG3aw-Imqudo9q9X7D7nLU2gWgbN0w=@pm.me/ > > [2] https://lore.kernel.org/bpf/87pll3c8bt.fsf@xxxxxxxxxx/ > > > > CC: Jose E. Marchesi <jose.marchesi@xxxxxxxxxx> > > Signed-off-by: Ihor Solodrai <ihor.solodrai@xxxxx> > > > > --- > > > > v1: https://lore.kernel.org/bpf/20250104001751.1869849-1-ihor.solodrai@xxxxx/ > > > > tools/testing/selftests/bpf/Makefile | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile > > index eb4d21651aa7..b043791fe6db 100644 > > --- a/tools/testing/selftests/bpf/Makefile > > +++ b/tools/testing/selftests/bpf/Makefile > > @@ -69,6 +69,10 @@ progs/timer_crash.c-CFLAGS := -fno-strict-aliasing > > progs/test_global_func9.c-CFLAGS := -fno-strict-aliasing > > progs/verifier_nocsr.c-CFLAGS := -fno-strict-aliasing > > > > +# Uninitialized variable warning on BPF_RAW_INSN > > +progs/verifier_bpf_fastcall.c-CFLAGS := -fno-strict-aliasing > > +progs/verifier_search_pruning.c-CFLAGS := -fno-strict-aliasing > > Specifying -fno-strict-aliasing for a sub-set of tests is not convenient, > as this list would have to be extended each time __imm_insn macro is used. > Either this flag should be used for test_progs compilation as a whole, > or the macro should be updated to use union as it was suggested previously. > Personally, I don't like the aliasing rules and would prefer -fno-strict-aliasing, > but changing macro is a simple and non-intrusive update, so I think it's a better option. The whole kernel is compiled with -fno-strict-aliasing, so I would do the same for bpf selftests and remove per-.c flags.