[PATCH v2] x86/patches-5.4: enable DCDE for x86(-64)

Alberto Bursi bobafetthotmail at gmail.com
Mon Jan 4 19:47:52 EST 2021



On 05/01/21 01:09, Rui Salvaterra wrote:
> Port and adapt Nick Piggin's original patch [1]. This enables dead code and
> data elimination at linking time (gc-sections) on x86(-64).
> 
> openwrt-x86-64-generic-kernel.bin size, with my config:
> 
> Before:	3138048 bytes
> After:	2937344 bytes
> 
> In other words, we save about 200 kB.
> 
> [1] https://lore.kernel.org/lkml/20170709031333.29443-1-npiggin@gmail.com/
> 
> Signed-off-by: Rui Salvaterra <rsalvaterra at gmail.com>


That's big savings but on a target where space footprint is mostly 
irrelevant. I'm curious why you are doing this.

Is this just the testing stage for a bigger plan where you and/or 
someone else roll out similar modifications to other targets where space 
footprint actually matters?

-Alberto


> ---
> v2: move the patch to x86/patches-5.4.
> 
>   ...nable-dead-code-and-data-elimination.patch | 127 ++++++++++++++++++
>   1 file changed, 127 insertions(+)
>   create mode 100644 target/linux/x86/patches-5.4/350-x86-enable-dead-code-and-data-elimination.patch
> 
> diff --git a/target/linux/x86/patches-5.4/350-x86-enable-dead-code-and-data-elimination.patch b/target/linux/x86/patches-5.4/350-x86-enable-dead-code-and-data-elimination.patch
> new file mode 100644
> index 0000000000..392ddd71ce
> --- /dev/null
> +++ b/target/linux/x86/patches-5.4/350-x86-enable-dead-code-and-data-elimination.patch
> @@ -0,0 +1,127 @@
> +From f08a0e4e59f92b4a88501653761cbca08935b9b6 Mon Sep 17 00:00:00 2001
> +From: Rui Salvaterra <rsalvaterra at gmail.com>
> +Date: Wed, 4 Nov 2020 19:45:04 +0000
> +Subject: [PATCH] x86: enable dead code and data elimination
> +
> +Adapt Nick Piggin's original patch [1]. This saves nearly 300 kiB on the final
> +vmlinuz (zstd-compressed).
> +
> +[1] https://lore.kernel.org/lkml/20170709031333.29443-1-npiggin@gmail.com/
> +
> +Signed-off-by: Rui Salvaterra <rsalvaterra at gmail.com>
> +---
> + arch/x86/Kconfig              |  1 +
> + arch/x86/kernel/vmlinux.lds.S | 24 ++++++++++++------------
> + 2 files changed, 13 insertions(+), 12 deletions(-)
> +
> +--- a/arch/x86/Kconfig
> ++++ b/arch/x86/Kconfig
> +@@ -184,6 +184,7 @@ config X86
> + 	select HAVE_FUNCTION_ERROR_INJECTION
> + 	select HAVE_KRETPROBES
> + 	select HAVE_KVM
> ++	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
> + 	select HAVE_LIVEPATCH			if X86_64
> + 	select HAVE_MEMBLOCK_NODE_MAP
> + 	select HAVE_MIXED_BREAKPOINTS_REGS
> +--- a/arch/x86/kernel/vmlinux.lds.S
> ++++ b/arch/x86/kernel/vmlinux.lds.S
> +@@ -242,14 +242,14 @@ SECTIONS
> + 	 * See static_cpu_has() for an example.
> + 	 */
> + 	.altinstr_aux : AT(ADDR(.altinstr_aux) - LOAD_OFFSET) {
> +-		*(.altinstr_aux)
> ++		KEEP(*(.altinstr_aux))
> + 	}
> +
> + 	INIT_DATA_SECTION(16)
> +
> + 	.x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
> + 		__x86_cpu_dev_start = .;
> +-		*(.x86_cpu_dev.init)
> ++		KEEP(*(.x86_cpu_dev.init))
> + 		__x86_cpu_dev_end = .;
> + 	}
> +
> +@@ -257,7 +257,7 @@ SECTIONS
> + 	.x86_intel_mid_dev.init : AT(ADDR(.x86_intel_mid_dev.init) - \
> + 								LOAD_OFFSET) {
> + 		__x86_intel_mid_dev_start = .;
> +-		*(.x86_intel_mid_dev.init)
> ++		KEEP(*(.x86_intel_mid_dev.init))
> + 		__x86_intel_mid_dev_end = .;
> + 	}
> + #endif
> +@@ -271,7 +271,7 @@ SECTIONS
> + 	. = ALIGN(8);
> + 	.parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
> + 		__parainstructions = .;
> +-		*(.parainstructions)
> ++		KEEP(*(.parainstructions))
> + 		__parainstructions_end = .;
> + 	}
> +
> +@@ -283,7 +283,7 @@ SECTIONS
> + 	. = ALIGN(8);
> + 	.altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
> + 		__alt_instructions = .;
> +-		*(.altinstructions)
> ++		KEEP(*(.altinstructions))
> + 		__alt_instructions_end = .;
> + 	}
> +
> +@@ -293,7 +293,7 @@ SECTIONS
> + 	 * get the address and the length of them to patch the kernel safely.
> + 	 */
> + 	.altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
> +-		*(.altinstr_replacement)
> ++		KEEP(*(.altinstr_replacement))
> + 	}
> +
> + 	/*
> +@@ -304,14 +304,14 @@ SECTIONS
> + 	 */
> + 	.iommu_table : AT(ADDR(.iommu_table) - LOAD_OFFSET) {
> + 		__iommu_table = .;
> +-		*(.iommu_table)
> ++		KEEP(*(.iommu_table))
> + 		__iommu_table_end = .;
> + 	}
> +
> + 	. = ALIGN(8);
> + 	.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
> + 		__apicdrivers = .;
> +-		*(.apicdrivers);
> ++		KEEP(*(.apicdrivers))
> + 		__apicdrivers_end = .;
> + 	}
> +
> +@@ -346,7 +346,7 @@ SECTIONS
> + 	. = ALIGN(PAGE_SIZE);
> + 	.smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
> + 		__smp_locks = .;
> +-		*(.smp_locks)
> ++		KEEP(*(.smp_locks))
> + 		. = ALIGN(PAGE_SIZE);
> + 		__smp_locks_end = .;
> + 	}
> +@@ -380,8 +380,8 @@ SECTIONS
> + 	. = ALIGN(PAGE_SIZE);
> + 	.brk : AT(ADDR(.brk) - LOAD_OFFSET) {
> + 		__brk_base = .;
> +-		. += 64 * 1024;		/* 64k alignment slop space */
> +-		*(.brk_reservation)	/* areas brk users have reserved */
> ++		. += 64 * 1024;			/* 64k alignment slop space */
> ++		KEEP(*(.brk_reservation))	/* areas brk users have reserved */
> + 		__brk_limit = .;
> + 	}
> +
> +@@ -407,7 +407,7 @@ SECTIONS
> + 	. = ALIGN(HPAGE_SIZE);
> + 	.init.scratch : AT(ADDR(.init.scratch) - LOAD_OFFSET) {
> + 		__init_scratch_begin = .;
> +-		*(.init.scratch)
> ++		KEEP(*(.init.scratch))
> + 		. = ALIGN(HPAGE_SIZE);
> + 		__init_scratch_end = .;
> + 	}
> 



More information about the openwrt-devel mailing list