Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4572546ybb; Tue, 7 Apr 2020 10:03:14 -0700 (PDT) X-Google-Smtp-Source: APiQypLYu7/YjRsGX15clP2xaIEi50XB1Uk57lHiBxdXw+sQHwDC0JOre5OkMZjmEvjx4eXsbQu9 X-Received: by 2002:a9d:7197:: with SMTP id o23mr2469752otj.286.1586278993863; Tue, 07 Apr 2020 10:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586278993; cv=none; d=google.com; s=arc-20160816; b=yqcc0pEzpJRk99p5wZNTrG2c2aEJvY7xpp+BVKwKyG5TnwalsMSBBIdcpyR3hDlhTW SYQ26p1HjDCedMJjMth31eVrM5v0TCgv9C/2iyubde1GhihAfBsJbuzRLg7/SDn8ym1U ZX+kyudTsvOE4pimtEfHyZWWWPBQShb82I63VnOkglLh3/hLQmEiCVSbrpYZufuwsZfJ H63mmjkdFEUIn0pN6rGqcnnkx2PPkOtx148u3jKIzOixacoXf1oz+ADEm1pNtI7hLhM3 flZRCgtbAxLCYX48xJh86MfQMVcR8RVFaR8W8FQnrx/hOkpLOdta3s09zP4mCTRyo7hh Q60g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=BKA4RM51A82x/5SpJbkyD9gWBCDUmnDILyC/0E/dflg=; b=aNYZird8X+EJoQ3LPbF2Nvkj9rgX6z0RwuSxH/o2BWSW3rG5cbnSzHhKV0EgFY/PkY NXqZWxjA7jnfxrGdkzHXonpxd62mlwuHlL2ONrH1vVLQGLVx9cjM9nsT0NUfgxPP0vzD YnWIqPjzVMCcBgqcARsYkov7em2ZWh/czB9IMWuVBKgbNeiKcj5FUnUwnHMXOZzBdQvL K+tmjR6fHePLmMfEWTDpXODbnknlsB1EhxzkCVHJfRlKfHZG6JFkYbFjgsXzHI1fC+95 ZWpmNL+7Uytu+qWX9Uceo9jsXGOk0utCG4ItIryDs8erHszNYkxkNCj+r6WJ0vd0z8ex pDeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ma3VTOaM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j25si1488368otk.154.2020.04.07.10.02.47; Tue, 07 Apr 2020 10:03:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ma3VTOaM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726628AbgDGRBT (ORCPT + 99 others); Tue, 7 Apr 2020 13:01:19 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:37395 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726527AbgDGRBS (ORCPT ); Tue, 7 Apr 2020 13:01:18 -0400 Received: by mail-pl1-f193.google.com with SMTP id x1so1473526plm.4 for ; Tue, 07 Apr 2020 10:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BKA4RM51A82x/5SpJbkyD9gWBCDUmnDILyC/0E/dflg=; b=ma3VTOaM3ccztMgbWUch6c9Nop0cKlddfRdpAgSYy7156lYP1wdkteuId5JaVDSzgv pstITV0JnBjl18ZnTE6upqD3TrTmYjV1BhYYPm/isptuMEyFwY+neCeERdoMYIA7FceE xNVwlvSMjCG83B8EHkpPJnmePjhK+X4KiRdfPjVc0byiuKoVyK5E3bk9YI6Dlvga6ir7 cVDQCpvkxG0SJFNfsJ0E5vidb8x267+9UBHEhnGyzZW9eCxi1GQ3ezR3fHYst8oiLvLz IFstetzqRlAla/WuwKTX5ClMVQozR86gOzJMPoKJLbYQRPkqoo62sEBKwhW77lGPmRfM 5SKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BKA4RM51A82x/5SpJbkyD9gWBCDUmnDILyC/0E/dflg=; b=eRJlCJGBMNpI3aur01IU8bA06I4tkXOU9PMiJ4GqnO643M5SIXq9AoMpC0n8e5I0Fa ggfbZfXg05RlabC6OG5qiV1CuCkloUJomzP9UuCm3X6O10oR4rjGuTlFzd9sBnycjz3n 1wzdwWCEhf9pmsdyedl5zQK0txYgvi16vFCCviITBYvZ8OZZ3A9m0ln1rMLyuY5k3ukm DaVrdBSl53stGPosNy+Pi3tLEmPOp5+VfthdWJBiKRUlNFToLNngjlsFdDZaAoCDvvY8 NLqC6e8piG7xdHMEvk6NleWqt5vKtcg/1HJePsdze627Hf06narimFfqNIspx91WoZr3 KINw== X-Gm-Message-State: AGi0Pua5apzyVpH90OIxsWcq4FkIhFNlC8NsMhfixpcsiHwnMEmahOoI Gj8aMO3P9k3nkpgouXvkw1gHe3fZc9rKcrJrLiiQfw== X-Received: by 2002:a17:90a:8085:: with SMTP id c5mr276765pjn.186.1586278877201; Tue, 07 Apr 2020 10:01:17 -0700 (PDT) MIME-Version: 1.0 References: <20200403051709.22407-1-masahiroy@kernel.org> <20200406112220.GB126804@google.com> In-Reply-To: From: Nick Desaulniers Date: Tue, 7 Apr 2020 10:01:04 -0700 Message-ID: Subject: Re: [PATCH] kbuild: support 'LLVM' to switch the default tools to Clang/LLVM To: Masahiro Yamada Cc: Matthias Maennich , Linux Kbuild mailing list , Nathan Chancellor , clang-built-linux , Jonathan Corbet , Michal Marek , "open list:DOCUMENTATION" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 7, 2020 at 9:17 AM Masahiro Yamada wrote: > > On Mon, Apr 6, 2020 at 8:22 PM 'Matthias Maennich' via Clang Built > Linux wrote: > > > > On Fri, Apr 03, 2020 at 02:17:09PM +0900, Masahiro Yamada wrote: > > >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' to use Clang and LLVM tools instead of > > >GCC and Binutils. You can pass LLVM=1 from the command line or as an > > >environment variable. Then, Kbuild will use LLVM toolchains in your > > >PATH environment. > > > > > >Please note LLVM=1 does not turn on the LLVM integrated assembler. > > >You need to explicitly pass AS=clang 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 > > >switch (https://lkml.org/lkml/2020/3/28/494). > > > > > >Some items in the discussion: > > > > > >- 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. > > > > > >- HOSTCC, HOSTCXX, etc. > > > > > > We can switch the host compilers in the same way: > > > > > > ifneq ($(LLVM),) > > > HOSTCC = clang > > > HOSTCXX = clang++ > > > else > > > HOSTCC = gcc > > > HOSTCXX = g++ > > > endif > > > > > > This may the right thing to do, but I could not make up my mind. > > > Because we do not frequently switch the host compiler, a counter > > > solution I had in my mind was to leave it to the default of the > > > system. > > > > > > HOSTCC = cc > > > HOSTCXX = c++ > > > > What about HOSTLD ? I saw recently, that setting HOSTLD=ld.lld is not > > yielding the expected result (some tools, like e.g. fixdep still require > > an `ld` to be in PATH to be built). I did not find the time to look into > > that yet, but I would like to consistently switch to the llvm toolchain > > (including linker and possibly more) also for hostprogs. > > > HOSTLD=ld.lld worked for me, but HOSTCC=clang did not. > > > > HOSTCC=clang without CC=clang fails to build objtool. > > The build system of objtool is meh. :( Let's tackle that in a follow up, with the goal of build hermiticity in mind. I think there's good feedback in this thread to inform the design of a v2: 1. CLANG_AS=0 to disable integrated as. Hopefully we won't need this much longer, so we don't need to spend too much time on this, Masahiro please just choose a name for this. llvm-as naming conventions doesn't follow the rest of binutils. 2. HOSTCC=clang HOSTLD=ld.lld set by LLVM=1 for helping with build hermiticity. > > > HOSTCC scripts/mod/sumversion.o > HOSTLD scripts/mod/modpost > CALL scripts/checksyscalls.sh > CALL scripts/atomic/check-atomics.sh > DESCEND objtool > error: unknown warning option '-Wstrict-aliasing=3'; did you mean > '-Wstring-plus-int'? [-Werror,-Wunknown-warning-option] > HOSTCC /home/masahiro/workspace/linux-kbuild/tools/objtool/fixdep.o > HOSTLD /home/masahiro/workspace/linux-kbuild/tools/objtool/fixdep-in.o > LINK /home/masahiro/workspace/linux-kbuild/tools/objtool/fixdep > CC /home/masahiro/workspace/linux-kbuild/tools/objtool/exec-cmd.o > CC /home/masahiro/workspace/linux-kbuild/tools/objtool/help.o > CC /home/masahiro/workspace/linux-kbuild/tools/objtool/pager.o > > > > > > > > Cheers, > > Matthias > > > > > > > > Many distributions support update-alternatives to switch the default > > > to GCC, Clang, or whatever, but reviewers were opposed to this > > > approach. So, this commit does not touch the host tools. > > > > > >Signed-off-by: Masahiro Yamada > > >--- > > > > > > Documentation/kbuild/kbuild.rst | 5 +++++ > > > Documentation/kbuild/llvm.rst | 5 +++++ > > > Makefile | 20 ++++++++++++++++---- > > > 3 files changed, 26 insertions(+), 4 deletions(-) > > > > > >diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst > > >index 510f38d7e78a..2d1fc03d346e 100644 > > >--- a/Documentation/kbuild/kbuild.rst > > >+++ b/Documentation/kbuild/kbuild.rst > > >@@ -262,3 +262,8 @@ KBUILD_BUILD_USER, KBUILD_BUILD_HOST > > > These two variables allow to override the user@host string displayed during > > > boot and in /proc/version. The default value is the output of the commands > > > whoami and host, respectively. > > >+ > > >+LLVM > > >+---- > > >+If this variable is set to 1, Kbuild will use Clang and LLVM utilities instead > > >+of GCC and GNU binutils to build the kernel. > > >diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst > > >index d6c79eb4e23e..4602369f6a4f 100644 > > >--- a/Documentation/kbuild/llvm.rst > > >+++ b/Documentation/kbuild/llvm.rst > > >@@ -55,6 +55,11 @@ additional parameters to `make`. > > > READELF=llvm-readelf HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar \\ > > > HOSTLD=ld.lld > > > > > >+You can use a single switch `LLVM=1` to use LLVM utilities by default (except > > >+for building host programs). > > >+ > > >+ make LLVM=1 HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar HOSTLD=ld.lld > > >+ > > > Getting Help > > > ------------ > > > > > >diff --git a/Makefile b/Makefile > > >index c91342953d9e..6db89ecdd942 100644 > > >--- a/Makefile > > >+++ b/Makefile > > >@@ -409,16 +409,28 @@ KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) > > > 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 > > > PAHOLE = pahole > > > LEX = flex > > > YACC = bison > > >-- > > >2.17.1 > > > > > >-- > > >You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > > >To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > > >To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200403051709.22407-1-masahiroy%40kernel.org. > > > > -- > > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200406112220.GB126804%40google.com. > > > > -- > Best Regards > Masahiro Yamada > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CAK7LNARkFN8jTD8F3CU7r_AL8dbqaKpUuou4MCLZvAYLGs9bYA%40mail.gmail.com. -- Thanks, ~Nick Desaulniers