Re: [PATCH 1/1] libbpf: Use (uintptr_t) for a u64 cast to a void pointer to fix build on 32-bit arches

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

 



On Thu, Mar 21, 2024 at 8:16 AM Arnaldo Carvalho de Melo
<acme@xxxxxxxxxx> wrote:
>
> Noticed on several perf container builds:
>
>   perfbuilder@number:~$ grep -B1 -A2 "cast to pointer"  dm.log/*\:*
>   dm.log/ubuntu:18.04-x-arm-libbpf.c: In function 'bpf_object__create_maps':
>   dm.log/ubuntu:18.04-x-arm:libbpf.c:5355:24: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
>   dm.log/ubuntu:18.04-x-arm-     map->mmaped = mmap((void *)map->map_extra, bpf_map_mmap_sz(map),
>   dm.log/ubuntu:18.04-x-arm-                        ^
>   --
>   dm.log/ubuntu:18.04-x-powerpc-libbpf.c: In function 'bpf_object__create_maps':
>   dm.log/ubuntu:18.04-x-powerpc:libbpf.c:5355:24: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
>   dm.log/ubuntu:18.04-x-powerpc-     map->mmaped = mmap((void *)map->map_extra, bpf_map_mmap_sz(map),
>   dm.log/ubuntu:18.04-x-powerpc-                        ^
>   --
>   dm.log/ubuntu:18.04-x-sh4-libbpf.c: In function 'bpf_object__create_maps':
>   dm.log/ubuntu:18.04-x-sh4:libbpf.c:5355:24: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
>   dm.log/ubuntu:18.04-x-sh4-     map->mmaped = mmap((void *)map->map_extra, bpf_map_mmap_sz(map),
>   dm.log/ubuntu:18.04-x-sh4-                        ^
>   perfbuilder@number:~$
>
> I think Namhyung mentioned as well on a chat conversation about noticing
> this on a 32-bit build on Debian.
>
> Fixes: 79ff13e99169ddb0 ("libbpf: Add support for bpf_arena.")
> Reported-by: Namhyung Kim <namhyung@xxxxxxxxxx>
> Cc: Alexei Starovoitov <ast@xxxxxxxxxx>
> Cc: Andrii Nakryiko <andrii@xxxxxxxxxx>
> Cc: Ian Rogers <irogers@xxxxxxxxxx>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> ---
>  tools/lib/bpf/libbpf.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>

We've already landed a similar fix in the bpf tree, see [0].

  [0] https://patchwork.kernel.org/project/netdevbpf/patch/20240319215143.1279312-1-andrii@xxxxxxxxxx/


> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index efab29b8935bd9f7..af0b0e24978558f8 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -14,6 +14,7 @@
>  #define _GNU_SOURCE
>  #endif
>  #include <stdlib.h>
> +#include <stdint.h>
>  #include <stdio.h>
>  #include <stdarg.h>
>  #include <libgen.h>
> @@ -5352,7 +5353,7 @@ bpf_object__create_maps(struct bpf_object *obj)
>                                         goto err_out;
>                         }
>                         if (map->def.type == BPF_MAP_TYPE_ARENA) {
> -                               map->mmaped = mmap((void *)map->map_extra, bpf_map_mmap_sz(map),
> +                               map->mmaped = mmap((void *)(uintptr_t)map->map_extra, bpf_map_mmap_sz(map),
>                                                    PROT_READ | PROT_WRITE,
>                                                    map->map_extra ? MAP_SHARED | MAP_FIXED : MAP_SHARED,
>                                                    map->fd, 0);
> --
> 2.44.0





[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