On Tue, Sep 14, 2021 at 11:21 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote: > > On Tue, Sep 14, 2021 at 10:00:04AM -0700, Andrii Nakryiko wrote: > > Perf code re-implements libbpf's btf__load_from_kernel_by_id() API as > > a weak function, presumably to dynamically link against old version of > > libbpf shared library. Unfortunately this causes compilation warning > > when perf is compiled against libbpf v0.6+. > > > > For now, just ignore deprecation warning, but there might be a better > > solution, depending on perf's needs. > > HI, > the problem we tried to solve is when perf is using symbols > which are not yet available in released libbpf.. but it all > linkes in default perf build because it's linked statically > libbpf.a in the tree > If you are always statically linking libbpf into perf, there is no need to implement this __weak shim. Libbpf is never going to deprecate an API if a new/replacement API hasn't been at least in a previous released version. So in this case btf__load_from_kernel_by_id() was added in libbpf 0.5, and btf__get_from_id() was marked deprecated in libbpf 0.6 (not yet released, of course). So with that, do you still think we need this __weak re-implementation? I was wondering if this was done to make latest perf code compile against some old libbpf source code or dynamically linked against old libbpf. But if that's not the case, the fix should be a removal of __weak btf__load_from_kernel_by_id(). > so now we have weak function with that warning disabled locally, > which I guess could work? also for future cases like that > > jirka > > > > > Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > > --- > > tools/perf/util/bpf-event.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c > > index 683f6d63560e..1a7112a87736 100644 > > --- a/tools/perf/util/bpf-event.c > > +++ b/tools/perf/util/bpf-event.c > > @@ -24,7 +24,10 @@ > > struct btf * __weak btf__load_from_kernel_by_id(__u32 id) > > { > > struct btf *btf; > > +#pragma GCC diagnostic push > > +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" > > int err = btf__get_from_id(id, &btf); > > +#pragma GCC diagnostic pop > > > > return err ? ERR_PTR(err) : btf; > > } > > -- > > 2.30.2 > > >