Re: [PATCH v2] selftests/bpf: workarounds for GCC BPF build

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

>  # Some utility functions use LLVM libraries
>  jit_disasm_helpers.c-CFLAGS = $(LLVM_CFLAGS)
>  
> @@ -507,7 +511,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







[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux