Unverified Commit 782aefb1 authored by Palmer Dabbelt's avatar Palmer Dabbelt
Browse files

Merge patch series "riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION"

Jisheng Zhang <jszhang@kernel.org> says:

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.

* b4-shazam-merge:
  riscv: disable HAVE_LD_DEAD_CODE_DATA_ELIMINATION for LLD
  riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION
  vmlinux.lds.h: use correct .init.data.* section name
  riscv: vmlinux-xip.lds.S: remove .alternative section
  riscv: move options to keep entries sorted
  riscv: Fix orphan section warnings caused by kernel/pi

Link: https://lore.kernel.org/r/20230523165502.2592-1-jszhang@kernel.org


Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parents e50db34e f7584322
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -105,6 +105,11 @@ config RISCV
	select HAVE_CONTEXT_TRACKING_USER
	select HAVE_DEBUG_KMEMLEAK
	select HAVE_DMA_CONTIGUOUS if MMU
	select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
	select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
	select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
	select HAVE_FUNCTION_GRAPH_TRACER
	select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION
	select HAVE_EBPF_JIT if MMU
	select HAVE_FUNCTION_ARG_ACCESS_API
	select HAVE_FUNCTION_ERROR_INJECTION
@@ -114,7 +119,8 @@ 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
	# https://github.com/ClangBuiltLinux/linux/issues/1881
	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if !LD_IS_LLD
	select HAVE_MOVE_PMD
	select HAVE_MOVE_PUD
	select HAVE_PCI
@@ -123,6 +129,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
@@ -148,11 +155,6 @@ config RISCV
	select TRACE_IRQFLAGS_SUPPORT
	select UACCESS_MEMCPY if !MMU
	select ZONE_DMA32 if 64BIT
	select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
	select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
	select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
	select HAVE_FUNCTION_GRAPH_TRACER
	select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION

config CLANG_SUPPORTS_DYNAMIC_FTRACE
	def_bool CC_IS_CLANG
+0 −6
Original line number Diff line number Diff line
@@ -98,12 +98,6 @@ SECTIONS
		__soc_builtin_dtb_table_end = .;
	}

	. = ALIGN(8);
	.alternative : {
		__alt_start = .;
		*(.alternative)
		__alt_end = .;
	}
	__init_end = .;

	. = ALIGN(16);
+3 −3
Original line number Diff line number Diff line
@@ -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 = .;
+1 −1
Original line number Diff line number Diff line
@@ -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()							\