infer --target from SRCARCH for CC=clang
Subsystems (3)
Nick Desaulniers
reviewerv4 cover infer --target from SRCARCH for CC=clang
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.
Instead, let's infer it from SRCARCH, and move some flag handling into a new file included from the top level Makefile.
Changes v3 -> v4:
* Remove the requirement that LLVM_IAS=1 be set, as per Masahiro.
* Remove the Documentation/ change from patch 2, as per Masahiro and Nathan.
* Add Documentation/ change as patch 3, from Masahiro.
* Reword commit message of patch 2, as per Nathan.
* Change patch 2 oneline to refer to --target and CC=clang (not CROSS_COMPILE).
* Carry Arnd's and Nathan's AB/RB/TB tags, confirmed ok on IRC+discord.
Changes v2 -> v3:
* Remove requirement that LLVM=1 be set. Instead, if building with just CC=clang LLVM_IAS=1 instead of LLVM=1 LLVM_IAS=1, you should use LD=ld.lld explicitly, or LD=aarch64-linux-gnu-ld. (As per Masahiro) Example:
$ ARCH=arm64 make CC=clang LLVM_IAS=1 LD=ld.lld OBJCOPY=llvm-objcopy \
STRIP=llvm-strip -j72 defconfig all (It's still preferable to use LLVM=1 IMO, but this is maximally flexible.)
* Change oneliner from LLVM=1 to CC=clang.
* Update Docs slightly.
Changes v1 -> v2:
* patch 1/2 untouched.
* Fix typos in commit message as per Geert and Masahiro.
* Use SRCARCH instead of ARCH, simplifying x86 handling, as per Masahiro. Add his sugguested by tag.
* change commit oneline from 'drop' to 'infer.'
* Add detail about explicit host --target and relationship of ARCH to SRCARCH, as per Masahiro.
*** BLURB HERE ***
Nick Desaulniers (2):
Makefile: infer --target from ARCH for CC=clang Documentation/llvm: update CROSS_COMPILE inferencing
Documentation/kbuild/llvm.rst | 17 +++++++++++++++++ scripts/Makefile.clang | 30 ++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-)
base-commit: 27932b6a2088eac7a5afa5471963b926cfbb4de7
prerequisite-patch-id: 0d3072ecb5fd06ff6fd6ea81fe601f6c54c23910
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
Nick Desaulniers
reviewerPATCH v4 1/2 Makefile: infer --target from ARCH for CC=clang
We get constant feedback that the command line invocation of make is too long when compiling with LLVM. CROSS_COMPILE is helpful when a toolchain has a prefix of the target triple, or is an absolute path outside of $PATH.
Since a Clang binary is generally multi-targeted, we can infer a given target from SRCARCH/ARCH. If CROSS_COMPILE is not set, simply set --target= for CLANG_FLAGS, KBUILD_CFLAGS, and KBUILD_AFLAGS based on $SRCARCH.
Previously, we'd cross compile via:
$ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make LLVM=1 LLVM_IAS=1 Now: $ ARCH=arm64 make LLVM=1 LLVM_IAS=1
For native builds (not involving cross compilation) we now explicitly specify a target triple rather than rely on the implicit host triple.
---
Changes v3 -> v4:
* Reword commit message and oneline, as per Nathan.
* Drop documentation change (it's the next patch, could be squashed in, I guess).
* Drop LLVM_IAS=1 requirement, as per Masahiro.
* Carry Arnd's and Nathan's AB/RB/TB tags, confirmed OK on IRC+Discord.
Changes v2 -> v3:
* Drop check/requirement for LLVM=1, as per Masahiro.
* Change oneliner from LLVM=1 LLVM_IAS=1 to CC=clang LLVM_IAS=1.
* Don't carry forward Nathan's RB/TB tags. :( Sorry Nathan, but thank you for testing+reviewing v2.
* Update wording of docs slightly.
Changes v1 -> v2:
* Fix typos in commit message as per Geert and Masahiro.
* Use SRCARCH instead of ARCH, simplifying x86 handling, as per Masahiro. Add his sugguested by tag.
* change commit oneline from 'drop' to 'infer.'
* Add detail about explicit host --target and relationship of ARCH to SRCARCH, as per Masahiro.
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/.
scripts/Makefile.clang | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-)
scripts/Makefile.clang +28 -2
@@ -1,6 +1,32 @@ -ifneq ($(CROSS_COMPILE),) +# Individual arch/{arch}/Makefiles 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),) +ifeq ($(SRCARCH),arm) +CLANG_FLAGS += --target=arm-linux-gnueabi +else ifeq ($(SRCARCH),arm64) +CLANG_FLAGS += --target=aarch64-linux-gnu +else ifeq ($(SRCARCH),hexagon) +CLANG_FLAGS += --target=hexagon-linux-gnu +else ifeq ($(SRCARCH),m68k) +CLANG_FLAGS += --target=m68k-linux-gnu +else ifeq ($(SRCARCH),mips) +CLANG_FLAGS += --target=mipsel-linux-gnu +else ifeq ($(SRCARCH),powerpc) +CLANG_FLAGS += --target=powerpc64le-linux-gnu +else ifeq ($(SRCARCH),riscv) +CLANG_FLAGS += --target=riscv64-linux-gnu +else ifeq ($(SRCARCH),s390) +CLANG_FLAGS += --target=s390x-linux-gnu +else ifeq ($(SRCARCH),x86) +CLANG_FLAGS += --target=x86_64-linux-gnu +else +$(error Specify CROSS_COMPILE or add '--target=' option to scripts/Makefile.clang) +endif # SRCARCH +else CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) -endif +endif # CROSS_COMPILE + ifeq ($(LLVM_IAS),1) CLANG_FLAGS += -integrated-as else
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
Re: [PATCH v4 1/2] Makefile: infer --target from ARCH for CC=clang
scripts/Makefile.clang line 6
Quoted 3 lines · Nick Desaulniers
scripts/Makefile.clang +2
-0+ifeq ($(SRCARCH),arm) +CLANG_FLAGS += --target=arm-linux-gnueabi
..,.
Ugh.
A wise man once said: "All problems in computer science can be solved with another level of indirection".
Just do it like this:
CLANG_TARGET_FLAGS_arm = arm-linux-gnueabi CLANG_TARGET_FLAGS_hexagon = hexagon-linux-gnu .. CLANG_TARGET_FLAGS = $(CLANG_TARGET_FLAGS_$(ARCH))
Which is a lot denser and simpler.
And then the only if-statement can be something along the lines of
ifeq ($(CLANG_TARGET_FLAGS),) $(error Specify clang target flags) else CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS) endif
Plus add *random handwaving* about all the details for CROSS_COMPILE and friends.
Linus
Nick Desaulniers
reviewerRe: [PATCH v4 1/2] Makefile: infer --target from ARCH for CC=clang
Quoted 22 lines · Linus Torvalds
scripts/Makefile.clang line 6
Quoted 3 lines · Nick Desaulniers
scripts/Makefile.clang +2
-0+ifeq ($(SRCARCH),arm) +CLANG_FLAGS += --target=arm-linux-gnueabi..,.
Ugh.
A wise man once said: "All problems in computer science can be solved with another level of indirection".
Just do it like this:
CLANG_TARGET_FLAGS_arm = arm-linux-gnueabi CLANG_TARGET_FLAGS_hexagon = hexagon-linux-gnu .. CLANG_TARGET_FLAGS = $(CLANG_TARGET_FLAGS_$(ARCH))Which is a lot denser and simpler.
Quoted 7 lines
And then the only if-statement can be something along the lines of
ifeq ($(CLANG_TARGET_FLAGS),) $(error Specify clang target flags) else CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS) endif
D'oh, just sent v5 before seeing this. SGTM will work on v6.
Quoted 5 lines
Plus add *random handwaving* about all the details for
CROSS_COMPILEand friends.Linus
Signature · 2 lines
Thanks, ~Nick Desaulniers
Nick Desaulniers
reviewerPATCH v4 2/2 Documentation/llvm: update CROSS_COMPILE inferencing
In reply to Nick DesaulniersAs noted by Masahiro, document how we can generally infer CROSS_COMPILE (and the more specific details about --target and --prefix) based on ARCH.
---
Note: Masahiro, I'm sorry for putting my name on this as you mostly wrote it. I touched it up slightly. I don't know how best to attribute it to you. If you'd prefer to take back authorship, please do; I'd rather not add your SOB without seeing it stated explicitly.
Documentation/kbuild/llvm.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
Documentation/kbuild/llvm.rst +17 -0
@@ -63,6 +63,23 @@ They can be enabled individually. The full list of the parameters: :: Currently, the integrated assembler is disabled by default. You can pass ``LLVM_IAS=1`` to enable it. +Omitting CROSS_COMPILE +---------------------- + +As explained above, ``CROSS_COMPILE`` is used to set ``--target=<triple>``. + +Unless ``LLVM_IAS=1`` is specified, ``CROSS_COMPILE`` is also used to derive +``--prefix=<path>`` to search for the GNU assembler. + +If ``CROSS_COMPILE`` is not specified, the ``--target=<triple>`` is inferred +from ``ARCH``. + +That means if you use only LLVM tools, ``CROSS_COMPILE`` becomes unnecessary. + +For example, to cross-compile the arm64 kernel:: + + ARCH=arm64 make LLVM=1 LLVM_IAS=1 + Supported Architectures -----------------------
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
Nick Desaulniers
reviewerQuoted 42 lines · Nick Desaulniers
We get constant feedback that the command line invocation of make is too long.
CROSS_COMPILEis 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.Instead, let's infer it from SRCARCH, and move some flag handling into a new file included from the top level
Makefile.Changes v3 -> v4:
* Remove the requirement that LLVM_IAS=1 be set, as per Masahiro.
* Remove theDocumentation/change from patch 2, as per Masahiro and Nathan.
* AddDocumentation/change as patch 3, from Masahiro.
* Reword commit message of patch 2, as per Nathan.
* Change patch 2 oneline to refer to --target and CC=clang (notCROSS_COMPILE).
* Carry Arnd's and Nathan's AB/RB/TB tags, confirmed ok on IRC+discord.Changes v2 -> v3:
* Remove requirement that LLVM=1 be set. Instead, if building with just CC=clang LLVM_IAS=1 instead of LLVM=1 LLVM_IAS=1, you should use LD=ld.lld explicitly, or LD=aarch64-linux-gnu-ld. (As per Masahiro) Example:$ ARCH=arm64 make CC=clang LLVM_IAS=1 LD=ld.lld OBJCOPY=llvm-objcopy \ STRIP=llvm-strip -j72 defconfig all(It's still preferable to use LLVM=1 IMO, but this is maximally flexible.)
* Change oneliner from LLVM=1 to CC=clang.
* Update Docs slightly.Changes v1 -> v2:
* patch 1/2 untouched.
* Fix typos in commit message as per Geert and Masahiro.
* Use SRCARCH instead of ARCH, simplifying x86 handling, as per Masahiro. Add his sugguested by tag.
* change commit oneline from 'drop' to 'infer.'
* Add detail about explicit host --target and relationship of ARCH to SRCARCH, as per Masahiro.
Quoted 1 line
*** BLURB HERE ***
Err, sorry, it looks like I did:
$ git format-patch HEAD~2 ... when I meant to do HEAD~3 ..., will resend.
Quoted 15 lines
Nick Desaulniers (2):
Makefile: infer --target from ARCH for CC=clangDocumentation/llvm: updateCROSS_COMPILEinferencingDocumentation/kbuild/llvm.rst | 17 +++++++++++++++++ scripts/Makefile.clang | 30 ++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-)base-commit:
27932b6a2088eac7a5afa5471963b926cfbb4de7
prerequisite-patch-id:0d3072ecb5fd06ff6fd6ea81fe601f6c54c23910--
2.32.0.554.ge1b32706d8-goog
Signature · 2 lines
Thanks, ~Nick Desaulniers