kernel: bump 5.4 to 5.4.156
[openwrt/staging/chunkeey.git] / target / linux / generic / hack-5.4 / 220-arm-gc_sections.patch
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
5
6 In combination with kernel symbol export stripping this significantly reduces
7 the kernel image size. Used on both ARM and MIPS architectures.
8
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>
12 ---
13 Makefile | 10 +++----
14 arch/arm/Kconfig | 1 +
15 arch/arm/boot/compressed/Makefile | 1 +
16 arch/arm/kernel/vmlinux.lds.S | 26 ++++++++--------
17 arch/mips/Kconfig | 1 +
18 arch/mips/kernel/vmlinux.lds.S | 4 +--
19 include/asm-generic/vmlinux.lds.h | 63 ++++++++++++++++++++-------------------
20 7 files changed, 55 insertions(+), 51 deletions(-)
21
22 --- a/arch/arm/Kconfig
23 +++ b/arch/arm/Kconfig
24 @@ -112,6 +112,7 @@ config ARM
25 select HAVE_UID16
26 select HAVE_VIRT_CPU_ACCOUNTING_GEN
27 select IRQ_FORCED_THREADING
28 + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
29 select MODULES_USE_ELF_REL
30 select NEED_DMA_MAP_STATE
31 select OF_EARLY_FLATTREE if OF
32 --- a/arch/arm/boot/compressed/Makefile
33 +++ b/arch/arm/boot/compressed/Makefile
34 @@ -108,6 +108,7 @@ ifeq ($(CONFIG_FUNCTION_TRACER),y)
35 ORIG_CFLAGS := $(KBUILD_CFLAGS)
36 KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
37 endif
38 +KBUILD_CFLAGS_KERNEL := $(patsubst -f%-sections,,$(KBUILD_CFLAGS_KERNEL))
39
40 # -fstack-protector-strong triggers protection checks in this code,
41 # but it is being used too early to link to meaningful stack_chk logic.
42 --- a/arch/arm/kernel/vmlinux.lds.S
43 +++ b/arch/arm/kernel/vmlinux.lds.S
44 @@ -73,7 +73,7 @@ SECTIONS
45 . = ALIGN(4);
46 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
47 __start___ex_table = .;
48 - ARM_MMU_KEEP(*(__ex_table))
49 + KEEP(*(__ex_table))
50 __stop___ex_table = .;
51 }
52
53 @@ -100,24 +100,24 @@ SECTIONS
54 }
55 .init.arch.info : {
56 __arch_info_begin = .;
57 - *(.arch.info.init)
58 + KEEP(*(.arch.info.init))
59 __arch_info_end = .;
60 }
61 .init.tagtable : {
62 __tagtable_begin = .;
63 - *(.taglist.init)
64 + KEEP(*(.taglist.init))
65 __tagtable_end = .;
66 }
67 #ifdef CONFIG_SMP_ON_UP
68 .init.smpalt : {
69 __smpalt_begin = .;
70 - *(.alt.smp.init)
71 + KEEP(*(.alt.smp.init))
72 __smpalt_end = .;
73 }
74 #endif
75 .init.pv_table : {
76 __pv_table_begin = .;
77 - *(.pv_table)
78 + KEEP(*(.pv_table))
79 __pv_table_end = .;
80 }
81
82 --- a/arch/arm/kernel/vmlinux.lds.h
83 +++ b/arch/arm/kernel/vmlinux.lds.h
84 @@ -28,7 +28,7 @@
85 #define PROC_INFO \
86 . = ALIGN(4); \
87 __proc_info_begin = .; \
88 - *(.proc.info.init) \
89 + KEEP(*(.proc.info.init)) \
90 __proc_info_end = .;
91
92 #define HYPERVISOR_TEXT \
93 @@ -39,11 +39,11 @@
94 #define IDMAP_TEXT \
95 ALIGN_FUNCTION(); \
96 __idmap_text_start = .; \
97 - *(.idmap.text) \
98 + KEEP(*(.idmap.text)) \
99 __idmap_text_end = .; \
100 . = ALIGN(PAGE_SIZE); \
101 __hyp_idmap_text_start = .; \
102 - *(.hyp.idmap.text) \
103 + KEEP(*(.hyp.idmap.text)) \
104 __hyp_idmap_text_end = .;
105
106 #define ARM_DISCARD \
107 @@ -86,12 +86,12 @@
108 . = ALIGN(8); \
109 .ARM.unwind_idx : { \
110 __start_unwind_idx = .; \
111 - *(.ARM.exidx*) \
112 + KEEP(*(.ARM.exidx*)) \
113 __stop_unwind_idx = .; \
114 } \
115 .ARM.unwind_tab : { \
116 __start_unwind_tab = .; \
117 - *(.ARM.extab*) \
118 + KEEP(*(.ARM.extab*)) \
119 __stop_unwind_tab = .; \
120 }
121
122 @@ -102,14 +102,14 @@
123 #define ARM_VECTORS \
124 __vectors_start = .; \
125 .vectors 0xffff0000 : AT(__vectors_start) { \
126 - *(.vectors) \
127 + KEEP(*(.vectors)) \
128 } \
129 . = __vectors_start + SIZEOF(.vectors); \
130 __vectors_end = .; \
131 \
132 __stubs_start = .; \
133 .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { \
134 - *(.stubs) \
135 + KEEP(*(.stubs)) \
136 } \
137 . = __stubs_start + SIZEOF(.stubs); \
138 __stubs_end = .; \