1 From ed0f941022515ff40473ea5335769a5dc2524a3f Mon Sep 17 00:00:00 2001
2 From: Yuntao Liu <liuyuntao12@huawei.com>
3 Date: Mon, 3 Jun 2024 16:37:50 +0100
4 Subject: [PATCH] ARM: 9404/1: arm32: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION
6 The current arm32 architecture does not yet support the
7 HAVE_LD_DEAD_CODE_DATA_ELIMINATION feature. arm32 is widely used in
8 embedded scenarios, and enabling this feature would be beneficial for
9 reducing the size of the kernel image.
11 In order to make this work, we keep the necessary tables by annotating
12 them with KEEP, also it requires further changes to linker script to KEEP
13 some tables and wildcard compiler generated sections into the right place.
14 When using ld.lld for linking, KEEP is not recognized within the OVERLAY
15 command, and Ard proposed a concise method to solve this problem.
17 It boots normally with defconfig, vexpress_defconfig and tinyconfig.
19 The size comparison of zImage is as follows:
20 defconfig vexpress_defconfig tinyconfig
21 5137712 5138024 424192 no dce
22 5032560 4997824 298384 dce
23 2.0% 2.7% 29.7% shrink
25 When using smaller config file, there is a significant reduction in the
28 We also tested this patch on a commercially available single-board
29 computer, and the comparison is as follows:
35 The zImage size has been reduced by approximately 3.2%, which is 70KB on
38 Signed-off-by: Yuntao Liu <liuyuntao12@huawei.com>
39 Tested-by: Arnd Bergmann <arnd@arndb.de>
40 Reviewed-by: Arnd Bergmann <arnd@arndb.de>
41 Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
42 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
44 arch/arm/Kconfig | 1 +
45 arch/arm/boot/compressed/vmlinux.lds.S | 2 +-
46 arch/arm/include/asm/vmlinux.lds.h | 2 +-
47 arch/arm/kernel/entry-armv.S | 3 +++
48 arch/arm/kernel/vmlinux-xip.lds.S | 4 ++--
49 arch/arm/kernel/vmlinux.lds.S | 6 +++---
50 drivers/firmware/efi/libstub/Makefile | 4 ++++
51 7 files changed, 15 insertions(+), 7 deletions(-)
53 --- a/arch/arm/Kconfig
54 +++ b/arch/arm/Kconfig
55 @@ -111,6 +111,7 @@ config ARM
57 select HAVE_KPROBES if !XIP_KERNEL && !CPU_ENDIAN_BE32 && !CPU_V7M
58 select HAVE_KRETPROBES if HAVE_KPROBES
59 + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
60 select HAVE_MOD_ARCH_SPECIFIC
62 select HAVE_OPTPROBES if !THUMB2_KERNEL
63 --- a/arch/arm/boot/compressed/vmlinux.lds.S
64 +++ b/arch/arm/boot/compressed/vmlinux.lds.S
65 @@ -125,7 +125,7 @@ SECTIONS
70 + .bss : { *(.bss .bss.*) }
73 . = ALIGN(8); /* the stack must be 64-bit aligned */
74 --- a/arch/arm/include/asm/vmlinux.lds.h
75 +++ b/arch/arm/include/asm/vmlinux.lds.h
79 __proc_info_begin = .; \
80 - *(.proc.info.init) \
81 + KEEP(*(.proc.info.init)) \
85 --- a/arch/arm/kernel/entry-armv.S
86 +++ b/arch/arm/kernel/entry-armv.S
87 @@ -1073,6 +1073,7 @@ vector_addrexcptn:
90 .section .vectors, "ax", %progbits
91 + .reloc .text, R_ARM_NONE, .
94 ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_swi )
95 @@ -1086,6 +1087,7 @@ THUMB( .reloc ., R_ARM_THM_PC12, .L__vec
97 #ifdef CONFIG_HARDEN_BRANCH_HISTORY
98 .section .vectors.bhb.loop8, "ax", %progbits
99 + .reloc .text, R_ARM_NONE, .
101 W(b) vector_bhb_loop8_und
102 ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_bhb_loop8_swi )
103 @@ -1098,6 +1100,7 @@ THUMB( .reloc ., R_ARM_THM_PC12, .L__vec
104 W(b) vector_bhb_loop8_fiq
106 .section .vectors.bhb.bpiall, "ax", %progbits
107 + .reloc .text, R_ARM_NONE, .
109 W(b) vector_bhb_bpiall_und
110 ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_bhb_bpiall_swi )
111 --- a/arch/arm/kernel/vmlinux-xip.lds.S
112 +++ b/arch/arm/kernel/vmlinux-xip.lds.S
113 @@ -63,7 +63,7 @@ SECTIONS
115 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
116 __start___ex_table = .;
117 - ARM_MMU_KEEP(*(__ex_table))
118 + ARM_MMU_KEEP(KEEP(*(__ex_table)))
119 __stop___ex_table = .;
122 @@ -83,7 +83,7 @@ SECTIONS
125 __arch_info_begin = .;
127 + KEEP(*(.arch.info.init))
131 --- a/arch/arm/kernel/vmlinux.lds.S
132 +++ b/arch/arm/kernel/vmlinux.lds.S
133 @@ -74,7 +74,7 @@ SECTIONS
135 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
136 __start___ex_table = .;
137 - ARM_MMU_KEEP(*(__ex_table))
138 + ARM_MMU_KEEP(KEEP(*(__ex_table)))
139 __stop___ex_table = .;
142 @@ -99,7 +99,7 @@ SECTIONS
145 __arch_info_begin = .;
147 + KEEP(*(.arch.info.init))
151 @@ -116,7 +116,7 @@ SECTIONS
154 __pv_table_begin = .;
160 --- a/drivers/firmware/efi/libstub/Makefile
161 +++ b/drivers/firmware/efi/libstub/Makefile
162 @@ -67,6 +67,10 @@ OBJECT_FILES_NON_STANDARD := y
163 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
166 +# The .data section would be renamed to .data.efistub, therefore, remove
167 +# `-fdata-sections` flag from KBUILD_CFLAGS_KERNEL
168 +KBUILD_CFLAGS_KERNEL := $(filter-out -fdata-sections, $(KBUILD_CFLAGS_KERNEL))
170 lib-y := efi-stub-helper.o gop.o secureboot.o tpm.o \
171 file.o mem.o random.o randomalloc.o pci.o \
172 skip_spaces.o lib-cmdline.o lib-ctype.o \