Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2756755rwb; Mon, 5 Sep 2022 00:29:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR4+9FjvsiWJGtj67Ho3i5uKmDovqlBYASrBEroHpAXjoZOaY/4Hz8lJhrcuWY7hlOD6Phcs X-Received: by 2002:a17:90a:243:b0:200:80ea:a6f3 with SMTP id t3-20020a17090a024300b0020080eaa6f3mr1283553pje.9.1662362988516; Mon, 05 Sep 2022 00:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662362988; cv=none; d=google.com; s=arc-20160816; b=DUibj6JZWg/CnHeL4kzhVierqiTBEVsfL7dZe6AZbsHSXo6+4ysnf55rX5/w84fEvp hqwks3KKoaaOITw3AOaDJWvhCFkREC0GQTy4KITL9zSaoeDaGbJ716Utwu5SvhxFX9NF pKc5uL0k24vQMnkFcimHd/1MaxlLy5TlKB2rGqVXNcBWpMxSU33jNyKADFPY14ri/HV0 CEn0EBVrSOdY1CQT4B4lUwI486geq+UBZLy4qekRT0UZohhrnIKydpV00sfb7GKWHKCP bSD/nSmDMn+fkHRVrzobpukYMxi7eYrvHVmYhlcPIm0pN/GRO+/QuadnDfHdzHf5eVsS QNfw== 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:dkim-filter; bh=2/aEuTIGQY1eRCS8ZnFpEZnaZhJYBAN2YOqc0m45zS0=; b=O3G6RbGG1W8VYDtyrQrqJeLKkjNTp7r8UGKjBh7ToWIXQ8dHgIc7Ebdew3rPnGIWPL NreYC3isvbwMzRn9sbkOajhXvGotdiPKUT4XpaFDQ2M7euqtqPiSg4UA9jOagkCcowk3 qMgSFTJMj7nPLp4hwRO+flEy4fdZGqAqGTcviscy/ZNWXuq8KIGUN4qZPk2B1vqM8e36 nzER7wijYGdosU8RmqW3Hr3DAE/bhZ3zfPSWF8FRHSS2M+8cCQ7BdU8CtYsv6r6+r1LZ OS3HONz8KLSMBIY23kwE+Vs7dmh5qeHaGaHzEdk5iDneUmqRSc/R8odI0uPArfqW7kPC FOFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=lKAB6BQc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x6-20020a170902ec8600b0017096e50b28si10835069plg.193.2022.09.05.00.29.35; Mon, 05 Sep 2022 00:29:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=lKAB6BQc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236002AbiIEGo5 (ORCPT + 99 others); Mon, 5 Sep 2022 02:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235644AbiIEGoz (ORCPT ); Mon, 5 Sep 2022 02:44:55 -0400 Received: from conssluserg-05.nifty.com (conssluserg-05.nifty.com [210.131.2.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04139DEF9; Sun, 4 Sep 2022 23:44:53 -0700 (PDT) Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (authenticated) by conssluserg-05.nifty.com with ESMTP id 2856icQV020648; Mon, 5 Sep 2022 15:44:39 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com 2856icQV020648 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1662360279; bh=2/aEuTIGQY1eRCS8ZnFpEZnaZhJYBAN2YOqc0m45zS0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lKAB6BQc70nahRxqaJZNtnfMD+5Yec10/NkTOmFn2bNQNge2AgFZW7dBoRJqR6MnI xPC/bll5EYabRy5wk4VM/2t1rCwklXfH+QePUY2EHAAwAI/+OQYY/bQlEF+vfb41jq O+0v+kq1iRSwlgz/idsyDS/fER9XuSMbET7bpuSSVbebJZfGOYlSQyXUZJAfiTqkJD WW1rymTI7myf1KQPXzI+OEG5yl2tukVLr+4rx+aN9kYriAWLRWx3bo0/AFtZfrskkb dN6ZtLlo7S6u9OdbHj7cLg6CxD2bQaclRl5Me77fQNz7p8voW1WVLVPGvzKwUB5QB3 cxlaHRJ2p496g== X-Nifty-SrcIP: [209.85.210.47] Received: by mail-ot1-f47.google.com with SMTP id m21-20020a9d6ad5000000b00638df677850so5607439otq.5; Sun, 04 Sep 2022 23:44:39 -0700 (PDT) X-Gm-Message-State: ACgBeo34pR0nBHRTtuT612LgxjSXtyvh58ogT003WVxEgvc1w62HPVfJ 1OKRW1bUZrAgAxDGgkKgq7cGN9/KoBTzNYmBKNk= X-Received: by 2002:a05:6830:658b:b0:63b:3501:7167 with SMTP id cn11-20020a056830658b00b0063b35017167mr12590275otb.343.1662360278092; Sun, 04 Sep 2022 23:44:38 -0700 (PDT) MIME-Version: 1.0 References: <20220831184408.2778264-1-ndesaulniers@google.com> <20220831184408.2778264-4-ndesaulniers@google.com> In-Reply-To: <20220831184408.2778264-4-ndesaulniers@google.com> From: Masahiro Yamada Date: Mon, 5 Sep 2022 15:44:01 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 3/5] Makefile.compiler: replace cc-ifversion with compiler-specific macros To: Nick Desaulniers Cc: Michal Marek , Nathan Chancellor , Tom Rix , Linux Kbuild mailing list , Linux Kernel Mailing List , clang-built-linux , X86 ML , Dmitrii Bundin , Fangrui Song , Alexey Alexandrov , Bill Wendling , Greg Thelen , Jonathan Corbet , "open list:DOCUMENTATION" , amd-gfx list , dri-devel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_SOFTFAIL, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 1, 2022 at 3:44 AM Nick Desaulniers wrote: > > cc-ifversion is GCC specific. Replace it with compiler specific > variants. Update the users of cc-ifversion to use these new macros. > Provide a helper for checking compiler versions for GCC and Clang > simultaneously, that will be used in a follow up patch. > > Cc: Jonathan Corbet > Cc: linux-doc@vger.kernel.org > Cc: amd-gfx@lists.freedesktop.org > Cc: dri-devel@lists.freedesktop.org > Link: https://github.com/ClangBuiltLinux/linux/issues/350 > Link: https://lore.kernel.org/llvm/CAGG=3QWSAUakO42kubrCap8fp-gm1ERJJAYXTnP1iHk_wrH=BQ@mail.gmail.com/ > Suggested-by: Bill Wendling > Signed-off-by: Nick Desaulniers > --- > Changes v1 -> v2: > * New patch. > > Documentation/kbuild/makefiles.rst | 44 +++++++++++++++------ > Makefile | 4 +- > drivers/gpu/drm/amd/display/dc/dml/Makefile | 12 ++---- > scripts/Makefile.compiler | 15 +++++-- > 4 files changed, 49 insertions(+), 26 deletions(-) > > diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst > index 11a296e52d68..e46f5b45c422 100644 > --- a/Documentation/kbuild/makefiles.rst > +++ b/Documentation/kbuild/makefiles.rst > @@ -682,22 +682,42 @@ more details, with real examples. > In the above example, -Wno-unused-but-set-variable will be added to > KBUILD_CFLAGS only if gcc really accepts it. > > - cc-ifversion > - cc-ifversion tests the version of $(CC) and equals the fourth parameter > - if version expression is true, or the fifth (if given) if the version > - expression is false. > + gcc-min-version > + gcc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater than > + or equal to the provided value and evaluates to y if so. > > Example:: > > - #fs/reiserfs/Makefile > - ccflags-y := $(call cc-ifversion, -lt, 0402, -O1) > + cflags-$(call gcc-min-version, 70100) := -foo > > - In this example, ccflags-y will be assigned the value -O1 if the > - $(CC) version is less than 4.2. > - cc-ifversion takes all the shell operators: > - -eq, -ne, -lt, -le, -gt, and -ge > - The third parameter may be a text as in this example, but it may also > - be an expanded variable or a macro. > + In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and > + $(CONFIG_GCC_VERSION) is >= 7.1. > + > + clang-min-version > + clang-min-version tests if the value of $(CONFIG_CLANG_VERSION) is greater > + than or equal to the provided value and evaluates to y if so. > + > + Example:: > + > + cflags-$(call clang-min-version, 110000) := -foo > + > + In this example, cflags-y will be assigned the value -foo if $(CC) is clang > + and $(CONFIG_CLANG_VERSION) is >= 11.0.0. > + > + cc-min-version > + cc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater > + than or equal to the first value provided, or if the value of > + $(CONFIG_CLANG_VERSION) is greater than or equal to the second value > + provided, and evaluates > + to y if so. > + > + Example:: > + > + cflags-$(call cc-min-version, 70100, 110000) := -foo > + > + In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and > + $(CONFIG_GCC_VERSION) is >= 7.1, or if $(CC) is clang and > + $(CONFIG_CLANG_VERSION) is >= 11.0.0. > > cc-cross-prefix > cc-cross-prefix is used to check if there exists a $(CC) in path with > diff --git a/Makefile b/Makefile > index 952d354069a4..caa39ecb1136 100644 > --- a/Makefile > +++ b/Makefile > @@ -972,7 +972,7 @@ ifdef CONFIG_CC_IS_GCC > KBUILD_CFLAGS += -Wno-maybe-uninitialized > endif > > -ifdef CONFIG_CC_IS_GCC > +ifeq ($(call gcc-min-version, 90100),y) > # The allocators already balk at large sizes, so silence the compiler > # warnings for bounds checks involving those possible values. While > # -Wno-alloc-size-larger-than would normally be used here, earlier versions > @@ -984,7 +984,7 @@ ifdef CONFIG_CC_IS_GCC > # ignored, continuing to default to PTRDIFF_MAX. So, left with no other > # choice, we must perform a versioned check to disable this warning. > # https://lore.kernel.org/lkml/20210824115859.187f272f@canb.auug.org.au > -KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0901, -Wno-alloc-size-larger-than) > +KBUILD_CFLAGS += -Wno-alloc-size-larger-than > endif > > # disable invalid "can't wrap" optimizations for signed / pointers > diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile b/drivers/gpu/drm/amd/display/dc/dml/Makefile > index 86a3b5bfd699..d8ee4743b2e3 100644 > --- a/drivers/gpu/drm/amd/display/dc/dml/Makefile > +++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile > @@ -33,20 +33,14 @@ ifdef CONFIG_PPC64 > dml_ccflags := -mhard-float -maltivec > endif > > -ifdef CONFIG_CC_IS_GCC > -ifeq ($(call cc-ifversion, -lt, 0701, y), y) > -IS_OLD_GCC = 1 > -endif > -endif > - > ifdef CONFIG_X86 > -ifdef IS_OLD_GCC > +ifeq ($(call gcc-min-version, 70100),y) > +dml_ccflags += -msse2 > +else > # Stack alignment mismatch, proceed with caution. > # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3 > # (8B stack alignment). > dml_ccflags += -mpreferred-stack-boundary=4 > -else > -dml_ccflags += -msse2 > endif > endif > > diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler > index d1739f0d3ce3..13dade724fa3 100644 > --- a/scripts/Makefile.compiler > +++ b/scripts/Makefile.compiler > @@ -61,9 +61,18 @@ cc-option-yn = $(call try-run,\ > cc-disable-warning = $(call try-run,\ > $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) > > -# cc-ifversion > -# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) > -cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4)) > +# gcc-min-version > +# Usage: cflags-$(call gcc-min-version, 70100) += -foo > +gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION) -ge $(1) ] && echo y) > + > +# clang-min-version > +# Usage: cflags-$(call clang-min-version, 110000) += -foo > +clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION) -ge $(1) ] && echo y) > + > +# cc-min-version > +# Usage: cflags-$(call cc-min-version, 701000, 110000) > +# ^ GCC ^ Clang > +cc-min-version = $(filter y, $(call gcc-min-version, $(1)), $(call clang-min-version, $(2))) A more intuitive and more efficient form would be: cc-min-version = $(or $(call gcc-min-version, $(1)), $(call clang-min-version, $(2))) In your implementation, both gcc-min-version and clang-min-version are expanded before being passed to $(filter ...). So the shell is always invoked twice. $(or A, B) is lazily expanded; A is evaluated first. If and only if A is empty, B is expanded. If gcc-min-version is met, the shell invocation in clang-min-version will be short-cut. But, I do not find a place where cc-min-version is useful. Looking at the next patch, # gcc-11+, clang-14+ ifeq ($(call cc-min-version, 110000, 140000),y) dwarf-version-y := 5 else dwarf-version-y := 4 endif ... can be written in a more simpler way: dwarf-version-y := 4 dwarf-version-$(call gcc-min-version, 110000) := 5 dwarf-version-$(call clang-min-version, 140000) := 5 With $(call cc-min-version, 110000, 140000), you never know the meaning of 110000, 140000 until you see the definition of this macro. So, you feel like adding the comment "gcc-11+, clang-14+". The latter form, the code is self-documenting. > # ld-option > # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) > -- > 2.37.2.672.g94769d06f0-goog > -- Best Regards Masahiro Yamada