diff mbox series

bpf: Fix various lib and testsuite build failures on 32-bit.

Message ID 20181128.125610.1742500262159613185.davem@davemloft.net
State Accepted, archived
Delegated to: BPF Maintainers
Headers show
Series bpf: Fix various lib and testsuite build failures on 32-bit. | expand

Commit Message

David Miller Nov. 28, 2018, 8:56 p.m. UTC
Cannot cast a u64 to a pointer on 32-bit without an intervening (long)
cast otherwise GCC warns.

Signed-off-by: David S. Miller <davem@davemloft.net>
--

Comments

Song Liu Nov. 28, 2018, 11:35 p.m. UTC | #1
On Wed, Nov 28, 2018 at 12:59 PM David Miller <davem@davemloft.net> wrote:
>
>
> Cannot cast a u64 to a pointer on 32-bit without an intervening (long)
> cast otherwise GCC warns.
>
> Signed-off-by: David S. Miller <davem@davemloft.net>

Acked-by: Song Liu <songliubraving@fb.com>


> --
>
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index eadcf8d..c2d641f 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -466,7 +466,7 @@ int btf__get_from_id(__u32 id, struct btf **btf)
>                 goto exit_free;
>         }
>
> -       *btf = btf__new((__u8 *)btf_info.btf, btf_info.btf_size, NULL);
> +       *btf = btf__new((__u8 *)(long)btf_info.btf, btf_info.btf_size, NULL);
>         if (IS_ERR(*btf)) {
>                 err = PTR_ERR(*btf);
>                 *btf = NULL;
> diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> index c1e688f6..1c57abb 100644
> --- a/tools/testing/selftests/bpf/test_progs.c
> +++ b/tools/testing/selftests/bpf/test_progs.c
> @@ -524,7 +524,7 @@ static void test_bpf_obj_id(void)
>                           load_time < now - 60 || load_time > now + 60 ||
>                           prog_infos[i].created_by_uid != my_uid ||
>                           prog_infos[i].nr_map_ids != 1 ||
> -                         *(int *)prog_infos[i].map_ids != map_infos[i].id ||
> +                         *(int *)(long)prog_infos[i].map_ids != map_infos[i].id ||
>                           strcmp((char *)prog_infos[i].name, expected_prog_name),
>                           "get-prog-info(fd)",
>                           "err %d errno %d i %d type %d(%d) info_len %u(%Zu) jit_enabled %d jited_prog_len %u xlated_prog_len %u jited_prog %d xlated_prog %d load_time %lu(%lu) uid %u(%u) nr_map_ids %u(%u) map_id %u(%u) name %s(%s)\n",
> @@ -539,7 +539,7 @@ static void test_bpf_obj_id(void)
>                           load_time, now,
>                           prog_infos[i].created_by_uid, my_uid,
>                           prog_infos[i].nr_map_ids, 1,
> -                         *(int *)prog_infos[i].map_ids, map_infos[i].id,
> +                         *(int *)(long)prog_infos[i].map_ids, map_infos[i].id,
>                           prog_infos[i].name, expected_prog_name))
>                         goto done;
>         }
> @@ -585,7 +585,7 @@ static void test_bpf_obj_id(void)
>                 bzero(&prog_info, sizeof(prog_info));
>                 info_len = sizeof(prog_info);
>
> -               saved_map_id = *(int *)(prog_infos[i].map_ids);
> +               saved_map_id = *(int *)((long)prog_infos[i].map_ids);
>                 prog_info.map_ids = prog_infos[i].map_ids;
>                 prog_info.nr_map_ids = 2;
>                 err = bpf_obj_get_info_by_fd(prog_fd, &prog_info, &info_len);
> @@ -593,12 +593,12 @@ static void test_bpf_obj_id(void)
>                 prog_infos[i].xlated_prog_insns = 0;
>                 CHECK(err || info_len != sizeof(struct bpf_prog_info) ||
>                       memcmp(&prog_info, &prog_infos[i], info_len) ||
> -                     *(int *)prog_info.map_ids != saved_map_id,
> +                     *(int *)(long)prog_info.map_ids != saved_map_id,
>                       "get-prog-info(next_id->fd)",
>                       "err %d errno %d info_len %u(%Zu) memcmp %d map_id %u(%u)\n",
>                       err, errno, info_len, sizeof(struct bpf_prog_info),
>                       memcmp(&prog_info, &prog_infos[i], info_len),
> -                     *(int *)prog_info.map_ids, saved_map_id);
> +                     *(int *)(long)prog_info.map_ids, saved_map_id);
>                 close(prog_fd);
>         }
>         CHECK(nr_id_found != nr_iters,
Alexei Starovoitov Nov. 29, 2018, 12:18 a.m. UTC | #2
On Wed, Nov 28, 2018 at 12:56:10PM -0800, David Miller wrote:
> 
> Cannot cast a u64 to a pointer on 32-bit without an intervening (long)
> cast otherwise GCC warns.
> 
> Signed-off-by: David S. Miller <davem@davemloft.net>

I was contemplating to apply that to bpf tree, but the first hunk is bpf-next only
and later hunks are in test_progs.c, hence applied to bpf-next tree.
Thanks!
diff mbox series

Patch

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index eadcf8d..c2d641f 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -466,7 +466,7 @@  int btf__get_from_id(__u32 id, struct btf **btf)
 		goto exit_free;
 	}
 
-	*btf = btf__new((__u8 *)btf_info.btf, btf_info.btf_size, NULL);
+	*btf = btf__new((__u8 *)(long)btf_info.btf, btf_info.btf_size, NULL);
 	if (IS_ERR(*btf)) {
 		err = PTR_ERR(*btf);
 		*btf = NULL;
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index c1e688f6..1c57abb 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -524,7 +524,7 @@  static void test_bpf_obj_id(void)
 			  load_time < now - 60 || load_time > now + 60 ||
 			  prog_infos[i].created_by_uid != my_uid ||
 			  prog_infos[i].nr_map_ids != 1 ||
-			  *(int *)prog_infos[i].map_ids != map_infos[i].id ||
+			  *(int *)(long)prog_infos[i].map_ids != map_infos[i].id ||
 			  strcmp((char *)prog_infos[i].name, expected_prog_name),
 			  "get-prog-info(fd)",
 			  "err %d errno %d i %d type %d(%d) info_len %u(%Zu) jit_enabled %d jited_prog_len %u xlated_prog_len %u jited_prog %d xlated_prog %d load_time %lu(%lu) uid %u(%u) nr_map_ids %u(%u) map_id %u(%u) name %s(%s)\n",
@@ -539,7 +539,7 @@  static void test_bpf_obj_id(void)
 			  load_time, now,
 			  prog_infos[i].created_by_uid, my_uid,
 			  prog_infos[i].nr_map_ids, 1,
-			  *(int *)prog_infos[i].map_ids, map_infos[i].id,
+			  *(int *)(long)prog_infos[i].map_ids, map_infos[i].id,
 			  prog_infos[i].name, expected_prog_name))
 			goto done;
 	}
@@ -585,7 +585,7 @@  static void test_bpf_obj_id(void)
 		bzero(&prog_info, sizeof(prog_info));
 		info_len = sizeof(prog_info);
 
-		saved_map_id = *(int *)(prog_infos[i].map_ids);
+		saved_map_id = *(int *)((long)prog_infos[i].map_ids);
 		prog_info.map_ids = prog_infos[i].map_ids;
 		prog_info.nr_map_ids = 2;
 		err = bpf_obj_get_info_by_fd(prog_fd, &prog_info, &info_len);
@@ -593,12 +593,12 @@  static void test_bpf_obj_id(void)
 		prog_infos[i].xlated_prog_insns = 0;
 		CHECK(err || info_len != sizeof(struct bpf_prog_info) ||
 		      memcmp(&prog_info, &prog_infos[i], info_len) ||
-		      *(int *)prog_info.map_ids != saved_map_id,
+		      *(int *)(long)prog_info.map_ids != saved_map_id,
 		      "get-prog-info(next_id->fd)",
 		      "err %d errno %d info_len %u(%Zu) memcmp %d map_id %u(%u)\n",
 		      err, errno, info_len, sizeof(struct bpf_prog_info),
 		      memcmp(&prog_info, &prog_infos[i], info_len),
-		      *(int *)prog_info.map_ids, saved_map_id);
+		      *(int *)(long)prog_info.map_ids, saved_map_id);
 		close(prog_fd);
 	}
 	CHECK(nr_id_found != nr_iters,