Re: [PATCH v5 1/2] kbuild: move vmlinux.a build rule to scripts/Makefile.vmlinux_a
From: Nicolas Schier
Date: Mon Mar 16 2026 - 09:45:47 EST
On Tue, Oct 28, 2025 at 06:28:21PM +0000, xur@xxxxxxxxxx wrote:
> From: Rong Xu <xur@xxxxxxxxxx>
>
> From: Masahiro Yamada <masahiroy@xxxxxxxxxx>
>
> Move the build rule for vmlinux.a to a separate file in preparation
> for supporting distributed builds with Clang ThinLTO.
>
> Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx>
> Tested-by: Rong Xu <xur@xxxxxxxxxx>
> ---
> Makefile | 16 +++++--------
> scripts/Makefile.vmlinux_a | 46 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 52 insertions(+), 10 deletions(-)
> create mode 100644 scripts/Makefile.vmlinux_a
>
> diff --git a/Makefile b/Makefile
> index b34a1f4c03967..89a25bac2bbab 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1198,7 +1198,7 @@ export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
> KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
> KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
>
> -export KBUILD_VMLINUX_LIBS
> +export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
> export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
>
> ifdef CONFIG_TRIM_UNUSED_KSYMS
> @@ -1207,16 +1207,12 @@ ifdef CONFIG_TRIM_UNUSED_KSYMS
> KBUILD_MODULES := y
> endif
>
> -# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
> -quiet_cmd_ar_vmlinux.a = AR $@
> - cmd_ar_vmlinux.a = \
> - rm -f $@; \
> - $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \
> - $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
> +PHONY += vmlinux_a
> +vmlinux_a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
> + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_a
>
> -targets += vmlinux.a
> -vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
> - $(call if_changed,ar_vmlinux.a)
> +vmlinux.a: vmlinux_a
> + @:
>
> PHONY += vmlinux_o
> vmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS)
> diff --git a/scripts/Makefile.vmlinux_a b/scripts/Makefile.vmlinux_a
> new file mode 100644
> index 0000000000000..9774f02b43b2f
> --- /dev/null
> +++ b/scripts/Makefile.vmlinux_a
> @@ -0,0 +1,46 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +PHONY := __default
> +__default: vmlinux.a
> +
> +include include/config/auto.conf
> +include $(srctree)/scripts/Kbuild.include
> +include $(srctree)/scripts/Makefile.lib
> +
> +# Link of built-in-fixup.a
> +# ---------------------------------------------------------------------------
> +
> +# '$(AR) mPi' needs --thin to workaround the bug of llvm-ar <= 14
> +quiet_cmd_ar_builtin_fixup = AR $@
> + cmd_ar_builtin_fixup = \
> + rm -f $@; \
> + $(AR) cDPrS --thin $@ $(KBUILD_VMLINUX_OBJS); \
> + $(AR) mPi --thin $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
Venkat Rao Bagalkote <venkat88@xxxxxxxxxxxxx> reported [1] that this
breaks builds on system with binutils < 2.38.
Documentation/process/changes.rst state binutils 2.30 as build
dependency; binutils 2.38 has been released in 02/2022.
I removed the patch set from kbuild-next-unstable and kbuild-for-next
for now.
The simpliest solution would be to declare binutils 2.38 as build
dependency; but I am afraid that it is still "too new", right now.
Can someone elaborate a bit on the comment about --thin and "the bug of
llvm-ar <= 14'?
May it be an option to introduce $(ar-option) macro?
Something like this? (untested)
ar-option = $(call try-run, \
( trap 'rm -f $(tmp-target).ar-option' EXIT INT HUP QUIT; \
$(AR) cr $(1) $(tmp-target).ar-option ),$(1),$(2) )
AR_THIN = $(call ar-option, --thin)
...
$(AR) cDPrS $(AR_THIN) $@ $(KBUILD_VMLINUX_OBJS); \
$(AR) mPi $(AR_THIN) $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
Kind regards,
Nicolas
[1]: https://lore.kernel.org/linux-next/476507c9-a371-4864-9e87-572c1ecae82d@xxxxxxxxxxxxx
Attachment:
signature.asc
Description: PGP signature