Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: "Alexis Lothoré" <alexis.lothore@bootlin.com>
To: Tony Ambardar <tony.ambardar@gmail.com>, bpf@vger.kernel.org
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Mykola Lysenko <mykolal@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf v1] selftests/bpf: Fix error compiling cgroup_ancestor.c with musl libc
Date: Wed, 9 Oct 2024 15:48:18 +0200	[thread overview]
Message-ID: <d7451a56-f883-4e98-b3a7-407138d09181@bootlin.com> (raw)
In-Reply-To: <20241008231232.634047-1-tony.ambardar@gmail.com>

Hello Tony,

On 10/9/24 01:12, Tony Ambardar wrote:
> Existing code calls connect() with a 'struct sockaddr_in6 *' argument
> where a 'struct sockaddr *' argument is declared, yielding compile errors
> when building for mips64el/musl-libc:
> 
> In file included from cgroup_ancestor.c:3:
> cgroup_ancestor.c: In function 'send_datagram':
> cgroup_ancestor.c:38:38: error: passing argument 2 of 'connect' from incompatible pointer type [-Werror=incompatible-pointer-types]
>    38 |         if (!ASSERT_OK(connect(sock, &addr, sizeof(addr)), "connect")) {
>       |                                      ^~~~~
>       |                                      |
>       |                                      struct sockaddr_in6 *
> ./test_progs.h:343:29: note: in definition of macro 'ASSERT_OK'
>   343 |         long long ___res = (res);                                       \
>       |                             ^~~
> In file included from .../netinet/in.h:10,
>                  from .../arpa/inet.h:9,
>                  from ./test_progs.h:17:
> .../sys/socket.h:386:19: note: expected 'const struct sockaddr *' but argument is of type 'struct sockaddr_in6 *'
>   386 | int connect (int, const struct sockaddr *, socklen_t);
>       |                   ^~~~~~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> 
> This only compiles because of a glibc extension allowing declaration of the
> argument as a "transparent union" which includes both types above.
> 
> Explicitly cast the argument to allow compiling for both musl and glibc.

Thanks for the fix and the details :) Indeed it looks like all other tests
perform this cast on connect (either to (void *) or (struct sockaddr *)) to
prevent this issue, so that's a miss on my side when I rewrote this test.

> Cc: Alexis Lothoré (eBPF Foundation) <alexis.lothore@bootlin.com>
> Fixes: f957c230e173 ("selftests/bpf: convert test_skb_cgroup_id_user to test_progs")
> Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>

Reviewed-by: Alexis Lothoré <alexis.lothore@bootlin.com>

> ---
>  tools/testing/selftests/bpf/prog_tests/cgroup_ancestor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_ancestor.c b/tools/testing/selftests/bpf/prog_tests/cgroup_ancestor.c
> index 9250a1e9f9af..3f9ffdf71343 100644
> --- a/tools/testing/selftests/bpf/prog_tests/cgroup_ancestor.c
> +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_ancestor.c
> @@ -35,7 +35,7 @@ static int send_datagram(void)
>  	if (!ASSERT_OK_FD(sock, "create socket"))
>  		return sock;
>  
> -	if (!ASSERT_OK(connect(sock, &addr, sizeof(addr)), "connect")) {
> +	if (!ASSERT_OK(connect(sock, (struct sockaddr *)&addr, sizeof(addr)), "connect")) {
>  		close(sock);
>  		return -1;
>  	}


-- 
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2024-10-09 13:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08 23:12 [PATCH bpf v1] selftests/bpf: Fix error compiling cgroup_ancestor.c with musl libc Tony Ambardar
2024-10-09 13:48 ` Alexis Lothoré [this message]
2024-10-10  1:40 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d7451a56-f883-4e98-b3a7-407138d09181@bootlin.com \
    --to=alexis.lothore@bootlin.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tony.ambardar@gmail.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox