2024-01-03 11:57:28 +00:00
|
|
|
From e3d8676f5722b7622685581e06e8f53e6138e3ab Mon Sep 17 00:00:00 2001
|
|
|
|
From: Felix Fietkau <nbd@nbd.name>
|
|
|
|
Date: Sat, 15 Jul 2017 23:42:36 +0200
|
|
|
|
Subject: use -ffunction-sections, -fdata-sections and --gc-sections
|
|
|
|
|
|
|
|
In combination with kernel symbol export stripping this significantly reduces
|
|
|
|
the kernel image size. Used on both ARM and MIPS architectures.
|
|
|
|
|
|
|
|
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
|
|
Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
|
|
|
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
|
|
|
|
---
|
|
|
|
--- a/arch/arm/Kconfig
|
|
|
|
+++ b/arch/arm/Kconfig
|
2024-03-08 14:04:26 +00:00
|
|
|
@@ -128,6 +128,7 @@ config ARM
|
2024-01-03 18:02:53 +00:00
|
|
|
select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU
|
2024-01-03 11:57:28 +00:00
|
|
|
select IRQ_FORCED_THREADING
|
|
|
|
select LOCK_MM_AND_FIND_VMA
|
|
|
|
+ select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
|
|
|
|
select MODULES_USE_ELF_REL
|
|
|
|
select NEED_DMA_MAP_STATE
|
|
|
|
select OF_EARLY_FLATTREE if OF
|
|
|
|
--- a/arch/arm/boot/compressed/Makefile
|
|
|
|
+++ b/arch/arm/boot/compressed/Makefile
|
2024-03-08 14:04:26 +00:00
|
|
|
@@ -92,6 +92,7 @@ endif
|
2024-01-03 11:57:28 +00:00
|
|
|
ifeq ($(CONFIG_USE_OF),y)
|
|
|
|
OBJS += $(libfdt_objs) fdt_check_mem_start.o
|
|
|
|
endif
|
|
|
|
+KBUILD_CFLAGS_KERNEL := $(patsubst -f%-sections,,$(KBUILD_CFLAGS_KERNEL))
|
|
|
|
|
|
|
|
OBJS += lib1funcs.o ashldi3.o bswapsdi2.o
|
|
|
|
|
|
|
|
--- a/arch/arm/kernel/vmlinux.lds.S
|
|
|
|
+++ b/arch/arm/kernel/vmlinux.lds.S
|
2024-03-08 14:04:26 +00:00
|
|
|
@@ -74,7 +74,7 @@ SECTIONS
|
2024-01-03 11:57:28 +00:00
|
|
|
. = ALIGN(4);
|
|
|
|
__ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
|
|
|
|
__start___ex_table = .;
|
|
|
|
- ARM_MMU_KEEP(*(__ex_table))
|
|
|
|
+ KEEP(*(__ex_table))
|
|
|
|
__stop___ex_table = .;
|
|
|
|
}
|
|
|
|
|
2024-03-08 14:04:26 +00:00
|
|
|
@@ -99,24 +99,24 @@ SECTIONS
|
2024-01-03 11:57:28 +00:00
|
|
|
}
|
|
|
|
.init.arch.info : {
|
|
|
|
__arch_info_begin = .;
|
|
|
|
- *(.arch.info.init)
|
|
|
|
+ KEEP(*(.arch.info.init))
|
|
|
|
__arch_info_end = .;
|
|
|
|
}
|
|
|
|
.init.tagtable : {
|
|
|
|
__tagtable_begin = .;
|
|
|
|
- *(.taglist.init)
|
|
|
|
+ KEEP(*(.taglist.init))
|
|
|
|
__tagtable_end = .;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_SMP_ON_UP
|
|
|
|
.init.smpalt : {
|
|
|
|
__smpalt_begin = .;
|
|
|
|
- *(.alt.smp.init)
|
|
|
|
+ KEEP(*(.alt.smp.init))
|
|
|
|
__smpalt_end = .;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
.init.pv_table : {
|
|
|
|
__pv_table_begin = .;
|
|
|
|
- *(.pv_table)
|
|
|
|
+ KEEP(*(.pv_table))
|
|
|
|
__pv_table_end = .;
|
|
|
|
}
|
|
|
|
|
|
|
|
--- a/arch/arm/include/asm/vmlinux.lds.h
|
|
|
|
+++ b/arch/arm/include/asm/vmlinux.lds.h
|
|
|
|
@@ -42,13 +42,13 @@
|
|
|
|
#define PROC_INFO \
|
|
|
|
. = ALIGN(4); \
|
|
|
|
__proc_info_begin = .; \
|
|
|
|
- *(.proc.info.init) \
|
|
|
|
+ KEEP(*(.proc.info.init)) \
|
|
|
|
__proc_info_end = .;
|
|
|
|
|
|
|
|
#define IDMAP_TEXT \
|
|
|
|
ALIGN_FUNCTION(); \
|
|
|
|
__idmap_text_start = .; \
|
|
|
|
- *(.idmap.text) \
|
|
|
|
+ KEEP(*(.idmap.text)) \
|
|
|
|
__idmap_text_end = .; \
|
|
|
|
|
|
|
|
#define ARM_DISCARD \
|
2024-03-08 14:04:26 +00:00
|
|
|
@@ -108,12 +108,12 @@
|
2024-01-03 11:57:28 +00:00
|
|
|
. = ALIGN(8); \
|
|
|
|
.ARM.unwind_idx : { \
|
|
|
|
__start_unwind_idx = .; \
|
|
|
|
- *(.ARM.exidx*) \
|
|
|
|
+ KEEP(*(.ARM.exidx*)) \
|
|
|
|
__stop_unwind_idx = .; \
|
|
|
|
} \
|
|
|
|
.ARM.unwind_tab : { \
|
|
|
|
__start_unwind_tab = .; \
|
|
|
|
- *(.ARM.extab*) \
|
|
|
|
+ KEEP(*(.ARM.extab*)) \
|
|
|
|
__stop_unwind_tab = .; \
|
|
|
|
}
|
|
|
|
|
2024-03-08 14:04:26 +00:00
|
|
|
@@ -125,7 +125,7 @@
|
2024-01-03 11:57:28 +00:00
|
|
|
__vectors_lma = .; \
|
|
|
|
OVERLAY 0xffff0000 : NOCROSSREFS AT(__vectors_lma) { \
|
|
|
|
.vectors { \
|
|
|
|
- *(.vectors) \
|
|
|
|
+ KEEP(*(.vectors)) \
|
|
|
|
} \
|
|
|
|
.vectors.bhb.loop8 { \
|
|
|
|
*(.vectors.bhb.loop8) \
|
2024-03-08 14:04:26 +00:00
|
|
|
@@ -143,7 +143,7 @@
|
2024-01-03 11:57:28 +00:00
|
|
|
\
|
|
|
|
__stubs_lma = .; \
|
|
|
|
.stubs ADDR(.vectors) + 0x1000 : AT(__stubs_lma) { \
|
|
|
|
- *(.stubs) \
|
|
|
|
+ KEEP(*(.stubs)) \
|
|
|
|
} \
|
|
|
|
ARM_LMA(__stubs, .stubs); \
|
|
|
|
. = __stubs_lma + SIZEOF(.stubs); \
|