Skip to contentSkip to conversation

Makefile: Remove '--gcc-toolchain' flag

PATCH Superseded Nathan Chancellor 6 participants 20 messages Mar 2, 2021 – Sep 29, 2021 Kbuild

lore
Share & tools
lore

Nathan Chancellor

author maintainer
#0 lore raw

PATCH 1/2 Makefile: Remove '--gcc-toolchain' flag

This is not necessary anymore now that we specify '--prefix=', which tells clang exactly where to find the GNU cross tools. This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

---
 Makefile | 4 ----
 1 file changed, 4 deletions(-)
Makefile +0 -4
index f9b54da2fca0..c20f0ad8be73 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN	:= $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS	+= --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS	+= -no-integrated-as

base-commit: 7a7fd0de4a9804299793e564a555a49c1fc924cb

Signature · 1 line
2.31.0.rc0.75.gec125d1bc1
author maintainer
#1 lore raw

PATCH 2/2 Makefile: Only specify '--prefix=' when building with clang + GNU as

When building with LLVM_IAS=1, there is no point to specifying '--prefix=' because that flag is only used to find the cross assembler, which is clang itself when building with LLVM_IAS=1. All of the other tools are invoked directly from PATH or a full path specified via the command line, which does not depend on the value of '--prefix='.

Sharing commands to reproduce issues becomes a little bit easier without a '--prefix=' value because that '--prefix=' value is specific to a user's machine due to it being an absolute path.

---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
index c20f0ad8be73..0413b8c594cd 100644
@@ -566,12 +566,12 @@ CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1 | sed 's/\#//g
 ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
 ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
+ifneq ($(LLVM_IAS),1)
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-endif
-ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS	+= -no-integrated-as
 endif
+endif
 CLANG_FLAGS	+= -Werror=unknown-warning-option
 KBUILD_CFLAGS	+= $(CLANG_FLAGS)
 KBUILD_AFLAGS	+= $(CLANG_FLAGS)
Signature · 1 line
2.31.0.rc0.75.gec125d1bc1
Reviewed-by on v1 1/2
#9 lore raw
In reply to Nathan Chancellor

Thanks for the clean-up!
--gcc-toolchain= is an obsscure way searching for GCC installation prefixes (--prefix). The logic is complex and different for different distributions/architectures.

If we specify --prefix= (-B) explicitly, --gcc-toolchain is not needed.

Quoted 35 lines · Nathan Chancellor

This is not necessary anymore now that we specify '--prefix=', which tells clang exactly where to find the GNU cross tools. This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

---
Makefile | 4 ----

1 file changed, 4 deletions(-)
Makefile +0 -4
index f9b54da2fca0..c20f0ad8be73 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN	:= $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS	+= --gcc-toolchain=$(GCC_TOOLCHAIN)

endif
ifneq ($(LLVM_IAS),1)
CLANG_FLAGS += -no-integrated-as

base-commit: 7a7fd0de4a9804299793e564a555a49c1fc924cb

Signature · 6 lines
2.31.0.rc0.75.gec125d1bc1

-- 
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 [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20210302210646.3044738-1-nathan%40kernel.org.
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] Makefile: Only specify '--prefix=' when building with clang + GNU as

In reply to Nathan Chancellor
Quoted 11 lines · Nathan Chancellor

When building with LLVM_IAS=1, there is no point to specifying '--prefix=' because that flag is only used to find the cross assembler, which is clang itself when building with LLVM_IAS=1. All of the other tools are invoked directly from PATH or a full path specified via the command line, which does not depend on the value of '--prefix='.

Sharing commands to reproduce issues becomes a little bit easier without a '--prefix=' value because that '--prefix=' value is specific to a user's machine due to it being an absolute path.

clang can spawn GNU as (if -f?no-integrated-as is specified) and GNU objcopy (-f?no-integrated-as and -gsplit-dwarf and -g[123]).

With LLVM_IAS=1, these cases are ruled out.

#3 lore raw

Re: [PATCH 2/2] Makefile: Only specify '--prefix=' when building with clang + GNU as

Quoted 12 lines · Fangrui Song
Quoted 10 lines · Nathan Chancellor

When building with LLVM_IAS=1, there is no point to specifying '--prefix=' because that flag is only used to find the cross assembler, which is clang itself when building with LLVM_IAS=1. All of the other tools are invoked directly from PATH or a full path specified via the command line, which does not depend on the value of '--prefix='.

Sharing commands to reproduce issues becomes a little bit easier without a '--prefix=' value because that '--prefix=' value is specific to a user's machine due to it being an absolute path.

Quoted 6 lines
Quoted 1 line

clang can spawn GNU as (if -f?no-integrated-as is specified) and GNU objcopy (-f?no-integrated-as and -gsplit-dwarf and -g[123]).

But -g get's set via CONFIG_DEBUG_INFO and -gsplit-dwarf by DEBUG_INFO_SPLIT. So if we say:

$ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make CC=clang LLVM_IAS=1

So cross compile, use clang, use the integrated assembler (ie. with this change, don't set --prefix), with either of the two above configs, which objcopy get's exec'd?

Quoted 2 lines

With LLVM_IAS=1, these cases are ruled out.

Signature · 2 lines
Thanks,
~Nick Desaulniers
Reviewed-by Tested-by on v1 1/2
#11 lore raw
In reply to Nathan Chancellor
Quoted 8 lines · Nathan Chancellor

This is not necessary anymore now that we specify '--prefix=', which tells clang exactly where to find the GNU cross tools. This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

Thanks for the patch!

I see this pattern still being used in arch/arm64/kernel/vdso32/Makefile, but that can be separate cleanups.

Quoted 24 lines
---
 Makefile | 4 ----
 1 file changed, 4 deletions(-)
Makefile +0 -4
index f9b54da2fca0..c20f0ad8be73 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS    += --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS    += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS    += -no-integrated-as

base-commit: 7a7fd0de4a9804299793e564a555a49c1fc924cb --
2.31.0.rc0.75.gec125d1bc1

Signature · 2 lines
Thanks,
~Nick Desaulniers
Reviewed-by Tested-by
#4 lore raw

Re: [PATCH 2/2] Makefile: Only specify '--prefix=' when building with clang + GNU as

In reply to Nick Desaulniers
Quoted 21 lines · Nick Desaulniers
Quoted 12 lines · Fangrui Song
Quoted 10 lines · Nathan Chancellor

When building with LLVM_IAS=1, there is no point to specifying '--prefix=' because that flag is only used to find the cross assembler, which is clang itself when building with LLVM_IAS=1. All of the other tools are invoked directly from PATH or a full path specified via the command line, which does not depend on the value of '--prefix='.

Sharing commands to reproduce issues becomes a little bit easier without a '--prefix=' value because that '--prefix=' value is specific to a user's machine due to it being an absolute path.

Quoted 6 lines
Quoted 1 line

clang can spawn GNU as (if -f?no-integrated-as is specified) and GNU objcopy (-f?no-integrated-as and -gsplit-dwarf and -g[123]).

Quoted 7 lines

But -g get's set via CONFIG_DEBUG_INFO and -gsplit-dwarf by DEBUG_INFO_SPLIT. So if we say:

$ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make CC=clang LLVM_IAS=1

So cross compile, use clang, use the integrated assembler (ie. with this change, don't set --prefix), with either of the two above configs, which objcopy get's exec'd?

Ok, I spoke to Fangrui more offline, and probably misread his response. From our chat:

```
Fangrui:
objcopy is only used for GNU as assembled object files
With integrated assembler, the object file streamer creates .o and
.dwo simultaneously
With GNU as, two objcopy commands are needed to extract .debug*.dwo to
.dwo files &&& another command to remove .debug*.dwo sections
```

I ran this series through a mix of LLVM=1 vs CC=clang, LLVM_IAS=1 vs unset, CROSS_COMPILE vs not, without issue.

Quoted 9 lines
Quoted 3 lines

With LLVM_IAS=1, these cases are ruled out.

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Thanks,
~Nick Desaulniers
#12 lore raw
In reply to Nathan Chancellor
Quoted 8 lines · Nathan Chancellor

This is not necessary anymore now that we specify '--prefix=', which tells clang exactly where to find the GNU cross tools. This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

[ CC Behan ]

Hahaha, that is a change of a very early commit in times of the LLVM/Clang Linux-kernel development.
So-to-say a historical change :-).

I will try this patchset later with latest Linux -v5.12-rc1+ and my custom patchset.

Thanks.

- Sedat -

Quoted 28 lines
---
 Makefile | 4 ----
 1 file changed, 4 deletions(-)
Makefile +0 -4
index f9b54da2fca0..c20f0ad8be73 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS    += --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS    += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS    += -no-integrated-as

base-commit: 7a7fd0de4a9804299793e564a555a49c1fc924cb --
2.31.0.rc0.75.gec125d1bc1

--
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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20210302210646.3044738-1-nathan%40kernel.org.

#10 lore raw
In reply to Fangrui Song

Hi.

Quoted 8 lines · Fangrui Song

Thanks for the clean-up!
--gcc-toolchain= is an obsscure way searching for GCC installation prefixes (--prefix). The logic is complex and different for different distributions/architectures.

If we specify --prefix= (-B) explicitly, --gcc-toolchain is not needed.

I tested this, and worked for me too.

Before applying this patch, could you please
help me understand the logic?

I checked the manual
(https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-b-dir)

-B<dir>, --prefix <arg>, --prefix=<arg>
Add <dir> to search path for binaries and object files used implicitly

--gcc-toolchain=<arg>, -gcc-toolchain <arg>
Use the gcc toolchain at the given directory

Hmm, this description is too concise
to understand how it works...

I use Ubuntu 20.10.

I use distro's default clang
located in /usr/bin/clang.

I place my aarch64 linaro toolchain in /home/masahiro/tools/aarch64-linaro-7.5/bin/aarch64-linux-gnu-gcc, which is not in my PATH environment.

From my some experiments,

clang --target=aarch64-linux-gnu -no-integrated-as \
--prefix=/home/masahiro/tools/aarch64-linaro-7.5/bin/aarch64-linux-gnu- ...

works almost equivalent to

PATH=/home/masahiro/tools/aarch64-linaro-7.5/bin:$PATH \
clang --target=aarch64-linux-gnu -no-integrated-as ...

Then, clang will pick up aarch64-linux-gnu-as
found in the search path.

Is this correct?

On the other hand, I could not understand
what the purpose of --gcc-toolchain= is.

Even if I add --gcc-toolchain=/home/masahiro/tools/aarch64-linaro-7.5, it does not make any difference, and it is completely useless.

I read the comment from stephenhines:
https://github.com/ClangBuiltLinux/linux/issues/78

How could --gcc-toolchain be used
in a useful way?

Quoted 28 lines · Nathan Chancellor
Quoted 27 lines

This is not necessary anymore now that we specify '--prefix=', which tells clang exactly where to find the GNU cross tools. This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

---
Makefile | 4 ----

1 file changed, 4 deletions(-)
Makefile +0 -4
index f9b54da2fca0..c20f0ad8be73 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS   += --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS   += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS   += --gcc-toolchain=$(GCC_TOOLCHAIN)

endif
ifneq ($(LLVM_IAS),1)
CLANG_FLAGS += -no-integrated-as

Quoted 8 lines
Quoted 8 lines

base-commit: 7a7fd0de4a9804299793e564a555a49c1fc924cb --
2.31.0.rc0.75.gec125d1bc1

--
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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20210302210646.3044738-1-nathan%40kernel.org.

--
Best Regards

Masahiro Yamada

Tested-by
#13 lore raw
In reply to Sedat Dilek
Quoted 11 lines · Sedat Dilek
Quoted 8 lines · Nathan Chancellor

This is not necessary anymore now that we specify '--prefix=', which tells clang exactly where to find the GNU cross tools. This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

Quoted 9 lines

[ CC Behan ]

Hahaha, that is a change of a very early commit in times of the LLVM/Clang Linux-kernel development.
So-to-say a historical change :-).

I will try this patchset later with latest Linux -v5.12-rc1+ and my custom patchset.

I tested these two patches in my build environment. So far no issues.
NOTE: I have not tested the combo: Clang and GNU AS.

- Sedat -

Quoted 28 lines
Quoted 28 lines
---
 Makefile | 4 ----
 1 file changed, 4 deletions(-)
Makefile +0 -4
index f9b54da2fca0..c20f0ad8be73 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS    += --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS    += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS    += -no-integrated-as

base-commit: 7a7fd0de4a9804299793e564a555a49c1fc924cb --
2.31.0.rc0.75.gec125d1bc1

--
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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20210302210646.3044738-1-nathan%40kernel.org.

#5 lore raw

Re: [PATCH 2/2] Makefile: Only specify '--prefix=' when building with clang + GNU as

In reply to Nathan Chancellor
Quoted 7 lines · Nathan Chancellor

When building with LLVM_IAS=1, there is no point to specifying '--prefix=' because that flag is only used to find the cross assembler, which is clang itself when building with LLVM_IAS=1. All of the other tools are invoked directly from PATH or a full path specified via the command line, which does not depend on the value of '--prefix='.

Quoted 5 lines

Sharing commands to reproduce issues becomes a little bit easier without a '--prefix=' value because that '--prefix=' value is specific to a user's machine due to it being an absolute path.

I was tricked by a couple of Reviewed-by/Tested-by tags.

With this patch applied, the code looks as follows:

ifneq ($(CROSS_COMPILE),)
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) ifneq ($(LLVM_IAS),1)
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) CLANG_FLAGS += -no-integrated-as
endif
endif

For the native build (empty CROSS_COMPILE),
you cannot add -no-integrated-as.

I dropped this from my tree.

Is the correct code as follows?

ifneq ($(LLVM_IAS),1)
CLANG_FLAGS += -no-integrated-as
ifneq ($(CROSS_COMPILE),)
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) endif
endif

Quoted 26 lines
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -3
index c20f0ad8be73..0413b8c594cd 100644
@@ -566,12 +566,12 @@ CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1 | sed 's/\#//g
 ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
 ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS    += --target=$(notdir $(CROSS_COMPILE:%-=%))
+ifneq ($(LLVM_IAS),1)
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS    += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-endif
-ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS    += -no-integrated-as
 endif
+endif
 CLANG_FLAGS    += -Werror=unknown-warning-option
 KBUILD_CFLAGS  += $(CLANG_FLAGS)
 KBUILD_AFLAGS  += $(CLANG_FLAGS)
--

2.31.0.rc0.75.gec125d1bc1

Signature · 2 lines
Best Regards
Masahiro Yamada
#6 lore raw

Re: [PATCH 2/2] Makefile: Only specify '--prefix=' when building with clang + GNU as

Quoted 42 lines · Masahiro Yamada
Quoted 7 lines · Nathan Chancellor

When building with LLVM_IAS=1, there is no point to specifying '--prefix=' because that flag is only used to find the cross assembler, which is clang itself when building with LLVM_IAS=1. All of the other tools are invoked directly from PATH or a full path specified via the command line, which does not depend on the value of '--prefix='.

Quoted 5 lines

Sharing commands to reproduce issues becomes a little bit easier without a '--prefix=' value because that '--prefix=' value is specific to a user's machine due to it being an absolute path.

I was tricked by a couple of Reviewed-by/Tested-by tags.

With this patch applied, the code looks as follows:

ifneq ($(CROSS_COMPILE),)
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) ifneq ($(LLVM_IAS),1)
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) CLANG_FLAGS += -no-integrated-as
endif
endif

For the native build (empty CROSS_COMPILE),
you cannot add -no-integrated-as.

I dropped this from my tree.

Is the correct code as follows?

Quoted 12 lines

ifneq ($(LLVM_IAS),1)
CLANG_FLAGS += -no-integrated-as
ifneq ($(CROSS_COMPILE),)
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) endif
endif

If you send v2, can you include comments from Fangrui Song?

Fangrui Song:
clang can spawn GNU as (if -f?no-integrated-as is specified) and GNU objcopy (-f?no-integrated-as and -gsplit-dwarf and -g[123]). objcopy is only used for GNU as assembled object files. With integrated assembler, the object file streamer creates .o and .dwo simultaneously.
With GNU as, two objcopy commands are needed to extract .debug*.dwo to .dwo files && another command to remove .debug*.dwo sections.

I did not know the objtool part, and I think it is worth recording.

Signature · 2 lines
Best Regards
Masahiro Yamada
author maintainer
#15 lore raw

PATCH v2 2/2 Makefile: Only specify '--prefix=' when building with clang + GNU as

In reply to Nathan Chancellor

When building with LLVM_IAS=1, there is no point to specifying '--prefix=' because that flag is only used to find GNU cross tools, which will not be used indirectly when using the integrated assembler. All of the tools are invoked directly from PATH or a full path specified via the command line, which does not depend on the value of '--prefix='.

Sharing commands to reproduce issues becomes a little bit easier without a '--prefix=' value because that '--prefix=' value is specific to a user's machine due to it being an absolute path.

Some further notes from Fangrui Song:

clang can spawn GNU as (if -f?no-integrated-as is specified) and GNU objcopy (-f?no-integrated-as and -gsplit-dwarf and -g[123]). objcopy is only used for GNU as assembled object files. With integrated assembler, the object file streamer creates .o and .dwo simultaneously.
With GNU as, two objcopy commands are needed to extract .debug*.dwo to .dwo files && another command to remove .debug*.dwo sections.

A small consequence of this change (to keep things simple) is that '--prefix=' will always be specified now, even with a native build, when it was not before. This should not be an issue due to the way that the Makefile searches for the prefix (based on elfedit's location). This ends up improving the experience for host builds because PATH is better respected and matches GCC's behavior more closely. See the below thread for more details:

https://lore.kernel.org/r/[email protected]/

---

v1 -> v2:

* Fix position of -no-integrated-as flag to fix native build (thanks to Masahiro for catching it and sorry for the breakage).

* Add Fangrui's comments about what GNU binaries clang can spawn at Masahiro's request.

* Reword commit message.

I did not carry tags forward so that people could re-review and test.

 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
index 182e93d91198..15292a6d63f5 100644
@@ -566,11 +566,11 @@ CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1 | sed 's/\#//g
 ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
 ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
-GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
-CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
 endif
 ifneq ($(LLVM_IAS),1)
 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)
Signature · 1 line
2.31.0.rc1
author maintainer
#14 lore raw

PATCH v2 1/2 Makefile: Remove '--gcc-toolchain' flag

In reply to Nathan Chancellor

This flag was originally added to allow clang to find the GNU cross tools in commit 785f11aa595b ("kbuild: Add better clang cross build support"). This flag was not enough to find the tools at times so '--prefix' was added to the list in commit ef8c4ed9db80 ("kbuild: allow to use GCC toolchain not in Clang search path") and improved upon in commit ca9b31f6bb9c ("Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation"). Now that '--prefix' specifies a full path and prefix, '--gcc-toolchain' serves no purpose because the kernel builds with '-nostdinc' and '-nostdlib'.

This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

---

v1 -> v2:

* Improve commit message (add history behind flag and link to Fangrui's documentation improvement).

I did not carry tags forward so that people could re-review and test.

 Makefile | 4 ----
 1 file changed, 4 deletions(-)
Makefile +0 -4
index 31dcdb3d61fa..182e93d91198 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS	+= --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS	+= --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN	:= $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS	+= --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS	+= -no-integrated-as

base-commit: a38fd8748464831584a19438cbb3082b5a2dab15

Signature · 1 line
2.31.0.rc1
Reviewed-by on v2 1/2
#16 lore raw
Quoted 10 lines · Nathan Chancellor

This flag was originally added to allow clang to find the GNU cross tools in commit 785f11aa595b ("kbuild: Add better clang cross build support"). This flag was not enough to find the tools at times so '--prefix' was added to the list in commit ef8c4ed9db80 ("kbuild: allow to use GCC toolchain not in Clang search path") and improved upon in commit ca9b31f6bb9c ("Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation"). Now that '--prefix' specifies a full path and prefix, '--gcc-toolchain' serves no purpose because the kernel builds with '-nostdinc' and '-nostdlib'.

Quoted 6 lines

This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

The wording looks good.

#17 lore raw
In reply to Nathan Chancellor
Quoted 15 lines · Nathan Chancellor

This flag was originally added to allow clang to find the GNU cross tools in commit 785f11aa595b ("kbuild: Add better clang cross build support"). This flag was not enough to find the tools at times so '--prefix' was added to the list in commit ef8c4ed9db80 ("kbuild: allow to use GCC toolchain not in Clang search path") and improved upon in commit ca9b31f6bb9c ("Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation"). Now that '--prefix' specifies a full path and prefix, '--gcc-toolchain' serves no purpose because the kernel builds with '-nostdinc' and '-nostdlib'.

This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

Quoted 8 lines

---

v1 -> v2:

* Improve commit message (add history behind flag and link to Fangrui's documentation improvement).

Both applied to linux-kbuild. Thanks.

Quoted 25 lines

I did not carry tags forward so that people could re-review and test.

 Makefile | 4 ----
 1 file changed, 4 deletions(-)
Makefile +0 -4
index 31dcdb3d61fa..182e93d91198 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS    += --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS    += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS    += -no-integrated-as

base-commit: a38fd8748464831584a19438cbb3082b5a2dab15 --
2.31.0.rc1

Signature · 2 lines
Best Regards
Masahiro Yamada
Tested-by
#18 lore raw
Quoted 21 lines · Masahiro Yamada
Quoted 19 lines · Nathan Chancellor

This flag was originally added to allow clang to find the GNU cross tools in commit 785f11aa595b ("kbuild: Add better clang cross build support"). This flag was not enough to find the tools at times so '--prefix' was added to the list in commit ef8c4ed9db80 ("kbuild: allow to use GCC toolchain not in Clang search path") and improved upon in commit ca9b31f6bb9c ("Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation"). Now that '--prefix' specifies a full path and prefix, '--gcc-toolchain' serves no purpose because the kernel builds with '-nostdinc' and '-nostdlib'.

This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

---

Quoted 8 lines
Quoted 4 lines

v1 -> v2:

* Improve commit message (add history behind flag and link to Fangrui's documentation improvement).

Both applied to linux-kbuild. Thanks.

Sorry for being pedantic: This misses my Tested-by#s (see [1]).

AFAICS v2 changes some comments in the commit only but not code?

- Sedat -

[1] https://marc.info/?l=linux-kernel&m=161480031518629&w=2
[2] https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git/commit/?h=kbuild&id=d4aa405bc9cd506532f075456645716cdd1739c1

Quoted 34 lines
Quoted 25 lines

I did not carry tags forward so that people could re-review and test.

 Makefile | 4 ----
 1 file changed, 4 deletions(-)
Makefile +0 -4
index 31dcdb3d61fa..182e93d91198 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS    += --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS    += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS    += -no-integrated-as
Quoted 4 lines

base-commit: a38fd8748464831584a19438cbb3082b5a2dab15 --
2.31.0.rc1

--
Best Regards
Masahiro Yamada

#19 lore raw
Quoted 29 lines · Sedat Dilek
Quoted 27 lines · Masahiro Yamada
Quoted 23 lines · Nathan Chancellor

This flag was originally added to allow clang to find the GNU cross tools in commit 785f11aa595b ("kbuild: Add better clang cross build support"). This flag was not enough to find the tools at times so '--prefix' was added to the list in commit ef8c4ed9db80 ("kbuild: allow to use GCC toolchain not in Clang search path") and improved upon in commit ca9b31f6bb9c ("Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation"). Now that '--prefix' specifies a full path and prefix, '--gcc-toolchain' serves no purpose because the kernel builds with '-nostdinc' and '-nostdlib'.

This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations.

---

v1 -> v2:

* Improve commit message (add history behind flag and link to Fangrui's documentation improvement).

Quoted 8 lines
Quoted 2 lines

Both applied to linux-kbuild. Thanks.

Sorry for being pedantic: This misses my Tested-by#s (see [1]).

AFAICS v2 changes some comments in the commit only but not code?

For 1/2, yes. The difference is only comments.

For 2/2, the code was changed. Actually, v1 was wrong.
That is why the tags were dropped.

I will re-add the tags to 1/2 since there is no code diff.

If you re-test 2/2, I will add your tag again.

Quoted 39 lines

- Sedat -

[1] https://marc.info/?l=linux-kernel&m=161480031518629&w=2
[2] https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git/commit/?h=kbuild&id=d4aa405bc9cd506532f075456645716cdd1739c1

Quoted 34 lines
Quoted 25 lines

I did not carry tags forward so that people could re-review and test.

 Makefile | 4 ----
 1 file changed, 4 deletions(-)
Makefile +0 -4
index 31dcdb3d61fa..182e93d91198 100644
@@ -568,10 +568,6 @@ ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS    += --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS    += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
-GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
-endif
-ifneq ($(GCC_TOOLCHAIN),)
-CLANG_FLAGS    += --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 ifneq ($(LLVM_IAS),1)
 CLANG_FLAGS    += -no-integrated-as
Quoted 4 lines

base-commit: a38fd8748464831584a19438cbb3082b5a2dab15 --
2.31.0.rc1

--
Best Regards
Masahiro Yamada

Signature · 2 lines
Best Regards
Masahiro Yamada
#7 lore raw

Re: [PATCH 2/2] Makefile: Only specify '--prefix=' when building with clang + GNU as

In reply to Nathan Chancellor
I love your patch! Perhaps something to improve:

Hi Nathan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on 7a7fd0de4a9804299793e564a555a49c1fc924cb]

url:    https://github.com/0day-ci/linux/commits/Nathan-Chancellor/Makefile-Remove-gcc-toolchain-flag/20210929-112213
base:   7a7fd0de4a9804299793e564a555a49c1fc924cb
config: x86_64-randconfig-a014-20210929 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project dc6e8dfdfe7efecfda318d43a06fae18b40eb498)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/74a168f9e88d9edf5aaa8209d2c39e676de2857a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nathan-Chancellor/Makefile-Remove-gcc-toolchain-flag/20210929-112213
git checkout 74a168f9e88d9edf5aaa8209d2c39e676de2857a
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash arch/x86/entry/ arch/x86/kernel/ arch/x86/lib/ kernel/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> arch/x86/entry/entry_64.S:47:1: warning: DWARF2 only supports one section per compilation unit
   .section .entry.text, "ax"
   ^
>> <instantiation>:11:2: warning: DWARF2 only supports one section per compilation unit
    .pushsection .altinstr_replacement,"ax"
    ^
   <instantiation>:1:1: note: while in macro instantiation
   ALTERNATIVE "jmp .Lend_2", "", ( 7*32+11)
   ^
   arch/x86/entry/entry_64.S:93:2: note: while in macro instantiation
    SWITCH_TO_KERNEL_CR3 scratch_reg=%rsp
    ^

arch/x86/entry/entry_64.S:741:2: warning: DWARF2 only supports one section per compilation unit
.section .fixup, "ax"
^
--

>> arch/x86/entry/entry_64_compat.S:20:2: warning: DWARF2 only supports one section per compilation unit
    .section .entry.text, "ax"
    ^
>> <instantiation>:11:2: warning: DWARF2 only supports one section per compilation unit
    .pushsection .altinstr_replacement,"ax"
    ^
   <instantiation>:1:1: note: while in macro instantiation
   ALTERNATIVE "jmp .Lend_2", "", ( 7*32+11)
   ^
   arch/x86/entry/entry_64_compat.S:55:2: note: while in macro instantiation
    SWITCH_TO_KERNEL_CR3 scratch_reg=%rax
    ^
--
>> arch/x86/kernel/head_64.S:42:2: warning: DWARF2 only supports one section per compilation unit
    .section ".head.text","ax"
    ^
   arch/x86/kernel/head_64.S:352:2: warning: DWARF2 only supports one section per compilation unit
    .section ".init.text","ax"
    ^
--
>> arch/x86/lib/copy_mc_64.S:138:2: warning: DWARF2 only supports one section per compilation unit
    .section .fixup, "ax"
    ^
--
>> <instantiation>:11:2: warning: DWARF2 only supports one section per compilation unit
    .pushsection .altinstr_replacement,"ax"
    ^
   arch/x86/lib/copy_page_64.S:17:2: note: while in macro instantiation
    ALTERNATIVE "jmp copy_page_regs", "", ( 3*32+16)
    ^
--
>> <instantiation>:11:2: warning: DWARF2 only supports one section per compilation unit
    .pushsection .altinstr_replacement,"ax"
    ^
   arch/x86/lib/copy_user_64.S:58:2: note: while in macro instantiation
    ALTERNATIVE "", ".byte 0x0f,0x01,0xcb", ( 9*32+20)
    ^
   <instantiation>:15:2: warning: DWARF2 only supports one section per compilation unit
    .section .fixup,"ax"
    ^
   arch/x86/lib/copy_user_64.S:61:2: note: while in macro instantiation
    ALIGN_DESTINATION
    ^
--
>> <instantiation>:11:2: warning: DWARF2 only supports one section per compilation unit
    .pushsection .altinstr_replacement,"ax"
    ^
   arch/x86/lib/getuser.S:56:2: note: while in macro instantiation
    ALTERNATIVE "", ".byte 0x0f,0x01,0xcb", ( 9*32+20)
    ^
--
>> arch/x86/lib/memcpy_64.S:10:1: warning: DWARF2 only supports one section per compilation unit
   .pushsection .noinstr.text, "ax"
   ^
   <instantiation>:13:2: warning: DWARF2 only supports one section per compilation unit
    .pushsection .altinstr_replacement,"ax"
    ^
   arch/x86/lib/memcpy_64.S:32:2: note: while in macro instantiation
    ALTERNATIVE_2 "jmp memcpy_orig", "", ( 3*32+16), "jmp memcpy_erms", ( 9*32+ 9)
    ^
--
>> <instantiation>:11:2: warning: DWARF2 only supports one section per compilation unit
    .pushsection .altinstr_replacement,"ax"
    ^
   arch/x86/lib/memmove_64.S:42:2: note: while in macro instantiation
    ALTERNATIVE "cmp $0x20, %rdx; jb 1f", "", (18*32+ 4)
    ^
--
>> <instantiation>:11:2: warning: DWARF2 only supports one section per compilation unit
    .pushsection .altinstr_replacement,"ax"
    ^
   arch/x86/lib/putuser.S:51:2: note: while in macro instantiation
    ALTERNATIVE "", ".byte 0x0f,0x01,0xcb", ( 9*32+20)
    ^

vim +47 arch/x86/entry/entry_64.S

6fd166aae78c0a arch/x86/entry/entry_64.S Peter Zijlstra 2017-12-04 45 ^1da177e4c3f41 arch/x86_64/kernel/entry.S Linus Torvalds 2005-04-16 46 .code64
ea7145477a461e arch/x86/kernel/entry_64.S Jiri Olsa 2011-03-07 @47 .section .entry.text, "ax"
ea7145477a461e arch/x86/kernel/entry_64.S Jiri Olsa 2011-03-07 48

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#8 lore raw

Re: [PATCH 2/2] Makefile: Only specify '--prefix=' when building with clang + GNU as

In reply to Nathan Chancellor
I love your patch! Perhaps something to improve:

Hi Nathan,

I love your patch! Perhaps something to improve:

[auto build test WARNING on 7a7fd0de4a9804299793e564a555a49c1fc924cb]

url:    https://github.com/0day-ci/linux/commits/Nathan-Chancellor/Makefile-Remove-gcc-toolchain-flag/20210929-112213
base:   7a7fd0de4a9804299793e564a555a49c1fc924cb
config: x86_64-randconfig-a011-20210929 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project dc6e8dfdfe7efecfda318d43a06fae18b40eb498)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/74a168f9e88d9edf5aaa8209d2c39e676de2857a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Nathan-Chancellor/Makefile-Remove-gcc-toolchain-flag/20210929-112213 git checkout 74a168f9e88d9edf5aaa8209d2c39e676de2857a
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash arch/x86/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> arch/x86/platform/pvh/head.S:22:2: warning: DWARF2 only supports one section per compilation unit
    .section ".head.text","ax"
    ^

vim +22 arch/x86/platform/pvh/head.S

7243b93345f7f8d arch/x86/xen/xen-pvh.S Boris Ostrovsky 2017-02-05 21
7243b93345f7f8d arch/x86/xen/xen-pvh.S Boris Ostrovsky 2017-02-05 @22 __HEAD
7243b93345f7f8d arch/x86/xen/xen-pvh.S Boris Ostrovsky 2017-02-05 23

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org