[PATCH 1/2] ARM: Require linker to support KEEP within OVERLAY for DCE

Nathan Chancellor nathan at kernel.org
Fri Jul 4 17:24:02 PDT 2025


On Fri, Jul 04, 2025 at 02:15:18PM -0500, Rob Landley wrote:
> On 3/13/25 03:48, Linus Walleij wrote:
> > On Tue, Mar 11, 2025 at 8:43 PM Nathan Chancellor <nathan at kernel.org> wrote:
> > 
> > > ld.lld prior to 21.0.0 does not support using the KEEP keyword within an
> > > overlay description, which may be needed to avoid discarding necessary
> > > sections within an overlay with '--gc-sections', which can be enabled
> > > for the kernel via CONFIG_LD_DEAD_CODE_DATA_ELIMINATION.
> > > 
> > > Disallow CONFIG_LD_DEAD_CODE_DATA_ELIMINATION without support for KEEP
> > > within OVERLAY and introduce a macro, OVERLAY_KEEP, that can be used to
> > > conditionally add KEEP when it is properly supported to avoid breaking
> > > old versions of ld.lld.
> 
> I bisected the 6.15 armv7l build break my mkroot project hit to this commit
> (e7607f7d6d81):
> 
>   LD      .tmp_vmlinux1
> Segmentation fault
> make[2]: *** [scripts/Makefile.vmlinux:77: vmlinux] Error 139
> make[1]: ***
> [/home/landley/toybox/clean/root/build/armv7l-tmp/linux/Makefile:1226:
> vmlinux] Error 2
> make: *** [Makefile:251: __sub-make] Error 2
> 
> The toolchain in question was built from gcc 11.4.0 and binutils 2.33.1
> which were the newest versions supported by
> https://github.com/richfelker/musl-cross-make when the still-current musl
> release (1.2.5) came out.
> 
> You can grab a binary toolchain to smoketest with from https://landley.net/bin/toolchains/latest/armv7l-linux-musleabihf-cross.tar.xz
> and build using the attached miniconfig ala:
> 
> for i in distclean allnoconfig ""
> do
>   CROSS_COMPILE=armv7l-linux-musleabihf- make ARCH=arm \
>     KCONFIG_ALLCONFIG=linux-miniconfig -j4 $i
> done
> 
> This _just_ seems to affect armv7l: armv5l and aarch64 still build fine.

Hmm, I do see a bug in that change, as it allows DCE to be turned on
with binutils older than 2.36, which should be avoided with something
like

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 3072731fe09c..962451e54fdd 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -121,7 +121,7 @@ config ARM
 	select HAVE_KERNEL_XZ
 	select HAVE_KPROBES if !XIP_KERNEL && !CPU_ENDIAN_BE32 && !CPU_V7M
 	select HAVE_KRETPROBES if HAVE_KPROBES
-	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if (LD_VERSION >= 23600 || LD_CAN_USE_KEEP_IN_OVERLAY)
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if (LD_VERSION >= 23600 || LD_IS_LLD) && LD_CAN_USE_KEEP_IN_OVERLAY
 	select HAVE_MOD_ARCH_SPECIFIC
 	select HAVE_NMI
 	select HAVE_OPTPROBES if !THUMB2_KERNEL

but it does not seem like your test configuration enables
CONFIG_LD_DEAD_CODE_DATA_ELIMINATION so I would expect this change to be
a no-op in that case? Does the above change work for you? I won't be
free to validate this until after the weekend.

Cheers,
Nathan



More information about the linux-arm-kernel mailing list