diff mbox series

[4/4] riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION

Message ID 20230511141211.2418-5-jszhang@kernel.org (mailing list archive)
State Superseded
Headers show
Series riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION | expand

Checks

Context Check Description
conchuod/tree_selection fail Failed to apply to next/pending-fixes or riscv/for-next

Commit Message

Jisheng Zhang May 11, 2023, 2:12 p.m. UTC
When trying to run linux with various opensource riscv core on
resource limited FPGA platforms, for example, those FPGAs with less
than 16MB SDRAM, I want to save mem as much as possible. One of the
major technologies is kernel size optimizations, I found that riscv
does not currently support HAVE_LD_DEAD_CODE_DATA_ELIMINATION, which
passes -fdata-sections, -ffunction-sections to CFLAGS and passes the
--gc-sections flag to the linker.

This not only benefits my case on FPGA but also benefits defconfigs.
Here are some notable improvements from enabling this with defconfigs:

nommu_k210_defconfig:
   text    data     bss     dec     hex
1112009  410288   59837 1582134  182436     before
 962838  376656   51285 1390779  1538bb     after

rv32_defconfig:
   text    data     bss     dec     hex
8804455 2816544  290577 11911576 b5c198     before
8692295 2779872  288977 11761144 b375f8     after

defconfig:
   text    data     bss     dec     hex
9438267 3391332  485333 13314932 cb2b74     before
9285914 3350052  483349 13119315 c82f53     after

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 arch/riscv/Kconfig              | 1 +
 arch/riscv/kernel/vmlinux.lds.S | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

Comments

Conor Dooley May 12, 2023, 1:58 p.m. UTC | #1
On Thu, May 11, 2023 at 10:12:11PM +0800, Jisheng Zhang wrote:

> diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> index e5f9f4677bbf..492dd4b8f3d6 100644
> --- a/arch/riscv/kernel/vmlinux.lds.S
> +++ b/arch/riscv/kernel/vmlinux.lds.S
> @@ -85,11 +85,11 @@ SECTIONS
>  	INIT_DATA_SECTION(16)
>  
>  	.init.pi : {
> -		*(.init.pi*)
> +		KEEP(*(.init.pi*))
>  	}

This section no longer exists in v6.4-rc1, it is now:
	/* Those sections result from the compilation of kernel/pi/string.c */
	.init.pidata : {
		*(.init.srodata.cst8*)
		*(.init__bug_table*)
		*(.init.sdata*)
	}

Cheers,
Conor.
Conor Dooley May 12, 2023, 3:16 p.m. UTC | #2
On Fri, May 12, 2023 at 02:58:49PM +0100, Conor Dooley wrote:
> On Thu, May 11, 2023 at 10:12:11PM +0800, Jisheng Zhang wrote:
> 
> > diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> > index e5f9f4677bbf..492dd4b8f3d6 100644
> > --- a/arch/riscv/kernel/vmlinux.lds.S
> > +++ b/arch/riscv/kernel/vmlinux.lds.S
> > @@ -85,11 +85,11 @@ SECTIONS
> >  	INIT_DATA_SECTION(16)
> >  
> >  	.init.pi : {
> > -		*(.init.pi*)
> > +		KEEP(*(.init.pi*))
> >  	}
> 
> This section no longer exists in v6.4-rc1, it is now:
> 	/* Those sections result from the compilation of kernel/pi/string.c */
> 	.init.pidata : {
> 		*(.init.srodata.cst8*)
> 		*(.init__bug_table*)
> 		*(.init.sdata*)
> 	}

Ahh, I see what has happened. This series was made on top of
riscv/fixes, but none of the patches are marked as a fix, leading to the
automation testing this as new content.

Sorry for the noise on this patch.
Jisheng Zhang May 12, 2023, 3:39 p.m. UTC | #3
On Fri, May 12, 2023 at 04:16:31PM +0100, Conor Dooley wrote:
> On Fri, May 12, 2023 at 02:58:49PM +0100, Conor Dooley wrote:
> > On Thu, May 11, 2023 at 10:12:11PM +0800, Jisheng Zhang wrote:
> > 
> > > diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> > > index e5f9f4677bbf..492dd4b8f3d6 100644
> > > --- a/arch/riscv/kernel/vmlinux.lds.S
> > > +++ b/arch/riscv/kernel/vmlinux.lds.S
> > > @@ -85,11 +85,11 @@ SECTIONS
> > >  	INIT_DATA_SECTION(16)
> > >  
> > >  	.init.pi : {
> > > -		*(.init.pi*)
> > > +		KEEP(*(.init.pi*))
> > >  	}
> > 
> > This section no longer exists in v6.4-rc1, it is now:
> > 	/* Those sections result from the compilation of kernel/pi/string.c */
> > 	.init.pidata : {
> > 		*(.init.srodata.cst8*)
> > 		*(.init__bug_table*)
> > 		*(.init.sdata*)
> > 	}
> 
> Ahh, I see what has happened. This series was made on top of
> riscv/fixes, but none of the patches are marked as a fix, leading to the

I need to touch the sections, and there's a fix in Palmer's tree which
will rename the section name, so rebased on the fix HEAD.

> automation testing this as new content.
> 
> Sorry for the noise on this patch.

Thank you for your review.
diff mbox series

Patch

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index f0663b52d052..a5feab2c3037 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -110,6 +110,7 @@  config RISCV
 	select HAVE_KPROBES if !XIP_KERNEL
 	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
 	select HAVE_KRETPROBES if !XIP_KERNEL
+	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
 	select HAVE_MOVE_PMD
 	select HAVE_MOVE_PUD
 	select HAVE_PCI
diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
index e5f9f4677bbf..492dd4b8f3d6 100644
--- a/arch/riscv/kernel/vmlinux.lds.S
+++ b/arch/riscv/kernel/vmlinux.lds.S
@@ -85,11 +85,11 @@  SECTIONS
 	INIT_DATA_SECTION(16)
 
 	.init.pi : {
-		*(.init.pi*)
+		KEEP(*(.init.pi*))
 	}
 
 	.init.bss : {
-		*(.init.bss)	/* from the EFI stub */
+		KEEP(*(.init.bss*))	/* from the EFI stub */
 	}
 	.exit.data :
 	{
@@ -112,7 +112,7 @@  SECTIONS
 	. = ALIGN(8);
 	.alternative : {
 		__alt_start = .;
-		*(.alternative)
+		KEEP(*(.alternative))
 		__alt_end = .;
 	}
 	__init_end = .;