Skip to content

Commit ed0f941

Browse files
Yuntao LiuRussell King (Oracle)
authored andcommitted
ARM: 9404/1: arm32: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION
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 <[email protected]> Tested-by: Arnd Bergmann <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent 9ac7ba1 commit ed0f941

File tree

7 files changed

+15
-7
lines changed

7 files changed

+15
-7
lines changed

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ config ARM
115115
select HAVE_KERNEL_XZ
116116
select HAVE_KPROBES if !XIP_KERNEL && !CPU_ENDIAN_BE32 && !CPU_V7M
117117
select HAVE_KRETPROBES if HAVE_KPROBES
118+
select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
118119
select HAVE_MOD_ARCH_SPECIFIC
119120
select HAVE_NMI
120121
select HAVE_OPTPROBES if !THUMB2_KERNEL

arch/arm/boot/compressed/vmlinux.lds.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ SECTIONS
125125

126126
. = BSS_START;
127127
__bss_start = .;
128-
.bss : { *(.bss) }
128+
.bss : { *(.bss .bss.*) }
129129
_end = .;
130130

131131
. = ALIGN(8); /* the stack must be 64-bit aligned */

arch/arm/include/asm/vmlinux.lds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define PROC_INFO \
4343
. = ALIGN(4); \
4444
__proc_info_begin = .; \
45-
*(.proc.info.init) \
45+
KEEP(*(.proc.info.init)) \
4646
__proc_info_end = .;
4747

4848
#define IDMAP_TEXT \

arch/arm/kernel/entry-armv.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ vector_addrexcptn:
10651065
.globl vector_fiq
10661066

10671067
.section .vectors, "ax", %progbits
1068+
.reloc .text, R_ARM_NONE, .
10681069
W(b) vector_rst
10691070
W(b) vector_und
10701071
ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_swi )
@@ -1078,6 +1079,7 @@ THUMB( .reloc ., R_ARM_THM_PC12, .L__vector_swi )
10781079

10791080
#ifdef CONFIG_HARDEN_BRANCH_HISTORY
10801081
.section .vectors.bhb.loop8, "ax", %progbits
1082+
.reloc .text, R_ARM_NONE, .
10811083
W(b) vector_rst
10821084
W(b) vector_bhb_loop8_und
10831085
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 )
10901092
W(b) vector_bhb_loop8_fiq
10911093

10921094
.section .vectors.bhb.bpiall, "ax", %progbits
1095+
.reloc .text, R_ARM_NONE, .
10931096
W(b) vector_rst
10941097
W(b) vector_bhb_bpiall_und
10951098
ARM( .reloc ., R_ARM_LDR_PC_G0, .L__vector_bhb_bpiall_swi )

arch/arm/kernel/vmlinux-xip.lds.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ SECTIONS
6363
. = ALIGN(4);
6464
__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
6565
__start___ex_table = .;
66-
ARM_MMU_KEEP(*(__ex_table))
66+
ARM_MMU_KEEP(KEEP(*(__ex_table)))
6767
__stop___ex_table = .;
6868
}
6969

@@ -83,7 +83,7 @@ SECTIONS
8383
}
8484
.init.arch.info : {
8585
__arch_info_begin = .;
86-
*(.arch.info.init)
86+
KEEP(*(.arch.info.init))
8787
__arch_info_end = .;
8888
}
8989
.init.tagtable : {

arch/arm/kernel/vmlinux.lds.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ SECTIONS
7474
. = ALIGN(4);
7575
__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
7676
__start___ex_table = .;
77-
ARM_MMU_KEEP(*(__ex_table))
77+
ARM_MMU_KEEP(KEEP(*(__ex_table)))
7878
__stop___ex_table = .;
7979
}
8080

@@ -99,7 +99,7 @@ SECTIONS
9999
}
100100
.init.arch.info : {
101101
__arch_info_begin = .;
102-
*(.arch.info.init)
102+
KEEP(*(.arch.info.init))
103103
__arch_info_end = .;
104104
}
105105
.init.tagtable : {
@@ -116,7 +116,7 @@ SECTIONS
116116
#endif
117117
.init.pv_table : {
118118
__pv_table_begin = .;
119-
*(.pv_table)
119+
KEEP(*(.pv_table))
120120
__pv_table_end = .;
121121
}
122122

drivers/firmware/efi/libstub/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_CFI), $(KBUILD_CFLAGS))
5656
# disable LTO
5757
KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO), $(KBUILD_CFLAGS))
5858

59+
# The .data section would be renamed to .data.efistub, therefore, remove
60+
# `-fdata-sections` flag from KBUILD_CFLAGS_KERNEL
61+
KBUILD_CFLAGS_KERNEL := $(filter-out -fdata-sections, $(KBUILD_CFLAGS_KERNEL))
62+
5963
lib-y := efi-stub-helper.o gop.o secureboot.o tpm.o \
6064
file.o mem.o random.o randomalloc.o pci.o \
6165
skip_spaces.o lib-cmdline.o lib-ctype.o \

0 commit comments

Comments
 (0)