kernel : Bump to 4.14.325
[librecmc/librecmc.git] / target / linux / generic / hack-4.14 / 220-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/Makefile
23 +++ b/Makefile
24 @@ -279,6 +279,11 @@ else
25  scripts/Kbuild.include: ;
26  include scripts/Kbuild.include
27  
28 +ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
29 +KBUILD_CFLAGS_KERNEL   += $(call cc-option,-ffunction-sections,)
30 +KBUILD_CFLAGS_KERNEL   += $(call cc-option,-fdata-sections,)
31 +endif
32 +
33  # Read KERNELRELEASE from include/config/kernel.release (if it exists)
34  KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
35  KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
36 @@ -797,11 +802,6 @@ ifdef CONFIG_DEBUG_SECTION_MISMATCH
37  KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
38  endif
39  
40 -ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
41 -KBUILD_CFLAGS  += $(call cc-option,-ffunction-sections,)
42 -KBUILD_CFLAGS  += $(call cc-option,-fdata-sections,)
43 -endif
44 -
45  # arch Makefile may override CC so keep this after arch Makefile is included
46  NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
47  CHECKFLAGS     += $(NOSTDINC_FLAGS)
48 --- a/arch/arm/Kconfig
49 +++ b/arch/arm/Kconfig
50 @@ -93,6 +93,7 @@ config ARM
51         select HAVE_UID16
52         select HAVE_VIRT_CPU_ACCOUNTING_GEN
53         select IRQ_FORCED_THREADING
54 +       select LD_DEAD_CODE_DATA_ELIMINATION
55         select MODULES_USE_ELF_REL
56         select NO_BOOTMEM
57         select OF_EARLY_FLATTREE if OF
58 --- a/arch/arm/boot/compressed/Makefile
59 +++ b/arch/arm/boot/compressed/Makefile
60 @@ -105,6 +105,7 @@ ifeq ($(CONFIG_FUNCTION_TRACER),y)
61  ORIG_CFLAGS := $(KBUILD_CFLAGS)
62  KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
63  endif
64 +KBUILD_CFLAGS_KERNEL := $(patsubst -f%-sections,,$(KBUILD_CFLAGS_KERNEL))
65  
66  # -fstack-protector-strong triggers protection checks in this code,
67  # but it is being used too early to link to meaningful stack_chk logic.
68 --- a/arch/arm/kernel/vmlinux.lds.S
69 +++ b/arch/arm/kernel/vmlinux.lds.S
70 @@ -31,7 +31,7 @@
71  #define PROC_INFO                                                      \
72         . = ALIGN(4);                                                   \
73         VMLINUX_SYMBOL(__proc_info_begin) = .;                          \
74 -       *(.proc.info.init)                                              \
75 +       KEEP(*(.proc.info.init))                                        \
76         VMLINUX_SYMBOL(__proc_info_end) = .;
77  
78  #define HYPERVISOR_TEXT                                                        \
79 @@ -42,11 +42,11 @@
80  #define IDMAP_TEXT                                                     \
81         ALIGN_FUNCTION();                                               \
82         VMLINUX_SYMBOL(__idmap_text_start) = .;                         \
83 -       *(.idmap.text)                                                  \
84 +       KEEP(*(.idmap.text))                                            \
85         VMLINUX_SYMBOL(__idmap_text_end) = .;                           \
86         . = ALIGN(PAGE_SIZE);                                           \
87         VMLINUX_SYMBOL(__hyp_idmap_text_start) = .;                     \
88 -       *(.hyp.idmap.text)                                              \
89 +       KEEP(*(.hyp.idmap.text))                                        \
90         VMLINUX_SYMBOL(__hyp_idmap_text_end) = .;
91  
92  #ifdef CONFIG_HOTPLUG_CPU
93 @@ -119,7 +119,7 @@ SECTIONS
94                 _stext = .;             /* Text and read-only data      */
95                         IDMAP_TEXT
96                         __exception_text_start = .;
97 -                       *(.exception.text)
98 +                       KEEP(*(.exception.text))
99                         __exception_text_end = .;
100                         IRQENTRY_TEXT
101                         SOFTIRQENTRY_TEXT
102 @@ -148,7 +148,7 @@ SECTIONS
103         __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
104                 __start___ex_table = .;
105  #ifdef CONFIG_MMU
106 -               *(__ex_table)
107 +               KEEP(*(__ex_table))
108  #endif
109                 __stop___ex_table = .;
110         }
111 @@ -160,12 +160,12 @@ SECTIONS
112         . = ALIGN(8);
113         .ARM.unwind_idx : {
114                 __start_unwind_idx = .;
115 -               *(.ARM.exidx*)
116 +               KEEP(*(.ARM.exidx*))
117                 __stop_unwind_idx = .;
118         }
119         .ARM.unwind_tab : {
120                 __start_unwind_tab = .;
121 -               *(.ARM.extab*)
122 +               KEEP(*(.ARM.extab*))
123                 __stop_unwind_tab = .;
124         }
125  #endif
126 @@ -186,13 +186,13 @@ SECTIONS
127         __vectors_lma = .;
128         OVERLAY 0xffff0000 : NOCROSSREFS AT(__vectors_lma) {
129                 .vectors {
130 -                       *(.vectors)
131 +                       KEEP(*(.vectors))
132                 }
133                 .vectors.bhb.loop8 {
134 -                       *(.vectors.bhb.loop8)
135 +                       KEEP(*(.vectors.bhb.loop8))
136                 }
137                 .vectors.bhb.bpiall {
138 -                       *(.vectors.bhb.bpiall)
139 +                       KEEP(*(.vectors.bhb.bpiall))
140                 }
141         }
142         ARM_LMA(__vectors, .vectors);
143 @@ -204,7 +204,7 @@ SECTIONS
144  
145         __stubs_lma = .;
146         .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_lma) {
147 -               *(.stubs)
148 +               KEEP(*(.stubs))
149         }
150         ARM_LMA(__stubs, .stubs);
151         . = __stubs_lma + SIZEOF(.stubs);
152 @@ -220,24 +220,24 @@ SECTIONS
153         }
154         .init.arch.info : {
155                 __arch_info_begin = .;
156 -               *(.arch.info.init)
157 +               KEEP(*(.arch.info.init))
158                 __arch_info_end = .;
159         }
160         .init.tagtable : {
161                 __tagtable_begin = .;
162 -               *(.taglist.init)
163 +               KEEP(*(.taglist.init))
164                 __tagtable_end = .;
165         }
166  #ifdef CONFIG_SMP_ON_UP
167         .init.smpalt : {
168                 __smpalt_begin = .;
169 -               *(.alt.smp.init)
170 +               KEEP(*(.alt.smp.init))
171                 __smpalt_end = .;
172         }
173  #endif
174         .init.pv_table : {
175                 __pv_table_begin = .;
176 -               *(.pv_table)
177 +               KEEP(*(.pv_table))
178                 __pv_table_end = .;
179         }
180         .init.data : {
181 --- a/arch/mips/Kconfig
182 +++ b/arch/mips/Kconfig
183 @@ -41,6 +41,7 @@ config MIPS
184         select HAVE_CBPF_JIT if (!64BIT && !CPU_MICROMIPS)
185         select HAVE_EBPF_JIT if (64BIT && !CPU_MICROMIPS)
186         select HAVE_CC_STACKPROTECTOR
187 +       select LD_DEAD_CODE_DATA_ELIMINATION
188         select HAVE_CONTEXT_TRACKING
189         select HAVE_COPY_THREAD_TLS
190         select HAVE_C_RECORDMCOUNT
191 --- a/arch/mips/kernel/vmlinux.lds.S
192 +++ b/arch/mips/kernel/vmlinux.lds.S
193 @@ -72,7 +72,7 @@ SECTIONS
194         /* Exception table for data bus errors */
195         __dbe_table : {
196                 __start___dbe_table = .;
197 -               *(__dbe_table)
198 +               KEEP(*(__dbe_table))
199                 __stop___dbe_table = .;
200         }
201  
202 @@ -124,7 +124,7 @@ SECTIONS
203         . = ALIGN(4);
204         .mips.machines.init : AT(ADDR(.mips.machines.init) - LOAD_OFFSET) {
205                 __mips_machines_start = .;
206 -               *(.mips.machines.init)
207 +               KEEP(*(.mips.machines.init))
208                 __mips_machines_end = .;
209         }
210  
211 --- a/include/asm-generic/vmlinux.lds.h
212 +++ b/include/asm-generic/vmlinux.lds.h
213 @@ -105,7 +105,7 @@
214  #ifdef CONFIG_FTRACE_MCOUNT_RECORD
215  #define MCOUNT_REC()   . = ALIGN(8);                           \
216                         VMLINUX_SYMBOL(__start_mcount_loc) = .; \
217 -                       *(__mcount_loc)                         \
218 +                       KEEP(*(__mcount_loc))                   \
219                         VMLINUX_SYMBOL(__stop_mcount_loc) = .;
220  #else
221  #define MCOUNT_REC()
222 @@ -113,7 +113,7 @@
223  
224  #ifdef CONFIG_TRACE_BRANCH_PROFILING
225  #define LIKELY_PROFILE()       VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \
226 -                               *(_ftrace_annotated_branch)                           \
227 +                               KEEP(*(_ftrace_annotated_branch))                     \
228                                 VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .;
229  #else
230  #define LIKELY_PROFILE()
231 @@ -121,7 +121,7 @@
232  
233  #ifdef CONFIG_PROFILE_ALL_BRANCHES
234  #define BRANCH_PROFILE()       VMLINUX_SYMBOL(__start_branch_profile) = .;   \
235 -                               *(_ftrace_branch)                             \
236 +                               KEEP(*(_ftrace_branch))                       \
237                                 VMLINUX_SYMBOL(__stop_branch_profile) = .;
238  #else
239  #define BRANCH_PROFILE()
240 @@ -237,7 +237,8 @@
241         LIKELY_PROFILE()                                                \
242         BRANCH_PROFILE()                                                \
243         TRACE_PRINTKS()                                                 \
244 -       TRACEPOINT_STR()
245 +       TRACEPOINT_STR()                                                \
246 +       *(.data.[a-zA-Z_]*)
247  
248  /*
249   * Data section helpers
250 @@ -501,7 +502,7 @@
251  #define ENTRY_TEXT                                                     \
252                 ALIGN_FUNCTION();                                       \
253                 VMLINUX_SYMBOL(__entry_text_start) = .;                 \
254 -               *(.entry.text)                                          \
255 +               KEEP(*(.entry.text))                                    \
256                 VMLINUX_SYMBOL(__entry_text_end) = .;
257  
258  #define IRQENTRY_TEXT                                                  \
259 @@ -608,7 +609,7 @@
260         . = ALIGN(sbss_align);                                          \
261         .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) {                         \
262                 *(.dynsbss)                                             \
263 -               *(.sbss)                                                \
264 +               *(.sbss .sbss.*)                                        \
265                 *(.scommon)                                             \
266         }
267