Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5624279pxv; Wed, 28 Jul 2021 15:38:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcW7paAK46H1aWQr+tjdIJMwcDes6k0Jz8Qj6nawWMCX0HNCFa3fSsty5POoQbPqDRCMbM X-Received: by 2002:a17:906:3514:: with SMTP id r20mr1597478eja.351.1627511923185; Wed, 28 Jul 2021 15:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627511923; cv=none; d=google.com; s=arc-20160816; b=WMyWGOMaTaQsff1Dzal6faa0+h8sipkfZXkviD5/qzAduRbUKxYhB25LYWarrZJF7s zd/h9KffIguwx27Nx1HfReM9bRMmn8enE+CB+VQAZJfbwQX6Jzp8umxGgGtU9/UMg+KI RA1CYoQ7bwv+7i2uHOGIrG+BogXnlMLgs7vXH3RBDApYuJC8tpt7NtTlwNjFMWh80p4z zUHzcCKnwpgKqTWcusWLoTXMObtlUuHIOsEuyQ+bgw+6k6TVG2x5WrYx3sOmz6WjxEJh CAwyZJNXVYjju2QAt9Cp67Ae78TpwtIV3HnJAHe+RoA+T15N74fZBvCkCtpOAFQY62oC xzIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature:dkim-filter; bh=TmY7u99GvKGaIrLNACsThniYgzMQ+Eus0lMGKUzW6R4=; b=u0/sYaQG1R6Eng7Yx4I73RFw41FofWN9/Gyj3wxG1S52S0428K6QPsIRxLyypaCSpL q+JVVtoR7e0qmLS614oCESK3vbL9WhRhyMb8xvvXh2920HOUh+5XmlIo6jfprkNGhNSw Nm3vI5H+TwZ6Ec10+YytbkTFABWQvmd1sy1YTdotQER9bCDxYQeRJF56AKxabrxA5vKt GX4URh2qFc8858aJALdnlfhQiT+tYtnrClBD+ZD85tT5yn6hHqo/jrB4S/zab9PXzK+o y72QRrg0oa373fECi2mz095382iF7sW+AwoD6g6OgrCPc7jiK5vQjaFMbHhY7UZEkSQK 91dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=UM02UuIi; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hs31si1288652ejc.321.2021.07.28.15.38.19; Wed, 28 Jul 2021 15:38:43 -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=@nifty.com header.s=dec2015msa header.b=UM02UuIi; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbhG1Wgx (ORCPT + 99 others); Wed, 28 Jul 2021 18:36:53 -0400 Received: from conssluserg-06.nifty.com ([210.131.2.91]:33668 "EHLO conssluserg-06.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232154AbhG1Wgw (ORCPT ); Wed, 28 Jul 2021 18:36:52 -0400 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (authenticated) by conssluserg-06.nifty.com with ESMTP id 16SMaSpw009511; Thu, 29 Jul 2021 07:36:28 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-06.nifty.com 16SMaSpw009511 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1627511789; bh=TmY7u99GvKGaIrLNACsThniYgzMQ+Eus0lMGKUzW6R4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UM02UuIiQNiR6b7PSxMr4UhwWU5fln/BxpEhyJlihPGhgMdTSaL5xiWZt/9Vk6G/k 8pUwijVsYwpwNakDdZ+fpgWhMblpM4hkJxEcQ18PmcJyeeDNzX/OLhDEpG9sa8jkU2 a0Og2+pB7DoqEV+eoNk2tk85qO5/nNFtrKsY13bEFKZh/6NZNRJwl0MiiDh7+Z+oCo EJDKMLy0MOU2njIm7kI5Uwv599Cx823l1pf6inIJkgjwoFYgSKDbSQJIstH5hsNjFh JKiOhuUTPXOa5K7550tf03MfjmoS91BkjWQ9YgYV7L03qhoMHZeEYp5+psp6urUn3G 0sXxhZF1azC8g== X-Nifty-SrcIP: [209.85.216.52] Received: by mail-pj1-f52.google.com with SMTP id m1so7411631pjv.2; Wed, 28 Jul 2021 15:36:28 -0700 (PDT) X-Gm-Message-State: AOAM533r8IZ7qHAYhXNSOh3JatettkLQtMFQJ+IW0aUtL5mdLC0LhnE/ zSKhas785dn0LU4jEoz12crDYVnIippx9EBzlx4= X-Received: by 2002:a17:90a:c506:: with SMTP id k6mr11696072pjt.198.1627511787958; Wed, 28 Jul 2021 15:36:27 -0700 (PDT) MIME-Version: 1.0 References: <20210708232522.3118208-1-ndesaulniers@google.com> <20210708232522.3118208-3-ndesaulniers@google.com> <0636b417-15bb-3f65-39f7-148d94fe22db@kernel.org> In-Reply-To: From: Masahiro Yamada Date: Thu, 29 Jul 2021 07:35:50 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 2/2] Makefile: infer CROSS_COMPILE from SRCARCH for LLVM=1 LLVM_IAS=1 To: Nick Desaulniers Cc: Nathan Chancellor , Miguel Ojeda , Fangrui Song , Michal Marek , Arnd Bergmann , Linux Kernel Mailing List , Linux Kbuild mailing list , clang-built-linux , Geert Uytterhoeven , Christoph Hellwig , Linus Torvalds Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 29, 2021 at 4:00 AM 'Nick Desaulniers' via Clang Built Linux wrote: > > On Tue, Jul 20, 2021 at 8:50 PM Masahiro Yamada wrote: > > > > On Wed, Jul 21, 2021 at 2:30 AM Nathan Chancellor wrote: > > > > > > On 7/20/2021 1:04 AM, Masahiro Yamada wrote: > > > > On Fri, Jul 9, 2021 at 8:25 AM 'Nick Desaulniers' via Clang Built > > > > Linux wrote: > > > >> > > > >> 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),) > > > > > > > > > > > > Do you need to check $(LLVM) ? > > > > > > > > > > > > LLVM=1 is a convenient switch to change all the > > > > defaults, but yet you can flip each tool individually. > > > > > > > > Instead of LLVM=1, you still should be able to > > > > get the equivalent setups by: > > > > > > > > > > > > make CC=clang LD=ld.lld AR=llvm-ar OBJCOPY=llvm-objcopy ... > > > > > > > > > > > > The --target option is passed to only > > > > KBUILD_CFLAGS and KBUILD_AFLAGS. > > > > > > > > So, when we talk about --target=, > > > > we only care about whether $(CC) is Clang. > > > > Not caring about $(AR), $(LD), or $(OBJCOPY). > > > > > > > > > > > > scripts/Makefile.clang is already guarded by: > > > > > > > > ifneq ($(findstring clang,$(CC_VERSION_TEXT)), > > > > > > $ make ARCH=arm64 CC=clang LLVM_IAS=1 > > > > > > will use the right compiler and assembler but none of the other binary > > > tools because '--prefix=' will not be set so CROSS_COMPILE needs to be > > > specified still, which defeats the purpose of this whole change. This > > > patch is designed to work for the "normal" case of saying "I want to use > > > all of the LLVM tools", not "I want to use clang by itself". > > > > > > I disagree. > > > > LLVM=1 is a shorthand. > > > > > > > > make LLVM=1 LLVM_IAS=1 > > > > should be equivalent to: > > > > make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \ > > OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump READELF=llvm-readelf \ > > HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar HOSTLD=ld.lld \ > > LLVM_IAS=1 > > > > > > > > We do not care about the origin of CC=clang, > > whether it came from LLVM=1 or every tool was explicitly, > > individually specified. > > > > > > > > ifneq ($(LLVM),) is a garbage code > > that checks a pointless thing. > > Masahiro, > Nathan is correct. Test for yourself; if you apply these two patches, > then apply: > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > index 956603f56724..a1b46811bdc6 100644 > --- a/scripts/Makefile.clang > +++ b/scripts/Makefile.clang > @@ -2,7 +2,6 @@ > # 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 > @@ -26,7 +25,6 @@ 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 # CROSS_COMPILE > > Then build as Nathan specified: > $ ARCH=arm64 make CC=clang LLVM_IAS=1 -j72 defconfig all Yes, LD is set to GNU ld, which is only for x86. $ ARCH=arm64 make CC=clang LLVM_IAS=1 LD=ld.lld \ OBJCOPY=llvm-objcopy STRIP=llvm-strip \ -j72 defconfig all worked for me. It is true that the most common use-case would be LLVM=1 LLVM_IAS=1, but as I said, there is no good reason to prevent this feature from working when CC, LD, etc. are specified individually. > ... > arch/arm64/Makefile:25: ld does not support --fix-cortex-a53-843419; > kernel may be susceptible to erratum > ... > LD arch/arm64/kernel/vdso/vdso.so.dbg > ld: unrecognised emulation mode: aarch64linux > Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu > elf_l1om elf_k1om i386pep i386pe > make[1]: *** [arch/arm64/kernel/vdso/Makefile:56: > arch/arm64/kernel/vdso/vdso.so.dbg] Error 1 > make: *** [arch/arm64/Makefile:193: vdso_prepare] Error 2 > > Nathan referred to --prefix, but in this failure, because > CROSS_COMPILE was never set, the top level Makefile set LD to: > 452 LD = $(CROSS_COMPILE)ld > in this case `ld` in my path was my host x86 linker, which is not > correct for a cross compilation of arm64 target. > > Perhaps we can somehow support "implicit CROSS_COMPILE" with just > CC=clang, and not LLVM=1, but I think it would be inflexible to > hardcode such target triple prefixes. What if someone has > arm-linux-gnueabi-as but not arm-linux-gnueabihf-as installed? That's > the point of CROSS_COMPILE in my opinion to provide such flexibility > at the cost of additional command line verbosity. > > For the common case of LLVM=1 though, this series is a simplification. > If users want to specify CC=clang, then they MUST use CROSS_COMPILE > when cross compiling. > > Please review the current approach and see if there's more I can > improve in a v3; otherwise I still think this series is good to go. > -- > Thanks, > ~Nick Desaulniers > > -- > 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/CAKwvOdkENUWd7OgJO%3DdNiYjH6D1aJ0puBgs4W7uuYO9xQiAiNg%40mail.gmail.com. -- Best Regards Masahiro Yamada