riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION
Subsystems (2)
cover riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION
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
patch1 and patch2 are clean ups.
patch3 fixes a typo.
patch4 finally enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION for riscv.
Jisheng Zhang (4):
riscv: vmlinux-xip.lds.S: remove .alternative section
riscv: move HAVE_RETHOOK to keep entries sorted
riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION vmlinux.lds.h: use correct .init.data.* section name
arch/riscv/Kconfig | 3 ++- arch/riscv/kernel/vmlinux-xip.lds.S | 6 ------ arch/riscv/kernel/vmlinux.lds.S | 6 +++--- include/asm-generic/vmlinux.lds.h | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/4 riscv: vmlinux-xip.lds.S: remove .alternative section
ALTERNATIVE mechanism can't work on XIP, and this is also reflected by below Kconfig dependency:
RISCV_ALTERNATIVE
... depends on !XIP_KERNEL ...
So there's no .alternative section at all for XIP case, remove it.
--- arch/riscv/kernel/vmlinux-xip.lds.S | 6 ------ 1 file changed, 6 deletions(-)
arch/riscv/kernel/vmlinux-xip.lds.S +0 -6
@@ -98,12 +98,6 @@ SECTIONS __soc_builtin_dtb_table_end = .; } - . = ALIGN(8); - .alternative : { - __alt_start = .; - *(.alternative) - __alt_end = .; - } __init_end = .; . = ALIGN(16);
Signature · 1 line
2.40.1
Re: [PATCH 1/4] riscv: vmlinux-xip.lds.S: remove .alternative section
Quoted 11 lines · Jisheng Zhang
ALTERNATIVE mechanism can't work on XIP, and this is also reflected by below
Kconfigdependency:
RISCV_ALTERNATIVE... depends on !XIP_KERNEL ...So there's no .alternative section at all for XIP case, remove it.
Signed-off-by Jisheng Zhang <[email protected]>
Just to note, this series doesn't apply on top of -rc1 - what is the base that you used?
Cheers,
Conor.
Quoted 24 lines
--- arch/riscv/kernel/vmlinux-xip.lds.S | 6 ------ 1 file changed, 6 deletions(-)arch/riscv/kernel/vmlinux-xip.lds.S +0
-6@@ -98,12 +98,6 @@ SECTIONS __soc_builtin_dtb_table_end = .; } - . = ALIGN(8); - .alternative : { - __alt_start = .; - *(.alternative) - __alt_end = .; - } __init_end = .; . = ALIGN(16);Signature · 1 line
2.40.1
Re: [PATCH 1/4] riscv: vmlinux-xip.lds.S: remove .alternative section
Quoted 9 lines · Conor Dooley
Quoted 8 lines · Jisheng Zhang
ALTERNATIVE mechanism can't work on XIP, and this is also reflected by below
Kconfigdependency:
RISCV_ALTERNATIVE... depends on !XIP_KERNEL ...
Quoted 8 lines
Quoted 3 lines
So there's no .alternative section at all for XIP case, remove it.
Signed-off-by Jisheng Zhang <[email protected]>Reviewed-by Conor Dooley <[email protected]>Just to note, this series doesn't apply on top of -rc1 - what is the base that you used?
rc1 + Palmer's fix branch
Thanks
Quoted 28 lines
Cheers,
Conor.Quoted 24 lines
--- arch/riscv/kernel/vmlinux-xip.lds.S | 6 ------ 1 file changed, 6 deletions(-)arch/riscv/kernel/vmlinux-xip.lds.S +0
-6@@ -98,12 +98,6 @@ SECTIONS __soc_builtin_dtb_table_end = .; } - . = ALIGN(8); - .alternative : { - __alt_start = .; - *(.alternative) - __alt_end = .; - } __init_end = .; . = ALIGN(16);Signature · 1 line
2.40.1
PATCH 2/4 riscv: move HAVE_RETHOOK to keep entries sorted
In reply to Jisheng ZhangCommit b57c2f124098 ("riscv: add riscv rethook implementation") selects the HAVE_RETHOOK option for the first time in riscv, but it breaks the entries order. Properly move its location to keep entries sorted.
--- arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/Kconfig +1 -1
@@ -110,7 +110,6 @@ config RISCV select HAVE_KPROBES if !XIP_KERNEL select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL select HAVE_KRETPROBES if !XIP_KERNEL - select HAVE_RETHOOK if !XIP_KERNEL select HAVE_MOVE_PMD select HAVE_MOVE_PUD select HAVE_PCI
@@ -119,6 +118,7 @@ config RISCV select HAVE_PERF_USER_STACK_DUMP select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API + select HAVE_RETHOOK if !XIP_KERNEL select HAVE_RSEQ select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS
Signature · 1 line
2.40.1
Re: [PATCH 2/4] riscv: move HAVE_RETHOOK to keep entries sorted
Quoted 3 lines · Jisheng Zhang
Commit
b57c2f124098("riscv: add riscv rethook implementation") selects theHAVE_RETHOOKoption for the first time in riscv, but it breaks the entries order. Properly move its location to keep entries sorted.
The entries need a rework in general, but it's only really worth doing the whole lot during the merge window to avoid a rake of conflicts.
Thanks,
Conor.
Quoted 29 lines
Signed-off-by Jisheng Zhang <[email protected]>--- arch/riscv/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/Kconfig +1
-1@@ -110,7 +110,6 @@ config RISCV select HAVE_KPROBES if !XIP_KERNEL select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL select HAVE_KRETPROBES if !XIP_KERNEL - select HAVE_RETHOOK if !XIP_KERNEL select HAVE_MOVE_PMD select HAVE_MOVE_PUD select HAVE_PCI@@ -119,6 +118,7 @@ config RISCV select HAVE_PERF_USER_STACK_DUMP select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API + select HAVE_RETHOOK if !XIP_KERNEL select HAVE_RSEQ select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTSSignature · 1 line
2.40.1
PATCH 3/4 vmlinux.lds.h: use correct .init.data.* section name
In reply to Jisheng ZhangIf building with -fdata-sections on riscv, LD_ORPHAN_WARN will warn similar as below:
riscv64-linux-gnu-ld: warning: orphan section .init.data.efi_loglevel' from ./drivers/firmware/efi/libstub/printk.stub.o' being placed in section `.init.data.efi_loglevel'
I believe this is caused by a a typo:
init.data.* should be .init.data.*
--- include/asm-generic/vmlinux.lds.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/vmlinux.lds.h +1 -1
@@ -688,7 +688,7 @@/* init and exit section handling */ #define INIT_DATA \ KEEP(*(SORT(___kentry+*))) \ - *(.init.data init.data.*) \ + *(.init.data .init.data.*) \ MEM_DISCARD(init.data*) \ KERNEL_CTORS() \ MCOUNT_REC() \
Signature · 1 line
2.40.1
Re: [PATCH 3/4] vmlinux.lds.h: use correct .init.data.* section name
Quoted 4 lines · Jisheng Zhang
If building with -fdata-sections on riscv,
LD_ORPHAN_WARNwill warn similar as below:
Quoted 8 lines
riscv64-linux-gnu-ld: warning: orphan section
.init.data.efi_loglevel' from./drivers/firmware/efi/libstub/printk.stub.o' being placed in section `.init.data.efi_loglevel'I believe this is caused by a a typo:
init.data.* should be .init.data.*Signed-off-by Jisheng Zhang <[email protected]>
Seems it's a fixup for all architectures, what's the Fix: tag?
Quoted 20 lines
--- include/asm-generic/vmlinux.lds.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/asm-generic/vmlinux.lds.h +1
-2@@ -688,7 +688,7 @@/* init and exit section handling */ #define INIT_DATA \ KEEP(*(SORT(___kentry+*))) \ - *(.init.data init.data.*) \ + *(.init.data .init.data.*) \ MEM_DISCARD(init.data*) \ KERNEL_CTORS() \ MCOUNT_REC() \ --2.40.1
Signature · 2 lines
Best Regards Guo Ren
PATCH 4/4 riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION
In reply to Jisheng ZhangWhen 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
--- arch/riscv/Kconfig | 1 + arch/riscv/kernel/vmlinux.lds.S | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/riscv/Kconfig +1 -0
@@ -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
arch/riscv/kernel/vmlinux.lds.S +3 -3
@@ -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 = .;
Signature · 1 line
2.40.1
arch/riscv/kernel/vmlinux.lds.S SECTIONS · line 89
Quoted 11 lines · Jisheng Zhang
arch/riscv/kernel/vmlinux.lds.S +1
-1@@ -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.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 15 lines · Conor Dooley
arch/riscv/kernel/vmlinux.lds.S SECTIONS · line 89
Quoted 11 lines · Jisheng Zhang
arch/riscv/kernel/vmlinux.lds.S +1
-1@@ -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:
Quoted 6 lines
/* 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.
Quoted 23 lines · Conor Dooley
Quoted 15 lines · Conor Dooley
arch/riscv/kernel/vmlinux.lds.S SECTIONS · line 89
Quoted 11 lines · Jisheng Zhang
arch/riscv/kernel/vmlinux.lds.S +1
-1@@ -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:
Quoted 6 lines
/* Those sections result from the compilation of kernel/pi/string.c */ .init.pidata : { *(.init.srodata.cst8*) *(.init__bug_table*) *(.init.sdata*) }
Quoted 2 lines
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.
Quoted 3 lines
automation testing this as new content.
Sorry for the noise on this patch.
Thank you for your review.