From patchwork Fri Nov 18 19:53:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 22499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp380902wrr; Fri, 18 Nov 2022 11:56:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf4tMHM1e3W4GJkyDfwvBxQqb1ihu9jI5qt1SI3hewm62TcSrCCYZ772A1FhweWXukVSUZb8 X-Received: by 2002:a63:e30e:0:b0:46f:f26e:e877 with SMTP id f14-20020a63e30e000000b0046ff26ee877mr7526813pgh.545.1668801398834; Fri, 18 Nov 2022 11:56:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668801398; cv=none; d=google.com; s=arc-20160816; b=q+/xTxeyP9d3dzzV3rqRtTjGkwuawUAbTjbFHA2xCmD0lMojDuDbCkz3UjL0mgu2Hv qMsg6dbSAyBx0Noht5f5hhUcHB7hVoL3PqEcDS6RQ41bGiDJbt1qqBdCLqfRrz3kooIk 9ZihqRqeOZDLIjyBpcvVGtO2kWPlVbktWP1VYbIXNyeFt+l/Mi3vUoQ6uIAnSZRkE22n ertBtdDpoAUIXIFAxeUHqpagoUygrZnCNo08VvN2kdyyquE8debuPUvnndmFwc611Z+K sGAwId+Gj3a3x+1z/+ToHU8oP/ag3LcenNzWIkmskLMJvOGSy8D0V/74ICyAEY1wuisL umRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9fWzqHtl6IYXVw8afx9aB5BpU8xOFd19EMEmQlJ+hxc=; b=Ctr+l/oWs7tGMSQ46yG3UMlBtHzfh7Qz0xQu49rEnpeUVNU2KqvTRWqOq8l4u1MavO ae0edvzMSYaaXCfzyHX1M2LYpION03BQwU77w/1r6cAyJ+b9aqloc9HQQEn167bDPY1I OK0d0c7PQRfyLTzBxxvW8ztcS3BOcyJ6/meqBHxKXIIuDRFzc3Aa08OjNJ8+TV0GmJHn LE4WkKF39BYgqF/YTu2xNOvyhAqBiqOjDok13n/z9TvxecCrN34n38ZJNE/sy94u6Dj/ XnCNQGcXHjurtEwJwq/lOaq0vk/mSOx6LOTxi8y0ttZbMQFTx0fvVhsQfVKx0OOHvHi6 rMDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RGlUo4bz; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a7-20020a634d07000000b0046b127a1e8bsi4741316pgb.488.2022.11.18.11.56.26; Fri, 18 Nov 2022 11:56:38 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=RGlUo4bz; 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 S231947AbiKRTxY (ORCPT + 99 others); Fri, 18 Nov 2022 14:53:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231393AbiKRTxQ (ORCPT ); Fri, 18 Nov 2022 14:53:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53B61B7E93; Fri, 18 Nov 2022 11:53:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D59B46269B; Fri, 18 Nov 2022 19:53:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62005C433B5; Fri, 18 Nov 2022 19:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668801195; bh=wUrXcoJycZccOLz2aaej5UsJmc9Iwi2+dKKmMfDV/h0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RGlUo4bz3GmYt03qSb/ffXbUyEfN55vN6z4W8851GmJwNQyrsLId8hwfNopcQXRVz SvtPfgdADwvMZBSWXT+GhRpZZq0Hl6AURqOZoR7KMX3JdLkd416INftQaVRJQ2wtR+ o94oSPE5mQIyHFPaVn9hmrLsO3zWuiqGF3Tf9d4rXOU+cFNOG5qbr70pSMefCDRYhZ HEOaaWDXeKf28Pd5SHpB5PMds+ZGRrCkYJlxrshyCLCqVkDALBivieo8KNndzmV+eZ 39ZVJGGKEwPJXOw2lQBMlMG3NrbeIsyxxd/vcf/DyjSeLh2rFb7NOFIl5K+n04FIV8 XMMA13BKlVNjg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 1/6] kbuild: add test-{le,ge,lt,gt} macros Date: Sat, 19 Nov 2022 04:53:02 +0900 Message-Id: <20221118195307.86049-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221118195307.86049-1-masahiroy@kernel.org> References: <20221118195307.86049-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749865095770359075?= X-GMAIL-MSGID: =?utf-8?q?1749865095770359075?= Because GNU Make is only able to handle strings, it is very hard to perform arighmetic in Makefiles. When we compare two integers, we invokes shell. One example is in the top Makefile: ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) This is more expensive than using built-in functions since it forks a process. If we know the two have the same number of digits, we can do better. This commit adds four macros, test-le, test-ge, test-lt, test-gt. $(call test-lt, A, B) is evaluated to 'y' if A is less than B, or empty otherwise. This will replace $(call shell test A -lt B). Again, the limitation is that A and B must have the same number of digits because these macros are based on $(sort ) function. $(call test-lt, 1, 9) --> y (Works!) $(call test-lt, 10, 9) --> y (Not work...) To make the latter work, you need to add '0' prefix to align the number of digits: $(call test-lt, 10, 09) --> empty (Works!) Actually, we can live with this limitation in many places. As for the example above, we know $(CONFIG_LLD_VERSION) is 6-digits because the minimal supported version of LLVM is 11.0.0. So, the shell invocation can be replaced with more efficient code: ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) Of course, this assumption will break when LLVM 100 is released, but it will be far in the future. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- arch/riscv/Makefile | 2 +- arch/x86/Makefile | 2 +- scripts/Kbuild.include | 10 ++++++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 58cd4f5e1c3a..303516c035f6 100644 --- a/Makefile +++ b/Makefile @@ -986,7 +986,7 @@ KBUILD_LDFLAGS += -mllvm -import-instr-limit=5 # Check for frame size exceeding threshold during prolog/epilog insertion # when using lld < 13.0.0. ifneq ($(CONFIG_FRAME_WARN),0) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN) endif endif diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 0d13b597cb55..faf2c2177094 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -37,7 +37,7 @@ else endif ifeq ($(CONFIG_LD_IS_LLD),y) -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 150000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y) KBUILD_CFLAGS += -mno-relax KBUILD_AFLAGS += -mno-relax ifndef CONFIG_AS_IS_LLVM diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 415a5d138de4..e72c7a49cd59 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -211,7 +211,7 @@ endif KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE) ifdef CONFIG_LTO_CLANG -ifeq ($(shell test $(CONFIG_LLD_VERSION) -lt 130000; echo $$?),0) +ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 130000),y) KBUILD_LDFLAGS += -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8) endif endif diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index cbe28744637b..9996f34327cb 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -11,6 +11,16 @@ space := $(empty) $(empty) space_escape := _-_SPACE_-_ pound := \# +### +# Comparison macros. +# Usage: $(call test-le, A, B) +# works like shell's "test A -le B", but A and B must have the same number of +# digits since it is just ASCII sort. +test-le = $(if $(filter $1, $(firstword $(sort $1 $2))),y) +test-ge = $(call test-le, $2, $1) +test-lt = $(if $(filter-out $2, $(firstword $(sort $1 $2))),y) +test-gt = $(call test-lt, $2, $1) + ### # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o dot-target = $(dir $@).$(notdir $@)