Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/bpftool: Fix compilation warnings in 32-bit mode

Fix few compilation warnings in bpftool when compiling in 32-bit mode.
Abstract away u64 to pointer conversion into a helper function.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200813204945.1020225-2-andriin@fb.com

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
09f44b75 a62f68c1

+20 -12
+1 -1
tools/bpf/bpftool/btf_dumper.c
··· 67 67 if (!info->btf_id || !info->nr_func_info || 68 68 btf__get_from_id(info->btf_id, &prog_btf)) 69 69 goto print; 70 - finfo = (struct bpf_func_info *)info->func_info; 70 + finfo = u64_to_ptr(info->func_info); 71 71 func_type = btf__type_by_id(prog_btf, finfo->type_id); 72 72 if (!func_type || !btf_is_func(func_type)) 73 73 goto print;
+2 -2
tools/bpf/bpftool/link.c
··· 106 106 switch (info->type) { 107 107 case BPF_LINK_TYPE_RAW_TRACEPOINT: 108 108 jsonw_string_field(json_wtr, "tp_name", 109 - (const char *)info->raw_tracepoint.tp_name); 109 + u64_to_ptr(info->raw_tracepoint.tp_name)); 110 110 break; 111 111 case BPF_LINK_TYPE_TRACING: 112 112 err = get_prog_info(info->prog_id, &prog_info); ··· 185 185 switch (info->type) { 186 186 case BPF_LINK_TYPE_RAW_TRACEPOINT: 187 187 printf("\n\ttp '%s' ", 188 - (const char *)info->raw_tracepoint.tp_name); 188 + (const char *)u64_to_ptr(info->raw_tracepoint.tp_name)); 189 189 break; 190 190 case BPF_LINK_TYPE_TRACING: 191 191 err = get_prog_info(info->prog_id, &prog_info);
+9 -1
tools/bpf/bpftool/main.h
··· 21 21 /* Make sure we do not use kernel-only integer typedefs */ 22 22 #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64 23 23 24 - #define ptr_to_u64(ptr) ((__u64)(unsigned long)(ptr)) 24 + static inline __u64 ptr_to_u64(const void *ptr) 25 + { 26 + return (__u64)(unsigned long)ptr; 27 + } 28 + 29 + static inline void *u64_to_ptr(__u64 ptr) 30 + { 31 + return (void *)(unsigned long)ptr; 32 + } 25 33 26 34 #define NEXT_ARG() ({ argc--; argv++; if (argc < 0) usage(); }) 27 35 #define NEXT_ARGP() ({ (*argc)--; (*argv)++; if (*argc < 0) usage(); })
+8 -8
tools/bpf/bpftool/prog.c
··· 428 428 p_info("no instructions returned"); 429 429 return -1; 430 430 } 431 - buf = (unsigned char *)(info->jited_prog_insns); 431 + buf = u64_to_ptr(info->jited_prog_insns); 432 432 member_len = info->jited_prog_len; 433 433 } else { /* DUMP_XLATED */ 434 434 if (info->xlated_prog_len == 0 || !info->xlated_prog_insns) { 435 435 p_err("error retrieving insn dump: kernel.kptr_restrict set?"); 436 436 return -1; 437 437 } 438 - buf = (unsigned char *)info->xlated_prog_insns; 438 + buf = u64_to_ptr(info->xlated_prog_insns); 439 439 member_len = info->xlated_prog_len; 440 440 } 441 441 ··· 444 444 return -1; 445 445 } 446 446 447 - func_info = (void *)info->func_info; 447 + func_info = u64_to_ptr(info->func_info); 448 448 449 449 if (info->nr_line_info) { 450 450 prog_linfo = bpf_prog_linfo__new(info); ··· 462 462 463 463 n = write(fd, buf, member_len); 464 464 close(fd); 465 - if (n != member_len) { 465 + if (n != (ssize_t)member_len) { 466 466 p_err("error writing output file: %s", 467 467 n < 0 ? strerror(errno) : "short write"); 468 468 return -1; ··· 492 492 __u32 i; 493 493 if (info->nr_jited_ksyms) { 494 494 kernel_syms_load(&dd); 495 - ksyms = (__u64 *) info->jited_ksyms; 495 + ksyms = u64_to_ptr(info->jited_ksyms); 496 496 } 497 497 498 498 if (json_output) 499 499 jsonw_start_array(json_wtr); 500 500 501 - lens = (__u32 *) info->jited_func_lens; 501 + lens = u64_to_ptr(info->jited_func_lens); 502 502 for (i = 0; i < info->nr_jited_func_lens; i++) { 503 503 if (ksyms) { 504 504 sym = kernel_syms_search(&dd, ksyms[i]); ··· 559 559 } else { 560 560 kernel_syms_load(&dd); 561 561 dd.nr_jited_ksyms = info->nr_jited_ksyms; 562 - dd.jited_ksyms = (__u64 *) info->jited_ksyms; 562 + dd.jited_ksyms = u64_to_ptr(info->jited_ksyms); 563 563 dd.btf = btf; 564 564 dd.func_info = func_info; 565 565 dd.finfo_rec_size = info->func_info_rec_size; ··· 1681 1681 goto out; 1682 1682 } 1683 1683 1684 - func_info = (struct bpf_func_info *)(info_linear->info.func_info); 1684 + func_info = u64_to_ptr(info_linear->info.func_info); 1685 1685 t = btf__type_by_id(btf, func_info[0].type_id); 1686 1686 if (!t) { 1687 1687 p_err("btf %d doesn't have type %d",