From patchwork Thu Jul 8 23:25:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 12366333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-32.0 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC205C07E99 for ; Thu, 8 Jul 2021 23:25:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF17A6161F for ; Thu, 8 Jul 2021 23:25:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbhGHX2M (ORCPT ); Thu, 8 Jul 2021 19:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbhGHX2M (ORCPT ); Thu, 8 Jul 2021 19:28:12 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F2D4C061574 for ; Thu, 8 Jul 2021 16:25:29 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v184-20020a257ac10000b02904f84a5c5297so8996097ybc.16 for ; Thu, 08 Jul 2021 16:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=urOO6z/E/vigRuyY41VEGZzBsmY3+0PNbgPSZ6JhbA8=; b=q9AAsmHEGJuqeAqSa0zZFJCgp9QTxFkcay8w3jlF4LA6Ch3FtAnVJt2Xg/LbiecI0T TQPbsEcjxkaMsAfHSsF9aNYPKLG95iKcL8r5s4RV+KTO6VspeVtWETOBzj4xP2/Pq+mp SWralMOg3c04MC+ov84m7oX0wCgp4QX0t1T6BTEt5Qu/wF7v5Dme3oQwI+zCmvT7VdKV UwrT2r3qXtaGMncUgRLgnnZ6N4j6d17WkcKJbb9ARLlKl6pU6f3Jz+ML7NOB41pJGdgG jMoqtNkVUKrBBD/01yeoYzHVTK4hMJGrPF+DYIm4B5PLvbSxSv0Vfg6+Z7MRAXOZGz1I XgMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=urOO6z/E/vigRuyY41VEGZzBsmY3+0PNbgPSZ6JhbA8=; b=ozGkuf0YXHZJqJk4JN/8S3NWdr08qtMJxiLGY+wVxTlO8LMCa77iFqnL2+Cgfe8Ji/ uEY3pq0yEpG7Eu8flfR63njBoc6eb3QBJkyaUOmHJUXpeQXKXt/4ruGUd90xn0h2nT0x JVlyfpLAKZ8zVbUvCvmq+khIQVnIsLqOZ4uMyWnIMB15I20dfOMKG9/nZI9N5fmMOFVE t47bw/LskeibD2lNVJTTdxthqu2O2KTY0zq33a1fPmGHWVb+RaEfqRy4tj8nhcaAh+jF DjukfdnDpcwjciQTQizbE727Eg6NOz/m/rdbdyoQOsjfImKp5Eb6k+BrnrwR94GLEuuT JYkQ== X-Gm-Message-State: AOAM5314VV2KQi/GWXfS06441XgJGnu2Fg/7RdPhJ4+KiEh/2XVc8JX9 Ag9XzXycujT017xHcuspaTS19nhHQ5J1cCURIT4= X-Google-Smtp-Source: ABdhPJzymA2MwLLldgqDqB0kWnz2aSrBCjLiR6U+N3DIThXrhx/3QQUHEVebbyr4g5apkeEeJIw3LtcG4zGwzVLTsCE= X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:9fd:98a9:be3a:391d]) (user=ndesaulniers job=sendgmr) by 2002:a25:508e:: with SMTP id e136mr39414843ybb.275.1625786728855; Thu, 08 Jul 2021 16:25:28 -0700 (PDT) Date: Thu, 8 Jul 2021 16:25:21 -0700 In-Reply-To: <20210708232522.3118208-1-ndesaulniers@google.com> Message-Id: <20210708232522.3118208-2-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210708232522.3118208-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v2 1/2] Makefile: move initial clang flag handling into scripts/Makefile.clang From: Nick Desaulniers To: Masahiro Yamada Cc: Miguel Ojeda , Fangrui Song , Michal Marek , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, Geert Uytterhoeven , Christoph Hellwig , Linus Torvalds , Nick Desaulniers Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org With some of the changes we'd like to make to CROSS_COMPILE, the initial block of clang flag handling which controls things like the target triple, whether or not to use the integrated assembler and how to find GAS, and erroring on unknown warnings is becoming unwieldy. Move it into its own file under scripts/. Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor --- MAINTAINERS | 1 + Makefile | 15 +-------------- scripts/Makefile.clang | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 scripts/Makefile.clang diff --git a/MAINTAINERS b/MAINTAINERS index 81e1edeceae4..9c1205c258c7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4433,6 +4433,7 @@ B: https://github.com/ClangBuiltLinux/linux/issues C: irc://chat.freenode.net/clangbuiltlinux F: Documentation/kbuild/llvm.rst F: include/linux/compiler-clang.h +F: scripts/Makefile.clang F: scripts/clang-tools/ K: \b(?i:clang|llvm)\b diff --git a/Makefile b/Makefile index cbab0dc53065..010e3a4e770b 100644 --- a/Makefile +++ b/Makefile @@ -586,20 +586,7 @@ endif CC_VERSION_TEXT = $(subst $(pound),,$(shell $(CC) --version 2>/dev/null | head -n 1)) ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) -ifneq ($(CROSS_COMPILE),) -CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) -endif -ifeq ($(LLVM_IAS),1) -CLANG_FLAGS += -integrated-as -else -CLANG_FLAGS += -no-integrated-as -GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) -CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) -endif -CLANG_FLAGS += -Werror=unknown-warning-option -KBUILD_CFLAGS += $(CLANG_FLAGS) -KBUILD_AFLAGS += $(CLANG_FLAGS) -export CLANG_FLAGS +include $(srctree)/scripts/Makefile.clang endif # Include this also for config targets because some architectures need diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang new file mode 100644 index 000000000000..297932e973d4 --- /dev/null +++ b/scripts/Makefile.clang @@ -0,0 +1,14 @@ +ifneq ($(CROSS_COMPILE),) +CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) +endif +ifeq ($(LLVM_IAS),1) +CLANG_FLAGS += -integrated-as +else +CLANG_FLAGS += -no-integrated-as +GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) +CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) +endif +CLANG_FLAGS += -Werror=unknown-warning-option +KBUILD_CFLAGS += $(CLANG_FLAGS) +KBUILD_AFLAGS += $(CLANG_FLAGS) +export CLANG_FLAGS From patchwork Thu Jul 8 23:25:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 12366335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-32.0 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36F3BC07E9C for ; Thu, 8 Jul 2021 23:25:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 207E261864 for ; Thu, 8 Jul 2021 23:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229832AbhGHX2Q (ORCPT ); Thu, 8 Jul 2021 19:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbhGHX2P (ORCPT ); Thu, 8 Jul 2021 19:28:15 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AEFEC061760 for ; Thu, 8 Jul 2021 16:25:32 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id t6-20020ac80dc60000b029024e988e8277so4529242qti.23 for ; Thu, 08 Jul 2021 16:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=SwO6fBZGz2iC3nN2qsSyi7QNR9xbovSrkFUoBq2YBxQ=; b=PicVCFX7aq3C0LfwA5o/vKjKqx2f9hG07XU7N7Ij5aRvpT3ZMf2+GA2T+bQ4XkA0wn uIBTsyHl4mTuFrohrFxYwB7C2JMuzxiQBxwqCHEPprMfajKRKBCTWlzbfXWV9HU3WIxz fVI+jUBLp5qip5uCMCgAoL5hZUZ9ZCftcP5uDn8jmaYrD3Uzfe1lsDvL1RGnb7SQxV3E Gn4sosY7Xsu2YdDA/qhGHy5BOhWxZn/GI9k6NS1W4DXayWEI8trfr8fzIn25jZImddjk 40K4u5VLkmwCDal1JieOoiTOwGIxT087Jg/CKe04fnlnyvZlTKfsLiH+scx9TDfNjfX0 G+Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=SwO6fBZGz2iC3nN2qsSyi7QNR9xbovSrkFUoBq2YBxQ=; b=SqcmJFe5pPQ/LLW3pG3p10xKwILa1bluapsagVrUDzgxGd6x3b7ua1pFzEgAmMbf49 6A0qV4zrhPLTsS1EUvcpEALrgLUWaUw74kjk5mGmZzJ3T2PUtZXCI5+fISMgZkA3EcBi IdWgbASKy1HH1Zyu6j39UMznXUeHar1QKk2so6i8jEnXdNuCwee/Yn01N3SEVBI/hL6h CSpKjYfH7zMmr3IgLhg2IgUy4YODaNfpZReDHS9dmtoObHck1dN+8Zfb9Za+DOn6kRFk mN/XXmTI3T+xoO/AvTk7lPorK4Tl+OBosQ0J4YPaswao/C6g4hXuWHaI6ARxnEXyd5Rj EsBA== X-Gm-Message-State: AOAM533kRpD0Gp841Srb6ilLtLMnsPGiCt4ssnCx78Qeqmkzc/kGgLK2 DvnPENq49VBivFE5WDkgaunCs/B6FK2lxdbo60k= X-Google-Smtp-Source: ABdhPJxbl4/glWYghmfTYXi+1oKuqYroUw6XvbRsXBsvOzn28ijUeZE6bkSwdkd8ihbLVreF/05ziSJl8qCWv0q3jrE= X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:9fd:98a9:be3a:391d]) (user=ndesaulniers job=sendgmr) by 2002:a05:6214:21cf:: with SMTP id d15mr33140677qvh.12.1625786731194; Thu, 08 Jul 2021 16:25:31 -0700 (PDT) Date: Thu, 8 Jul 2021 16:25:22 -0700 In-Reply-To: <20210708232522.3118208-1-ndesaulniers@google.com> Message-Id: <20210708232522.3118208-3-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210708232522.3118208-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v2 2/2] Makefile: infer CROSS_COMPILE from SRCARCH for LLVM=1 LLVM_IAS=1 From: Nick Desaulniers To: Masahiro Yamada Cc: Miguel Ojeda , Fangrui Song , Michal Marek , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, Geert Uytterhoeven , Christoph Hellwig , Linus Torvalds , Nick Desaulniers , Nathan Chancellor Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org We get constant feedback that the command line invocation of make is too long. CROSS_COMPILE is helpful when a toolchain has a prefix of the target triple, or is an absolute path outside of $PATH, but it's mostly redundant for a given SRCARCH. SRCARCH itself is derived from ARCH (normalized for a few different targets). If CROSS_COMPILE is not set, simply set --target= for CLANG_FLAGS, KBUILD_CFLAGS, and KBUILD_AFLAGS based on $SRCARCH. Previously, we'd cross compile via: $ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make LLVM=1 LLVM_IAS=1 Now: $ ARCH=arm64 make LLVM=1 LLVM_IAS=1 For native builds (not involving cross compilation) we now explicitly specify a target triple rather than rely on the implicit host triple. Link: https://github.com/ClangBuiltLinux/linux/issues/1399 Suggested-by: Arnd Bergmann Suggested-by: Nathan Chancellor Suggested-by: Masahiro Yamada Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor --- Changes v1 -> v2: * Fix typos in commit message as per Geert and Masahiro. * Use SRCARCH instead of ARCH, simplifying x86 handling, as per Masahiro. Add his sugguested by tag. * change commit oneline from 'drop' to 'infer.' * Add detail about explicit host --target and relationship of ARCH to SRCARCH, as per Masahiro. Changes RFC -> v1: * Rebase onto linux-kbuild/for-next * Keep full target triples since missing the gnueabi suffix messes up 32b ARM. Drop Fangrui's sugguested by tag. Update commit message to drop references to arm64. * Flush out TODOS. * Add note about -EL/-EB, -m32/-m64. * Add note to Documentation/. Documentation/kbuild/llvm.rst | 5 +++++ scripts/Makefile.clang | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst index b18401d2ba82..80c63dd9a6d1 100644 --- a/Documentation/kbuild/llvm.rst +++ b/Documentation/kbuild/llvm.rst @@ -46,6 +46,11 @@ example: :: clang --target=aarch64-linux-gnu foo.c +When both ``LLVM=1`` and ``LLVM_IAS=1`` are used, ``CROSS_COMPILE`` becomes +unnecessary and can be inferred from ``ARCH``. Example: :: + + ARCH=arm64 make LLVM=1 LLVM_IAS=1 + LLVM Utilities -------------- diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang index 297932e973d4..956603f56724 100644 --- a/scripts/Makefile.clang +++ b/scripts/Makefile.clang @@ -1,6 +1,36 @@ -ifneq ($(CROSS_COMPILE),) +# Individual arch/{arch}/Makfiles should use -EL/-EB to set intended endianness +# and -m32/-m64 to set word size based on Kconfigs instead of relying on the +# target triple. +ifeq ($(CROSS_COMPILE),) +ifneq ($(LLVM),) +ifeq ($(LLVM_IAS),1) +ifeq ($(SRCARCH),arm) +CLANG_FLAGS += --target=arm-linux-gnueabi +else ifeq ($(SRCARCH),arm64) +CLANG_FLAGS += --target=aarch64-linux-gnu +else ifeq ($(SRCARCH),hexagon) +CLANG_FLAGS += --target=hexagon-linux-gnu +else ifeq ($(SRCARCH),m68k) +CLANG_FLAGS += --target=m68k-linux-gnu +else ifeq ($(SRCARCH),mips) +CLANG_FLAGS += --target=mipsel-linux-gnu +else ifeq ($(SRCARCH),powerpc) +CLANG_FLAGS += --target=powerpc64le-linux-gnu +else ifeq ($(SRCARCH),riscv) +CLANG_FLAGS += --target=riscv64-linux-gnu +else ifeq ($(SRCARCH),s390) +CLANG_FLAGS += --target=s390x-linux-gnu +else ifeq ($(SRCARCH),x86) +CLANG_FLAGS += --target=x86_64-linux-gnu +else +$(error Specify CROSS_COMPILE or add '--target=' option to scripts/Makefile.clang) +endif # SRCARCH +endif # LLVM_IAS +endif # LLVM +else CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) -endif +endif # CROSS_COMPILE + ifeq ($(LLVM_IAS),1) CLANG_FLAGS += -integrated-as else