Re: [PATCH v9 perf,bpf 04/15] perf, bpf: synthesize bpf events with bpf_program__get_prog_info_linear()

From: Arnaldo Carvalho de Melo
Date: Thu Mar 14 2019 - 14:31:02 EST


Em Thu, Mar 14, 2019 at 04:45:22PM +0000, Song Liu escreveu:
> > On Mar 13, 2019, at 10:08 PM, Song Liu <songliubraving@xxxxxx> wrote:
> >> On Mar 13, 2019, at 2:08 PM, Arnaldo Carvalho de Melo <arnaldo.melo@xxxxxxxxx> wrote:
> >> Em Wed, Mar 13, 2019 at 06:00:30PM -0300, Arnaldo Carvalho de Melo escreveu:
> >>> Em Mon, Mar 11, 2019 at 10:30:40PM -0700, Song Liu escreveu:
> >>>> /* Synthesize PERF_RECORD_KSYMBOL */
> >>>> for (i = 0; i < sub_prog_cnt; i++) {
> >>>> + u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(info->prog_tags);
> >>> Need this:
> >>> - u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(info->prog_tags);
> >>> + u8 (*prog_tags)[BPF_TAG_SIZE] = (u8 *)(info->prog_tags);
> >>>
> >>> To overcome this on debian:experimental-x-mips, i.e. Debian Experimental
> >>> cross building to MIPS 32-bit:

> >>> util/bpf-event.c: In function 'perf_event__synthesize_one_bpf_prog':
> >>> util/bpf-event.c:143:35: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
> >>> u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(info->prog_tags);

> >> Argh, hit the send button too fast, that is not the only case and then
> >> my change just changed the error:

> >> util/bpf-event.c: In function 'perf_event__synthesize_one_bpf_prog':
> >> util/bpf-event.c:143:35: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
> >> u8 (*prog_tags)[BPF_TAG_SIZE] = (u8 *)(info->prog_tags);

> >> util/bpf-event.c:143:35: error: initialization of 'u8 (*)[8]' {aka 'unsigned char (*)[8]'} from incompatible pointer type 'u8 *' {aka 'unsigned char *'} [-Werror=incompatible-pointer-types]
> >> util/bpf-event.c:144:22: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
> >> __u32 *prog_lens = (__u32 *)(info->jited_func_lens);


> >> cc1: all warnings being treated as errors
> >> mv: cannot stat '/tmp/build/perf/util/.bpf-event.o.tmp': No such file or directory

> > We can fix it with the following:

> > - u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(info->prog_tags);
> > - __u32 *prog_lens = (__u32 *)(info->jited_func_lens);
> > - __u64 *prog_addrs = (__u64 *)(info->jited_ksyms);
> > - void *func_infos = (void *)(info->func_info);
> > + u8 (*prog_tags)[BPF_TAG_SIZE] = (void *)(intptr_t)(info->prog_tags);
> > + __u32 *prog_lens = (__u32 *)(intptr_t)(info->jited_func_lens);
> > + __u64 *prog_addrs = (__u64 *)(intptr_t)(info->jited_ksyms);
> > + void *func_infos = (void *)(intptr_t)(info->func_info);

> Actually, I think uintptr_t is better than intptr_t here.

Yeap, did the trick:

$ dm debian:experimental-x-mips
1 debian:experimental-x-mips : Ok mips-linux-gnu-gcc (Debian 8.3.0-2) 8.3.0
$

Works as well with x86_64 with a recent distro such as fedora:30 or
ubuntu:19.04, building it with both gcc and clang:

$ dm fedora:30 ubuntu:19.04
1 fedora:30 : Ok gcc (GCC) 9.0.1 20190227 (Red Hat 9.0.1-0.8), clang version 8.0.0 (Fedora 8.0.0-0.5.rc3.fc30)
2 ubuntu:19.04 : Ok gcc (Ubuntu 8.3.0-2ubuntu2) 8.3.0, clang version 8.0.0-+rc4-1ubuntu1 (tags/RELEASE_800/rc4)
$

Continuing with the review/tests...

- Arnaldo