]> git.ipfire.org Git - thirdparty/openwrt.git/blob
0455e9e76838af30f413ee304fd9d0941ea0d7c6
[thirdparty/openwrt.git] /
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
5
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.
10
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.
16
17 It boots normally with defconfig, vexpress_defconfig and tinyconfig.
18
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
24
25 When using smaller config file, there is a significant reduction in the
26 size of the zImage.
27
28 We also tested this patch on a commercially available single-board
29 computer, and the comparison is as follows:
30 a15eb_config
31 2161384 no dce
32 2092240 dce
33 3.2% shrink
34
35 The zImage size has been reduced by approximately 3.2%, which is 70KB on
36 2.1M.
37
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>
43 ---
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(-)
52
53 --- a/arch/arm/Kconfig
54 +++ b/arch/arm/Kconfig
55 @@ -111,6 +111,7 @@ config ARM
56 select HAVE_KERNEL_XZ
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
61 select HAVE_NMI
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
66
67 . = BSS_START;
68 __bss_start = .;
69 - .bss : { *(.bss) }
70 + .bss : { *(.bss .bss.*) }
71 _end = .;
72
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
76 @@ -42,7 +42,7 @@
77 #define PROC_INFO \
78 . = ALIGN(4); \
79 __proc_info_begin = .; \
80 - *(.proc.info.init) \
81 + KEEP(*(.proc.info.init)) \
82 __proc_info_end = .;
83
84 #define IDMAP_TEXT \
85 --- a/arch/arm/kernel/entry-armv.S
86 +++ b/arch/arm/kernel/entry-armv.S
87 @@ -1073,6 +1073,7 @@ vector_addrexcptn:
88 .globl vector_fiq
89
90 .section .vectors, "ax", %progbits
91 + .reloc .text, R_ARM_NONE, .
92 W(b) vector_rst
93 W(b) vector_und
94 ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_swi )
95 @@ -1086,6 +1087,7 @@ THUMB( .reloc ., R_ARM_THM_PC12, .L__vec
96
97 #ifdef CONFIG_HARDEN_BRANCH_HISTORY
98 .section .vectors.bhb.loop8, "ax", %progbits
99 + .reloc .text, R_ARM_NONE, .
100 W(b) vector_rst
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
105
106 .section .vectors.bhb.bpiall, "ax", %progbits
107 + .reloc .text, R_ARM_NONE, .
108 W(b) vector_rst
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
114 . = ALIGN(4);
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 = .;
120 }
121
122 @@ -83,7 +83,7 @@ SECTIONS
123 }
124 .init.arch.info : {
125 __arch_info_begin = .;
126 - *(.arch.info.init)
127 + KEEP(*(.arch.info.init))
128 __arch_info_end = .;
129 }
130 .init.tagtable : {
131 --- a/arch/arm/kernel/vmlinux.lds.S
132 +++ b/arch/arm/kernel/vmlinux.lds.S
133 @@ -74,7 +74,7 @@ SECTIONS
134 . = ALIGN(4);
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 = .;
140 }
141
142 @@ -99,7 +99,7 @@ SECTIONS
143 }
144 .init.arch.info : {
145 __arch_info_begin = .;
146 - *(.arch.info.init)
147 + KEEP(*(.arch.info.init))
148 __arch_info_end = .;
149 }
150 .init.tagtable : {
151 @@ -116,7 +116,7 @@ SECTIONS
152 #endif
153 .init.pv_table : {
154 __pv_table_begin = .;
155 - *(.pv_table)
156 + KEEP(*(.pv_table))
157 __pv_table_end = .;
158 }
159
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.
164 KCOV_INSTRUMENT := n
165
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))
169 +
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 \