diff --git a/src/feature/linux/dse/config b/src/feature/linux/dse/config new file mode 100644 index 0000000000000000000000000000000000000000..d1769dfcd9802248b29248c54a65516e4d4933b5 --- /dev/null +++ b/src/feature/linux/dse/config @@ -0,0 +1,6 @@ +CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y +CONFIG_LD_DEAD_CODE_DATA_ELIMINATION_DEBUG=y +CONFIG_TRIM_UNUSED_SYSCALLS=y +CONFIG_USED_SYSCALLS="sys_dup sys_dup3 sys_ioctl sys_mknodat sys_mkdirat sys_unlinkat sys_symlinkat sys_linkat sys_mount sys_chdir sys_chroot sys_fchmodat sys_fchownat sys_openat sys_close sys_pipe2 sys_getdents64 sys_lseek sys_read sys_write sys_pselect6 sys_ppoll sys_exit sys_sched_yield sys_kill sys_reboot sys_getpgid sys_prctl sys_gettimeofday sys_getpid sys_getppid sys_getuid sys_geteuid sys_brk sys_munmap sys_clone sys_execve sys_mmap sys_wait4 sys_statx" +CONFIG_TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_GROUP=y + diff --git a/src/feature/linux/dse/v6.6-rc2/0001-DCE-add-debug-support.patch b/src/feature/linux/dse/v6.6-rc2/0001-DCE-add-debug-support.patch new file mode 100644 index 0000000000000000000000000000000000000000..1645dc1d9837207a138a6e50f3e86d4251788d84 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0001-DCE-add-debug-support.patch @@ -0,0 +1,49 @@ +From 1837f2c02271be24c3882c5d2e6eb83e51151730 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Tue, 26 Sep 2023 06:35:11 +0800 +Subject: [PATCH 01/23] DCE: add debug support + +Enable --print-gc-sections for --gc-sections to monitor which sections +are really eliminated. + +Signed-off-by: Zhangjin Wu +--- + Makefile | 3 +++ + init/Kconfig | 7 +++++++ + 2 files changed, 10 insertions(+) + +diff --git a/Makefile b/Makefile +index 57698d048e2c..a4e522b747cb 100644 +--- a/Makefile ++++ b/Makefile +@@ -938,6 +938,9 @@ ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION + KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections + KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y + LDFLAGS_vmlinux += --gc-sections ++ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION_DEBUG ++LDFLAGS_vmlinux += --print-gc-sections ++endif + endif + + ifdef CONFIG_SHADOW_CALL_STACK +diff --git a/init/Kconfig b/init/Kconfig +index 6d35728b94b2..4350d8ba7db4 100644 +--- a/init/Kconfig ++++ b/init/Kconfig +@@ -1404,6 +1404,13 @@ config LD_DEAD_CODE_DATA_ELIMINATION + present. This option is not well tested yet, so use at your + own risk. + ++config LD_DEAD_CODE_DATA_ELIMINATION_DEBUG ++ bool "Debug dead code and data elimination (EXPERIMENTAL)" ++ depends on LD_DEAD_CODE_DATA_ELIMINATION ++ default n ++ help ++ Enable --print-gc-sections for --gc-sections ++ + config LD_ORPHAN_WARN + def_bool y + depends on ARCH_WANT_LD_ORPHAN_WARN +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0002-DCE-DSE-add-unused-syscalls-elimination-configure-su.patch b/src/feature/linux/dse/v6.6-rc2/0002-DCE-DSE-add-unused-syscalls-elimination-configure-su.patch new file mode 100644 index 0000000000000000000000000000000000000000..a1917ee19af86487a0004316325a4c38bc2a87a7 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0002-DCE-DSE-add-unused-syscalls-elimination-configure-su.patch @@ -0,0 +1,94 @@ +From 747ee52e862a15d42be2fa817bcd2dccb19c4842 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Tue, 26 Sep 2023 06:36:21 +0800 +Subject: [PATCH 02/23] DCE/DSE: add unused syscalls elimination configure + support + +A minimal embedded Linux system may only has a very few of functions and +only uses a minimal subset of the posix syscalls, the unused syscalls +will never be used and eventually in a dead status, that also means disk +storage and memory footprint waste. + +Based on dead code elimination support, it is able to further eliminate +the above dead or unused syscalls. + +Firstly, both a new common CONFIG_TRIM_UNUSED_SYSCALLS option and a new +architecture specific HAVE_TRIM_UNUSED_SYSCALLS are added to enable or +disable such feature. + +Secondly, a new CONFIG_USED_SYSCALLS option is added to allow configure +the syscalls used in a target system. CONFIG_USED_SYSCALLS can be a list +of the used syscalls or a file to store such a list. + +Based on the above options, it is able to only reserve the used syscalls +and let CONFIG_LD_DEAD_CODE_DATA_ELIMINATION trim the unused ones for us +automatically. + +Signed-off-by: Zhangjin Wu +--- + init/Kconfig | 42 ++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 42 insertions(+) + +diff --git a/init/Kconfig b/init/Kconfig +index 4350d8ba7db4..aa648ce8bca1 100644 +--- a/init/Kconfig ++++ b/init/Kconfig +@@ -1457,6 +1457,11 @@ config BPF + bool + select CRYPTO_LIB_SHA1 + ++config HAVE_TRIM_UNUSED_SYSCALLS ++ bool ++ depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION ++ default n ++ + menuconfig EXPERT + bool "Configure standard kernel features (expert users)" + # Unhide debug options, to make the on-by-default options visible +@@ -1683,6 +1688,43 @@ config MEMBARRIER + + If unsure, say Y. + ++config TRIM_UNUSED_SYSCALLS ++ bool "Trim unused syscalls (EXPERIMENTAL)" if EXPERT ++ default n ++ depends on HAVE_TRIM_UNUSED_SYSCALLS ++ depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION ++ select LD_DEAD_CODE_DATA_ELIMINATION ++ help ++ Say Y here to trim all of the unused syscalls for a target system. ++ ++ Note, this is only for minimal embedded systems, please don't use it ++ for generic Linux distributions. ++ ++ If unsure, say N. ++ ++config USED_SYSCALLS ++ string "Configure used syscalls (EXPERIMENTAL)" if EXPERT ++ depends on TRIM_UNUSED_SYSCALLS ++ default "" ++ help ++ This option allows to configure the syscalls used in a target system, ++ the unused ones will be disabled and trimmed by TRIM_UNUSED_SYSCALLS. ++ ++ The used syscalls should be listed one by one like this: ++ ++ write exit reboot ++ ++ Or put them into a file specified by this option, one syscall per ++ line is recommended for such a config file: ++ ++ write ++ exit ++ reboot ++ ++ Note, If keep this empty, all of the syscalls will be trimmed. ++ ++ If unsure, please disable TRIM_UNUSED_SYSCALLS. ++ + config KALLSYMS + bool "Load all symbols for debugging/ksymoops" if EXPERT + default y +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0003-DCE-DSE-Add-a-new-scripts-Makefile.syscalls.patch b/src/feature/linux/dse/v6.6-rc2/0003-DCE-DSE-Add-a-new-scripts-Makefile.syscalls.patch new file mode 100644 index 0000000000000000000000000000000000000000..1e7f6c27a1724c79ff850d6dcf400529c4b3c288 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0003-DCE-DSE-Add-a-new-scripts-Makefile.syscalls.patch @@ -0,0 +1,58 @@ +From 0a2da78c7e0a2b1979e8a4e77f0cc600fd859da8 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Tue, 26 Sep 2023 06:38:56 +0800 +Subject: [PATCH 03/23] DCE/DSE: Add a new scripts/Makefile.syscalls + +When CONFIG_TRIM_UNUSED_SYSCALLS is enabled, get used syscalls from +CONFIG_USED_SYSCALLS. CONFIG_USED_SYSCALLS may be a list of used +syscalls or a file to store such a list. + +If CONFIG_USED_SYSCALLS is configured as a list of the used syscalls, +directly record them in a used_syscalls variable, if it is a file to +store the list, record the file name to the used_syscalls_file variable +and put its content to the used_syscalls variable. + +Signed-off-by: Zhangjin Wu +--- + scripts/Makefile.syscalls | 29 +++++++++++++++++++++++++++++ + 1 file changed, 29 insertions(+) + create mode 100644 scripts/Makefile.syscalls + +diff --git a/scripts/Makefile.syscalls b/scripts/Makefile.syscalls +new file mode 100644 +index 000000000000..5864d3a85996 +--- /dev/null ++++ b/scripts/Makefile.syscalls +@@ -0,0 +1,29 @@ ++# SPDX-License-Identifier: GPL-2.0 ++ ++ifndef SCRIPTS_MAKEFILE_SYSCALLS ++ SCRIPTS_MAKEFILE_SYSCALLS = 1 ++ ++ ifdef CONFIG_TRIM_UNUSED_SYSCALLS ++ ifneq ($(wildcard $(CONFIG_USED_SYSCALLS)),) ++ used_syscalls_file = $(CONFIG_USED_SYSCALLS) ++ ifeq ($(shell test -s $(used_syscalls_file); echo $$?),0) ++ used_syscalls != cat $(CONFIG_USED_SYSCALLS) ++ endif ++ else ++ ifeq ($(subst /,,$(CONFIG_USED_SYSCALLS)),$(CONFIG_USED_SYSCALLS)) ++ used_syscalls = $(CONFIG_USED_SYSCALLS) ++ else ++ $(error No such file: $(CONFIG_USED_SYSCALLS)) ++ endif ++ endif ++ ++ ifneq ($(used_syscalls),) ++ used_syscalls := $(subst $(space),|,$(strip $(used_syscalls))) ++ endif ++ ++ used_syscalls_deps = $(used_syscalls_file) $(objtree)/.config ++ ++ export used_syscalls used_syscalls_deps ++ endif # CONFIG_TRIM_UNUSED_SYSCALLS ++ ++endif # SCRIPTS_MAKEFILE_SYSCALLS +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0004-DCE-DSE-mips-add-HAVE_TRIM_UNUSED_SYSCALLS-support.patch b/src/feature/linux/dse/v6.6-rc2/0004-DCE-DSE-mips-add-HAVE_TRIM_UNUSED_SYSCALLS-support.patch new file mode 100644 index 0000000000000000000000000000000000000000..618534c6e47da395ce3d2d599ae27127cb8ca488 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0004-DCE-DSE-mips-add-HAVE_TRIM_UNUSED_SYSCALLS-support.patch @@ -0,0 +1,84 @@ +From 85248a8d835ca263971419bac9549948e6976db8 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Tue, 26 Sep 2023 06:40:08 +0800 +Subject: [PATCH 04/23] DCE/DSE: mips: add HAVE_TRIM_UNUSED_SYSCALLS support + +For HAVE_TRIM_UNUSED_SYSCALLS, the syscall tables are hacked with the +input used syscalls. + +Based on the used syscalls information, a new version of tbl file is +generated from the original tbl file and named with a 'used' suffix. + +With this new tbl file, both unistd_nr_*.h and syscall_table_*.h files +are updated to only include the used syscalls. + + $ grep _Linux_syscalls -ur arch/mips/include/generated/asm/ + arch/mips/include/generated/asm/unistd_nr_n64.h:#define __NR_64_Linux_syscalls 165 + arch/mips/include/generated/asm/unistd_nr_n32.h:#define __NR_N32_Linux_syscalls 165 + arch/mips/include/generated/asm/unistd_nr_o32.h:#define __NR_O32_Linux_syscalls 89 + + $ grep -vr sys_ni_syscall arch/mips/include/generated/asm/syscall_table_*.h + arch/mips/include/generated/asm/syscall_table_n32.h:__SYSCALL(58, sys_exit) + arch/mips/include/generated/asm/syscall_table_n32.h:__SYSCALL(164, sys_reboot) + arch/mips/include/generated/asm/syscall_table_n64.h:__SYSCALL(58, sys_exit) + arch/mips/include/generated/asm/syscall_table_n64.h:__SYSCALL(164, sys_reboot) + arch/mips/include/generated/asm/syscall_table_o32.h:__SYSCALL(1, sys_exit) + arch/mips/include/generated/asm/syscall_table_o32.h:__SYSCALL(88, sys_reboot) + +Signed-off-by: Zhangjin Wu +--- + arch/mips/Kconfig | 1 + + arch/mips/kernel/syscalls/Makefile | 23 +++++++++++++++++++++-- + 2 files changed, 22 insertions(+), 2 deletions(-) + +diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig +index bc8421859006..8a6927eff23d 100644 +--- a/arch/mips/Kconfig ++++ b/arch/mips/Kconfig +@@ -89,6 +89,7 @@ config MIPS + select HAVE_SPARSE_SYSCALL_NR + select HAVE_STACKPROTECTOR + select HAVE_SYSCALL_TRACEPOINTS ++ select HAVE_TRIM_UNUSED_SYSCALLS if HAVE_LD_DEAD_CODE_DATA_ELIMINATION + select HAVE_VIRT_CPU_ACCOUNTING_GEN if 64BIT || !SMP + select IRQ_FORCED_THREADING + select ISA if EISA +diff --git a/arch/mips/kernel/syscalls/Makefile b/arch/mips/kernel/syscalls/Makefile +index e6b21de65cca..1e292a9f84a0 100644 +--- a/arch/mips/kernel/syscalls/Makefile ++++ b/arch/mips/kernel/syscalls/Makefile +@@ -26,10 +26,29 @@ sysnr_pfx_unistd_nr_n32 := N32 + sysnr_pfx_unistd_nr_n64 := 64 + sysnr_pfx_unistd_nr_o32 := O32 + +-$(kapi)/unistd_nr_%.h: $(src)/syscall_%.tbl $(sysnr) FORCE ++ifndef CONFIG_TRIM_UNUSED_SYSCALLS ++tbl = $(src)/syscall_%.tbl ++else ++ ++include $(srctree)/scripts/Makefile.syscalls ++ ++orig_tbl = $(src)/syscall_%.tbl ++ tbl_dir = arch/$(SRCARCH)/include/generated/tbl ++ tbl = $(tbl_dir)/syscall_used_%.tbl ++ ++quiet_cmd_used = USED $@ ++ cmd_used = sed -E -e "/^[0-9]*[[:space:]]/{/(^($(used_syscalls))[[:space:]]|[[:space:]]($(used_syscalls))[[:space:]]|[[:space:]]($(used_syscalls))$$)/!{s/^/\#/g}}" $< > $@; ++ ++$(tbl): $(orig_tbl) $(used_syscalls_deps) FORCE ++ $(Q)mkdir -p $(tbl_dir) ++ $(call cmd,used) ++ ++endif ++ ++$(kapi)/unistd_nr_%.h: $(tbl) $(sysnr) FORCE + $(call if_changed,sysnr) + +-$(kapi)/syscall_table_%.h: $(src)/syscall_%.tbl $(systbl) FORCE ++$(kapi)/syscall_table_%.h: $(tbl) $(systbl) FORCE + $(call if_changed,systbl) + + uapisyshdr-y += unistd_n32.h \ +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0005-DCE-DSE-riscv-move-syscall-tables-to-syscalls.patch b/src/feature/linux/dse/v6.6-rc2/0005-DCE-DSE-riscv-move-syscall-tables-to-syscalls.patch new file mode 100644 index 0000000000000000000000000000000000000000..0e08f44b6928a8f6dc9c554b855b81b33bffe30c --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0005-DCE-DSE-riscv-move-syscall-tables-to-syscalls.patch @@ -0,0 +1,78 @@ +From d4e655f218abbea524e6a94bfa85352abf2bd79c Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Tue, 26 Sep 2023 06:41:16 +0800 +Subject: [PATCH 05/23] DCE/DSE: riscv: move syscall tables to syscalls/ + +Both syscall table and compat syscall table share some dead syscalls +elimination code, to avoid cluttering the main RISC-V kernel Makefile, +let's move these tables and the corresponding compile settings to +syscalls/. + +Signed-off-by: Zhangjin Wu +--- + arch/riscv/kernel/Makefile | 5 +---- + arch/riscv/kernel/syscalls/Makefile | 10 ++++++++++ + .../riscv/kernel/{ => syscalls}/compat_syscall_table.c | 0 + arch/riscv/kernel/{ => syscalls}/syscall_table.c | 0 + 4 files changed, 11 insertions(+), 4 deletions(-) + create mode 100644 arch/riscv/kernel/syscalls/Makefile + rename arch/riscv/kernel/{ => syscalls}/compat_syscall_table.c (100%) + rename arch/riscv/kernel/{ => syscalls}/syscall_table.c (100%) + +diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile +index 95cf25d48405..40aebbf06880 100644 +--- a/arch/riscv/kernel/Makefile ++++ b/arch/riscv/kernel/Makefile +@@ -8,8 +8,6 @@ CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) + CFLAGS_REMOVE_patch.o = $(CC_FLAGS_FTRACE) + CFLAGS_REMOVE_sbi.o = $(CC_FLAGS_FTRACE) + endif +-CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,) +-CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,) + + ifdef CONFIG_KEXEC + AFLAGS_kexec_relocate.o := -mcmodel=medany $(call cc-option,-mno-relax) +@@ -48,7 +46,7 @@ obj-y += ptrace.o + obj-y += reset.o + obj-y += setup.o + obj-y += signal.o +-obj-y += syscall_table.o ++obj-y += syscalls/ + obj-y += sys_riscv.o + obj-y += time.o + obj-y += traps.o +@@ -95,7 +93,6 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o + obj-$(CONFIG_CFI_CLANG) += cfi.o + + obj-$(CONFIG_EFI) += efi.o +-obj-$(CONFIG_COMPAT) += compat_syscall_table.o + obj-$(CONFIG_COMPAT) += compat_signal.o + obj-$(CONFIG_COMPAT) += compat_vdso/ + +diff --git a/arch/riscv/kernel/syscalls/Makefile b/arch/riscv/kernel/syscalls/Makefile +new file mode 100644 +index 000000000000..65abd0871ee5 +--- /dev/null ++++ b/arch/riscv/kernel/syscalls/Makefile +@@ -0,0 +1,10 @@ ++# SPDX-License-Identifier: GPL-2.0-only ++# ++# Makefile for the RISC-V syscall tables ++# ++ ++CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,) ++CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,) ++ ++obj-y += syscall_table.o ++obj-$(CONFIG_COMPAT) += compat_syscall_table.o +diff --git a/arch/riscv/kernel/compat_syscall_table.c b/arch/riscv/kernel/syscalls/compat_syscall_table.c +similarity index 100% +rename from arch/riscv/kernel/compat_syscall_table.c +rename to arch/riscv/kernel/syscalls/compat_syscall_table.c +diff --git a/arch/riscv/kernel/syscall_table.c b/arch/riscv/kernel/syscalls/syscall_table.c +similarity index 100% +rename from arch/riscv/kernel/syscall_table.c +rename to arch/riscv/kernel/syscalls/syscall_table.c +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0006-DCE-DSE-riscv-add-HAVE_TRIM_UNUSED_SYSCALLS-support.patch b/src/feature/linux/dse/v6.6-rc2/0006-DCE-DSE-riscv-add-HAVE_TRIM_UNUSED_SYSCALLS-support.patch new file mode 100644 index 0000000000000000000000000000000000000000..ded7b2835b88bfbeb9f5de199dee2995c9a08888 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0006-DCE-DSE-riscv-add-HAVE_TRIM_UNUSED_SYSCALLS-support.patch @@ -0,0 +1,88 @@ +From 28439f0c7d78fee759a4ed3853bb8eb539b354cb Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Tue, 26 Sep 2023 06:42:23 +0800 +Subject: [PATCH 06/23] DCE/DSE: riscv: add HAVE_TRIM_UNUSED_SYSCALLS support + +For HAVE_TRIM_UNUSED_SYSCALLS, the syscall tables are hacked with the +inputing unused_syscalls. + +Firstly, the intermediate preprocessed .i files are generated from the +original C version of syscall tables respectively, and named with a +'used' suffix: syscall_table_used.i, compat_syscall_table_used.i. + +Secondly, all of the unused syscalls are commented. + +At last, two new objective files sufixed with 'used' are generated from +the hacked .i files and they are linked into the eventual kernel image. + +Signed-off-by: Zhangjin Wu +--- + arch/riscv/Kconfig | 1 + + arch/riscv/kernel/syscalls/Makefile | 37 +++++++++++++++++++++++++++++ + 2 files changed, 38 insertions(+) + +diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig +index d607ab0f7c6d..b5e726b49a6f 100644 +--- a/arch/riscv/Kconfig ++++ b/arch/riscv/Kconfig +@@ -140,6 +140,7 @@ config RISCV + select HAVE_RSEQ + select HAVE_STACKPROTECTOR + select HAVE_SYSCALL_TRACEPOINTS ++ select HAVE_TRIM_UNUSED_SYSCALLS if HAVE_LD_DEAD_CODE_DATA_ELIMINATION + select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU + select IRQ_DOMAIN + select IRQ_FORCED_THREADING +diff --git a/arch/riscv/kernel/syscalls/Makefile b/arch/riscv/kernel/syscalls/Makefile +index 65abd0871ee5..3b5969aaa9e8 100644 +--- a/arch/riscv/kernel/syscalls/Makefile ++++ b/arch/riscv/kernel/syscalls/Makefile +@@ -3,8 +3,45 @@ + # Makefile for the RISC-V syscall tables + # + ++ifndef CONFIG_TRIM_UNUSED_SYSCALLS ++ + CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,) + CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,) + + obj-y += syscall_table.o + obj-$(CONFIG_COMPAT) += compat_syscall_table.o ++else # CONFIG_TRIM_UNUSED_SYSCALLS ++ ++include $(srctree)/scripts/Makefile.syscalls ++ ++CFLAGS_syscall_table_used.o += $(call cc-option,-Wno-override-init,) ++CFLAGS_compat_syscall_table_used.o += $(call cc-option,-Wno-override-init,) ++ ++obj-y += syscall_table_used.o ++obj-$(CONFIG_COMPAT) += compat_syscall_table_used.o ++ ++# comment the unused syscalls ++quiet_cmd_used = USED $@ ++ cmd_used = sed -E -e '/^\[([0-9]+|\([0-9]+ \+ [0-9]+\))\] = /{/= *__riscv_(__sys_|sys_|compat_)*($(used_syscalls)),/!{s%^%/* %g;s%$$% */%g}}' -i $@; ++ ++$(obj)/syscall_table_used.c: $(src)/syscall_table.c ++ $(Q)cp $< $@ ++ ++$(obj)/syscall_table_used.i: $(src)/syscall_table_used.c $(used_syscalls_deps) FORCE ++ $(call if_changed_dep,cpp_i_c) ++ $(call cmd,used) ++ ++$(obj)/syscall_table_used.o: $(obj)/syscall_table_used.i FORCE ++ $(call if_changed,cc_o_c) ++ ++$(obj)/compat_syscall_table_used.c: $(src)/compat_syscall_table.c ++ $(Q)cp $< $@ ++ ++$(obj)/compat_syscall_table_used.i: $(src)/compat_syscall_table_used.c $(used_syscalls_deps) FORCE ++ $(call if_changed_dep,cpp_i_c) ++ $(call cmd,used) ++ ++$(obj)/compat_syscall_table_used.o: $(obj)/compat_syscall_table_used.i FORCE ++ $(call if_changed,cc_o_c) ++ ++endif # CONFIG_TRIM_UNUSED_SYSCALLS +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0007-DCE-DSE-riscv-trim-syscall-tables.patch b/src/feature/linux/dse/v6.6-rc2/0007-DCE-DSE-riscv-trim-syscall-tables.patch new file mode 100644 index 0000000000000000000000000000000000000000..e824c43210f5c1b43926a1180375b56c31b8554d --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0007-DCE-DSE-riscv-trim-syscall-tables.patch @@ -0,0 +1,150 @@ +From 03d4950bbe79b95ec363a73f68d5657514b3a078 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Tue, 26 Sep 2023 06:43:32 +0800 +Subject: [PATCH 07/23] DCE/DSE: riscv: trim syscall tables + +When the maximum nr of the used syscalls is smaller than __NR_syscalls +(original syscalls total). It is able to update __NR_syscalls to +(maximum nr + 1) and further trim the '>= (maximum nr + 1)' part of the +syscall tables: + +For example: + + sys_call_table [143] = { + [0 ... 143 - 1] = sys_ni_syscall, + [64] = sys_write, + [93] = sys_exit, + [142] = sys_reboot, + } + +The >= 143 part of the syscall tables can be trimmed. + +At the same time, the syscall >= 143 from user space must be ignored +from do_trap_ecall_u() of traps.c. + +Signed-off-by: Zhangjin Wu +--- + arch/riscv/include/asm/unistd.h | 2 ++ + arch/riscv/kernel/Makefile | 2 ++ + arch/riscv/kernel/syscalls/Makefile | 22 +++++++++++++++++++ + .../kernel/syscalls/compat_syscall_table.c | 4 ++-- + arch/riscv/kernel/syscalls/syscall_table.c | 4 ++-- + 5 files changed, 30 insertions(+), 4 deletions(-) + +diff --git a/arch/riscv/include/asm/unistd.h b/arch/riscv/include/asm/unistd.h +index 221630bdbd07..4d8e41f446ff 100644 +--- a/arch/riscv/include/asm/unistd.h ++++ b/arch/riscv/include/asm/unistd.h +@@ -23,4 +23,6 @@ + + #include + ++#ifndef NR_syscalls + #define NR_syscalls (__NR_syscalls) ++#endif +diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile +index 40aebbf06880..e75424c10729 100644 +--- a/arch/riscv/kernel/Makefile ++++ b/arch/riscv/kernel/Makefile +@@ -49,7 +49,9 @@ obj-y += signal.o + obj-y += syscalls/ + obj-y += sys_riscv.o + obj-y += time.o ++ifneq ($(CONFIG_TRIM_UNUSED_SYSCALLS),y) + obj-y += traps.o ++endif + obj-y += riscv_ksyms.o + obj-y += stacktrace.o + obj-y += cacheinfo.o +diff --git a/arch/riscv/kernel/syscalls/Makefile b/arch/riscv/kernel/syscalls/Makefile +index 3b5969aaa9e8..f1a0597c8b24 100644 +--- a/arch/riscv/kernel/syscalls/Makefile ++++ b/arch/riscv/kernel/syscalls/Makefile +@@ -14,9 +14,18 @@ else # CONFIG_TRIM_UNUSED_SYSCALLS + + include $(srctree)/scripts/Makefile.syscalls + ++# calculate syscalls total from $(obj)/syscall_table_used.i ++ifneq ($(used_syscalls),) ++ NR_syscalls := $$(($$(sed -E -n -e '/^\[([0-9]+|\([0-9]+ \+ [0-9]+\))\] = /{s/^\[(.*)\].*/\1/gp}' $(obj)/syscall_table_used.i | bc | sort -g | tail -1 | grep '[0-9]' || echo -1) + 1)) ++else ++ NR_syscalls := 0 ++endif ++ ++CFLAGS_traps_used.o += -DNR_syscalls=$(NR_syscalls) + CFLAGS_syscall_table_used.o += $(call cc-option,-Wno-override-init,) + CFLAGS_compat_syscall_table_used.o += $(call cc-option,-Wno-override-init,) + ++obj-y += traps_used.o + obj-y += syscall_table_used.o + obj-$(CONFIG_COMPAT) += compat_syscall_table_used.o + +@@ -24,15 +33,26 @@ obj-$(CONFIG_COMPAT) += compat_syscall_table_used.o + quiet_cmd_used = USED $@ + cmd_used = sed -E -e '/^\[([0-9]+|\([0-9]+ \+ [0-9]+\))\] = /{/= *__riscv_(__sys_|sys_|compat_)*($(used_syscalls)),/!{s%^%/* %g;s%$$% */%g}}' -i $@; + ++# update the syscalls total ++quiet_cmd_snr = SNR $@ ++ cmd_snr = snr=$(NR_syscalls); if [ $$snr -ne 0 ]; then \ ++ sed -i -e "s/sys_call_table\[.*\] =/sys_call_table[($$snr)] =/g;s/\[0 ... (.*) - 1\] = __riscv_sys_ni_syscall/[0 ... ($$snr) - 1] = __riscv_sys_ni_syscall/g" $@; \ ++ fi; ++ ++$(obj)/traps_used.c: $(src)/../traps.c $(obj)/syscall_table_used.i FORCE ++ $(Q)cp $< $@ ++ + $(obj)/syscall_table_used.c: $(src)/syscall_table.c + $(Q)cp $< $@ + + $(obj)/syscall_table_used.i: $(src)/syscall_table_used.c $(used_syscalls_deps) FORCE + $(call if_changed_dep,cpp_i_c) + $(call cmd,used) ++ $(call cmd,snr) + + $(obj)/syscall_table_used.o: $(obj)/syscall_table_used.i FORCE + $(call if_changed,cc_o_c) ++ $(call cmd,force_checksrc) + + $(obj)/compat_syscall_table_used.c: $(src)/compat_syscall_table.c + $(Q)cp $< $@ +@@ -40,8 +60,10 @@ $(obj)/compat_syscall_table_used.c: $(src)/compat_syscall_table.c + $(obj)/compat_syscall_table_used.i: $(src)/compat_syscall_table_used.c $(used_syscalls_deps) FORCE + $(call if_changed_dep,cpp_i_c) + $(call cmd,used) ++ $(call cmd,snr) + + $(obj)/compat_syscall_table_used.o: $(obj)/compat_syscall_table_used.i FORCE + $(call if_changed,cc_o_c) ++ $(call cmd,force_checksrc) + + endif # CONFIG_TRIM_UNUSED_SYSCALLS +diff --git a/arch/riscv/kernel/syscalls/compat_syscall_table.c b/arch/riscv/kernel/syscalls/compat_syscall_table.c +index ad7f2d712f5f..4756b6858eac 100644 +--- a/arch/riscv/kernel/syscalls/compat_syscall_table.c ++++ b/arch/riscv/kernel/syscalls/compat_syscall_table.c +@@ -17,7 +17,7 @@ + + asmlinkage long compat_sys_rt_sigreturn(void); + +-void * const compat_sys_call_table[__NR_syscalls] = { +- [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall, ++void * const compat_sys_call_table[NR_syscalls] = { ++ [0 ... NR_syscalls - 1] = __riscv_sys_ni_syscall, + #include + }; +diff --git a/arch/riscv/kernel/syscalls/syscall_table.c b/arch/riscv/kernel/syscalls/syscall_table.c +index dda913764903..d2b3233ae5d4 100644 +--- a/arch/riscv/kernel/syscalls/syscall_table.c ++++ b/arch/riscv/kernel/syscalls/syscall_table.c +@@ -16,7 +16,7 @@ + #undef __SYSCALL + #define __SYSCALL(nr, call) [nr] = __riscv_##call, + +-void * const sys_call_table[__NR_syscalls] = { +- [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall, ++void * const sys_call_table[NR_syscalls] = { ++ [0 ... NR_syscalls - 1] = __riscv_sys_ni_syscall, + #include + }; +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0008-DCE-DSE-allow-keep-unique-bounded-sections.patch b/src/feature/linux/dse/v6.6-rc2/0008-DCE-DSE-allow-keep-unique-bounded-sections.patch new file mode 100644 index 0000000000000000000000000000000000000000..4f3c3ef9ec6a1f9fb91902732d60154194609c02 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0008-DCE-DSE-allow-keep-unique-bounded-sections.patch @@ -0,0 +1,75 @@ +From 2250eb9a55202212fa484a32779c6423cecc40e2 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Mon, 20 Feb 2023 20:23:41 +0800 +Subject: [PATCH 08/23] DCE/DSE: allow keep unique bounded sections + +The bounded sections may break the elimination of some dead code. + +Some unused syscalls have been wrongly kept by `__ex_table`, we will +unique `__ex_table` for every inserting and then remove the unused ones +explicitly and eventually, the unused syscalls will be eliminated. + +In the future, we should find better methods to solve such issue: + + Some code may use '.pushsection/.popsection' to insert data + to a bounded section, use `sys_sendfile` as an example: + + sys_sendfile: + + ".pushsection __ex_table,\"\"\n" + ... + ".long ((" insn ") - .)\n" + ... + ".popsection" + + `insn` is an address in `sys_sendfile`, even if no real user uses + sys_sendfile, the keeping of __ex_table will become a 'user' and + break the elimination of `sys_sendfile`. + +All of the bounded sections should be uniqued, and we should check if +they are the last users of the code, if so, those sections should be +removed and the code should be eliminated. + +Signed-off-by: Zhangjin Wu +--- + include/asm-generic/vmlinux.lds.h | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h +index 9c59409104f6..ea8170e11ab1 100644 +--- a/include/asm-generic/vmlinux.lds.h ++++ b/include/asm-generic/vmlinux.lds.h +@@ -103,6 +103,7 @@ + #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L* + #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..compoundliteral* + #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]* ++#define BSEC_MAIN(sec) sec sec##.[0-9a-zA-Z_]* + #else + #define TEXT_MAIN .text + #define DATA_MAIN .data +@@ -110,6 +111,7 @@ + #define RODATA_MAIN .rodata + #define BSS_MAIN .bss + #define SBSS_MAIN .sbss ++#define BSEC_MAIN(sec) sec + #endif + + /* +@@ -201,12 +203,12 @@ + + #define BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_) \ + _BEGIN_##_label_ = .; \ +- KEEP(*(_sec_)) \ ++ KEEP(*(BSEC_MAIN(_sec_))) \ + _END_##_label_ = .; + + #define BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_) \ + _label_##_BEGIN_ = .; \ +- KEEP(*(_sec_)) \ ++ KEEP(*(BSEC_MAIN(_sec_))) \ + _label_##_END_ = .; + + #define BOUNDED_SECTION_BY(_sec_, _label_) \ +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0009-compiler-add-a-global-__QUITE_UNIQUE_ID.patch b/src/feature/linux/dse/v6.6-rc2/0009-compiler-add-a-global-__QUITE_UNIQUE_ID.patch new file mode 100644 index 0000000000000000000000000000000000000000..26acebdc39c1a69662362e7fa1fd679126df2f90 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0009-compiler-add-a-global-__QUITE_UNIQUE_ID.patch @@ -0,0 +1,62 @@ +From 85c0678cf3f6883e730e87f45fbba574f541df35 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Sat, 22 Jul 2023 01:46:55 +0800 +Subject: [PATCH 09/23] compiler: add a global __QUITE_UNIQUE_ID() + +Differs from __UNIQUE_ID(), __QUITE_UNIQUE_ID() also appends the +__COUNTER__ info to make it more unique. + +Besides, seems assembly code also require such a unique id, let's make +it global, the same to the required __PASTE macro. + +Signed-off-by: Zhangjin Wu +--- + include/linux/compiler.h | 5 +++++ + include/linux/compiler_types.h | 8 ++++---- + 2 files changed, 9 insertions(+), 4 deletions(-) + +diff --git a/include/linux/compiler.h b/include/linux/compiler.h +index d7779a18b24f..405b19cf6cf3 100644 +--- a/include/linux/compiler.h ++++ b/include/linux/compiler.h +@@ -227,6 +227,11 @@ static inline void *offset_to_ptr(const int *off) + + #endif /* __ASSEMBLY__ */ + ++/* Quite-unique ID. */ ++#ifndef __QUITE_UNIQUE_ID ++# define __QUITE_UNIQUE_ID(prefix) __PASTE(__PASTE(prefix, __LINE__), __COUNTER__) ++#endif ++ + /* &a[0] degrades to a pointer: a different type from an array */ + #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) + +diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h +index c523c6683789..0b79e19d1017 100644 +--- a/include/linux/compiler_types.h ++++ b/include/linux/compiler_types.h +@@ -70,10 +70,6 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } + # define __builtin_warning(x, y...) (1) + #endif /* __CHECKER__ */ + +-/* Indirect macros required for expanded argument pasting, eg. __LINE__. */ +-#define ___PASTE(a,b) a##b +-#define __PASTE(a,b) ___PASTE(a,b) +- + #ifdef __KERNEL__ + + /* Attributes */ +@@ -308,6 +304,10 @@ struct ftrace_likely_data { + + #endif /* __ASSEMBLY__ */ + ++/* Indirect macros required for expanded argument pasting, eg. __LINE__. */ ++#define ___PASTE(a, b) a##b ++#define __PASTE(a, b) ___PASTE(a, b) ++ + /* + * The below symbols may be defined for one or more, but not ALL, of the above + * compilers. We don't consider that to be an error, so set them to nothing. +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0010-compiler-add-unique-__SECTION_ID-and-__SECTION_NAME.patch b/src/feature/linux/dse/v6.6-rc2/0010-compiler-add-unique-__SECTION_ID-and-__SECTION_NAME.patch new file mode 100644 index 0000000000000000000000000000000000000000..02a50c7c27cdb4b10b664a26200454a913ce8499 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0010-compiler-add-unique-__SECTION_ID-and-__SECTION_NAME.patch @@ -0,0 +1,53 @@ +From be852d67256659bff409ef39ebc35d5dd80092f2 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Sat, 22 Jul 2023 11:32:24 +0800 +Subject: [PATCH 10/23] compiler: add unique __SECTION_ID() and + __SECTION_NAME() + +Two new section helpers are added for LD_DEAD_CODE_DATA_ELIMINATION to +generate unique section id and unique section name (strigified section +id). + +Signed-off-by: Zhangjin Wu +--- + include/linux/compiler.h | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +diff --git a/include/linux/compiler.h b/include/linux/compiler.h +index 405b19cf6cf3..1ca12b97dfa9 100644 +--- a/include/linux/compiler.h ++++ b/include/linux/compiler.h +@@ -227,11 +227,30 @@ static inline void *offset_to_ptr(const int *off) + + #endif /* __ASSEMBLY__ */ + ++/* Import __stringify */ ++#ifndef __stringify ++#include ++#endif ++ + /* Quite-unique ID. */ + #ifndef __QUITE_UNIQUE_ID + # define __QUITE_UNIQUE_ID(prefix) __PASTE(__PASTE(prefix, __LINE__), __COUNTER__) + #endif + ++/* Quite-unique Section ID. */ ++#ifndef __SECTION_ID ++#ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION ++# define __SECTION_ID(prefix) __QUITE_UNIQUE_ID(prefix.) ++#else ++# define __SECTION_ID(prefix) prefix ++#endif ++#endif ++ ++/* Quite-unique Section NAME. */ ++#ifndef __SECTION_NAME ++# define __SECTION_NAME(prefix) __stringify(__SECTION_ID(prefix)) ++#endif ++ + /* &a[0] degrades to a pointer: a different type from an array */ + #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) + +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0011-compiler-add-unique-LABEL_ID-and-LABEL_NAME.patch b/src/feature/linux/dse/v6.6-rc2/0011-compiler-add-unique-LABEL_ID-and-LABEL_NAME.patch new file mode 100644 index 0000000000000000000000000000000000000000..360a86366d922c5a5ad988a031e8975475bf79bf --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0011-compiler-add-unique-LABEL_ID-and-LABEL_NAME.patch @@ -0,0 +1,36 @@ +From 4f458d5631d14bddbfb4de6d6e73d3657e0aa8ae Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Sun, 23 Jul 2023 12:33:48 +0800 +Subject: [PATCH 11/23] compiler: add unique LABEL_ID() and LABEL_NAME() + +unique LABEL is required by SHF_LINK_ORDER support. + +Signed-off-by: Zhangjin Wu +--- + include/linux/compiler.h | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/include/linux/compiler.h b/include/linux/compiler.h +index 1ca12b97dfa9..272428308cca 100644 +--- a/include/linux/compiler.h ++++ b/include/linux/compiler.h +@@ -251,6 +251,16 @@ static inline void *offset_to_ptr(const int *off) + # define __SECTION_NAME(prefix) __stringify(__SECTION_ID(prefix)) + #endif + ++/* Unique Label ID. */ ++/* Label is file scope, __LINE__ is enough, and not change in the same macro call */ ++#ifndef __LABEL_ID ++# define __LABEL_ID(prefix) __PASTE(__PASTE(prefix, _), __LINE__) ++#endif ++ ++#ifndef __LABEL_NAME ++# define __LABEL_NAME(prefix) __stringify(__LABEL_ID(prefix)) ++#endif ++ + /* &a[0] degrades to a pointer: a different type from an array */ + #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) + +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0012-DCE-DSE-add-HAVE_TRIM_KEPT_UNUSED_SYSCALLS-control-s.patch b/src/feature/linux/dse/v6.6-rc2/0012-DCE-DSE-add-HAVE_TRIM_KEPT_UNUSED_SYSCALLS-control-s.patch new file mode 100644 index 0000000000000000000000000000000000000000..8c99425891064b6c143b6c273e71080bc199930d --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0012-DCE-DSE-add-HAVE_TRIM_KEPT_UNUSED_SYSCALLS-control-s.patch @@ -0,0 +1,60 @@ +From 01162ca1746bc8eae06c14763791e9def338f41d Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Fri, 21 Jul 2023 19:07:03 +0800 +Subject: [PATCH 12/23] DCE/DSE: add HAVE_TRIM_KEPT_UNUSED_SYSCALLS control + support + +Some syscalls are wrongly kept by the sections like __ex_table. + +Here adds a control option to allow use some methods to remove the +__ex_table entries wrongly kept the unused syscalls. + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + init/Kconfig | 22 ++++++++++++++++++++++ + 1 file changed, 22 insertions(+) + +diff --git a/init/Kconfig b/init/Kconfig +index aa648ce8bca1..558724fc4356 100644 +--- a/init/Kconfig ++++ b/init/Kconfig +@@ -1462,6 +1462,11 @@ config HAVE_TRIM_UNUSED_SYSCALLS + depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION + default n + ++config HAVE_TRIM_KEPT_UNUSED_SYSCALLS ++ bool ++ depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION ++ default n ++ + menuconfig EXPERT + bool "Configure standard kernel features (expert users)" + # Unhide debug options, to make the on-by-default options visible +@@ -1725,6 +1730,23 @@ config USED_SYSCALLS + + If unsure, please disable TRIM_UNUSED_SYSCALLS. + ++choice ++ prompt "Trim wrongly kept unused syscalls" if EXPERT ++ default TRIM_KEPT_UNUSED_SYSCALLS_NONE ++ depends on TRIM_UNUSED_SYSCALLS ++ depends on HAVE_TRIM_KEPT_UNUSED_SYSCALLS ++ help ++ This option selects the method to trim unused syscall wrongly kept. ++ ++config TRIM_KEPT_UNUSED_SYSCALLS_NONE ++ bool "none (EXPERIMENTAL)" if EXPERT ++ help ++ Say Y here to not trim kept unused sections. ++ ++ If unsure, choose this. ++ ++endchoice ++ + config KALLSYMS + bool "Load all symbols for debugging/ksymoops" if EXPERT + default y +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0013-DCE-DSE-add-selectable-HAVE_SECTION_NO_KEEP_SUPPORT-.patch b/src/feature/linux/dse/v6.6-rc2/0013-DCE-DSE-add-selectable-HAVE_SECTION_NO_KEEP_SUPPORT-.patch new file mode 100644 index 0000000000000000000000000000000000000000..a2dbb3f11b0bd1be8e5568fb0d1c92dbf26bb74d --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0013-DCE-DSE-add-selectable-HAVE_SECTION_NO_KEEP_SUPPORT-.patch @@ -0,0 +1,83 @@ +From 2b4a2197b2b22e3da293d6d69befc21a12c1e997 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Sun, 23 Jul 2023 11:06:00 +0800 +Subject: [PATCH 13/23] DCE/DSE: add selectable HAVE_SECTION_NO_KEEP_SUPPORT + support + +It is able to drop the brute KEEP() keyword for some sections, when the +sections are able to link or group together with one of the used +sections. + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + include/asm-generic/vmlinux.lds.h | 28 ++++++++++++++++++++-------- + init/Kconfig | 9 +++++++++ + 2 files changed, 29 insertions(+), 8 deletions(-) + +diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h +index ea8170e11ab1..faae817df3e2 100644 +--- a/include/asm-generic/vmlinux.lds.h ++++ b/include/asm-generic/vmlinux.lds.h +@@ -201,18 +201,30 @@ + # endif + #endif + +-#define BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_) \ +- _BEGIN_##_label_ = .; \ +- KEEP(*(BSEC_MAIN(_sec_))) \ ++#ifdef CONFIG_SECTION_NO_KEEP_SUPPORT ++#define NO_KEEP(sec) sec ++#else ++#define NO_KEEP(sec) KEEP(sec) ++#endif ++ ++#define _BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_, _KEEP_, ...) \ ++ _BEGIN_##_label_ = .; \ ++ _KEEP_(*(BSEC_MAIN(_sec_))) \ + _END_##_label_ = .; + +-#define BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_) \ +- _label_##_BEGIN_ = .; \ +- KEEP(*(BSEC_MAIN(_sec_))) \ ++#define BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_, ...) \ ++ _BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_, ##__VA_ARGS__, KEEP) ++ ++#define _BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_, _KEEP_, ...)\ ++ _label_##_BEGIN_ = .; \ ++ _KEEP_(*(BSEC_MAIN(_sec_))) \ + _label_##_END_ = .; + +-#define BOUNDED_SECTION_BY(_sec_, _label_) \ +- BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop) ++#define BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_, ...) \ ++ _BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_, ##__VA_ARGS__, KEEP) ++ ++#define BOUNDED_SECTION_BY(_sec_, _label_, ...) \ ++ _BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop, ##__VA_ARGS__, KEEP) + + #define BOUNDED_SECTION(_sec) BOUNDED_SECTION_BY(_sec, _sec) + +diff --git a/init/Kconfig b/init/Kconfig +index 558724fc4356..e1b5189fd654 100644 +--- a/init/Kconfig ++++ b/init/Kconfig +@@ -1467,6 +1467,15 @@ config HAVE_TRIM_KEPT_UNUSED_SYSCALLS + depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION + default n + ++config HAVE_SECTION_NO_KEEP_SUPPORT ++ bool ++ ++config SECTION_NO_KEEP_SUPPORT ++ bool ++ depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION ++ depends on HAVE_SECTION_NO_KEEP_SUPPORT ++ default n ++ + menuconfig EXPERT + bool "Configure standard kernel features (expert users)" + # Unhide debug options, to make the on-by-default options visible +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0014-DCE-DSE-add-SECTION_SHF_LINK_ORDER_SUPPORT-control-s.patch b/src/feature/linux/dse/v6.6-rc2/0014-DCE-DSE-add-SECTION_SHF_LINK_ORDER_SUPPORT-control-s.patch new file mode 100644 index 0000000000000000000000000000000000000000..e1e548ae4de7c223304f4026ca6e40955d2dcb93 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0014-DCE-DSE-add-SECTION_SHF_LINK_ORDER_SUPPORT-control-s.patch @@ -0,0 +1,40 @@ +From e6a0de67f2c78172f71f1bcc8c3bec981ee63d84 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Sun, 23 Jul 2023 12:39:41 +0800 +Subject: [PATCH 14/23] DCE/DSE: add SECTION_SHF_LINK_ORDER_SUPPORT control + support + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + init/Kconfig | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/init/Kconfig b/init/Kconfig +index e1b5189fd654..84cb56821ccc 100644 +--- a/init/Kconfig ++++ b/init/Kconfig +@@ -1469,11 +1469,20 @@ config HAVE_TRIM_KEPT_UNUSED_SYSCALLS + + config HAVE_SECTION_NO_KEEP_SUPPORT + bool ++ default HAVE_SECTION_SHF_LINK_ORDER_SUPPORT + + config SECTION_NO_KEEP_SUPPORT + bool + depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION + depends on HAVE_SECTION_NO_KEEP_SUPPORT ++ default SECTION_SHF_LINK_ORDER_SUPPORT ++ ++config HAVE_SECTION_SHF_LINK_ORDER_SUPPORT ++ bool ++ ++config SECTION_SHF_LINK_ORDER_SUPPORT ++ bool ++ depends on HAVE_SECTION_SHF_LINK_ORDER_SUPPORT + default n + + menuconfig EXPERT +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0015-DCE-DSE-add-TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_LINK_OR.patch b/src/feature/linux/dse/v6.6-rc2/0015-DCE-DSE-add-TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_LINK_OR.patch new file mode 100644 index 0000000000000000000000000000000000000000..bef6aaf2e357877133352fe744a3a84b2f97dca2 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0015-DCE-DSE-add-TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_LINK_OR.patch @@ -0,0 +1,40 @@ +From a3b012d25b6776e9ba569b9b8618be225c0b6ef1 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Sun, 23 Jul 2023 12:40:07 +0800 +Subject: [PATCH 15/23] DCE/DSE: add + TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_LINK_ORDER option + +This will select SECTION_SHF_LINK_ORDER_SUPPORT + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + init/Kconfig | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/init/Kconfig b/init/Kconfig +index 84cb56821ccc..200fd4073fe0 100644 +--- a/init/Kconfig ++++ b/init/Kconfig +@@ -1763,6 +1763,18 @@ config TRIM_KEPT_UNUSED_SYSCALLS_NONE + + If unsure, choose this. + ++config TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_LINK_ORDER ++ bool "SHF_LINK_ORDER attribute (EXPERIMENTAL)" if EXPERT ++ select SECTION_SHF_LINK_ORDER_SUPPORT ++ help ++ Say Y here to trim more 'unused' syscalls wrongly kept by __ex_table ++ like sections in kernel space. ++ ++ This option enables the section SHF_LINK_ORDER attribute method, it ++ is faster than objcopy. ++ ++ If unsure, not choose this. ++ + endchoice + + config KALLSYMS +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0016-DCE-DSE-add-SECTION_SHF_GROUP_SUPPORT-control-suppor.patch b/src/feature/linux/dse/v6.6-rc2/0016-DCE-DSE-add-SECTION_SHF_GROUP_SUPPORT-control-suppor.patch new file mode 100644 index 0000000000000000000000000000000000000000..aaef6f9252278eb3e647a118bb5ab74105d85782 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0016-DCE-DSE-add-SECTION_SHF_GROUP_SUPPORT-control-suppor.patch @@ -0,0 +1,49 @@ +From ac17d50fbbe12a4d4a3df50b1a9591c09862b745 Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Sun, 23 Jul 2023 12:41:29 +0800 +Subject: [PATCH 16/23] DCE/DSE: add SECTION_SHF_GROUP_SUPPORT control support + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + init/Kconfig | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/init/Kconfig b/init/Kconfig +index 200fd4073fe0..3239ccd18af5 100644 +--- a/init/Kconfig ++++ b/init/Kconfig +@@ -1469,13 +1469,13 @@ config HAVE_TRIM_KEPT_UNUSED_SYSCALLS + + config HAVE_SECTION_NO_KEEP_SUPPORT + bool +- default HAVE_SECTION_SHF_LINK_ORDER_SUPPORT ++ default HAVE_SECTION_SHF_LINK_ORDER_SUPPORT || HAVE_SECTION_SHF_GROUP_SUPPORT + + config SECTION_NO_KEEP_SUPPORT + bool + depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION + depends on HAVE_SECTION_NO_KEEP_SUPPORT +- default SECTION_SHF_LINK_ORDER_SUPPORT ++ default SECTION_SHF_LINK_ORDER_SUPPORT || SECTION_SHF_GROUP_SUPPORT + + config HAVE_SECTION_SHF_LINK_ORDER_SUPPORT + bool +@@ -1485,6 +1485,14 @@ config SECTION_SHF_LINK_ORDER_SUPPORT + depends on HAVE_SECTION_SHF_LINK_ORDER_SUPPORT + default n + ++config HAVE_SECTION_SHF_GROUP_SUPPORT ++ bool ++ ++config SECTION_SHF_GROUP_SUPPORT ++ bool ++ depends on HAVE_SECTION_SHF_GROUP_SUPPORT ++ default n ++ + menuconfig EXPERT + bool "Configure standard kernel features (expert users)" + # Unhide debug options, to make the on-by-default options visible +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0017-DCE-DSE-add-TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_GROUP-o.patch b/src/feature/linux/dse/v6.6-rc2/0017-DCE-DSE-add-TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_GROUP-o.patch new file mode 100644 index 0000000000000000000000000000000000000000..63d1cc66f65531bab9bfcb701f1ccf490be82d3a --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0017-DCE-DSE-add-TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_GROUP-o.patch @@ -0,0 +1,40 @@ +From 40913ea71e4439024c9413184be2a6708b92a37a Mon Sep 17 00:00:00 2001 +From: Zhangjin Wu +Date: Sun, 23 Jul 2023 12:41:52 +0800 +Subject: [PATCH 17/23] DCE/DSE: add TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_GROUP + option + +This will select SECTION_SHF_GROUP_SUPPORT + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + init/Kconfig | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/init/Kconfig b/init/Kconfig +index 3239ccd18af5..f1c91a670046 100644 +--- a/init/Kconfig ++++ b/init/Kconfig +@@ -1783,6 +1783,18 @@ config TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_LINK_ORDER + + If unsure, not choose this. + ++config TRIM_KEPT_UNUSED_SYSCALLS_BY_SHF_GROUP ++ bool "SHF_GROUP attribute (EXPERIMENTAL)" if EXPERT ++ select SECTION_SHF_GROUP_SUPPORT ++ help ++ Say Y here to trim more 'unused' syscalls wrongly kept by __ex_table ++ like sections in kernel space. ++ ++ This option enables the section SHF_GROUP attribute method, it ++ is faster than objcopy. ++ ++ If unsure, not choose this. ++ + endchoice + + config KALLSYMS +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0018-DCE-DSE-inhibit-.size-directive-for-SHF_GROUP.patch b/src/feature/linux/dse/v6.6-rc2/0018-DCE-DSE-inhibit-.size-directive-for-SHF_GROUP.patch new file mode 100644 index 0000000000000000000000000000000000000000..932a3390275da3b5cc28bed9460daa57c1d0b3d3 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0018-DCE-DSE-inhibit-.size-directive-for-SHF_GROUP.patch @@ -0,0 +1,32 @@ +From 979eb1e078787d850865c2812f67afed68faa7a2 Mon Sep 17 00:00:00 2001 +From: Yuan Tan +Date: Sun, 23 Jul 2023 12:42:50 +0800 +Subject: [PATCH 18/23] DCE/DSE: inhibit .size directive for SHF_GROUP + +.size directive fails in some functions with SHF_GROUP, this is not +really required for normal building, inhibit it to silence the compiling +failures with SHF_GROUP. + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + Makefile | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/Makefile b/Makefile +index a4e522b747cb..f67b6e8d2c45 100644 +--- a/Makefile ++++ b/Makefile +@@ -936,6 +936,9 @@ endif + # `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0). + ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION + KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections ++ifdef CONFIG_SECTION_SHF_GROUP_SUPPORT ++KBUILD_CFLAGS_KERNEL += -finhibit-size-directive ++endif + KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y + LDFLAGS_vmlinux += --gc-sections + ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION_DEBUG +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0019-DCE-DSE-vmlinux.lds.h-allow-NO_KEEP-on-__ex_table-se.patch b/src/feature/linux/dse/v6.6-rc2/0019-DCE-DSE-vmlinux.lds.h-allow-NO_KEEP-on-__ex_table-se.patch new file mode 100644 index 0000000000000000000000000000000000000000..e585ad6dd6100b2e6b5fc9ca25505f51624729e8 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0019-DCE-DSE-vmlinux.lds.h-allow-NO_KEEP-on-__ex_table-se.patch @@ -0,0 +1,28 @@ +From abfcd5ac47030bdd699e31ff95536a4141d50174 Mon Sep 17 00:00:00 2001 +From: Yuan Tan +Date: Sun, 23 Jul 2023 13:30:06 +0800 +Subject: [PATCH 19/23] DCE/DSE: vmlinux.lds.h: allow NO_KEEP on __ex_table + sections + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + include/asm-generic/vmlinux.lds.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h +index faae817df3e2..3a7369bc356b 100644 +--- a/include/asm-generic/vmlinux.lds.h ++++ b/include/asm-generic/vmlinux.lds.h +@@ -658,7 +658,7 @@ + #define EXCEPTION_TABLE(align) \ + . = ALIGN(align); \ + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \ +- BOUNDED_SECTION_BY(__ex_table, ___ex_table) \ ++ BOUNDED_SECTION_BY(__ex_table, ___ex_table, NO_KEEP) \ + } + + /* +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0020-DCE-DSE-riscv-add-HAVE_TRIM_KEPT_UNUSED_SYSCALLS-sup.patch b/src/feature/linux/dse/v6.6-rc2/0020-DCE-DSE-riscv-add-HAVE_TRIM_KEPT_UNUSED_SYSCALLS-sup.patch new file mode 100644 index 0000000000000000000000000000000000000000..f5bfb9929c33166cd3d07082d9c8daed9caa1731 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0020-DCE-DSE-riscv-add-HAVE_TRIM_KEPT_UNUSED_SYSCALLS-sup.patch @@ -0,0 +1,71 @@ +From 54184df9976f9756400c6e0bd05957ebd527ac94 Mon Sep 17 00:00:00 2001 +From: Yuan Tan +Date: Sat, 22 Jul 2023 10:32:52 +0800 +Subject: [PATCH 20/23] DCE/DSE: riscv: add HAVE_TRIM_KEPT_UNUSED_SYSCALLS + support + +Some unused syscalls are wrongly kept by the section like __ex_table, +this uniques the section and select HAVE_TRIM_KEPT_UNUSED_SYSCALLS to +drop the wrong KEPT automatically. + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + arch/riscv/Kconfig | 1 + + arch/riscv/include/asm/asm-extable.h | 18 ++++++++++-------- + 2 files changed, 11 insertions(+), 8 deletions(-) + +diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig +index b5e726b49a6f..9aa7a814c460 100644 +--- a/arch/riscv/Kconfig ++++ b/arch/riscv/Kconfig +@@ -141,6 +141,7 @@ config RISCV + select HAVE_STACKPROTECTOR + select HAVE_SYSCALL_TRACEPOINTS + select HAVE_TRIM_UNUSED_SYSCALLS if HAVE_LD_DEAD_CODE_DATA_ELIMINATION ++ select HAVE_TRIM_KEPT_UNUSED_SYSCALLS if HAVE_TRIM_UNUSED_SYSCALLS + select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU + select IRQ_DOMAIN + select IRQ_FORCED_THREADING +diff --git a/arch/riscv/include/asm/asm-extable.h b/arch/riscv/include/asm/asm-extable.h +index 00a96e7a9664..ef2baf407f90 100644 +--- a/arch/riscv/include/asm/asm-extable.h ++++ b/arch/riscv/include/asm/asm-extable.h +@@ -9,10 +9,12 @@ + + #ifdef CONFIG_MMU + ++#include ++ + #ifdef __ASSEMBLY__ + + #define __ASM_EXTABLE_RAW(insn, fixup, type, data) \ +- .pushsection __ex_table, "a"; \ ++ .pushsection __SECTION_ID(__ex_table), "a"; \ + .balign 4; \ + .long ((insn) - .); \ + .long ((fixup) - .); \ +@@ -30,13 +32,13 @@ + #include + #include + +-#define __ASM_EXTABLE_RAW(insn, fixup, type, data) \ +- ".pushsection __ex_table, \"a\"\n" \ +- ".balign 4\n" \ +- ".long ((" insn ") - .)\n" \ +- ".long ((" fixup ") - .)\n" \ +- ".short (" type ")\n" \ +- ".short (" data ")\n" \ ++#define __ASM_EXTABLE_RAW(insn, fixup, type, data) \ ++ ".pushsection " __SECTION_NAME(__ex_table) ", \"a\"\n" \ ++ ".balign 4\n" \ ++ ".long ((" insn ") - .)\n" \ ++ ".long ((" fixup ") - .)\n" \ ++ ".short (" type ")\n" \ ++ ".short (" data ")\n" \ + ".popsection\n" + + #define _ASM_EXTABLE(insn, fixup) \ +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0021-DCE-DSE-riscv-add-NO_KEEP-support-for-C-functions.patch b/src/feature/linux/dse/v6.6-rc2/0021-DCE-DSE-riscv-add-NO_KEEP-support-for-C-functions.patch new file mode 100644 index 0000000000000000000000000000000000000000..832dc0d556b172a6b20468b977fb7e17e9658290 --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0021-DCE-DSE-riscv-add-NO_KEEP-support-for-C-functions.patch @@ -0,0 +1,43 @@ +From 0d260bcad2c12a8a6aab83cfb5bfca4841bb35f3 Mon Sep 17 00:00:00 2001 +From: Yuan Tan +Date: Sun, 23 Jul 2023 13:31:36 +0800 +Subject: [PATCH 21/23] DCE/DSE: riscv: add NO_KEEP support for C functions + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + arch/riscv/include/asm/asm-extable.h | 17 ++++++++++++++++- + 1 file changed, 16 insertions(+), 1 deletion(-) + +diff --git a/arch/riscv/include/asm/asm-extable.h b/arch/riscv/include/asm/asm-extable.h +index ef2baf407f90..5b5a209ea142 100644 +--- a/arch/riscv/include/asm/asm-extable.h ++++ b/arch/riscv/include/asm/asm-extable.h +@@ -32,8 +32,23 @@ + #include + #include + ++#ifdef CONFIG_SECTION_SHF_LINK_ORDER_SUPPORT ++#define __ASM_EXTABLE_PUSH_SECTION \ ++ __LABEL_NAME(.L__ex_table) ":" \ ++ ".pushsection " __SECTION_NAME(__ex_table) ", \"ao\"," __LABEL_NAME(.L__ex_table) "\n" ++ ++#elif defined(CONFIG_SECTION_SHF_GROUP_SUPPORT) ++#define __ASM_EXTABLE_PUSH_SECTION \ ++ ".attach_to_group " __SECTION_NAME(__ex_table) "\n" \ ++ ".pushsection " __SECTION_NAME(__ex_table) ", \"a?\"\n" ++ ++#else ++#define __ASM_EXTABLE_PUSH_SECTION \ ++ ".pushsection " __SECTION_NAME(__ex_table) ", \"a\"\n" ++#endif ++ + #define __ASM_EXTABLE_RAW(insn, fixup, type, data) \ +- ".pushsection " __SECTION_NAME(__ex_table) ", \"a\"\n" \ ++ __ASM_EXTABLE_PUSH_SECTION \ + ".balign 4\n" \ + ".long ((" insn ") - .)\n" \ + ".long ((" fixup ") - .)\n" \ +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0022-DCE-DSE-riscv-add-NO_KEEP-support-for-assembly-__ex_.patch b/src/feature/linux/dse/v6.6-rc2/0022-DCE-DSE-riscv-add-NO_KEEP-support-for-assembly-__ex_.patch new file mode 100644 index 0000000000000000000000000000000000000000..4f0ee210e10e0ec710821351825a4b767d22415f --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0022-DCE-DSE-riscv-add-NO_KEEP-support-for-assembly-__ex_.patch @@ -0,0 +1,186 @@ +From 4c7165e8feaf9a92f2bd26105b32522de0591805 Mon Sep 17 00:00:00 2001 +From: Yuan Tan +Date: Sun, 23 Jul 2023 16:33:30 +0800 +Subject: [PATCH 22/23] DCE/DSE: riscv: add NO_KEEP support for assembly + __ex_table sections + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + arch/riscv/include/asm/asm-extable.h | 22 ++++++++-- + arch/riscv/lib/uaccess.S | 60 ++++++++++++++-------------- + 2 files changed, 47 insertions(+), 35 deletions(-) + +diff --git a/arch/riscv/include/asm/asm-extable.h b/arch/riscv/include/asm/asm-extable.h +index 5b5a209ea142..819b93b2616f 100644 +--- a/arch/riscv/include/asm/asm-extable.h ++++ b/arch/riscv/include/asm/asm-extable.h +@@ -13,8 +13,23 @@ + + #ifdef __ASSEMBLY__ + ++#ifdef CONFIG_SECTION_SHF_LINK_ORDER_SUPPORT ++#define __ASM_EXTABLE_PUSH_SECTION \ ++ __LABEL_ID(.L__ex_table) : \ ++ .pushsection __SECTION_NAME(__ex_table), "ao", __LABEL_ID(.L__ex_table) ++ ++#elif defined(CONFIG_SECTION_SHF_GROUP_SUPPORT) ++#define __ASM_EXTABLE_PUSH_SECTION \ ++ .attach_to_group __SECTION_ID(__ex_table); \ ++ .pushsection __SECTION_ID(__ex_table), "a?" ++ ++#else ++#define __ASM_EXTABLE_PUSH_SECTION \ ++ .pushsection __SECTION_ID(__ex_table), "a" ++#endif ++ + #define __ASM_EXTABLE_RAW(insn, fixup, type, data) \ +- .pushsection __SECTION_ID(__ex_table), "a"; \ ++ __ASM_EXTABLE_PUSH_SECTION; \ + .balign 4; \ + .long ((insn) - .); \ + .long ((fixup) - .); \ +@@ -22,9 +37,8 @@ + .short (data); \ + .popsection; + +- .macro _asm_extable, insn, fixup +- __ASM_EXTABLE_RAW(\insn, \fixup, EX_TYPE_FIXUP, 0) +- .endm ++#define _asm_extable(insn, fixup) \ ++ __ASM_EXTABLE_RAW(insn, fixup, EX_TYPE_FIXUP, 0) + + #else /* __ASSEMBLY__ */ + +diff --git a/arch/riscv/lib/uaccess.S b/arch/riscv/lib/uaccess.S +index 09b47ebacf2e..91c76d3fbe2f 100644 +--- a/arch/riscv/lib/uaccess.S ++++ b/arch/riscv/lib/uaccess.S +@@ -4,11 +4,9 @@ + #include + #include + +- .macro fixup op reg addr lbl +-100: +- \op \reg, \addr +- _asm_extable 100b, \lbl +- .endm ++#define fixup(op, reg, addr, lbl) \ ++ 100: op reg, addr; \ ++ _asm_extable(100b, lbl) + + ENTRY(__asm_copy_to_user) + ENTRY(__asm_copy_from_user) +@@ -50,9 +48,9 @@ ENTRY(__asm_copy_from_user) + beq a0, t1, .Lskip_align_dst + 1: + /* a5 - one byte for copying data */ +- fixup lb a5, 0(a1), 10f ++ fixup(lb, a5, 0(a1), 10f) + addi a1, a1, 1 /* src */ +- fixup sb a5, 0(a0), 10f ++ fixup(sb, a5, 0(a0), 10f) + addi a0, a0, 1 /* dst */ + bltu a0, t1, 1b /* t1 - start of aligned dst */ + +@@ -77,22 +75,22 @@ ENTRY(__asm_copy_from_user) + */ + addi t0, t0, -(8*SZREG) /* not to over run */ + 2: +- fixup REG_L a4, 0(a1), 10f +- fixup REG_L a5, SZREG(a1), 10f +- fixup REG_L a6, 2*SZREG(a1), 10f +- fixup REG_L a7, 3*SZREG(a1), 10f +- fixup REG_L t1, 4*SZREG(a1), 10f +- fixup REG_L t2, 5*SZREG(a1), 10f +- fixup REG_L t3, 6*SZREG(a1), 10f +- fixup REG_L t4, 7*SZREG(a1), 10f +- fixup REG_S a4, 0(a0), 10f +- fixup REG_S a5, SZREG(a0), 10f +- fixup REG_S a6, 2*SZREG(a0), 10f +- fixup REG_S a7, 3*SZREG(a0), 10f +- fixup REG_S t1, 4*SZREG(a0), 10f +- fixup REG_S t2, 5*SZREG(a0), 10f +- fixup REG_S t3, 6*SZREG(a0), 10f +- fixup REG_S t4, 7*SZREG(a0), 10f ++ fixup(REG_L, a4, 0(a1), 10f) ++ fixup(REG_L, a5, SZREG(a1), 10f) ++ fixup(REG_L, a6, 2*SZREG(a1), 10f) ++ fixup(REG_L, a7, 3*SZREG(a1), 10f) ++ fixup(REG_L, t1, 4*SZREG(a1), 10f) ++ fixup(REG_L, t2, 5*SZREG(a1), 10f) ++ fixup(REG_L, t3, 6*SZREG(a1), 10f) ++ fixup(REG_L, t4, 7*SZREG(a1), 10f) ++ fixup(REG_S, a4, 0(a0), 10f) ++ fixup(REG_S, a5, SZREG(a0), 10f) ++ fixup(REG_S, a6, 2*SZREG(a0), 10f) ++ fixup(REG_S, a7, 3*SZREG(a0), 10f) ++ fixup(REG_S, t1, 4*SZREG(a0), 10f) ++ fixup(REG_S, t2, 5*SZREG(a0), 10f) ++ fixup(REG_S, t3, 6*SZREG(a0), 10f) ++ fixup(REG_S, t4, 7*SZREG(a0), 10f) + addi a0, a0, 8*SZREG + addi a1, a1, 8*SZREG + bltu a0, t0, 2b +@@ -130,7 +128,7 @@ ENTRY(__asm_copy_from_user) + sub t4, a5, t3 + + /* Load the first word to combine with second word */ +- fixup REG_L a5, 0(a1), 10f ++ fixup(REG_L, a5, 0(a1), 10f) + + 3: + /* Main shifting copy +@@ -142,11 +140,11 @@ ENTRY(__asm_copy_from_user) + + /* At least one iteration will be executed */ + srl a4, a5, t3 +- fixup REG_L a5, SZREG(a1), 10f ++ fixup(REG_L, a5, SZREG(a1), 10f) + addi a1, a1, SZREG + sll a2, a5, t4 + or a2, a2, a4 +- fixup REG_S a2, 0(a0), 10f ++ fixup(REG_S, a2, 0(a0), 10f) + addi a0, a0, SZREG + bltu a0, t1, 3b + +@@ -163,9 +161,9 @@ ENTRY(__asm_copy_from_user) + */ + bgeu a0, t0, .Lout_copy_user /* check if end of copy */ + 4: +- fixup lb a5, 0(a1), 10f ++ fixup(lb, a5, 0(a1), 10f) + addi a1, a1, 1 /* src */ +- fixup sb a5, 0(a0), 10f ++ fixup(sb, a5, 0(a0), 10f) + addi a0, a0, 1 /* dst */ + bltu a0, t0, 4b /* t0 - end of dst */ + +@@ -205,7 +203,7 @@ ENTRY(__clear_user) + bgeu t0, t1, 2f + bltu a0, t0, 4f + 1: +- fixup REG_S, zero, (a0), 11f ++ fixup(REG_S, zero, (a0), 11f) + addi a0, a0, SZREG + bltu a0, t1, 1b + 2: +@@ -217,12 +215,12 @@ ENTRY(__clear_user) + li a0, 0 + ret + 4: /* Edge case: unalignment */ +- fixup sb, zero, (a0), 11f ++ fixup(sb, zero, (a0), 11f) + addi a0, a0, 1 + bltu a0, t0, 4b + j 1b + 5: /* Edge case: remainder */ +- fixup sb, zero, (a0), 11f ++ fixup(sb, zero, (a0), 11f) + addi a0, a0, 1 + bltu a0, a3, 5b + j 3b +-- +2.25.1 + diff --git a/src/feature/linux/dse/v6.6-rc2/0023-DCE-DSE-select-both-section-link-order-and-section-g.patch b/src/feature/linux/dse/v6.6-rc2/0023-DCE-DSE-select-both-section-link-order-and-section-g.patch new file mode 100644 index 0000000000000000000000000000000000000000..a8296f772a807225c7893e37b43b1254ea7d2dce --- /dev/null +++ b/src/feature/linux/dse/v6.6-rc2/0023-DCE-DSE-select-both-section-link-order-and-section-g.patch @@ -0,0 +1,32 @@ +From 574dbb6669c977845cb868ee8d81ab7efd56d20f Mon Sep 17 00:00:00 2001 +From: Yuan Tan +Date: Tue, 26 Sep 2023 02:35:39 +0800 +Subject: [PATCH 23/23] DCE/DSE: select both section link order and section + group + +select section group while ld >= 2.37 + +select section link order while ld >= 2.37 + +Signed-off-by: Yuan Tan +Signed-off-by: Zhangjin Wu +--- + arch/riscv/Kconfig | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig +index 9aa7a814c460..e1966dbe38c5 100644 +--- a/arch/riscv/Kconfig ++++ b/arch/riscv/Kconfig +@@ -138,6 +138,8 @@ config RISCV + select HAVE_REGS_AND_STACK_ACCESS_API + select HAVE_RETHOOK if !XIP_KERNEL + select HAVE_RSEQ ++ select HAVE_SECTION_SHF_GROUP_SUPPORT if HAVE_LD_DEAD_CODE_DATA_ELIMINATION && LD_VERSION >= 23700 ++ select HAVE_SECTION_SHF_LINK_ORDER_SUPPORT if HAVE_LD_DEAD_CODE_DATA_ELIMINATION && LD_VERSION >= 23700 + select HAVE_STACKPROTECTOR + select HAVE_SYSCALL_TRACEPOINTS + select HAVE_TRIM_UNUSED_SYSCALLS if HAVE_LD_DEAD_CODE_DATA_ELIMINATION +-- +2.25.1 +