kernel: bump 5.4 to 5.4.28
[oweals/openwrt.git] / target / linux / generic / hack-5.4 / 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/arch/arm/Kconfig
23 +++ b/arch/arm/Kconfig
24 @@ -111,6 +111,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 @@ -106,6 +106,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 @@ -100,24 +100,24 @@ SECTIONS
45         }
46         .init.arch.info : {
47                 __arch_info_begin = .;
48 -               *(.arch.info.init)
49 +               KEEP(*(.arch.info.init))
50                 __arch_info_end = .;
51         }
52         .init.tagtable : {
53                 __tagtable_begin = .;
54 -               *(.taglist.init)
55 +               KEEP(*(.taglist.init))
56                 __tagtable_end = .;
57         }
58  #ifdef CONFIG_SMP_ON_UP
59         .init.smpalt : {
60                 __smpalt_begin = .;
61 -               *(.alt.smp.init)
62 +               KEEP(*(.alt.smp.init))
63                 __smpalt_end = .;
64         }
65  #endif
66         .init.pv_table : {
67                 __pv_table_begin = .;
68 -               *(.pv_table)
69 +               KEEP(*(.pv_table))
70                 __pv_table_end = .;
71         }
72  
73 --- a/arch/arm/kernel/vmlinux.lds.h
74 +++ b/arch/arm/kernel/vmlinux.lds.h
75 @@ -22,13 +22,13 @@
76  #define ARM_MMU_DISCARD(x)
77  #else
78  #define ARM_MMU_KEEP(x)
79 -#define ARM_MMU_DISCARD(x)     x
80 +#define ARM_MMU_DISCARD(x)     KEEP(x)
81  #endif
82  
83  #define PROC_INFO                                                      \
84                 . = ALIGN(4);                                           \
85                 __proc_info_begin = .;                                  \
86 -               *(.proc.info.init)                                      \
87 +               KEEP(*(.proc.info.init))                                \
88                 __proc_info_end = .;
89  
90  #define HYPERVISOR_TEXT                                                        \
91 @@ -39,11 +39,11 @@
92  #define IDMAP_TEXT                                                     \
93                 ALIGN_FUNCTION();                                       \
94                 __idmap_text_start = .;                                 \
95 -               *(.idmap.text)                                          \
96 +               KEEP(*(.idmap.text))                                    \
97                 __idmap_text_end = .;                                   \
98                 . = ALIGN(PAGE_SIZE);                                   \
99                 __hyp_idmap_text_start = .;                             \
100 -               *(.hyp.idmap.text)                                      \
101 +               KEEP(*(.hyp.idmap.text))                                \
102                 __hyp_idmap_text_end = .;
103  
104  #define ARM_DISCARD                                                    \
105 @@ -86,12 +86,12 @@
106         . = ALIGN(8);                                                   \
107         .ARM.unwind_idx : {                                             \
108                 __start_unwind_idx = .;                                 \
109 -               *(.ARM.exidx*)                                          \
110 +               KEEP(*(.ARM.exidx*))                                    \
111                 __stop_unwind_idx = .;                                  \
112         }                                                               \
113         .ARM.unwind_tab : {                                             \
114                 __start_unwind_tab = .;                                 \
115 -               *(.ARM.extab*)                                          \
116 +               KEEP(*(.ARM.extab*))                                    \
117                 __stop_unwind_tab = .;                                  \
118         }
119  
120 @@ -102,14 +102,14 @@
121  #define ARM_VECTORS                                                    \
122         __vectors_start = .;                                            \
123         .vectors 0xffff0000 : AT(__vectors_start) {                     \
124 -               *(.vectors)                                             \
125 +               KEEP(*(.vectors))                                       \
126         }                                                               \
127         . = __vectors_start + SIZEOF(.vectors);                         \
128         __vectors_end = .;                                              \
129                                                                         \
130         __stubs_start = .;                                              \
131         .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) {            \
132 -               *(.stubs)                                               \
133 +               KEEP(*(.stubs))                                         \
134         }                                                               \
135         . = __stubs_start + SIZEOF(.stubs);                             \
136         __stubs_end = .;                                                \