[PATCH] kbuild: Use ld.lld for linking host programs when LLVM is set
Nathan Chancellor <[email protected]>
| Newsgroups | org.kernel.vger.linux-kbuild,dev.linux.lists.llvm,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <20260610-kbuild-use-lld-for-linking-hostprogs-v1-1-70396fe42ee3@kernel.org> |
Currently, host programs are linked with HOSTCC using the toolchain's default linker. This can result in confusing behavior when using the LLVM Kbuild variable (which states that the user would like to build with the LLVM toolchain instead of the GNU one), as clang's default linker is ld for most platforms, not ld.lld. The documentation mentions HOSTLD=ld.lld is set but this variable is not used by Kbuild proper, only within some tools/ projects. Kbuild provides the HOSTLDFLAGS variable, which allow users to provide the '-fuse-ld' or '--ld-path' flags to customize what linker is used, but this is not super obvious to folks not familiar with Kbuild. If the user has not customized the linker already using one of these flags, default to ld.lld when using the LLVM variable, which is more in line with user expectations when using that variable. Closes: https://github.com/ClangBuiltLinux/linux/issues/2167 Signed-off-by: Nathan Chancellor <[email protected]> --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 37fdb454b637..ae263f964e82 100644 --- a/Makefile +++ b/Makefile @@ -525,6 +525,9 @@ OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX) OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX) READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX) STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX) +ifeq ($(filter -fuse-ld=% --ld-path=%,$(KBUILD_HOSTLDFLAGS)),) +KBUILD_HOSTLDFLAGS += -fuse-ld=lld +endif else CC = $(CROSS_COMPILE)gcc LD = $(CROSS_COMPILE)ld --- base-commit: 1a1e62a5a48494cdf33e3bfb82fb8f408da7c4cc change-id: 20260610-kbuild-use-lld-for-linking-hostprogs-0cf3588755b7 Best regards, -- Cheers, Nathan