Skip to content

Commit 09f44b7

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
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 <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a62f68c commit 09f44b7

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

tools/bpf/bpftool/btf_dumper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
6767
if (!info->btf_id || !info->nr_func_info ||
6868
btf__get_from_id(info->btf_id, &prog_btf))
6969
goto print;
70-
finfo = (struct bpf_func_info *)info->func_info;
70+
finfo = u64_to_ptr(info->func_info);
7171
func_type = btf__type_by_id(prog_btf, finfo->type_id);
7272
if (!func_type || !btf_is_func(func_type))
7373
goto print;

tools/bpf/bpftool/link.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
106106
switch (info->type) {
107107
case BPF_LINK_TYPE_RAW_TRACEPOINT:
108108
jsonw_string_field(json_wtr, "tp_name",
109-
(const char *)info->raw_tracepoint.tp_name);
109+
u64_to_ptr(info->raw_tracepoint.tp_name));
110110
break;
111111
case BPF_LINK_TYPE_TRACING:
112112
err = get_prog_info(info->prog_id, &prog_info);
@@ -185,7 +185,7 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
185185
switch (info->type) {
186186
case BPF_LINK_TYPE_RAW_TRACEPOINT:
187187
printf("\n\ttp '%s' ",
188-
(const char *)info->raw_tracepoint.tp_name);
188+
(const char *)u64_to_ptr(info->raw_tracepoint.tp_name));
189189
break;
190190
case BPF_LINK_TYPE_TRACING:
191191
err = get_prog_info(info->prog_id, &prog_info);

tools/bpf/bpftool/main.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121
/* Make sure we do not use kernel-only integer typedefs */
2222
#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
2323

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+
}
2533

2634
#define NEXT_ARG() ({ argc--; argv++; if (argc < 0) usage(); })
2735
#define NEXT_ARGP() ({ (*argc)--; (*argv)++; if (*argc < 0) usage(); })

tools/bpf/bpftool/prog.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,14 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
428428
p_info("no instructions returned");
429429
return -1;
430430
}
431-
buf = (unsigned char *)(info->jited_prog_insns);
431+
buf = u64_to_ptr(info->jited_prog_insns);
432432
member_len = info->jited_prog_len;
433433
} else { /* DUMP_XLATED */
434434
if (info->xlated_prog_len == 0 || !info->xlated_prog_insns) {
435435
p_err("error retrieving insn dump: kernel.kptr_restrict set?");
436436
return -1;
437437
}
438-
buf = (unsigned char *)info->xlated_prog_insns;
438+
buf = u64_to_ptr(info->xlated_prog_insns);
439439
member_len = info->xlated_prog_len;
440440
}
441441

@@ -444,7 +444,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
444444
return -1;
445445
}
446446

447-
func_info = (void *)info->func_info;
447+
func_info = u64_to_ptr(info->func_info);
448448

449449
if (info->nr_line_info) {
450450
prog_linfo = bpf_prog_linfo__new(info);
@@ -462,7 +462,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
462462

463463
n = write(fd, buf, member_len);
464464
close(fd);
465-
if (n != member_len) {
465+
if (n != (ssize_t)member_len) {
466466
p_err("error writing output file: %s",
467467
n < 0 ? strerror(errno) : "short write");
468468
return -1;
@@ -492,13 +492,13 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
492492
__u32 i;
493493
if (info->nr_jited_ksyms) {
494494
kernel_syms_load(&dd);
495-
ksyms = (__u64 *) info->jited_ksyms;
495+
ksyms = u64_to_ptr(info->jited_ksyms);
496496
}
497497

498498
if (json_output)
499499
jsonw_start_array(json_wtr);
500500

501-
lens = (__u32 *) info->jited_func_lens;
501+
lens = u64_to_ptr(info->jited_func_lens);
502502
for (i = 0; i < info->nr_jited_func_lens; i++) {
503503
if (ksyms) {
504504
sym = kernel_syms_search(&dd, ksyms[i]);
@@ -559,7 +559,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
559559
} else {
560560
kernel_syms_load(&dd);
561561
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);
563563
dd.btf = btf;
564564
dd.func_info = func_info;
565565
dd.finfo_rec_size = info->func_info_rec_size;
@@ -1681,7 +1681,7 @@ static char *profile_target_name(int tgt_fd)
16811681
goto out;
16821682
}
16831683

1684-
func_info = (struct bpf_func_info *)(info_linear->info.func_info);
1684+
func_info = u64_to_ptr(info_linear->info.func_info);
16851685
t = btf__type_by_id(btf, func_info[0].type_id);
16861686
if (!t) {
16871687
p_err("btf %d doesn't have type %d",

0 commit comments

Comments
 (0)