]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ARM: 9404/1: arm32: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION
authorYuntao Liu <liuyuntao12@huawei.com>
Mon, 3 Jun 2024 15:37:50 +0000 (16:37 +0100)
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Mon, 10 Jun 2024 11:01:33 +0000 (12:01 +0100)
The current arm32 architecture does not yet support the
HAVE_LD_DEAD_CODE_DATA_ELIMINATION feature. arm32 is widely used in
embedded scenarios, and enabling this feature would be beneficial for
reducing the size of the kernel image.

In order to make this work, we keep the necessary tables by annotating
them with KEEP, also it requires further changes to linker script to KEEP
some tables and wildcard compiler generated sections into the right place.
When using ld.lld for linking, KEEP is not recognized within the OVERLAY
command, and Ard proposed a concise method to solve this problem.

It boots normally with defconfig, vexpress_defconfig and tinyconfig.

The size comparison of zImage is as follows:
defconfig       vexpress_defconfig      tinyconfig
5137712         5138024                 424192          no dce
5032560         4997824                 298384          dce
2.0%            2.7%                    29.7%           shrink

When using smaller config file, there is a significant reduction in the
size of the zImage.

We also tested this patch on a commercially available single-board
computer, and the comparison is as follows:
a15eb_config
2161384         no dce
2092240         dce
3.2%            shrink

The zImage size has been reduced by approximately 3.2%, which is 70KB on
2.1M.

Signed-off-by: Yuntao Liu <liuyuntao12@huawei.com>
Tested-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
arch/arm/Kconfig
arch/arm/boot/compressed/vmlinux.lds.S
arch/arm/include/asm/vmlinux.lds.h
arch/arm/kernel/entry-armv.S
arch/arm/kernel/vmlinux-xip.lds.S
arch/arm/kernel/vmlinux.lds.S
drivers/firmware/efi/libstub/Makefile

index 9e0749b2244612ada1737c118c4b89b29fd084a8..08572703d94d522865d709acd8f7ac354f073406 100644 (file)
@@ -115,6 +115,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
        select HAVE_MOD_ARCH_SPECIFIC
        select HAVE_NMI
        select HAVE_OPTPROBES if !THUMB2_KERNEL
index 3fcb3e62dc5692c5ea8ccdb47d97c169d7b0ac76..d411abd4310ea97f14401cd73b21d77250af095f 100644 (file)
@@ -125,7 +125,7 @@ SECTIONS
 
   . = BSS_START;
   __bss_start = .;
-  .bss                 : { *(.bss) }
+  .bss                 : { *(.bss .bss.*) }
   _end = .;
 
   . = ALIGN(8);                /* the stack must be 64-bit aligned */
index 4c8632d5c432c3c7e9351ebae65a90ee9a4c31db..d60f6e83a9f700f3fc5fe1e08b09c7263f49bf79 100644 (file)
@@ -42,7 +42,7 @@
 #define PROC_INFO                                                      \
                . = ALIGN(4);                                           \
                __proc_info_begin = .;                                  \
-               *(.proc.info.init)                                      \
+               KEEP(*(.proc.info.init))                                \
                __proc_info_end = .;
 
 #define IDMAP_TEXT                                                     \
index 6150a716828c3eca335ed52df75fe7fdcf40eb57..f01d23a220e65d20789a7aeebeffb629fcaf126b 100644 (file)
@@ -1065,6 +1065,7 @@ vector_addrexcptn:
        .globl  vector_fiq
 
        .section .vectors, "ax", %progbits
+       .reloc  .text, R_ARM_NONE, .
        W(b)    vector_rst
        W(b)    vector_und
 ARM(   .reloc  ., R_ARM_LDR_PC_G0, .L__vector_swi              )
@@ -1078,6 +1079,7 @@ THUMB(    .reloc  ., R_ARM_THM_PC12, .L__vector_swi               )
 
 #ifdef CONFIG_HARDEN_BRANCH_HISTORY
        .section .vectors.bhb.loop8, "ax", %progbits
+       .reloc  .text, R_ARM_NONE, .
        W(b)    vector_rst
        W(b)    vector_bhb_loop8_und
 ARM(   .reloc  ., R_ARM_LDR_PC_G0, .L__vector_bhb_loop8_swi    )
@@ -1090,6 +1092,7 @@ THUMB(    .reloc  ., R_ARM_THM_PC12, .L__vector_bhb_loop8_swi     )
        W(b)    vector_bhb_loop8_fiq
 
        .section .vectors.bhb.bpiall, "ax", %progbits
+       .reloc  .text, R_ARM_NONE, .
        W(b)    vector_rst
        W(b)    vector_bhb_bpiall_und
 ARM(   .reloc  ., R_ARM_LDR_PC_G0, .L__vector_bhb_bpiall_swi   )
index c16d196b5aad3e159c160295fd21c75c3cb7055b..5eddb75a7174083f7bf143798f339171540c8475 100644 (file)
@@ -63,7 +63,7 @@ SECTIONS
        . = ALIGN(4);
        __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
                __start___ex_table = .;
-               ARM_MMU_KEEP(*(__ex_table))
+               ARM_MMU_KEEP(KEEP(*(__ex_table)))
                __stop___ex_table = .;
        }
 
@@ -83,7 +83,7 @@ SECTIONS
        }
        .init.arch.info : {
                __arch_info_begin = .;
-               *(.arch.info.init)
+               KEEP(*(.arch.info.init))
                __arch_info_end = .;
        }
        .init.tagtable : {
index bd9127c4b451015bb67b64cc273ff10ebb68a398..de373c6c2ae8780f190bef7357c4d70f3b3064cc 100644 (file)
@@ -74,7 +74,7 @@ SECTIONS
        . = ALIGN(4);
        __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
                __start___ex_table = .;
-               ARM_MMU_KEEP(*(__ex_table))
+               ARM_MMU_KEEP(KEEP(*(__ex_table)))
                __stop___ex_table = .;
        }
 
@@ -99,7 +99,7 @@ SECTIONS
        }
        .init.arch.info : {
                __arch_info_begin = .;
-               *(.arch.info.init)
+               KEEP(*(.arch.info.init))
                __arch_info_end = .;
        }
        .init.tagtable : {
@@ -116,7 +116,7 @@ SECTIONS
 #endif
        .init.pv_table : {
                __pv_table_begin = .;
-               *(.pv_table)
+               KEEP(*(.pv_table))
                __pv_table_end = .;
        }
 
index 06f0428a723cb8f6be287a81600cd49b40fb3341..5a8a9b3429b564d7f4f0415ffd01cf5598c9c3c5 100644 (file)
@@ -56,6 +56,10 @@ KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_CFI), $(KBUILD_CFLAGS))
 # disable LTO
 KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO), $(KBUILD_CFLAGS))
 
+# The .data section would be renamed to .data.efistub, therefore, remove
+# `-fdata-sections` flag from KBUILD_CFLAGS_KERNEL
+KBUILD_CFLAGS_KERNEL := $(filter-out -fdata-sections, $(KBUILD_CFLAGS_KERNEL))
+
 lib-y                          := efi-stub-helper.o gop.o secureboot.o tpm.o \
                                   file.o mem.o random.o randomalloc.o pci.o \
                                   skip_spaces.o lib-cmdline.o lib-ctype.o \