* [PATCH bpf v1] selftests/bpf: Fix error compiling cgroup_ancestor.c with musl libc
@ 2024-10-08 23:12 Tony Ambardar
2024-10-09 13:48 ` Alexis Lothoré
2024-10-10 1:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Tony Ambardar @ 2024-10-08 23:12 UTC (permalink / raw)
To: bpf
Cc: Tony Ambardar, Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, linux-kselftest,
Alexis Lothoré
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.
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>
---
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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf v1] selftests/bpf: Fix error compiling cgroup_ancestor.c with musl libc
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é
2024-10-10 1:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Alexis Lothoré @ 2024-10-09 13:48 UTC (permalink / raw)
To: Tony Ambardar, bpf
Cc: Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, linux-kselftest
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf v1] selftests/bpf: Fix error compiling cgroup_ancestor.c with musl libc
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é
@ 2024-10-10 1:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-10 1:40 UTC (permalink / raw)
To: Tony Ambardar
Cc: bpf, andrii, eddyz87, mykolal, ast, daniel, martin.lau, song,
yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah,
linux-kselftest, alexis.lothore
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Tue, 8 Oct 2024 16:12:32 -0700 you 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
>
> [...]
Here is the summary with links:
- [bpf,v1] selftests/bpf: Fix error compiling cgroup_ancestor.c with musl libc
https://git.kernel.org/bpf/bpf/c/60f802e2d6e1
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-10 1:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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é
2024-10-10 1:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox