Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1083127pxk; Fri, 25 Sep 2020 05:57:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmXOMRL3uEoeFoBrManNfOvR2c2G3w7iUqcQ1IHH5OQoh19zbRVeJahuWpA9BmzbcAQ4S7 X-Received: by 2002:aa7:da10:: with SMTP id r16mr1158279eds.333.1601038622502; Fri, 25 Sep 2020 05:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601038622; cv=none; d=google.com; s=arc-20160816; b=SMWHTu/fPEK8dU6uem6c519sHWx1bt4itQLxIP00SNqSlaTsTIZVhP0CiTU3yZrbME B+oogYdj7wZiWIgute/inD4PZHPYYFIGFFbUq1K4JLqiObHQblEr5nfaj++d65KMuWOS Mzcsqe6ci0Nas0fnVQleltB5co+P5N2xfiukVo1Dsk+vkv5TjStnrM+vbrMPAiohzkPj zPtPmpMiuJy0dBmavA0veAdpjvKfcBUSj4AbnkdIih5c9kYe4uU+C0kXS+zYIiblLGxu wd+adI9oFly1LW/egKoSX5aJHBg+JH6VJeeYScbLhilBTT7/L3XlEFA2I1/0JUlIfYSv epXg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pZD+YCF71Pl0+ATlU8r9gkUVDxdxPlrdXIw4nDYo8dQ=; b=uYjh5hxsRJSCjkPzir1u9NJNfBiJrVyqP+ki3adwJFy1qVGcKmbUarXgsb2ZdwcNiP 55trdNpKXRSfnU/P1HBt+34KE8XZIlFZjRknEneQ/8jnZa9LFJV7cdUZ45TG5bCFix5H lspsZX36gskRpinGChzKb4E1jtcI51qAhVnKL2qTXWBFe/aXLnV0wb1iqh2dpwFmil5u 0vA3/T7jcXHTWx1dg0/ROAMr8XHLGU6aJnDWPEYFW5INdO7n41u8nTtBgmRAr/KHkrJq glCR8/im5glJTlQK4ZFa3/tJoz2zcV5utgD8lyZ+hg5PGDo7Tvo7uaidfi7fJNwHy3NI VC1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EjpPeeBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq11si1818567edb.63.2020.09.25.05.56.39; Fri, 25 Sep 2020 05:57:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EjpPeeBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729599AbgIYMyn (ORCPT + 99 others); Fri, 25 Sep 2020 08:54:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:33594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729594AbgIYMyl (ORCPT ); Fri, 25 Sep 2020 08:54:41 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CE67B2072E; Fri, 25 Sep 2020 12:54:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601038481; bh=kL53Yr0XeyiWupLmaGRqYxZjUQiCqY3balbspMAqUAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EjpPeeBXl81wcCLD0ImXex3PbyAcCOcJ+8cVFrBfXJzxOW+88MEtPDqacP+g3osL+ F7wzKVR5QsZWKyA40vG986Sxt0i2Zga/DtLKmxTml2qMFYub2YAJkJ6hePLA1i6k2Z PgBytnJOiFePpPpg+cKipvwC3bpJjP9SLvMLJG00= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nick Desaulniers Subject: [PATCH 4.19 33/37] kbuild: support LLVM=1 to switch the default tools to Clang/LLVM Date: Fri, 25 Sep 2020 14:49:01 +0200 Message-Id: <20200925124725.938789823@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200925124720.972208530@linuxfoundation.org> References: <20200925124720.972208530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masahiro Yamada commit a0d1c951ef08ed24f35129267e3595d86f57f5d3 upstream. As Documentation/kbuild/llvm.rst implies, building the kernel with a full set of LLVM tools gets very verbose and unwieldy. Provide a single switch LLVM=1 to use Clang and LLVM tools instead of GCC and Binutils. You can pass it from the command line or as an environment variable. Please note LLVM=1 does not turn on the integrated assembler. You need to pass LLVM_IAS=1 to use it. When the upstream kernel is ready for the integrated assembler, I think we can make it default. We discussed what we need, and we agreed to go with a simple boolean flag that switches both target and host tools: https://lkml.org/lkml/2020/3/28/494 https://lkml.org/lkml/2020/4/3/43 Some items discussed, but not adopted: - LLVM_DIR When multiple versions of LLVM are installed, I just thought supporting LLVM_DIR=/path/to/my/llvm/bin/ might be useful. CC = $(LLVM_DIR)clang LD = $(LLVM_DIR)ld.lld ... However, we can handle this by modifying PATH. So, we decided to not do this. - LLVM_SUFFIX Some distributions (e.g. Debian) package specific versions of LLVM with naming conventions that use the version as a suffix. CC = clang$(LLVM_SUFFIX) LD = ld.lld(LLVM_SUFFIX) ... will allow a user to pass LLVM_SUFFIX=-11 to use clang-11 etc., but the suffixed versions in /usr/bin/ are symlinks to binaries in /usr/lib/llvm-#/bin/, so this can also be handled by PATH. Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor # build Tested-by: Nick Desaulniers Reviewed-by: Nick Desaulniers Signed-off-by: Nick Desaulniers [nd: conflict in exported vars list from not backporting commit e83b9f55448a ("kbuild: add ability to generate BTF type info for vmlinux")] [nd: hunk against Documentation/kbuild/kbuild.rst dropped due to not backporting commit cd238effefa2 ("docs: kbuild: convert docs to ReST and rename to *.rst")] Signed-off-by: Greg Kroah-Hartman --- Documentation/kbuild/llvm.rst | 8 ++++++-- Makefile | 29 +++++++++++++++++++++++------ tools/objtool/Makefile | 6 ++++++ 3 files changed, 35 insertions(+), 8 deletions(-) --- a/Documentation/kbuild/llvm.rst +++ b/Documentation/kbuild/llvm.rst @@ -47,8 +47,12 @@ example: LLVM Utilities -------------- -LLVM has substitutes for GNU binutils utilities. These can be invoked as -additional parameters to `make`. +LLVM has substitutes for GNU binutils utilities. Kbuild supports `LLVM=1` +to enable them. + + make LLVM=1 + +They can be enabled individually. The full list of the parameters: make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \\ OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump OBJSIZE=llvm-size \\ --- a/Makefile +++ b/Makefile @@ -358,8 +358,13 @@ HOST_LFS_CFLAGS := $(shell getconf LFS_C HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null) HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null) -HOSTCC = gcc -HOSTCXX = g++ +ifneq ($(LLVM),) +HOSTCC = clang +HOSTCXX = clang++ +else +HOSTCC = gcc +HOSTCXX = g++ +endif KBUILD_HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \ $(HOSTCFLAGS) @@ -368,16 +373,28 @@ KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAG KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS) # Make variables (CC, etc...) -LD = $(CROSS_COMPILE)ld -CC = $(CROSS_COMPILE)gcc CPP = $(CC) -E +ifneq ($(LLVM),) +CC = clang +LD = ld.lld +AR = llvm-ar +NM = llvm-nm +OBJCOPY = llvm-objcopy +OBJDUMP = llvm-objdump +READELF = llvm-readelf +OBJSIZE = llvm-size +STRIP = llvm-strip +else +CC = $(CROSS_COMPILE)gcc +LD = $(CROSS_COMPILE)ld AR = $(CROSS_COMPILE)ar NM = $(CROSS_COMPILE)nm -STRIP = $(CROSS_COMPILE)strip OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump -OBJSIZE = $(CROSS_COMPILE)size READELF = $(CROSS_COMPILE)readelf +OBJSIZE = $(CROSS_COMPILE)size +STRIP = $(CROSS_COMPILE)strip +endif LEX = flex YACC = bison AWK = awk --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -7,9 +7,15 @@ ARCH := x86 endif # always use the host compiler +ifneq ($(LLVM),) +HOSTAR ?= llvm-ar +HOSTCC ?= clang +HOSTLD ?= ld.lld +else HOSTAR ?= ar HOSTCC ?= gcc HOSTLD ?= ld +endif AR = $(HOSTAR) CC = $(HOSTCC) LD = $(HOSTLD)