linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>, Andrii Nakryiko <andrii@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	bpf@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: [PATCH 1/1] libbpf: Use (uintptr_t) for a u64 cast to a void pointer to fix build on 32-bit arches
Date: Thu, 21 Mar 2024 12:16:20 -0300	[thread overview]
Message-ID: <ZfxKeSF5e6mXpnrs@x1> (raw)

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@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/bpf/libbpf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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

             reply	other threads:[~2024-03-21 15:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-21 15:16 Arnaldo Carvalho de Melo [this message]
2024-03-21 15:59 ` [PATCH 1/1] libbpf: Use (uintptr_t) for a u64 cast to a void pointer to fix build on 32-bit arches Andrii Nakryiko
2024-03-21 16:06   ` Arnaldo Carvalho de Melo

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=ZfxKeSF5e6mXpnrs@x1 \
    --to=acme@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=irogers@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).