Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp650429pxh; Tue, 9 Nov 2021 16:51:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+MDUEk2uEXpIT8zgwdBa4VeAjnGyCf5/mFaRTaOzr2cinBFkP1yO/+eehhmp3AlMbqFni X-Received: by 2002:aa7:c5ca:: with SMTP id h10mr16310219eds.194.1636505476541; Tue, 09 Nov 2021 16:51:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636505476; cv=none; d=google.com; s=arc-20160816; b=Fkm0oYNTK3peLVxugdl8npRyIJfNohUXW6RRQ+t2lHVTHkh9QR6JQsODwIumKVjs7M EYYUWaz0h6JszYNyoBpV9XIFLuT98qzL+86IdgUgn28mmMwfWZx3uZLkhOh+6wdyg6qm 7be5P3geyQiku5AY9eGBI/8h/u3SQFeuQUuau+iiSwxn9MCPN6S3kOpKsHnSG0/RBuJg RsrgHfGClQJquOSH3Ih0Il7y6kHcscQsknCy7lzHbHQeXydJ1kCF3FTcPnaysGDZp+Z6 p5OYDk9lkTRxXTZfyMozkPEnOpaW1wkaaUUtIJHRAarLnOM2UwgKZvj3EmLUVFa1DQYK pZHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=OYebiZkSqfk+SEyJR1FyCrAiQ21EGEQnskwkiymG0qo=; b=Qq1K6jDf+kNPbWDhpHlspmSprEw12rBZm7gOhK8u+Cgeiz7THRudBpE0BqmSTkrHke xrCSJ9p4YlNio2hIZ4fHyB8VBkgD24qCIIGRYDBL4G0sg4T3yi1S1unTQl4P6iHR17j0 l2VG9rs7+BnO1xo/VY1Q+zin0BjT6MqPX+FkBtNpHDGh5VfRGkmrJNIfl9jzG9tz/ccU Lc4Dgzhx0ymaRcNEAKJnDWqdCFKNl+OJM0Ru9njl//GeDsBfVT1/k24seJRwT0/n9kI/ kdGOEzWAkmTOKNB1PEGjgURQIkQZPs2FCKgXBnaV10I8dT7VzO5jirSdSHo7270jr8nJ Wjcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Wi8B15wZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc22si12662025ejc.587.2021.11.09.16.50.53; Tue, 09 Nov 2021 16:51:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Wi8B15wZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229544AbhKIXgF (ORCPT + 99 others); Tue, 9 Nov 2021 18:36:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbhKIXgD (ORCPT ); Tue, 9 Nov 2021 18:36:03 -0500 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 379E4C061764; Tue, 9 Nov 2021 15:33:16 -0800 (PST) Received: by mail-yb1-xb34.google.com with SMTP id g17so1532764ybe.13; Tue, 09 Nov 2021 15:33:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OYebiZkSqfk+SEyJR1FyCrAiQ21EGEQnskwkiymG0qo=; b=Wi8B15wZj4cc+h6CBGFJUarrPgW7jwmN7+G3E5tTlOgfIPxGwnD7zY/SrSiJ8TVdkb quBMKPwJIp5s7CF64Vlz+4bv97K4YHTo3Hj1ywfqlDENr+irvzqXXzhW5U2HNUUnCpl/ P3GhTadjyFHFAM9lYJAPfHr38HlGJ7QYDDapCa9IQ00+OUl7mi32FCaPGitGIgz3C8O3 0pryorpjVu5D/p7XNPSFQPR3GSOK/PWK8d47qJuMSvGhOyO2NnQX0rCvdQwg18S4ETtb wckiZts4oOHw3rmzyCNtmcRCHhcQ2fGu7u50gFoBQz7a7fdSb7Vn1VyJqPZYusK2FvT+ Pu5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OYebiZkSqfk+SEyJR1FyCrAiQ21EGEQnskwkiymG0qo=; b=Qf0MIOVOoP6b+iFHXCO4Q4NNYpgpdfpupmsUe3vzWI9At/StAuZbO4WWkDcSwUHL8w hh0kZufm9GMYZP7+FzrZvxzkuBk1hNfnvCPlg5wqDvOnGKDC/A2DGEj0c0o4eAgufV0e Z2HnDc5ZlYobyawNRMuLKc4U+Q54FHC+AwMYJQp1s4FY+OwrQu8nxErcnlB/Gath5OZ9 BCVNp/9mVFUkFtGgiRcIb+Bx4oZZEDJhZFSfOZ2U6nrHMn+dKalKc+YgYC16Y+9YwYVQ 51/WZbH4rjQ3FPMMeT1GKxacge0nEDMqAqb8nTAJ9StXiQsPyUjv9DAyKRdsCdtanzId nL1g== X-Gm-Message-State: AOAM5321NPSolrMVXAwDrUN6wjir17K3Fz6/mFW1z8HTqYukyMoZs7Dc N+i6KGsSM+jtAQBTEhevQLjzWjK2HctPGZQ7r+g= X-Received: by 2002:a05:6902:1023:: with SMTP id x3mr12837122ybt.267.1636500795508; Tue, 09 Nov 2021 15:33:15 -0800 (PST) MIME-Version: 1.0 References: <20211109140707.1689940-1-jolsa@kernel.org> <20211109140707.1689940-2-jolsa@kernel.org> In-Reply-To: From: Andrii Nakryiko Date: Tue, 9 Nov 2021 15:33:04 -0800 Message-ID: Subject: Re: [PATCH 1/2] perf tools: Add more weak libbpf functions To: Ian Rogers Cc: Jiri Olsa , Arnaldo Carvalho de Melo , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , "linux-perf-use." , Andrii Nakryiko Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 9, 2021 at 10:50 AM Ian Rogers wrote: > > On Tue, Nov 9, 2021 at 6:07 AM Jiri Olsa wrote: > > > > We hit the window where perf uses libbpf functions, that did not > > make it to the official libbpf release yet and it's breaking perf > > build with dynamicly linked libbpf. > > > > Fixing this by providing the new interface as weak functions which > > calls the original libbpf functions. Fortunatelly the changes were > > just renames. > > Could we just provide these functions behind a libbpf version #if ? > Weak symbols break things in subtle ways, under certain circumstances > the weak symbol is preferred over the strong due to lazy object file > resolution: > https://maskray.me/blog/2021-06-20-symbol-processing#archive-processing > This bit me last week, but in general you get away with it as the lazy > object file will get processed in an archive exposing the strong > symbol. With an #if you either get a linker error for 2 definitions or > 0 definitions, and it's clear what is broken. > > In the past we had problems due to constant propagation from weak > const variables, where #if was the solution: > https://lore.kernel.org/lkml/20191001003623.255186-1-irogers@google.com/ > > There was some recent conversation on libbpf version for pahole here: > https://lore.kernel.org/bpf/CAP-5=fUc3LtU0WYg-Py9Jf+9picaWHJdSw=sdOMA54uY3p1pdw@mail.gmail.com/T/ > https://lore.kernel.org/bpf/20211021183330.460681-1-irogers@google.com/ > > Thanks, > Ian > > > Signed-off-by: Jiri Olsa > > --- > > tools/perf/util/bpf-event.c | 27 +++++++++++++++++++++++++++ > > 1 file changed, 27 insertions(+) > > > > diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c > > index 4d3b4cdce176..ceb96360fd12 100644 > > --- a/tools/perf/util/bpf-event.c > > +++ b/tools/perf/util/bpf-event.c > > @@ -33,6 +33,33 @@ struct btf * __weak btf__load_from_kernel_by_id(__u32 id) > > return err ? ERR_PTR(err) : btf; > > } > > > > +struct bpf_program * __weak > > +bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prev) > > +{ > > +#pragma GCC diagnostic push > > +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" > > + return bpf_program__next(prev, obj); > > +#pragma GCC diagnostic pop > > +} > > + > > +struct bpf_map * __weak > > +bpf_object__next_map(const struct bpf_object *obj, const struct bpf_map *prev) > > +{ > > +#pragma GCC diagnostic push > > +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" > > + return bpf_map__next(prev, obj); > > +#pragma GCC diagnostic pop > > +} > > + > > +const void * __weak > > +btf__raw_data(const struct btf *btf_ro, __u32 *size) > > +{ > > +#pragma GCC diagnostic push > > +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" > > + return btf__get_raw_data(btf_ro, size); you can still use old variants for the time being, if you want. Were new APIs used accidentally? Libbpf maintains a guarantee that if some API is deprecated in favor of the new one, there will be at least one full libbpf release where both APIs are available and not marked as deprecated. > > +#pragma GCC diagnostic pop > > +} > > + > > static int snprintf_hex(char *buf, size_t size, unsigned char *data, size_t len) > > { > > int ret = 0; > > -- > > 2.31.1 > >