Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp841071rwe; Wed, 31 Aug 2022 12:01:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR4IMAA/oNpLmKcHvdSXW17r9TVHUhDuXYH9UwXbsW4RXW3Lp5xFgfEc+bVdNQRgxJf0jKxY X-Received: by 2002:aa7:8c44:0:b0:535:ed0c:f401 with SMTP id e4-20020aa78c44000000b00535ed0cf401mr16878343pfd.48.1661972486001; Wed, 31 Aug 2022 12:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661972485; cv=none; d=google.com; s=arc-20160816; b=iE528we/Fy8Hl/CiOUIUex51yOLLrcni4ER/tytJwWUOLrFxO3bjRu185sdAZue4zu fWFxIK8ECvzoIskkob5tysRAuhoH5d7iDc20fk+8t8yiLAcMhrxzZ4jQwsp4kFWPEJfb F54iQyNOUVFknkHWNREzSPdUVWsEc/CD9YT2ip/Fy0Vdu/fnKZc0EgyTL8cXe1C3R47t HyhD5z/QVUJEIswquOF1fLQLKmcY4c3RBBh5b22ArrNM4x13Cq3VfrVEgWVJ1ZdRN8NL ISjaDrgEp3eq64yLfDWcPK2LTFsM6axHsGJ/PaGF0rdWNfMFXMaKyZFfUPLrxuGE5gSD 82ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=jeIDU7bkvi8qrUeCQKjSgf4R1NQDEDk5WzvSWsZHRgY=; b=mLU0PR+8lFkRu9w4vEfMVcdprl6a1rRF7dzTQLctOb5ZcgRVGO8qEpHuLKutm3B9bl uXE9cBpyTjmiiDQfKPU5R949ECTSCQIioSwGMtwlKV2u/JhJBsaGQ46lEv0MjytLnz65 K1l8Jv4LhlM9bAog6KWhSaGZOW67xhP4YqK99YXi4zgr5uXtc236231OybHEZ5BWn+0R WNZOODD9CW+5DUTgouYGYk9xXAhHCvVu36c+sOzmUve4nSHtdpfCX0m+uKDdPUoae/AJ fsAU0l64bWvKlObbufiaMRdqE+qY5MnqkU7554p7uojGWB1rNa3wydAeZHwODg356TNb GP0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hx1WadVF; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y2-20020a655b42000000b00429a132d2c8si5604148pgr.279.2022.08.31.12.01.15; Wed, 31 Aug 2022 12:01:25 -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=@google.com header.s=20210112 header.b=hx1WadVF; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232935AbiHaSoe (ORCPT + 99 others); Wed, 31 Aug 2022 14:44:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232912AbiHaSo1 (ORCPT ); Wed, 31 Aug 2022 14:44:27 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9B0625F8 for ; Wed, 31 Aug 2022 11:44:20 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33dc888dc62so210024627b3.4 for ; Wed, 31 Aug 2022 11:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc; bh=jeIDU7bkvi8qrUeCQKjSgf4R1NQDEDk5WzvSWsZHRgY=; b=hx1WadVFGfM2WHW+QMiqbRpB+tGtox/ZvfK2iSj6s7TWGpw2+YfDNLd71aeLJikF5A ut7591nG+1XtZZnWDLGHqvw7JJwxJ0XUqThW+DOuVmXx5U3HEA3SXJbmTWIaXpZ2woGZ RTEaI3LgVK8uilz+J1vZWsPlPY0651QNaHnpsTlpgvFMVxMQjssruP9r+aB90KHTVpR/ SrpgK6Xxyza7FDY2erOi2mdc5Qq7aDYAg+yKZnkJsavJ/Dfs+V/FjohIVlEbMIrrrnc8 VTZr1169mV2GmgrWFZhOXY+DTyvlyMMDWkpUhba503fcTfGVw+anr6JRNo1wjKRsiWNd VysQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc; bh=jeIDU7bkvi8qrUeCQKjSgf4R1NQDEDk5WzvSWsZHRgY=; b=6gbSFYKVNUu7jzJFgDJh7G7kPgiy6mE+h5y7VHOeYOdMpWtByTc22T56X5krIrZsuv pK+e91JAYWPJx6l50+er+wQ9biXuAQBbgw1z7CyvAajvye7YLOjONOZ0sz3WTEvqwtju NU+e+9aFyApzqKTMDZml/T2r/PfPQ0MUWusVH397yOuZx2MjFS6sXghPINiH84omNJZY Cz49P/AfMAR2XRklAtu/O4iYfRMQi/bQVmdyZeVg+i0ZLmE8ikJ+F/DvMM4wSBqsaljD +1XyruXZSjr3igK/MFnIOUzEp6/2X1pVs76On5bCNAyzGz2a+462l1iUhA2yeuyE4e6J 8D0w== X-Gm-Message-State: ACgBeo1TeQNQN2PQysIOWRF8zvITAH6xPNB68bZRTsJiLZXB/v781HEt 5BB/YvRTlVZHFhNUO+Ph0Cl5PHjgAvfjfYaSvBs= X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:0:100e:712:5f5d:95d5:9a3:d41]) (user=ndesaulniers job=sendgmr) by 2002:a25:7608:0:b0:694:220b:8bf6 with SMTP id r8-20020a257608000000b00694220b8bf6mr16732077ybc.210.1661971460048; Wed, 31 Aug 2022 11:44:20 -0700 (PDT) Date: Wed, 31 Aug 2022 11:44:06 -0700 In-Reply-To: <20220831184408.2778264-1-ndesaulniers@google.com> Mime-Version: 1.0 References: <20220831184408.2778264-1-ndesaulniers@google.com> X-Developer-Key: i=ndesaulniers@google.com; a=ed25519; pk=lvO/pmg+aaCb6dPhyGC1GyOCvPueDrrc8Zeso5CaGKE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1661971448; l=6313; i=ndesaulniers@google.com; s=20211004; h=from:subject; bh=4nrhFDfzIr6P2uEi5X9UGCfe5n7Png+PEC4jrJ9T2hY=; b=Asevhm76deGOJCh2wzvhWYmHcNqfB9w30KRQRslJFMSwOMNo1qdlvq1fib/n0CQt0uFs4EHOV7W4 zd9FYCZZAcwt9VhTRml2m/KTX3mSvtSLn8veXUGEL29ZkuqxycP8 X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220831184408.2778264-4-ndesaulniers@google.com> Subject: [PATCH v2 3/5] Makefile.compiler: replace cc-ifversion with compiler-specific macros From: Nick Desaulniers To: Masahiro Yamada Cc: Michal Marek , Nathan Chancellor , Tom Rix , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, x86@kernel.org, Dmitrii Bundin , Fangrui Song , Alexey Alexandrov , Bill Wendling , Greg Thelen , Nick Desaulniers , Jonathan Corbet , linux-doc@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham 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 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))) # ld-option # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) -- 2.37.2.672.g94769d06f0-goog