From patchwork Wed Jul 7 22:43:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 12364161 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=-31.6 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=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 59EF3C07E95 for ; Wed, 7 Jul 2021 22:43:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 374E661CD3 for ; Wed, 7 Jul 2021 22:43:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231321AbhGGWp7 (ORCPT ); Wed, 7 Jul 2021 18:45:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbhGGWp6 (ORCPT ); Wed, 7 Jul 2021 18:45:58 -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 347BEC061574 for ; Wed, 7 Jul 2021 15:43:17 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v184-20020a257ac10000b02904f84a5c5297so4421979ybc.16 for ; Wed, 07 Jul 2021 15:43:17 -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=oQNGvy//YsByQbA2jNjuQSDvdEyrDDI3RHX9PIliM8M=; b=Afcdzv2tyx8L2xlhLRBKLqSDEg82F0PL17xPoY7Bh8Bm9YxYAp7Ztde4Mptwb3zdrx ijG1XcdOIogp8odOH9P+snlnYUWLLQ+9giDSSi1tMWJkXyYT4mcEkIFyurJmabQWk+O/ BqLGt0KWhuR2CO3PbuOXNAgGpu+vtJONkSpawv7KcquUalHbNMbGU4uNykaIcKbJO4j8 v/txcOPTf6XP7VNG2sYN19+wrQU2ebrsPn8MsXZOxi+K4ZB3p2ICYbPmE+VGEVXslesb BGxjUEjMoTcO30JKpNt+iBu6ZGvi96vNtpDX2QvrrIysLZRc+WRWkdY5FWyYKbwCDXUJ za7g== 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=oQNGvy//YsByQbA2jNjuQSDvdEyrDDI3RHX9PIliM8M=; b=Bu1TVl36HDY9vOfnv2vQSrnUkQ/lTtlw4TmaEs7dFUYeAxvdF7ah0a6QmBVJXrSVf+ dIdJ4fcWqKXgNs9IOTgqgrOLOmo5CZZ9/aqTSetDoJXjAZzBybyfyuDhbJRw3Jw0HJxt D8h8MH1fMguf5PHyAjH+jONeYXe/SmZSY9MVqhRulsdYMRgJ8t57rzXujASrb7RykkoH U4Qe7VevZJ+tXLPef6yNCE/oGUMO5HF/tBgSKNvK/RX1ciqpvG5O9CQVFzPzc44zTWls KQ/KNb8VXwieC8Dcnef0pszPpKPScWlp/TekL8cRZdUcB0aqnOA9x/z2eFjRqNe7lab/ pCHg== X-Gm-Message-State: AOAM531OQX36IvCkJhOCYTxdUa3pihlCRX4lZaQ5tmO2ikOu5erAdG5O FhqDF77nQMnvWVZ8awsiZd+joqp1SuFbuehk180= X-Google-Smtp-Source: ABdhPJxtgNcTGrkpVWraln9pSlgwMQdfn7B62i4Nu04ljHLEv2kCroW3BSmWTF1AVvyWeeE2N2TN2PKPO4ogI0/XX3U= X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:d417:6e24:4a54:1792]) (user=ndesaulniers job=sendgmr) by 2002:a25:8082:: with SMTP id n2mr34615840ybk.79.1625697796357; Wed, 07 Jul 2021 15:43:16 -0700 (PDT) Date: Wed, 7 Jul 2021 15:43:09 -0700 In-Reply-To: <20210707224310.1403944-1-ndesaulniers@google.com> Message-Id: <20210707224310.1403944-2-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210707224310.1403944-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH 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, 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 --- Changes RFC -> v1: * Rename new file as per Nathan. 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 Wed Jul 7 22:43:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 12364163 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=-28.8 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,UNWANTED_LANGUAGE_BODY,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 EB29AC07E9E for ; Wed, 7 Jul 2021 22:43:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB8A861CCA for ; Wed, 7 Jul 2021 22:43:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231345AbhGGWqB (ORCPT ); Wed, 7 Jul 2021 18:46:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231343AbhGGWqA (ORCPT ); Wed, 7 Jul 2021 18:46:00 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0AC4C06175F for ; Wed, 7 Jul 2021 15:43:19 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id 44-20020aed30af0000b029024e8ccfcd07so2174952qtf.11 for ; Wed, 07 Jul 2021 15:43:19 -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=/85l2E8K+20QVvNNb2KxNFZMM43rwvEksKDAAvMmyxw=; b=aMgaH0f60ri4+7q3inDHhAzPnvNA8hvYOKgJ9NqPtv+6JhaqB+ORX55cfzdeRuc9+Z 2YA1ByZYy8zsokIagV+qVw247owxNutuGtky3IjJzAobpcTE0+UiYO/i3y1VLfu8AwLx PxV3YbDoi7UG3RwYwob47yzZs2nd4823aAb/F+nb8Y/H3txTg74ZcfDwVqqEtTLHz7i6 1zBQfvhkXUiD5Kq6CNIuoZglsK1TS/taTEvbbCja5z/0raBo9mTY22/N44nC4KLhvpDg ah7OERSNSuM0WBC9u4QIJZOiG557syp5PDMPgpbINv5eiCs3tjLJ9uRFc7dngP2qNO/Q uGbA== 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=/85l2E8K+20QVvNNb2KxNFZMM43rwvEksKDAAvMmyxw=; b=GtM8iRrGGEXuSuWCkxDJhd1cpsJT8W5fEdsjbngNyTT5vZYaxgH4cGxwflBqqTrCgi VQFQ1IECckq2Yn5G2+Hq1S8BJRlYU7QXX3v4CLtV2y8gV+4CWM0lGXCGTfpT7Qn/8Era exc6kI9el8/PpHy7JYm8y++yaU0hIjUNssdPoT8IPIs6pci0VuxgID2bCq8xrQrGISI+ OVs6m34xCbtnFg+dqvvNrIPM16a0WZgUu/VnDO6etoMCnbQscx8bnSJ1eKLaxKDJ2tp2 9K4xoNaZa9PITbM2VSS9lIXoi0a/J03+HhAqVEm9ycm6v2IIlhbQQYP8uqrqin80fAuO u9iw== X-Gm-Message-State: AOAM532SJMHlMJBGDZDSeam+F30ysGc+iOMthvNpVlDI/gxy+Rrn8Phc kft+hLrwDiEL0MEBFxA+Md+sGOZPC0BS0frsmM8= X-Google-Smtp-Source: ABdhPJxItucFemx8YM3vONxVgiXV68A9Y6Uq5ZiQ3ccTpoCn7Jqfyh8C8HwRkUeIOlNw44d+dcOXVnrlV3US2kUCHb0= X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:d417:6e24:4a54:1792]) (user=ndesaulniers job=sendgmr) by 2002:a05:6214:1a0a:: with SMTP id fh10mr26007149qvb.59.1625697798784; Wed, 07 Jul 2021 15:43:18 -0700 (PDT) Date: Wed, 7 Jul 2021 15:43:10 -0700 In-Reply-To: <20210707224310.1403944-1-ndesaulniers@google.com> Message-Id: <20210707224310.1403944-3-ndesaulniers@google.com> Mime-Version: 1.0 References: <20210707224310.1403944-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH 2/2] Makefile: drop CROSS_COMPILE 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, 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 ARCH. If CROSS_COMPILE is not set, simply set --target= for CLANG_FLAGS, KBUILD_CFLAGS, and KBUILD_AFLAGS based on $ARCH. Previously, we'd cross compile via: $ ARCH=arm64 CROSS_COMPILE=aarch64-linxu-gnu make LLVM=1 LLVM_IAS=1 Now: $ ARCH=arm64 make LLVM=1 LLVM_IAS=1 Link: https://github.com/ClangBuiltLinux/linux/issues/1399 Suggested-by: Arnd Bergmann Suggested-by: Nathan Chancellor Signed-off-by: Nick Desaulniers --- 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 | 38 +++++++++++++++++++++++++++++++++-- 2 files changed, 41 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..a79088797a50 100644 --- a/scripts/Makefile.clang +++ b/scripts/Makefile.clang @@ -1,6 +1,40 @@ -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 ($(ARCH),arm) +CLANG_FLAGS += --target=arm-linux-gnueabi +else ifeq ($(ARCH),arm64) +CLANG_FLAGS += --target=aarch64-linux-gnu +else ifeq ($(ARCH),hexagon) +CLANG_FLAGS += --target=hexagon-linux-gnu +else ifeq ($(ARCH),i386) +CLANG_FLAGS += --target=i686-linux-gnu +else ifeq ($(ARCH),m68k) +CLANG_FLAGS += --target=m68k-linux-gnu +else ifeq ($(ARCH),mips) +CLANG_FLAGS += --target=mipsel-linux-gnu +else ifeq ($(ARCH),powerpc) +CLANG_FLAGS += --target=powerpc64le-linux-gnu +else ifeq ($(ARCH),riscv) +CLANG_FLAGS += --target=riscv64-linux-gnu +else ifeq ($(ARCH),s390) +CLANG_FLAGS += --target=s390x-linux-gnu +else ifeq ($(ARCH),x86) +CLANG_FLAGS += --target=x86_64-linux-gnu +else ifeq ($(ARCH),x86_64) +CLANG_FLAGS += --target=x86_64-linux-gnu +else +$(error Specify CROSS_COMPILE or add '--target=' option to scripts/Makefile.clang) +endif # ARCH +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