[PATCH v2 1/8] init/Kconfig: add CONFIG_TRIM_UNUSED_SYSCALLS and related options
Yuan Tan
tanyuan at tinylab.org
Tue Oct 14 23:17:17 PDT 2025
From: Yuhang Zheng <z1652074432 at gmail.com>
Introduce configuration options to enable dead code/data elimination for
unused system calls.
This change adds the following Kconfig symbols:
- TRIM_UNUSED_SYSCALLS: user option to enable trimming of unused system
calls
- HAVE_TRIM_UNUSED_SYSCALLS: architecture capability symbol
- USED_SYSCALLS: string list of system calls to keep(separated by spaces)
These options integrate with scripts/Makefile.asm-headers and syscalltbl.sh
to generate syscall tables only for selected entries. The feature depends
on LD_DEAD_CODE_DATA_ELIMINATION and on architectures that use
syscalltbl.sh to generate their syscall tables.
Signed-off-by: Yuhang Zheng <z1652074432 at gmail.com>
Signed-off-by: Yuan Tan <tanyuan at tinylab.org>
Signed-off-by: Zhangjin Wu <falcon at tinylab.org>
---
init/Kconfig | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/init/Kconfig b/init/Kconfig
index cab3ad28ca49..2c6f86c44d96 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1628,6 +1628,9 @@ config SYSFS_SYSCALL
config HAVE_PCSPKR_PLATFORM
bool
+config HAVE_TRIM_UNUSED_SYSCALLS
+ bool
+
menuconfig EXPERT
bool "Configure standard kernel features (expert users)"
# Unhide debug options, to make the on-by-default options visible
@@ -1932,6 +1935,36 @@ config CACHESTAT_SYSCALL
If unsure say Y here.
+config TRIM_UNUSED_SYSCALLS
+ bool "Trim unused syscalls" if EXPERT
+ default n
+ depends on HAVE_TRIM_UNUSED_SYSCALLS
+ depends on LD_DEAD_CODE_DATA_ELIMINATION
+ help
+ Enable this option to trim unused system calls from the final kernel
+ image. Only the syscalls explicitly listed in CONFIG_USED_SYSCALLS
+ will be kept.
+
+ Note that some unused syscalls may still be retained if their sections
+ are forcibly kept by other sections created with .pushsection and
+ preserved via KEEP() in the linker script.
+
+ If unsure, say N.
+
+config USED_SYSCALLS
+ string "Configure used syscalls" if EXPERT
+ depends on TRIM_UNUSED_SYSCALLS
+ default ""
+ help
+ Specify a list of system calls that should be kept when
+ TRIM_UNUSED_SYSCALLS is enabled.
+
+ The system calls should be listed one by one, separated by spaces.
+ For example, set CONFIG_USED_SYSCALLS="write exit reboot". If left
+ empty, all 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.43.0
More information about the linux-riscv
mailing list