]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ARM: 9443/1: Require linker to support KEEP within OVERLAY for DCE
authorNathan Chancellor <nathan@kernel.org>
Thu, 20 Mar 2025 21:33:49 +0000 (22:33 +0100)
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Wed, 26 Mar 2025 13:31:47 +0000 (13:31 +0000)
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.

Cc: stable@vger.kernel.org
Link: https://github.com/llvm/llvm-project/commit/381599f1fe973afad3094e55ec99b1620dba7d8c
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
arch/arm/Kconfig
arch/arm/include/asm/vmlinux.lds.h
init/Kconfig

index 202dbd17ad2ff455eb9fc214f7e4b1de967ea9e1..25ed6f1a7c7ae54cae3102c66257de598f04db3c 100644 (file)
@@ -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_IS_LLD)
+       select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if (LD_VERSION >= 23600 || LD_CAN_USE_KEEP_IN_OVERLAY)
        select HAVE_MOD_ARCH_SPECIFIC
        select HAVE_NMI
        select HAVE_OPTPROBES if !THUMB2_KERNEL
index 89697f2047159a11110c8cc4ed006cbb70b67a06..a54db342653ab0fcaa3a42ae4f7d4e8587e4c8ff 100644 (file)
 #define NOCROSSREFS
 #endif
 
+#ifdef CONFIG_LD_CAN_USE_KEEP_IN_OVERLAY
+#define OVERLAY_KEEP(x)                KEEP(x)
+#else
+#define OVERLAY_KEEP(x)                x
+#endif
+
 /* Set start/end symbol names to the LMA for the section */
 #define ARM_LMA(sym, section)                                          \
        sym##_start = LOADADDR(section);                                \
index d0d021b3fa3b3da5576421b4e1c63baf6c8afc09..fc994f5cd5dba8d7a6c76c4d2b05ae110f27271e 100644 (file)
@@ -129,6 +129,11 @@ config CC_HAS_COUNTED_BY
        # https://github.com/llvm/llvm-project/pull/112636
        depends on !(CC_IS_CLANG && CLANG_VERSION < 190103)
 
+config LD_CAN_USE_KEEP_IN_OVERLAY
+       # ld.lld prior to 21.0.0 did not support KEEP within an overlay description
+       # https://github.com/llvm/llvm-project/pull/130661
+       def_bool LD_IS_BFD || LLD_VERSION >= 210000
+
 config RUSTC_HAS_COERCE_POINTEE
        def_bool RUSTC_VERSION >= 108400