Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3382201rdg; Tue, 17 Oct 2023 12:57:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwAykvcKjvgLarQKZreLtPAKyGL/CmydMQ5CY1fWRpwgcMnh/vY4vs61BQfYPLeLhSCGDC X-Received: by 2002:a05:6830:310a:b0:6bf:2476:a97e with SMTP id b10-20020a056830310a00b006bf2476a97emr4359161ots.5.1697572641478; Tue, 17 Oct 2023 12:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697572641; cv=none; d=google.com; s=arc-20160816; b=gf66D/n6A37dX7ZOWN8ymB+0yQNPrrW6hnOqoTv8MCc0tv97nYUvjZ3WaVyb1KKrVB tPQnmpfD3OW7FYHW0x1hWIfggFN4rWgFrH3PtvDWa5m0UfJ9Y6CUFy4l+yRyadu1eA6b dXCEfJmo1fhYOW2tLnqtLKNiGJc8MxknhQUOawbjjfGCZosd96oJgcIUN5JXRUjMtUoQ DKnnVoiCfw3wZnIgRJTKWha2kfFBbi5Qr8Qyevi4uhQF0OBAu5orPKcNTtAHrHgoTkrc 4336EjZ4lxQdTplJn+kql11bZ055POlO6IKZGoTzeW90Vbi53jJm8r9+pidRi0rH8LgO /z6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Vl//DC5ziIO68KUbpNSRqo4FW+IItW9RRn+Fwf7gHXM=; fh=k9cQgIfc2VC3TIc8CzKP5fij+D9a1LYgPbpbzr036E8=; b=e787Qt5spHmw6LXxeRdyDf9buX73jT2FdiwwyBg6lSx9DVeMn3aWJegEmK/56SnLds GE90Y8xephoqg31UB+yWXzwZPs8gvetREQpUCS2dVdosS9LCT4VF/x2TMShnuCjDfXwO q/3Zx5AzqiMwiiX71SstAVR09N9uFrUkLBAkJYgSMf5GjPTmyQLlrwoVBB5fjRVYesK+ dyrEjW4ea3cORRrLUzFPVoLdgw5yfW5hhYiZ3ZM3tVoedWeqOwmSQkGWbehKQKezArYn fBI9ZvSzsFj9N/zt/GHJGa896AkO43c0q3F+Eme+aAlSMpqVUfNDTBna013j5b8Flq4p Q/Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HUlGL12+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id q17-20020aa79831000000b006b77c54544dsi2146652pfl.195.2023.10.17.12.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 12:57:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HUlGL12+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7C47C807CF6F; Tue, 17 Oct 2023 12:57:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233940AbjJQT5J (ORCPT + 99 others); Tue, 17 Oct 2023 15:57:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232198AbjJQT5H (ORCPT ); Tue, 17 Oct 2023 15:57:07 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF6C5C4; Tue, 17 Oct 2023 12:57:05 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-53d9f001b35so10451698a12.2; Tue, 17 Oct 2023 12:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697572624; x=1698177424; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Vl//DC5ziIO68KUbpNSRqo4FW+IItW9RRn+Fwf7gHXM=; b=HUlGL12+FadNoXde4zwwNJr8nYACjm/xbZHn2KE0nxNlgIYJXAiTmPyZqdTZ3GoyBe rYZFasu5JOxqAvDpPcJWbO/0geyXyXl9PXvYV+lOm42QWVh40vlI7EOMcAA4GZZ1LlbY T4uuQ0NzZO8d7HtJSyp0CHN65eQgCzJywDhLpc7sydgncwEGaAcoJYgWfVoeIkxu6jdn A20x1ImV7BWpJl3R8RjB6dK9F3GjotDXVBTZ63PoKI8i0hP7kZAz3FO6TGXVOAgyyP0x zWExuLuM/GQWWeMoJ8Ij8fSTcdRoAd691/OK8NYRRjXSTKyToHERoj2fWQpMvTo0Vu3u iT3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697572624; x=1698177424; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vl//DC5ziIO68KUbpNSRqo4FW+IItW9RRn+Fwf7gHXM=; b=jpWU71QUrH90NkgegaJh01FdbCag11C2S1bTktVubuMwARXfJypuAHCt+LaFNhzQW0 jlqSfmBifMEhVQo1Z31+jKthZQYIanpwMFQggRjBnPNtc2V+0stdfGsx6Rz1RMV4YFKh 7/oSu+iz8naCS0CvibuYK8PmaOz6XSx963k13VctR5amUBZsSyXEWw+BUf0H6wFF2Bs/ eF0zvhfm49MB4RdqPP5SIym1K/fC0B7LXlV3J6nH6L2sJR0VzWqIzqjBbPaUdycOLQH4 yeK81b4aurKTvXmyNwcbRYQhAwibA8LHzjl52TaU/d2sL/Xd388EFP5dauU2kq1DtLbW Uung== X-Gm-Message-State: AOJu0YxOMgDe73lO4jArZGyptwPQ6ueZBbRAXBwSmv0lM1ZGIm/y0i1P 8JlpTmgIUS1FEsEVJ02FLGJutPFJAxTCu3k+cTA= X-Received: by 2002:a05:6402:4315:b0:53d:fbf6:72c with SMTP id m21-20020a056402431500b0053dfbf6072cmr2852702edc.1.1697572623918; Tue, 17 Oct 2023 12:57:03 -0700 (PDT) MIME-Version: 1.0 References: <20231017103742.130927-1-masahiroy@kernel.org> <20231017103742.130927-2-masahiroy@kernel.org> In-Reply-To: <20231017103742.130927-2-masahiroy@kernel.org> From: Andrii Nakryiko Date: Tue, 17 Oct 2023 12:56:52 -0700 Message-ID: Subject: Re: [PATCH 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Alex Gaynor , Alexei Starovoitov , Alice Ryhl , Andreas Hindborg , Andrii Nakryiko , Benno Lossin , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Boqun Feng , Daniel Borkmann , Gary Guo , Hao Luo , Jiri Olsa , John Fastabend , KP Singh , Martin KaFai Lau , Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Song Liu , Stanislav Fomichev , Wedson Almeida Filho , Yonghong Song , bpf@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 17 Oct 2023 12:57:18 -0700 (PDT) On Tue, Oct 17, 2023 at 3:38=E2=80=AFAM Masahiro Yamada wrote: > > scripts/pahole-flags.sh is executed so many times. > > You can check how many times it is invoked during the build, as follows: > > $ cat <> scripts/pahole-flags.sh > > echo "scripts/pahole-flags.sh was executed" >&2 > > EOF > > $ make -s > scripts/pahole-flags.sh was executed > scripts/pahole-flags.sh was executed > scripts/pahole-flags.sh was executed > scripts/pahole-flags.sh was executed > scripts/pahole-flags.sh was executed > [ lots of repeated lines suppressed... ] > > This scripts is exectuted more than 20 times during the kernel build > because PAHOLE_FLAGS is a recursively expanded variable and exported > to sub-processes. > > With the GNU Make >=3D 4.4, it is executed more than 60 times because > exported variables are also passed to other $(shell ) invocations. > Without careful coding, it is known to cause an exponential fork > explosion. [1] > > The use of $(shell ) in an exported recursive variable is likely wrong > because $(shell ) is always evaluated due to the 'export' keyword, and > the evaluation can occur multiple times by the nature of recursive > variables. > > Convert the shell script to a Makefile, which is included only when > CONFIG_DEBUG_INFO_BTF=3Dy. > > [1]: https://savannah.gnu.org/bugs/index.php?64746 > > Signed-off-by: Masahiro Yamada > --- > > Makefile | 4 +--- > scripts/Makefile.btf | 19 +++++++++++++++++++ > scripts/pahole-flags.sh | 30 ------------------------------ > 3 files changed, 20 insertions(+), 33 deletions(-) > create mode 100644 scripts/Makefile.btf > delete mode 100755 scripts/pahole-flags.sh > > diff --git a/Makefile b/Makefile > index fed9a6cc3665..eaddec67e5e1 100644 > --- a/Makefile > +++ b/Makefile > @@ -513,8 +513,6 @@ LZ4 =3D lz4c > XZ =3D xz > ZSTD =3D zstd > > -PAHOLE_FLAGS =3D $(shell PAHOLE=3D$(PAHOLE) $(srctree)/scripts/pahole-= flags.sh) What if we just used :=3D here? Wouldn't it avoid unnecessary multiple exec= utions? I don't make Makefile.btf approach, just curious why :=3D doesn't work, if it doesn't. > - > CHECKFLAGS :=3D -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ > -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) > NOSTDINC_FLAGS :=3D > @@ -605,7 +603,6 @@ export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MO= DULE > export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE > export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE= KBUILD_LDFLAGS_MODULE > export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL > -export PAHOLE_FLAGS > > # Files to ignore in find ... statements > > @@ -1002,6 +999,7 @@ KBUILD_CPPFLAGS +=3D $(call cc-option,-fmacro-prefix= -map=3D$(srctree)/=3D) > # include additional Makefiles when needed > include-y :=3D scripts/Makefile.extrawarn > include-$(CONFIG_DEBUG_INFO) +=3D scripts/Makefile.debug > +include-$(CONFIG_DEBUG_INFO_BTF)+=3D scripts/Makefile.btf > include-$(CONFIG_KASAN) +=3D scripts/Makefile.kasan > include-$(CONFIG_KCSAN) +=3D scripts/Makefile.kcsan > include-$(CONFIG_KMSAN) +=3D scripts/Makefile.kmsan > diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf > new file mode 100644 > index 000000000000..82377e470aed > --- /dev/null > +++ b/scripts/Makefile.btf > @@ -0,0 +1,19 @@ > +# SPDX-License-Identifier: GPL-2.0 > + > +pahole-ver :=3D $(CONFIG_PAHOLE_VERSION) > +pahole-flags-y :=3D > + > +# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars > +ifeq ($(call test-le, $(pahole-ver), 121),y) > +pahole-flags-$(call test-ge, $(pahole-ver), 118) +=3D --skip_encod= ing_btf_vars > +endif > + > +pahole-flags-$(call test-ge, $(pahole-ver), 121) +=3D --btf_gen_fl= oats > + > +pahole-flags-$(call test-ge, $(pahole-ver), 122) +=3D -j > + > +pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) +=3D --lang_exclu= de=3Drust > + > +pahole-flags-$(call test-ge, $(pahole-ver), 125) +=3D --skip_encod= ing_btf_inconsistent_proto --btf_gen_optimized > + > +export PAHOLE_FLAGS :=3D $(pahole-flags-y) > diff --git a/scripts/pahole-flags.sh b/scripts/pahole-flags.sh > deleted file mode 100755 > index 728d55190d97..000000000000 > --- a/scripts/pahole-flags.sh > +++ /dev/null > @@ -1,30 +0,0 @@ > -#!/bin/sh > -# SPDX-License-Identifier: GPL-2.0 > - > -extra_paholeopt=3D > - > -if ! [ -x "$(command -v ${PAHOLE})" ]; then > - exit 0 > -fi > - > -pahole_ver=3D$($(dirname $0)/pahole-version.sh ${PAHOLE}) > - > -if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then > - # pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars > - extra_paholeopt=3D"${extra_paholeopt} --skip_encoding_btf_vars" > -fi > -if [ "${pahole_ver}" -ge "121" ]; then > - extra_paholeopt=3D"${extra_paholeopt} --btf_gen_floats" > -fi > -if [ "${pahole_ver}" -ge "122" ]; then > - extra_paholeopt=3D"${extra_paholeopt} -j" > -fi > -if [ "${pahole_ver}" -ge "124" ]; then > - # see PAHOLE_HAS_LANG_EXCLUDE > - extra_paholeopt=3D"${extra_paholeopt} --lang_exclude=3Drust" > -fi > -if [ "${pahole_ver}" -ge "125" ]; then > - extra_paholeopt=3D"${extra_paholeopt} --skip_encoding_btf_inconsi= stent_proto --btf_gen_optimized" > -fi > - > -echo ${extra_paholeopt} > -- > 2.40.1 >