1 From e3d8676f5722b7622685581e06e8f53e6138e3ab Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Sat, 15 Jul 2017 23:42:36 +0200
4 Subject: use -ffunction-sections, -fdata-sections and --gc-sections
6 In combination with kernel symbol export stripping this significantly reduces
7 the kernel image size. Used on both ARM and MIPS architectures.
9 Signed-off-by: Felix Fietkau <nbd@nbd.name>
10 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
11 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
13 --- a/arch/arm/Kconfig
14 +++ b/arch/arm/Kconfig
15 @@ -118,6 +118,7 @@ config ARM
17 select HAVE_VIRT_CPU_ACCOUNTING_GEN
18 select IRQ_FORCED_THREADING
19 + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
20 select MODULES_USE_ELF_REL
21 select NEED_DMA_MAP_STATE
22 select OF_EARLY_FLATTREE if OF
23 --- a/arch/arm/boot/compressed/Makefile
24 +++ b/arch/arm/boot/compressed/Makefile
25 @@ -92,6 +92,7 @@ endif
26 ifeq ($(CONFIG_USE_OF),y)
27 OBJS += $(libfdt_objs) fdt_check_mem_start.o
29 +KBUILD_CFLAGS_KERNEL := $(patsubst -f%-sections,,$(KBUILD_CFLAGS_KERNEL))
31 # -fstack-protector-strong triggers protection checks in this code,
32 # but it is being used too early to link to meaningful stack_chk logic.
33 --- a/arch/arm/kernel/vmlinux.lds.S
34 +++ b/arch/arm/kernel/vmlinux.lds.S
35 @@ -75,7 +75,7 @@ SECTIONS
37 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
38 __start___ex_table = .;
39 - ARM_MMU_KEEP(*(__ex_table))
41 __stop___ex_table = .;
44 @@ -100,24 +100,24 @@ SECTIONS
47 __arch_info_begin = .;
49 + KEEP(*(.arch.info.init))
55 + KEEP(*(.taglist.init))
58 #ifdef CONFIG_SMP_ON_UP
62 + KEEP(*(.alt.smp.init))
73 --- a/arch/arm/include/asm/vmlinux.lds.h
74 +++ b/arch/arm/include/asm/vmlinux.lds.h
78 __proc_info_begin = .; \
79 - *(.proc.info.init) \
80 + KEEP(*(.proc.info.init)) \
85 __idmap_text_start = .; \
87 + KEEP(*(.idmap.text)) \
88 __idmap_text_end = .; \
94 __start_unwind_idx = .; \
96 + KEEP(*(.ARM.exidx*)) \
97 __stop_unwind_idx = .; \
100 __start_unwind_tab = .; \
102 + KEEP(*(.ARM.extab*)) \
103 __stop_unwind_tab = .; \
108 OVERLAY 0xffff0000 : NOCROSSREFS AT(__vectors_lma) { \
111 + KEEP(*(.vectors)) \
113 .vectors.bhb.loop8 { \
114 *(.vectors.bhb.loop8) \
118 .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_lma) { \
122 ARM_LMA(__stubs, .stubs); \
123 . = __stubs_lma + SIZEOF(.stubs); \