Skip to contentSkip to conversation

LD_DEAD_CODE_DATA_ELIMINATION fixes and enabling for powerpc

PATCH Superseded Nicholas Piggin 4 participants 22 messages Apr 20, 2018 – May 14, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nicholas Piggin

author reviewer
#0 lore raw

cover LD_DEAD_CODE_DATA_ELIMINATION fixes and enabling for powerpc

A few people have been interested in this again. And I promised if it remains dead code it should be removed, so I would like to have another try.

I think I got snagged on the modules problem last time and did not take the time to work it out, this time I just turned off the compile options for modules (the linker option was never set anyway so no loss).

This includes some linker script catches and ideas from others, I didn't documnt them all, but thanks for looking.

I would be interested to help other archs get this working too, if anybody needs some help.

Thanks,
Nick

Nicholas Piggin (4):
kbuild: Fix asm-generic/vmlinux.lds.h for
LD_DEAD_CODE_DATA_ELIMINATION
kbuild: LD_DEAD_CODE_DATA_ELIMINATION no
-ffunction-sections/-fdata-sections for module build
kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if
enabled
powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

 Makefile                          |  4 +--
 arch/Kconfig                      | 15 ----------
 arch/powerpc/Kconfig              |  1 +
 arch/powerpc/kernel/vmlinux.lds.S | 22 +++++++-------
 include/asm-generic/vmlinux.lds.h | 49 ++++++++++++++++++-------------
 init/Kconfig                      | 27 +++++++++++++++++
 6 files changed, 70 insertions(+), 48 deletions(-)
Signature · 1 line
2.17.0
author reviewer
#1 lore raw

PATCH 1/4 kbuild: Fix asm-generic/vmlinux.lds.h for LD_DEAD_CODE_DATA_ELIMINATION

KEEP more tables, and add the function/data section wildcard to more section selections.

This is a little ad-hoc at the moment, but kernel code should be moved to consistently use .text..x (note: double dots) for explicit sections and all references to it in the linker script can be made with TEXT_MAIN, and similarly for other sections.

For now, let's see if major architectures move to enabling this option then we can do some refactoring passes. Otherwise if it remains unused or superseded by LTO, this may not be required.

---
 include/asm-generic/vmlinux.lds.h | 49 ++++++++++++++++++-------------
 1 file changed, 29 insertions(+), 20 deletions(-)
include/asm-generic/vmlinux.lds.h +29 -20
index 278841c75b97..23f5f8d22f56 100644
@@ -64,15 +64,24 @@
  * generates .data.identifier sections, which need to be pulled in with
  * .data. We don't want to pull in .data..other sections, which Linux
  * has defined. Same for text and bss.
+ *
+ * RODATA_MAIN is not used because existing code already defines .rodata.x
+ * sections to be brought in with rodata.
  */
 #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
 #define DATA_MAIN .data .data.[0-9a-zA-Z_]*
+#define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
+#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]*
 #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]*
+#define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
 #else
 #define TEXT_MAIN .text
 #define DATA_MAIN .data
+#define SDATA_MAIN .sdata
+#define RODATA_MAIN .rodata
 #define BSS_MAIN .bss
+#define SBSS_MAIN .sbss
 #endif
 
 /*
@@ -105,7 +114,7 @@
 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
 #define MCOUNT_REC()	. = ALIGN(8);				\
 			VMLINUX_SYMBOL(__start_mcount_loc) = .; \
-			*(__mcount_loc)				\
+			KEEP(*(__mcount_loc))			\
 			VMLINUX_SYMBOL(__stop_mcount_loc) = .;
 #else
 #define MCOUNT_REC()
@@ -113,7 +122,7 @@
 
 #ifdef CONFIG_TRACE_BRANCH_PROFILING
 #define LIKELY_PROFILE()	VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \
-				*(_ftrace_annotated_branch)			      \
+				KEEP(*(_ftrace_annotated_branch))		      \
 				VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .;
 #else
 #define LIKELY_PROFILE()
@@ -121,7 +130,7 @@
 
 #ifdef CONFIG_PROFILE_ALL_BRANCHES
 #define BRANCH_PROFILE()	VMLINUX_SYMBOL(__start_branch_profile) = .;   \
-				*(_ftrace_branch)			      \
+				KEEP(*(_ftrace_branch))			      \
 				VMLINUX_SYMBOL(__stop_branch_profile) = .;
 #else
 #define BRANCH_PROFILE()
@@ -238,8 +247,8 @@
 	*(DATA_MAIN)							\
 	*(.ref.data)							\
 	*(.data..shared_aligned) /* percpu related */			\
-	MEM_KEEP(init.data)						\
-	MEM_KEEP(exit.data)						\
+	MEM_KEEP(init.data*)						\
+	MEM_KEEP(exit.data*)						\
 	*(.data.unlikely)						\
 	VMLINUX_SYMBOL(__start_once) = .;				\
 	*(.data.once)							\
@@ -289,8 +298,8 @@
 	VMLINUX_SYMBOL(__start_init_task) = .;				\
 	VMLINUX_SYMBOL(init_thread_union) = .;				\
 	VMLINUX_SYMBOL(init_stack) = .;					\
-	*(.data..init_task)						\
-	*(.data..init_thread_info)					\
+	KEEP(*(.data..init_task))					\
+	KEEP(*(.data..init_thread_info))				\
 	. = VMLINUX_SYMBOL(__start_init_task) + THREAD_SIZE;		\
 	VMLINUX_SYMBOL(__end_init_task) = .;
 
@@ -487,8 +496,8 @@
 		*(.text.hot TEXT_MAIN .text.fixup .text.unlikely)	\
 		*(.text..refcount)					\
 		*(.ref.text)						\
-	MEM_KEEP(init.text)						\
-	MEM_KEEP(exit.text)						\
+	MEM_KEEP(init.text*)						\
+	MEM_KEEP(exit.text*)						\
 
 
 /* sched.text is aling to function alignment to secure we have same
@@ -538,7 +547,7 @@
 		VMLINUX_SYMBOL(__softirqentry_text_end) = .;
 
 /* Section used for early init (in .S files) */
-#define HEAD_TEXT  *(.head.text)
+#define HEAD_TEXT  KEEP(*(.head.text))
 
 #define HEAD_TEXT_SECTION							\
 	.head.text : AT(ADDR(.head.text) - LOAD_OFFSET) {		\
@@ -579,11 +588,11 @@
 /* init and exit section handling */
 #define INIT_DATA							\
 	KEEP(*(SORT(___kentry+*)))					\
-	*(.init.data)							\
-	MEM_DISCARD(init.data)						\
+	*(.init.data init.data.*)					\
+	MEM_DISCARD(init.data*)						\
 	KERNEL_CTORS()							\
 	MCOUNT_REC()							\
-	*(.init.rodata)							\
+	*(.init.rodata .init.rodata.*)					\
 	FTRACE_EVENTS()							\
 	TRACE_SYSCALLS()						\
 	KPROBE_BLACKLIST()						\
@@ -602,16 +611,16 @@
 	EARLYCON_TABLE()
 
 #define INIT_TEXT							\
-	*(.init.text)							\
+	*(.init.text .init.text.*)					\
 	*(.text.startup)						\
-	MEM_DISCARD(init.text)
+	MEM_DISCARD(init.text*)
 
 #define EXIT_DATA							\
-	*(.exit.data)							\
+	*(.exit.data .exit.data.*)					\
 	*(.fini_array)							\
 	*(.dtors)							\
-	MEM_DISCARD(exit.data)						\
-	MEM_DISCARD(exit.rodata)
+	MEM_DISCARD(exit.data*)						\
+	MEM_DISCARD(exit.rodata*)
 
 #define EXIT_TEXT							\
 	*(.exit.text)							\
@@ -629,7 +638,7 @@
 	. = ALIGN(sbss_align);						\
 	.sbss : AT(ADDR(.sbss) - LOAD_OFFSET) {				\
 		*(.dynsbss)						\
-		*(.sbss)						\
+		*(SBSS_MAIN)						\
 		*(.scommon)						\
 	}
 
@@ -754,7 +763,7 @@
 #define NOTES								\
 	.notes : AT(ADDR(.notes) - LOAD_OFFSET) {			\
 		VMLINUX_SYMBOL(__start_notes) = .;			\
-		*(.note.*)						\
+		KEEP(*(.note.*))					\
 		VMLINUX_SYMBOL(__stop_notes) = .;			\
 	}
 
Signature · 1 line
2.17.0
author reviewer
#2 lore raw

PATCH 2/4 kbuild: LD_DEAD_CODE_DATA_ELIMINATION no -ffunction-sections/-fdata-sections for module build

In reply to Nicholas Piggin

Modules do not tend to cope with -ffunction-sections, even though they do not link with -gc-sections. It may be possible for unused symbols to be trimmed from modules, but in general that would take much more work in architecture module linker scripts.

For now, enable these only for kernel build.

---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
index e811e0c509c5..2ed651403bb4 100644
@@ -799,8 +799,8 @@ KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
 endif
 
 ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
-KBUILD_CFLAGS	+= $(call cc-option,-ffunction-sections,)
-KBUILD_CFLAGS	+= $(call cc-option,-fdata-sections,)
+KBUILD_CFLAGS_KERNEL	+= $(call cc-option,-ffunction-sections,)
+KBUILD_CFLAGS_KERNEL	+= $(call cc-option,-fdata-sections,)
 endif
 
 # arch Makefile may override CC so keep this after arch Makefile is included
Signature · 1 line
2.17.0
author reviewer
#3 lore raw

PATCH 3/4 kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if enabled

In reply to Nicholas Piggin

Architectures that are capable can select HAVE_LD_DEAD_CODE_DATA_ELIMINATION to enable selection of that option (as an EXPERT kernel option).

---
 arch/Kconfig | 15 ---------------
 init/Kconfig | 27 +++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 15 deletions(-)
arch/Kconfig +0 -15
index 8e0d665c8d53..3234b73d4626 100644
@@ -596,21 +596,6 @@ config CC_STACKPROTECTOR_AUTO
 
 endchoice
 
-config LD_DEAD_CODE_DATA_ELIMINATION
-	bool
-	help
-	  Select this if the architecture wants to do dead code and
-	  data elimination with the linker by compiling with
-	  -ffunction-sections -fdata-sections and linking with
-	  --gc-sections.
-
-	  This requires that the arch annotates or otherwise protects
-	  its external entry points from being discarded. Linker scripts
-	  must also merge .text.*, .data.*, and .bss.* correctly into
-	  output sections. Care must be taken not to pull in unrelated
-	  sections (e.g., '.text.init'). Typically '.' in section names
-	  is used to distinguish them from label names / C identifiers.
-
 config HAVE_ARCH_WITHIN_STACK_FRAMES
 	bool
 	help
init/Kconfig +27 -0
index f013afc74b11..1706d963766b 100644
@@ -1038,6 +1038,33 @@ config CC_OPTIMIZE_FOR_SIZE
 
 endchoice
 
+config HAVE_LD_DEAD_CODE_DATA_ELIMINATION
+	bool
+	help
+	  This requires that the arch annotates or otherwise protects
+	  its external entry points from being discarded. Linker scripts
+	  must also merge .text.*, .data.*, and .bss.* correctly into
+	  output sections. Care must be taken not to pull in unrelated
+	  sections (e.g., '.text.init'). Typically '.' in section names
+	  is used to distinguish them from label names / C identifiers.
+
+config LD_DEAD_CODE_DATA_ELIMINATION
+	bool "Dead code and data elimination (EXPERIMENTAL)"
+	depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION
+	depends on EXPERT
+	help
+	  Select this if the architecture wants to do dead code and
+	  data elimination with the linker by compiling with
+	  -ffunction-sections -fdata-sections, and linking with
+	  --gc-sections.
+
+	  This can reduce on disk and in-memory size of the kernel
+	  code and static data, particularly for small configs and
+	  on small systems. This has the possibility of introducing
+	  silently broken kernel if the required annotations are not
+	  present. This option is not well tested yet, so use at your
+	  own risk.
+
 config SYSCTL
 	bool
 
Signature · 1 line
2.17.0
author reviewer
#4 lore raw

PATCH 4/4 powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

In reply to Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

---
 arch/powerpc/Kconfig              |  1 +
 arch/powerpc/kernel/vmlinux.lds.S | 22 +++++++++++-----------
 2 files changed, 12 insertions(+), 11 deletions(-)
arch/powerpc/Kconfig +1 -0
index c32a181a7cbb..ee6dbe2efc8b 100644
@@ -205,6 +205,7 @@ config PPC
 	select HAVE_KPROBES
 	select HAVE_KPROBES_ON_FTRACE
 	select HAVE_KRETPROBES
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
 	select HAVE_LIVEPATCH			if HAVE_DYNAMIC_FTRACE_WITH_REGS
 	select HAVE_MEMBLOCK
 	select HAVE_MEMBLOCK_NODE_MAP
arch/powerpc/kernel/vmlinux.lds.S +11 -11
index c8af90ff49f0..89381dc959ce 100644
@@ -89,7 +89,7 @@ SECTIONS
 	 */
 	.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
 #ifdef CONFIG_LD_HEAD_STUB_CATCH
-		*(.linker_stub_catch);
+		KEEP(*(.linker_stub_catch));
 		. = . ;
 #endif
 
@@ -98,7 +98,7 @@ SECTIONS
 		ALIGN_FUNCTION();
 #endif
 		/* careful! __ftr_alt_* sections need to be close to .text */
-		*(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
+		*(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
@@ -170,10 +170,10 @@ SECTIONS
 	.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
 		INIT_DATA
 		__vtop_table_begin = .;
-		*(.vtop_fixup);
+		KEEP(*(.vtop_fixup));
 		__vtop_table_end = .;
 		__ptov_table_begin = .;
-		*(.ptov_fixup);
+		KEEP(*(.ptov_fixup));
 		__ptov_table_end = .;
 	}
 
@@ -194,26 +194,26 @@ SECTIONS
 	. = ALIGN(8);
 	__ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
 		__start___ftr_fixup = .;
-		*(__ftr_fixup)
+		KEEP(*(__ftr_fixup))
 		__stop___ftr_fixup = .;
 	}
 	. = ALIGN(8);
 	__mmu_ftr_fixup : AT(ADDR(__mmu_ftr_fixup) - LOAD_OFFSET) {
 		__start___mmu_ftr_fixup = .;
-		*(__mmu_ftr_fixup)
+		KEEP(*(__mmu_ftr_fixup))
 		__stop___mmu_ftr_fixup = .;
 	}
 	. = ALIGN(8);
 	__lwsync_fixup : AT(ADDR(__lwsync_fixup) - LOAD_OFFSET) {
 		__start___lwsync_fixup = .;
-		*(__lwsync_fixup)
+		KEEP(*(__lwsync_fixup))
 		__stop___lwsync_fixup = .;
 	}
 #ifdef CONFIG_PPC64
 	. = ALIGN(8);
 	__fw_ftr_fixup : AT(ADDR(__fw_ftr_fixup) - LOAD_OFFSET) {
 		__start___fw_ftr_fixup = .;
-		*(__fw_ftr_fixup)
+		KEEP(*(__fw_ftr_fixup))
 		__stop___fw_ftr_fixup = .;
 	}
 #endif
@@ -226,7 +226,7 @@ SECTIONS
 	. = ALIGN(8);
 	.machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
 		__machine_desc_start = . ;
-		*(.machine.desc)
+		KEEP(*(.machine.desc))
 		__machine_desc_end = . ;
 	}
 #ifdef CONFIG_RELOCATABLE
@@ -274,7 +274,7 @@ SECTIONS
 	.data : AT(ADDR(.data) - LOAD_OFFSET) {
 		DATA_DATA
 		*(.data.rel*)
-		*(.sdata)
+		*(SDATA_MAIN)
 		*(.sdata2)
 		*(.got.plt) *(.got)
 		*(.plt)
@@ -289,7 +289,7 @@ SECTIONS
 
 	.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
 		__start_opd = .;
-		*(.opd)
+		KEEP(*(.opd))
 		__end_opd = .;
 	}
 
Signature · 1 line
2.17.0
#5 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Quoted 6 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

Quoted 7 lines
text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

Quoted 114 lines
---
 arch/powerpc/Kconfig              |  1 +
 arch/powerpc/kernel/vmlinux.lds.S | 22 +++++++++++-----------
 2 files changed, 12 insertions(+), 11 deletions(-)
arch/powerpc/Kconfig +1 -0
index c32a181a7cbb..ee6dbe2efc8b 100644
@@ -205,6 +205,7 @@ config PPC
        select HAVE_KPROBES
        select HAVE_KPROBES_ON_FTRACE
        select HAVE_KRETPROBES
+       select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
        select HAVE_LIVEPATCH                   if HAVE_DYNAMIC_FTRACE_WITH_REGS
        select HAVE_MEMBLOCK
        select HAVE_MEMBLOCK_NODE_MAP
arch/powerpc/kernel/vmlinux.lds.S +11 -12
index c8af90ff49f0..89381dc959ce 100644
@@ -89,7 +89,7 @@ SECTIONS
         */
        .text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
 #ifdef CONFIG_LD_HEAD_STUB_CATCH
-               *(.linker_stub_catch);
+               KEEP(*(.linker_stub_catch));
                . = . ;
 #endif
 
@@ -98,7 +98,7 @@ SECTIONS
                ALIGN_FUNCTION();
 #endif
                /* careful! __ftr_alt_* sections need to be close to .text */
-               *(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
+               *(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
                SCHED_TEXT
                CPUIDLE_TEXT
                LOCK_TEXT
@@ -170,10 +170,10 @@ SECTIONS
        .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
                INIT_DATA
                __vtop_table_begin = .;
-               *(.vtop_fixup);
+               KEEP(*(.vtop_fixup));
                __vtop_table_end = .;
                __ptov_table_begin = .;
-               *(.ptov_fixup);
+               KEEP(*(.ptov_fixup));
                __ptov_table_end = .;
        }
 
@@ -194,26 +194,26 @@ SECTIONS
        . = ALIGN(8);
        __ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
                __start___ftr_fixup = .;
-               *(__ftr_fixup)
+               KEEP(*(__ftr_fixup))
                __stop___ftr_fixup = .;
        }
        . = ALIGN(8);
        __mmu_ftr_fixup : AT(ADDR(__mmu_ftr_fixup) - LOAD_OFFSET) {
                __start___mmu_ftr_fixup = .;
-               *(__mmu_ftr_fixup)
+               KEEP(*(__mmu_ftr_fixup))
                __stop___mmu_ftr_fixup = .;
        }
        . = ALIGN(8);
        __lwsync_fixup : AT(ADDR(__lwsync_fixup) - LOAD_OFFSET) {
                __start___lwsync_fixup = .;
-               *(__lwsync_fixup)
+               KEEP(*(__lwsync_fixup))
                __stop___lwsync_fixup = .;
        }
 #ifdef CONFIG_PPC64
        . = ALIGN(8);
        __fw_ftr_fixup : AT(ADDR(__fw_ftr_fixup) - LOAD_OFFSET) {
                __start___fw_ftr_fixup = .;
-               *(__fw_ftr_fixup)
+               KEEP(*(__fw_ftr_fixup))
                __stop___fw_ftr_fixup = .;
        }
 #endif
@@ -226,7 +226,7 @@ SECTIONS
        . = ALIGN(8);
        .machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
                __machine_desc_start = . ;
-               *(.machine.desc)
+               KEEP(*(.machine.desc))
                __machine_desc_end = . ;
        }
 #ifdef CONFIG_RELOCATABLE
@@ -274,7 +274,7 @@ SECTIONS
        .data : AT(ADDR(.data) - LOAD_OFFSET) {
                DATA_DATA
                *(.data.rel*)
-               *(.sdata)
+               *(SDATA_MAIN)
                *(.sdata2)
                *(.got.plt) *(.got)
                *(.plt)
@@ -289,7 +289,7 @@ SECTIONS
 
        .opd : AT(ADDR(.opd) - LOAD_OFFSET) {
                __start_opd = .;
-               *(.opd)
+               KEEP(*(.opd))
                __end_opd = .;
        }
 
--

2.17.0

author reviewer
#6 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Quoted 11 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 10 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde
Quoted 7 lines
Quoted 3 lines

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

Thanks,
Nick

#7 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Quoted 16 lines · Nicholas Piggin
Quoted 13 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 12 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

[ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

I've used /boot/config-4.15.0-2-powerpc from my current debian package. Rebuild master with and without option, boot ok, load/unload module ok.

$ size nick/vmlinux.with*
   text    data     bss     dec     hex filename
7386425 2364370 1425432 11176227 aa8923 nick/vmlinux.with
7461457 2475122 1428064 11364643 ad6923 nick/vmlinux.without

This is not clear why with option the size of kernel is slightly bigger:

$ du -sk nick/vmlinux.with*
124488 nick/vmlinux.with
124004 nick/vmlinux.without
Quoted 2 lines

Thanks,
Nick

author reviewer
#8 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Quoted 34 lines · On Fri, 20 Apr 2018 22:08:27 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 16 lines · Nicholas Piggin
Quoted 13 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 12 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

[ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

I've used /boot/config-4.15.0-2-powerpc from my current debian package. Rebuild master with and without option, boot ok, load/unload module ok.

$ size nick/vmlinux.with*
   text    data     bss     dec     hex filename
7386425 2364370 1425432 11176227 aa8923 nick/vmlinux.with
7461457 2475122 1428064 11364643 ad6923 nick/vmlinux.without
Quoted 5 lines

This is not clear why with option the size of kernel is slightly bigger:

$ du -sk nick/vmlinux.with*
124488 nick/vmlinux.with
124004 nick/vmlinux.without

Not sure. readelf -S vmlinux may show something.

To really get lots of detail, you can add to the top level Makefile:

LDFLAGS_vmlinux += -M

Then it will print the link map for you and other details. Actually it will output several times because we link vmlinux 2-3 times, so just take the last one. There is a lot of data there.

#9 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Nick,

Quoted 43 lines · Nicholas Piggin
Quoted 34 lines · On Fri, 20 Apr 2018 22:08:27 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 16 lines · Nicholas Piggin
Quoted 13 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 12 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

[ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

I've used /boot/config-4.15.0-2-powerpc from my current debian package. Rebuild master with and without option, boot ok, load/unload module ok.

$ size nick/vmlinux.with*
   text    data     bss     dec     hex filename
7386425 2364370 1425432 11176227 aa8923 nick/vmlinux.with
7461457 2475122 1428064 11364643 ad6923 nick/vmlinux.without
Quoted 5 lines

This is not clear why with option the size of kernel is slightly bigger:

$ du -sk nick/vmlinux.with*
124488 nick/vmlinux.with
124004 nick/vmlinux.without
Quoted 5 lines

Not sure. readelf -S vmlinux may show something.

To really get lots of detail, you can add to the top level Makefile:

LDFLAGS_vmlinux += -M

Here is what I did:

$ git diff
Makefile +1 -0
index 619a85ad716b..1a2e3d142a59 100644
@@ -4,6 +4,7 @@ PATCHLEVEL = 17
 SUBLEVEL = 0
 EXTRAVERSION = -rc3
 NAME = Fearless Coyote
+LDFLAGS_vmlinux += -M
 
 # *DOCUMENTATION*
 # To see a list of typical targets execute "make help"

Then:

$ rm ppc32/arch/powerpc/kernel/vmlinux.lds
$ make O=ppc32 ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- W=1 V=1

-> I did not see anything specific. I must be missing one step, but I don't see which one.

Quoted 4 lines

Then it will print the link map for you and other details. Actually it will output several times because we link vmlinux 2-3 times, so just take the last one. There is a lot of data there.

author reviewer
#10 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Quoted 60 lines · On Wed, 2 May 2018 11:17:52 +0200 Mathieu Malaterre <[email protected]> wrote:

Nick,

Quoted 43 lines · Nicholas Piggin
Quoted 34 lines · On Fri, 20 Apr 2018 22:08:27 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 16 lines · Nicholas Piggin
Quoted 13 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 12 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

[ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

I've used /boot/config-4.15.0-2-powerpc from my current debian package. Rebuild master with and without option, boot ok, load/unload module ok.

$ size nick/vmlinux.with*
   text    data     bss     dec     hex filename
7386425 2364370 1425432 11176227 aa8923 nick/vmlinux.with
7461457 2475122 1428064 11364643 ad6923 nick/vmlinux.without
Quoted 5 lines

This is not clear why with option the size of kernel is slightly bigger:

$ du -sk nick/vmlinux.with*
124488 nick/vmlinux.with
124004 nick/vmlinux.without  
Quoted 5 lines

Not sure. readelf -S vmlinux may show something.

To really get lots of detail, you can add to the top level Makefile:

LDFLAGS_vmlinux += -M

Here is what I did:

$ git diff
Makefile +0 -0
index 619a85ad716b..1a2e3d142a59 100644

Makefile PATCHLEVEL = 17 · line 7

Quoted 4 lines
Makefile +1 -0
@@ -4,6 +4,7 @@ PATCHLEVEL = 17
 SUBLEVEL = 0
 EXTRAVERSION = -rc3
 NAME = Fearless Coyote
+LDFLAGS_vmlinux += -M

That'll get overwritten further down. Put it down with another line that starts with LDFLAGS_vmlinux +=

Thanks,
Nick

#11 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Quoted 57 lines · Nicholas Piggin
Quoted 54 lines · On Wed, 2 May 2018 11:17:52 +0200 Mathieu Malaterre <[email protected]> wrote:

Nick,

Quoted 43 lines · Nicholas Piggin
Quoted 34 lines · On Fri, 20 Apr 2018 22:08:27 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 16 lines · Nicholas Piggin
Quoted 13 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 12 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

[ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

I've used /boot/config-4.15.0-2-powerpc from my current debian package. Rebuild master with and without option, boot ok, load/unload module ok.

$ size nick/vmlinux.with*
   text    data     bss     dec     hex filename
7386425 2364370 1425432 11176227 aa8923 nick/vmlinux.with
7461457 2475122 1428064 11364643 ad6923 nick/vmlinux.without
Quoted 5 lines

This is not clear why with option the size of kernel is slightly bigger:

$ du -sk nick/vmlinux.with*
124488 nick/vmlinux.with
124004 nick/vmlinux.without
Quoted 5 lines

Not sure. readelf -S vmlinux may show something.

To really get lots of detail, you can add to the top level Makefile:

LDFLAGS_vmlinux += -M

Here is what I did:

Quoted 13 lines

Makefile PATCHLEVEL = 17 · line 7

Quoted 10 lines
$ git diff
Makefile +1 -0
index 619a85ad716b..1a2e3d142a59 100644
@@ -4,6 +4,7 @@ PATCHLEVEL = 17
 SUBLEVEL = 0
 EXTRAVERSION = -rc3
 NAME = Fearless Coyote
+LDFLAGS_vmlinux += -M

That'll get overwritten further down. Put it down with another line that starts with LDFLAGS_vmlinux +=

Sorry about that, I was not paying attention :(

Anyway I cannot make sense of the output with -M.

Here is a quick summary if needed (with option / without option).

$ ./scripts/bloat-o-meter nick/vmlinux.without nick/vmlinux.with | head
add/remove: 0/647 grow/shrink: 852/1846 up/down: 11276/-95033 (-83757)
Function                                     old     new   delta
SiSInitPtr                                  2212    2600    +388
xmon_core.isra                              7540    7900    +360
ata_attach_transport                         840    1032    +192
via_pmu_interrupt                           2828    3004    +176
matroxfb_init                               3000    3156    +156
fbcon_scroll                                3092    3248    +156
__do_adjtimex                               1716    1868    +152
fbcon_event_notify                          2044    2184    +140
$ ./scripts/bloat-o-meter nick/vmlinux.without nick/vmlinux.with | tail
aty_set_pll18818                             540       -    -540
sel_ib_pkey_sid                              556       -    -556
pci_dev_acs_enabled                          608       -    -608
aa_label_find_merge                          752       -    -752
drmem_update_dt                              796       -    -796
powerpc_macros                              1176       -   -1176
ima_restore_measurement_list                1224       -   -1224
rtas_os_term_buf                            2048       -   -2048
vle_opcodes                                 8200       -   -8200
Total: Before=9927171, After=9843414, chg -0.84%
Quoted 2 lines

Thanks,
Nick

#12 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

In reply to Mathieu Malaterre

Le 20/04/2018 à 22:08, Mathieu Malaterre a écrit :

Quoted 29 lines · Nicholas Piggin
Quoted 16 lines
Quoted 13 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 12 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

[ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

I've used /boot/config-4.15.0-2-powerpc from my current debian package. Rebuild master with and without option, boot ok, load/unload module ok.

Quoted 6 lines
$ size nick/vmlinux.with*
    text    data     bss     dec     hex filename
7386425 2364370 1425432 11176227 aa8923 nick/vmlinux.with
7461457 2475122 1428064 11364643 ad6923 nick/vmlinux.without

This is not clear why with option the size of kernel is slightly bigger:

The file contains also debug symbols, which might differ.
Only the LOAD part of the file is interesting, that's the part you get when doing ppc-linux-objcopy vmlinux vmlinux.bin -O binary

You can see it with readelf -l vmlinux

Christophe

Quoted 8 lines
$ du -sk nick/vmlinux.with*
124488 nick/vmlinux.with
124004 nick/vmlinux.without
Quoted 2 lines

Thanks,
Nick

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

#13 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Christophe,

Quoted 45 lines · christophe leroy
Quoted 42 lines · Mathieu Malaterre
Quoted 22 lines · Nicholas Piggin
Quoted 18 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 14 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

Quoted 6 lines
Quoted 3 lines

^^^

Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

I've used /boot/config-4.15.0-2-powerpc from my current debian package. Rebuild master with and without option, boot ok, load/unload module ok.

$ size nick/vmlinux.with*
    text    data     bss     dec     hex filename
7386425 2364370 1425432 11176227 aa8923 nick/vmlinux.with
7461457 2475122 1428064 11364643 ad6923 nick/vmlinux.without
Quoted 8 lines
Quoted 1 line

This is not clear why with option the size of kernel is slightly bigger:

The file contains also debug symbols, which might differ.
Only the LOAD part of the file is interesting, that's the part you get when doing ppc-linux-objcopy vmlinux vmlinux.bin -O binary

You can see it with readelf -l vmlinux

Here is what I see:

$ diff -u <(readelf -l nick/vmlinux.with) <(readelf -l nick/vmlinux.without)
--- /proc/self/fd/11 2018-04-23 12:59:52.413101612 +0200
+++ /proc/self/fd/12 2018-04-23 12:59:52.417101567 +0200
@@ -5,9 +5,9 @@

Program Headers:

   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
-  LOAD           0x010000 0xc0000000 0x00000000 0x950f34 0xaad018 RWE 0x10000
-  NOTE           0x867640 0xc0857640 0x00857640 0x00024 0x00024     0x4
-  NOTE           0x867664 0xc0857664 0x00857664 0x0000c 0x0000c     0x1
+  LOAD           0x010000 0xc0000000 0x00000000 0x97ef34 0xadba68 RWE 0x10000
+  NOTE           0x87f640 0xc086f640 0x0086f640 0x00024 0x00024     0x4
+  NOTE           0x87f664 0xc086f664 0x0086f664 0x0000c 0x0000c     0x1

Section to Segment mapping:
Segment Sections...

Quoted 17 lines

Christophe

Quoted 8 lines
$ du -sk nick/vmlinux.with*
124488 nick/vmlinux.with
124004 nick/vmlinux.without
Quoted 2 lines

Thanks,
Nick

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

#14 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

In reply to Nicholas Piggin

Hi Nicholas,

2018-04-20 19:41 GMT+09:00 Nicholas Piggin <[email protected]>:

Quoted 18 lines
Quoted 15 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 13 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

Quoted 8 lines
Quoted 3 lines

^^^

Do you want somebody else to provide those numbers ?

If you have a booting kernel, yes some more numbers would be good.

Thanks,
Nick

I applied this series because I want it to be more tested in linux-next.

Some requests:

- Could you provide information to replace '[ppc32 numbers here]'? (or just remove it)

- V2 is welcome if you have code improvement.
(I thought so from your comments)

Thanks.

Signature · 2 lines
Best Regards
Masahiro Yamada
author reviewer
#15 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Quoted 25 lines · On Mon, 7 May 2018 09:46:43 +0900 Masahiro Yamada…

Hi Nicholas,

2018-04-20 19:41 GMT+09:00 Nicholas Piggin <[email protected]>:

Quoted 22 lines
Quoted 18 lines · On Fri, 20 Apr 2018 12:00:49 +0200 Mathieu Malaterre <[email protected]> wrote:
Quoted 6 lines · Nicholas Piggin

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

Quoted 7 lines
text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

^^^

Do you want somebody else to provide those numbers ?

Quoted 8 lines
Quoted 4 lines

If you have a booting kernel, yes some more numbers would be good.

Thanks,
Nick

I applied this series because I want it to be more tested in linux-next.

Thank you.

Quoted 4 lines

Some requests:

- Could you provide information to replace '[ppc32 numbers here]'? (or just remove it)

Yes there were some numbers reported, I can give you an updated changelog.

Quoted 2 lines

- V2 is welcome if you have code improvement.
(I thought so from your comments)

I'll see where it ended up and send you updated patches if necessary.

Thanks,
Nick

#16 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

In reply to Nicholas Piggin

Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :

Quoted 46 lines

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

---
  arch/powerpc/Kconfig              |  1 +
  arch/powerpc/kernel/vmlinux.lds.S | 22 +++++++++++-----------
  2 files changed, 12 insertions(+), 11 deletions(-)
arch/powerpc/Kconfig +1 -0
index c32a181a7cbb..ee6dbe2efc8b 100644
@@ -205,6 +205,7 @@ config PPC
  	select HAVE_KPROBES
  	select HAVE_KPROBES_ON_FTRACE
  	select HAVE_KRETPROBES
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
  	select HAVE_LIVEPATCH			if HAVE_DYNAMIC_FTRACE_WITH_REGS
  	select HAVE_MEMBLOCK
  	select HAVE_MEMBLOCK_NODE_MAP
arch/powerpc/kernel/vmlinux.lds.S +1 -1
index c8af90ff49f0..89381dc959ce 100644
@@ -89,7 +89,7 @@ SECTIONS
  	 */
  	.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
  #ifdef CONFIG_LD_HEAD_STUB_CATCH
-		*(.linker_stub_catch);
+		KEEP(*(.linker_stub_catch));
  		. = . ;
  #endif
 

arch/powerpc/kernel/vmlinux.lds.S SECTIONS · line 101

Quoted 5 lines
arch/powerpc/kernel/vmlinux.lds.S +1 -1
@@ -98,7 +98,7 @@ SECTIONS
  		ALIGN_FUNCTION();
  #endif
  		/* careful! __ftr_alt_* sections need to be close to .text */
-		*(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
+		*(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);

Why not use TEXT_MAIN here instead of .text .text.[0-9a-zA-Z_]* ?

Christophe

Quoted 75 lines
arch/powerpc/kernel/vmlinux.lds.S +9 -9
  		SCHED_TEXT
  		CPUIDLE_TEXT
  		LOCK_TEXT
@@ -170,10 +170,10 @@ SECTIONS
  	.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
  		INIT_DATA
  		__vtop_table_begin = .;
-		*(.vtop_fixup);
+		KEEP(*(.vtop_fixup));
  		__vtop_table_end = .;
  		__ptov_table_begin = .;
-		*(.ptov_fixup);
+		KEEP(*(.ptov_fixup));
  		__ptov_table_end = .;
  	}
 
@@ -194,26 +194,26 @@ SECTIONS
  	. = ALIGN(8);
  	__ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
  		__start___ftr_fixup = .;
-		*(__ftr_fixup)
+		KEEP(*(__ftr_fixup))
  		__stop___ftr_fixup = .;
  	}
  	. = ALIGN(8);
  	__mmu_ftr_fixup : AT(ADDR(__mmu_ftr_fixup) - LOAD_OFFSET) {
  		__start___mmu_ftr_fixup = .;
-		*(__mmu_ftr_fixup)
+		KEEP(*(__mmu_ftr_fixup))
  		__stop___mmu_ftr_fixup = .;
  	}
  	. = ALIGN(8);
  	__lwsync_fixup : AT(ADDR(__lwsync_fixup) - LOAD_OFFSET) {
  		__start___lwsync_fixup = .;
-		*(__lwsync_fixup)
+		KEEP(*(__lwsync_fixup))
  		__stop___lwsync_fixup = .;
  	}
  #ifdef CONFIG_PPC64
  	. = ALIGN(8);
  	__fw_ftr_fixup : AT(ADDR(__fw_ftr_fixup) - LOAD_OFFSET) {
  		__start___fw_ftr_fixup = .;
-		*(__fw_ftr_fixup)
+		KEEP(*(__fw_ftr_fixup))
  		__stop___fw_ftr_fixup = .;
  	}
  #endif
@@ -226,7 +226,7 @@ SECTIONS
  	. = ALIGN(8);
  	.machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
  		__machine_desc_start = . ;
-		*(.machine.desc)
+		KEEP(*(.machine.desc))
  		__machine_desc_end = . ;
  	}
  #ifdef CONFIG_RELOCATABLE
@@ -274,7 +274,7 @@ SECTIONS
  	.data : AT(ADDR(.data) - LOAD_OFFSET) {
  		DATA_DATA
  		*(.data.rel*)
-		*(.sdata)
+		*(SDATA_MAIN)
  		*(.sdata2)
  		*(.got.plt) *(.got)
  		*(.plt)
@@ -289,7 +289,7 @@ SECTIONS
 
  	.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
  		__start_opd = .;
-		*(.opd)
+		KEEP(*(.opd))
  		__end_opd = .;
  	}
 
author reviewer
#17 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Quoted 46 lines · On Fri, 20 Apr 2018 12:01:34 +0200 Christophe LEROY <[email protected]>…

Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :

Quoted 45 lines

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

---
  arch/powerpc/Kconfig              |  1 +
  arch/powerpc/kernel/vmlinux.lds.S | 22 +++++++++++-----------
  2 files changed, 12 insertions(+), 11 deletions(-)
arch/powerpc/Kconfig +1 -0
index c32a181a7cbb..ee6dbe2efc8b 100644
@@ -205,6 +205,7 @@ config PPC
  	select HAVE_KPROBES
  	select HAVE_KPROBES_ON_FTRACE
  	select HAVE_KRETPROBES
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
  	select HAVE_LIVEPATCH			if HAVE_DYNAMIC_FTRACE_WITH_REGS
  	select HAVE_MEMBLOCK
  	select HAVE_MEMBLOCK_NODE_MAP
arch/powerpc/kernel/vmlinux.lds.S +1 -1
index c8af90ff49f0..89381dc959ce 100644
@@ -89,7 +89,7 @@ SECTIONS
  	 */
  	.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
  #ifdef CONFIG_LD_HEAD_STUB_CATCH
-		*(.linker_stub_catch);
+		KEEP(*(.linker_stub_catch));
  		. = . ;
  #endif
 
Quoted 8 lines

arch/powerpc/kernel/vmlinux.lds.S SECTIONS · line 101

Quoted 6 lines
arch/powerpc/kernel/vmlinux.lds.S +1 -1
@@ -98,7 +98,7 @@ SECTIONS
  		ALIGN_FUNCTION();
  #endif
  		/* careful! __ftr_alt_* sections need to be close to .text */
-		*(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
+		*(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);  

Why not use TEXT_MAIN here instead of .text .text.[0-9a-zA-Z_]* ?

It's from my early patch before we added those in the generic linker script. Yes your version looks nicer.

Thanks,
Nick

#18 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

Le 20/04/2018 à 12:36, Nicholas Piggin a écrit :

Quoted 10 lines
Quoted 7 lines · On Fri, 20 Apr 2018 12:01:34 +0200 Christophe LEROY <[email protected]>…

Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :

Quoted 6 lines

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

Here a few results, obtained with readelf -l vmlinux | grep LOAD

First val is filesz, second is memsz, for each config you get the size before and after activation of LD_DCDE, and the difference between the two.

mpc83xx_defconfig:

Before: 0x5ecfe0 0x60b69c
After:  0x5d2fe0 0x5f04a4
Diff:   0x01a000 0x01b4c8

mpc83xx_defconfig without CONFIG_MODULE:

Before: 0x5c1040 0x5e0614
After:  0x55f040 0x57d314
Diff:   0x062000 0x063300

mpc885_ads_defconfig:

Before: 0x36eda4 0x38da04
After:  0x316da4 0x333764
Diff:   0x058000 0x05a2a0

Custom mpc885 config:

Before: 0x719948 0x78bc34
After:  0x6b9948 0x72a99c
Diff:   0x060000 0x061298

Custom mpc8321 config:

Before: 0x70f714 0x7d766c
After:  0x6af714 0x7763ec
Diff:   0x060000 0x061280
Quoted 47 lines
Quoted 32 lines
Quoted 32 lines
---
   arch/powerpc/Kconfig              |  1 +
   arch/powerpc/kernel/vmlinux.lds.S | 22 +++++++++++-----------
   2 files changed, 12 insertions(+), 11 deletions(-)
arch/powerpc/Kconfig +1 -0
index c32a181a7cbb..ee6dbe2efc8b 100644
@@ -205,6 +205,7 @@ config PPC
   	select HAVE_KPROBES
   	select HAVE_KPROBES_ON_FTRACE
   	select HAVE_KRETPROBES
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
   	select HAVE_LIVEPATCH			if HAVE_DYNAMIC_FTRACE_WITH_REGS
   	select HAVE_MEMBLOCK
   	select HAVE_MEMBLOCK_NODE_MAP
arch/powerpc/kernel/vmlinux.lds.S +1 -1
index c8af90ff49f0..89381dc959ce 100644
@@ -89,7 +89,7 @@ SECTIONS
   	 */
   	.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
   #ifdef CONFIG_LD_HEAD_STUB_CATCH
-		*(.linker_stub_catch);
+		KEEP(*(.linker_stub_catch));
   		. = . ;
   #endif
 
Quoted 8 lines

arch/powerpc/kernel/vmlinux.lds.S SECTIONS · line 101

Quoted 6 lines
arch/powerpc/kernel/vmlinux.lds.S +1 -1
@@ -98,7 +98,7 @@ SECTIONS
   		ALIGN_FUNCTION();
   #endif
   		/* careful! __ftr_alt_* sections need to be close to .text */
-		*(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
+		*(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);

Why not use TEXT_MAIN here instead of .text .text.[0-9a-zA-Z_]* ?

It's from my early patch before we added those in the generic linker script. Yes your version looks nicer.

Thanks,
Nick

Tested-by on v1 4/4
#19 lore raw

Re: [PATCH 4/4] powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

In reply to Nicholas Piggin

Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :

Quoted 10 lines

This requires further changes to linker script to KEEP some tables and wildcard compiler generated sections into the right place. This includes pp32 modifications from Christophe Leroy.

When compiling powernv_defconfig with this option:

text       data      bss       dec        filename
11827621   4810490   1341080   17979191   vmlinux
11752437   4598858   1338776   17690071   vmlinux.dcde
Quoted 5 lines

Resulting kernel is almost 400kB smaller (and still boots).

[ppc32 numbers here]

Tested on MPC885 and MPC8321E, CONFIG_MODULE unset.

Christophe

Quoted 111 lines
---
  arch/powerpc/Kconfig              |  1 +
  arch/powerpc/kernel/vmlinux.lds.S | 22 +++++++++++-----------
  2 files changed, 12 insertions(+), 11 deletions(-)
arch/powerpc/Kconfig +1 -0
index c32a181a7cbb..ee6dbe2efc8b 100644
@@ -205,6 +205,7 @@ config PPC
  	select HAVE_KPROBES
  	select HAVE_KPROBES_ON_FTRACE
  	select HAVE_KRETPROBES
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
  	select HAVE_LIVEPATCH			if HAVE_DYNAMIC_FTRACE_WITH_REGS
  	select HAVE_MEMBLOCK
  	select HAVE_MEMBLOCK_NODE_MAP
arch/powerpc/kernel/vmlinux.lds.S +11 -11
index c8af90ff49f0..89381dc959ce 100644
@@ -89,7 +89,7 @@ SECTIONS
  	 */
  	.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
  #ifdef CONFIG_LD_HEAD_STUB_CATCH
-		*(.linker_stub_catch);
+		KEEP(*(.linker_stub_catch));
  		. = . ;
  #endif
 
@@ -98,7 +98,7 @@ SECTIONS
  		ALIGN_FUNCTION();
  #endif
  		/* careful! __ftr_alt_* sections need to be close to .text */
-		*(.text.hot .text .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
+		*(.text.hot .text .text.[0-9a-zA-Z_]* .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
  		SCHED_TEXT
  		CPUIDLE_TEXT
  		LOCK_TEXT
@@ -170,10 +170,10 @@ SECTIONS
  	.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
  		INIT_DATA
  		__vtop_table_begin = .;
-		*(.vtop_fixup);
+		KEEP(*(.vtop_fixup));
  		__vtop_table_end = .;
  		__ptov_table_begin = .;
-		*(.ptov_fixup);
+		KEEP(*(.ptov_fixup));
  		__ptov_table_end = .;
  	}
 
@@ -194,26 +194,26 @@ SECTIONS
  	. = ALIGN(8);
  	__ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
  		__start___ftr_fixup = .;
-		*(__ftr_fixup)
+		KEEP(*(__ftr_fixup))
  		__stop___ftr_fixup = .;
  	}
  	. = ALIGN(8);
  	__mmu_ftr_fixup : AT(ADDR(__mmu_ftr_fixup) - LOAD_OFFSET) {
  		__start___mmu_ftr_fixup = .;
-		*(__mmu_ftr_fixup)
+		KEEP(*(__mmu_ftr_fixup))
  		__stop___mmu_ftr_fixup = .;
  	}
  	. = ALIGN(8);
  	__lwsync_fixup : AT(ADDR(__lwsync_fixup) - LOAD_OFFSET) {
  		__start___lwsync_fixup = .;
-		*(__lwsync_fixup)
+		KEEP(*(__lwsync_fixup))
  		__stop___lwsync_fixup = .;
  	}
  #ifdef CONFIG_PPC64
  	. = ALIGN(8);
  	__fw_ftr_fixup : AT(ADDR(__fw_ftr_fixup) - LOAD_OFFSET) {
  		__start___fw_ftr_fixup = .;
-		*(__fw_ftr_fixup)
+		KEEP(*(__fw_ftr_fixup))
  		__stop___fw_ftr_fixup = .;
  	}
  #endif
@@ -226,7 +226,7 @@ SECTIONS
  	. = ALIGN(8);
  	.machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
  		__machine_desc_start = . ;
-		*(.machine.desc)
+		KEEP(*(.machine.desc))
  		__machine_desc_end = . ;
  	}
  #ifdef CONFIG_RELOCATABLE
@@ -274,7 +274,7 @@ SECTIONS
  	.data : AT(ADDR(.data) - LOAD_OFFSET) {
  		DATA_DATA
  		*(.data.rel*)
-		*(.sdata)
+		*(SDATA_MAIN)
  		*(.sdata2)
  		*(.got.plt) *(.got)
  		*(.plt)
@@ -289,7 +289,7 @@ SECTIONS
 
  	.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
  		__start_opd = .;
-		*(.opd)
+		KEEP(*(.opd))
  		__end_opd = .;
  	}
 
Tested-by on the v1 series
#20 lore raw
In reply to Nicholas Piggin
Quoted 11 lines · Nicholas Piggin

A few people have been interested in this again. And I promised if it remains dead code it should be removed, so I would like to have another try.

I think I got snagged on the modules problem last time and did not take the time to work it out, this time I just turned off the compile options for modules (the linker option was never set anyway so no loss).

This includes some linker script catches and ideas from others, I didn't documnt them all, but thanks for looking.

This series works for me. v2 from Christophe was triggering a kernel panic (call stack mentioned set_pte_at...).

So if needed:

Env: Mac Mini G4, with custom config.

Quoted 26 lines

I would be interested to help other archs get this working too, if anybody needs some help.

Thanks,
Nick

Nicholas Piggin (4):
kbuild: Fix asm-generic/vmlinux.lds.h for
LD_DEAD_CODE_DATA_ELIMINATION
kbuild: LD_DEAD_CODE_DATA_ELIMINATION no
-ffunction-sections/-fdata-sections for module build
kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if
enabled
powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

 Makefile                          |  4 +--
 arch/Kconfig                      | 15 ----------
 arch/powerpc/Kconfig              |  1 +
 arch/powerpc/kernel/vmlinux.lds.S | 22 +++++++-------
 include/asm-generic/vmlinux.lds.h | 49 ++++++++++++++++++-------------
 init/Kconfig                      | 27 +++++++++++++++++
 6 files changed, 70 insertions(+), 48 deletions(-)

--
2.17.0

#21 lore raw
In reply to Nicholas Piggin

Le 20/04/2018 à 09:34, Nicholas Piggin a écrit :

Quoted 11 lines

A few people have been interested in this again. And I promised if it remains dead code it should be removed, so I would like to have another try.

I think I got snagged on the modules problem last time and did not take the time to work it out, this time I just turned off the compile options for modules (the linker option was never set anyway so no loss).

This includes some linker script catches and ideas from others, I didn't documnt them all, but thanks for looking.

Thanks a lot.

It works well on both my 8xx and 83xx targets. I don't have CONFIG_MODULE set.

Christophe

Quoted 24 lines

I would be interested to help other archs get this working too, if anybody needs some help.

Thanks,
Nick

Nicholas Piggin (4):
kbuild: Fix asm-generic/vmlinux.lds.h for
LD_DEAD_CODE_DATA_ELIMINATION
kbuild: LD_DEAD_CODE_DATA_ELIMINATION no
-ffunction-sections/-fdata-sections for module build
kbuild: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selectable if
enabled
powerpc: Allow LD_DEAD_CODE_DATA_ELIMINATION to be selected

  Makefile                          |  4 +--
  arch/Kconfig                      | 15 ----------
  arch/powerpc/Kconfig              |  1 +
  arch/powerpc/kernel/vmlinux.lds.S | 22 +++++++-------
  include/asm-generic/vmlinux.lds.h | 49 ++++++++++++++++++-------------
  init/Kconfig                      | 27 +++++++++++++++++
  6 files changed, 70 insertions(+), 48 deletions(-)