diff mbox series

selftests/bpf: ignore pointer types check with clang

Message ID 20230412095912.188453-1-andrea.righi@canonical.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series selftests/bpf: ignore pointer types check with clang | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-7 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-21 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-31 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-34 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-33 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-10 fail Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32 on s390x with gcc

Commit Message

Andrea Righi April 12, 2023, 9:59 a.m. UTC
Building bpf selftests with clang can trigger errors like the following:

  CLNG-BPF [test_maps] bpf_iter_netlink.bpf.o
progs/bpf_iter_netlink.c:32:4: error: incompatible pointer types assigning to 'struct sock *' from 'struct sock___17 *' [-Werror,-Wincompatible-pointer-types]
        s = &nlk->sk;
          ^ ~~~~~~~~
1 error generated.

This is due to the fact that bpftool emits duplicate data types with
different names in vmlinux.h (i.e., `struct sock` in this case) and
these types, despite having a different name, represent in fact the same
object.

Add -Wno-incompatible-pointer-types to CLANG_CLAGS to prevent these
errors.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
---
 tools/testing/selftests/bpf/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Alexei Starovoitov April 14, 2023, 4:56 a.m. UTC | #1
On Wed, Apr 12, 2023 at 2:59 AM Andrea Righi <andrea.righi@canonical.com> wrote:
>
> Building bpf selftests with clang can trigger errors like the following:
>
>   CLNG-BPF [test_maps] bpf_iter_netlink.bpf.o
> progs/bpf_iter_netlink.c:32:4: error: incompatible pointer types assigning to 'struct sock *' from 'struct sock___17 *' [-Werror,-Wincompatible-pointer-types]
>         s = &nlk->sk;
>           ^ ~~~~~~~~
> 1 error generated.

I cannot reproduce this and BPF CI doesn't complain about it either.
What kind of clang do you use?
Some special version and build flags?
Andrea Righi April 14, 2023, 6:15 a.m. UTC | #2
On Thu, Apr 13, 2023 at 09:56:00PM -0700, Alexei Starovoitov wrote:
> On Wed, Apr 12, 2023 at 2:59 AM Andrea Righi <andrea.righi@canonical.com> wrote:
> >
> > Building bpf selftests with clang can trigger errors like the following:
> >
> >   CLNG-BPF [test_maps] bpf_iter_netlink.bpf.o
> > progs/bpf_iter_netlink.c:32:4: error: incompatible pointer types assigning to 'struct sock *' from 'struct sock___17 *' [-Werror,-Wincompatible-pointer-types]
> >         s = &nlk->sk;
> >           ^ ~~~~~~~~
> > 1 error generated.
> 
> I cannot reproduce this and BPF CI doesn't complain about it either.
> What kind of clang do you use?
> Some special version and build flags?

I'm using Ubuntu clang version 15.0.7 (Ubuntu 23.04), no special build
flag (unless Ubuntu enables some different default flags, but it
shouldn't be the case... I'll double check).

-Andrea
Ilya Leoshkevich April 14, 2023, 4:15 p.m. UTC | #3
On Fri, Apr 14, 2023 at 08:15:03AM +0200, Andrea Righi wrote:
> On Thu, Apr 13, 2023 at 09:56:00PM -0700, Alexei Starovoitov wrote:
> > On Wed, Apr 12, 2023 at 2:59 AM Andrea Righi <andrea.righi@canonical.com> wrote:
> > >
> > > Building bpf selftests with clang can trigger errors like the following:
> > >
> > >   CLNG-BPF [test_maps] bpf_iter_netlink.bpf.o
> > > progs/bpf_iter_netlink.c:32:4: error: incompatible pointer types assigning to 'struct sock *' from 'struct sock___17 *' [-Werror,-Wincompatible-pointer-types]
> > >         s = &nlk->sk;
> > >           ^ ~~~~~~~~
> > > 1 error generated.
> > 
> > I cannot reproduce this and BPF CI doesn't complain about it either.
> > What kind of clang do you use?
> > Some special version and build flags?
> 
> I'm using Ubuntu clang version 15.0.7 (Ubuntu 23.04), no special build
> flag (unless Ubuntu enables some different default flags, but it
> shouldn't be the case... I'll double check).
> 
> -Andrea

Hi,

FWIW, I see similar errors when I don't use recent pahole.

Best regards,
Ilya
Andrea Righi April 14, 2023, 4:28 p.m. UTC | #4
On Fri, Apr 14, 2023 at 06:15:38PM +0200, Ilya Leoshkevich wrote:
> On Fri, Apr 14, 2023 at 08:15:03AM +0200, Andrea Righi wrote:
> > On Thu, Apr 13, 2023 at 09:56:00PM -0700, Alexei Starovoitov wrote:
> > > On Wed, Apr 12, 2023 at 2:59 AM Andrea Righi <andrea.righi@canonical.com> wrote:
> > > >
> > > > Building bpf selftests with clang can trigger errors like the following:
> > > >
> > > >   CLNG-BPF [test_maps] bpf_iter_netlink.bpf.o
> > > > progs/bpf_iter_netlink.c:32:4: error: incompatible pointer types assigning to 'struct sock *' from 'struct sock___17 *' [-Werror,-Wincompatible-pointer-types]
> > > >         s = &nlk->sk;
> > > >           ^ ~~~~~~~~
> > > > 1 error generated.
> > > 
> > > I cannot reproduce this and BPF CI doesn't complain about it either.
> > > What kind of clang do you use?
> > > Some special version and build flags?
> > 
> > I'm using Ubuntu clang version 15.0.7 (Ubuntu 23.04), no special build
> > flag (unless Ubuntu enables some different default flags, but it
> > shouldn't be the case... I'll double check).
> > 
> > -Andrea
> 
> Hi,
> 
> FWIW, I see similar errors when I don't use recent pahole.

I'm using pahole v1.24.

-Andrea
Alexei Starovoitov April 15, 2023, 1:15 a.m. UTC | #5
On Fri, Apr 14, 2023 at 9:28 AM Andrea Righi <andrea.righi@canonical.com> wrote:
>
> On Fri, Apr 14, 2023 at 06:15:38PM +0200, Ilya Leoshkevich wrote:
> > On Fri, Apr 14, 2023 at 08:15:03AM +0200, Andrea Righi wrote:
> > > On Thu, Apr 13, 2023 at 09:56:00PM -0700, Alexei Starovoitov wrote:
> > > > On Wed, Apr 12, 2023 at 2:59 AM Andrea Righi <andrea.righi@canonical.com> wrote:
> > > > >
> > > > > Building bpf selftests with clang can trigger errors like the following:
> > > > >
> > > > >   CLNG-BPF [test_maps] bpf_iter_netlink.bpf.o
> > > > > progs/bpf_iter_netlink.c:32:4: error: incompatible pointer types assigning to 'struct sock *' from 'struct sock___17 *' [-Werror,-Wincompatible-pointer-types]
> > > > >         s = &nlk->sk;
> > > > >           ^ ~~~~~~~~
> > > > > 1 error generated.
> > > >
> > > > I cannot reproduce this and BPF CI doesn't complain about it either.
> > > > What kind of clang do you use?
> > > > Some special version and build flags?
> > >
> > > I'm using Ubuntu clang version 15.0.7 (Ubuntu 23.04), no special build
> > > flag (unless Ubuntu enables some different default flags, but it
> > > shouldn't be the case... I'll double check).
> > >
> > > -Andrea
> >
> > Hi,
> >
> > FWIW, I see similar errors when I don't use recent pahole.
>
> I'm using pahole v1.24.

I believe Ilya is correct.

struct sock___17 is likely coming from vmlinux.h
Which means that there were errors due vmlinux build which
caused multiple structs to be present in BTF
and therefore bpftool generated such broken vmlinux.h

The BTF section in such vmlinux is likely much larger than normal.
Let's get to the bottom of it instead of masking build error.

Please try pahole 1.25.
Andrea Righi April 15, 2023, 8:31 a.m. UTC | #6
On Fri, Apr 14, 2023 at 06:15:41PM -0700, Alexei Starovoitov wrote:
> On Fri, Apr 14, 2023 at 9:28 AM Andrea Righi <andrea.righi@canonical.com> wrote:
> >
> > On Fri, Apr 14, 2023 at 06:15:38PM +0200, Ilya Leoshkevich wrote:
> > > On Fri, Apr 14, 2023 at 08:15:03AM +0200, Andrea Righi wrote:
> > > > On Thu, Apr 13, 2023 at 09:56:00PM -0700, Alexei Starovoitov wrote:
> > > > > On Wed, Apr 12, 2023 at 2:59 AM Andrea Righi <andrea.righi@canonical.com> wrote:
> > > > > >
> > > > > > Building bpf selftests with clang can trigger errors like the following:
> > > > > >
> > > > > >   CLNG-BPF [test_maps] bpf_iter_netlink.bpf.o
> > > > > > progs/bpf_iter_netlink.c:32:4: error: incompatible pointer types assigning to 'struct sock *' from 'struct sock___17 *' [-Werror,-Wincompatible-pointer-types]
> > > > > >         s = &nlk->sk;
> > > > > >           ^ ~~~~~~~~
> > > > > > 1 error generated.
> > > > >
> > > > > I cannot reproduce this and BPF CI doesn't complain about it either.
> > > > > What kind of clang do you use?
> > > > > Some special version and build flags?
> > > >
> > > > I'm using Ubuntu clang version 15.0.7 (Ubuntu 23.04), no special build
> > > > flag (unless Ubuntu enables some different default flags, but it
> > > > shouldn't be the case... I'll double check).
> > > >
> > > > -Andrea
> > >
> > > Hi,
> > >
> > > FWIW, I see similar errors when I don't use recent pahole.
> >
> > I'm using pahole v1.24.
> 
> I believe Ilya is correct.
> 
> struct sock___17 is likely coming from vmlinux.h
> Which means that there were errors due vmlinux build which
> caused multiple structs to be present in BTF
> and therefore bpftool generated such broken vmlinux.h
> 
> The BTF section in such vmlinux is likely much larger than normal.
> Let's get to the bottom of it instead of masking build error.
> 
> Please try pahole 1.25.

Yay! Success. Everything is working fine with pahole 1.25. Please ignore
my patch, the fix is to simply upgrade pahole.

Thanks!
-Andrea
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index b677dcd0b77a..0d9ef819a065 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -356,7 +356,8 @@  BPF_CFLAGS = -g -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) 		\
 	     -I$(abspath $(OUTPUT)/../usr/include)
 
 CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
-	       -Wno-compare-distinct-pointer-types
+	       -Wno-compare-distinct-pointer-types \
+	       -Wno-incompatible-pointer-types
 
 $(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline
 $(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline